1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Thread not finding class

Discussion in 'Development' started by RoyalMCPE, Apr 4, 2019.

  1. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I'm currently making a port of SynapsePM. But I'm having issues with creating the SynapseSocket here. The error that is being thrown is
    Code:
    04.04 03:08:57 [Server] HavenClient thread/CRITICAL Error: "Class 'CoreEssentials\network\lib\HavenSocket' not found" (EXCEPTION) in "/virions/CoreEssentials/src/CoreEssentials/network/lib/HavenClient" at line 87
    . (I know it says it's something else but I've copied it line from line only fixes the errors). Did something change that's causing this? Anything is helpful, hack or not.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You need to let the class loader register again on the new thread
     
    jasonwynn10 likes this.
  3. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    PHP:
    <?php

    namespace CoreEssentials\network\lib;

    use 
    pocketmine\Thread;
    use 
    CoreEssentials\network\SocketUtils;
    use 
    CoreEssentials\network\lib\HavenSocket;

    class 
    HavenClient extends Thread {
       
        
    /** @var string */
        
    public const VERSION '0.3.0';
       
        
    /** @var \ThreadedLogger */
        
    private $mLogger;
        
    /** @var string */
        
    private $mInterface;
        
    /** @var int */
        
    private $mPort;
        
    /** @var bool */
        
    private $mShutdown;
        
    /** @var \Threaded */
        
    private $mExtrenalQueue$mInternalQueue;
        
    /** @var string */
        
    private $mMainPath;
        
    /** @var bool */
        
    private $mNeedAuth false;
        
    /** @var bool */
        
    private $mConnected true;
        
    /** @var bool */
        
    public $mNeedReconnect false;
       
        public function 
    __construct(\ThreadedLogger $pLogger, \ClassLoader $pLoaderint $pPortstring $pInterface '127.0.0.1') {
            
    $this->mLogger $pLogger;
            
    $this->mInterface $pInterface;
            
    $this->mPort = (int)$pPort;
            if(
    $pPort or $pPort 65536) {
                throw new \
    Exception("Invalid port range");
            }
            
    $this->setClassLoader($pLoader);
            
    $this->mShutdown false;
            
    $this->mExtrenalQueue = new \Threaded;
            
    $this->mInternalQueue = new \Threaded;
            if(\
    Phar::running(true) !== '') {
                
    $this->mMainPath = \Phar::running(true);
            } else {
                
    $this->mMainPath = \getcwd() . DIRECTORY_SEPARATOR;
            }
            
    $this->start();
        }
       
        public function 
    reconnect(): void {
            
    $this->mNeedReconnect true;
        }
       
        public function 
    needAuth(): bool {
            return 
    $this->mNeedAuth;
        }
       
        public function 
    setNeedAuth(bool $pNeed): void {
            
    $this->mNeedAuth $pNeed;
        }
       
        public function 
    isConnected(): bool {
            return 
    $this->mConnected;
        }
       
        public function 
    setConnectionStatus(bool $pConnected): void {
            
    $this->mConnected $pConnected;
        }
       
        public function 
    quit(): void {
            
    $this->shutdown();
            
    parent::quit();
        }
       
        public function 
    run(): void {
            
    $this->registerClassLoader();
            
    gc_enable();
            
    error_reporting(-1);
            
    ini_set("display_errors""1");
            
    ini_set("display_startup_errors""1");
           
            
    set_error_handler([$this"errorHandler"], E_ALL);
            
    register_shutdown_function([$this"shutdownHandler"]);
            try {
                
    $socket = new HavenSocket($this->getLogger(), $this->mPort$this->mInterface);
                new 
    ServerConnection($this$socket);
            } catch(\
    Throwable $exception) {
                
    $this->mLogger->logException($exception);
            }
        }
       
        public function 
    shutdownHandler(): void {
            if(!
    $this->mShutdown) {
                
    $this->getLogger()->emergency("HavenLib crashed!");
            }
        }
       
        public function 
    errorHandler($pErrorNo$pErrorStr$pErrorFile$pErrorLine$pContext$pTrace null): bool {
            if(
    error_reporting() === 0) {
                return 
    false;
            }
           
            
    $error_no = isset(SocketUtils::ERROR_CONVERSION[$pErrorNo]) ? SocketUtils::ERROR_CONVERSION[$pErrorNo] : $pErrorNo;
            if((
    $pos strpos($pErrorStr"\n"))) {
                
    $error_str substr($pErrorStr0$pos);
            }
            
    $error_path $this->cleanPath($pErrorFile);
           
            
    $this->getLogger()->debug("An " $error_no " error happened: \"" $error_str "\" int \"" $error_path "\" at line $pErrorLine");
           
            foreach((
    $pTrace $this->getTrace($pTrace === null 0$pTrace)) as $line) {
                
    $this->getLogger()->debug($line);
            }
            return 
    true;
        }
       
        public function 
    getTrace($pStart 1$pTrace null): array {
            if(
    is_null($pTrace)) {
                if(
    function_exists("xdebug_get_function_stack")) {
                    
    $pTrace array_reverse(xdebug_get_function_stack());
                } else {
                    
    $excption = new \Exception();
                    
    $pTrace $excption->getTrace();
                }
            }
           
            
    $messages = [];
            
    $j 0;
            for(
    $i = (int)$pStart; isset($pTrace[$i]); ++$i, ++$j) {
                
    $parameters "";
                if(isset(
    $pTrace[$i]["args"]) or isset($pTrace[$i]["params"])) {
                    if(isset(
    $pTrace[$i]["args"])) {
                        
    $args $pTrace[$i]["args"];
                    } else {
                        
    $args $pTrace[$i]["params"];
                    }
                    foreach(
    $args as $value) {
                        
    $parameters .= (is_object($value) ? get_class($value) . ' ' . (method_exists($value"__toString()") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
                    }
                }
                
    $messages[] = "#" $j . (isset($pTrace[$i]["file"]) ? $this->cleanPath($pTrace[$i]["file"]) : "") . "(" . (isset($pTrace[$i]["line"]) ? $pTrace[$i]["line"] : "") . "): " . (isset($pTrace[$i]["class"]) ? $pTrace[$i]["class"] . (($pTrace[$i]["type"] === "dynamic" or $pTrace[$i]["type"] === "->") ? "->" "::") : "") . $pTrace[$i]["function"] . "(" substr($parameters0, -2) . ")";
            }
            return 
    $messages;
        }
       
        public function 
    cleanPath(string $pPath): string {
            return 
    rtrim(str_replace(["\\"".php""phar://"rtrim(str_replace(["\\""phar://"], ["/"""], $this->mMainPath), "/")], ["/"""""""], $pPath), "/");
        }
       
        public function 
    getExtrnalQueue(): \Threaded {
            return 
    $this->mExtrenalQueue;
        }
       
        public function 
    getInternalQueue(): \Threaded {
            return 
    $this->mInternalQueue;
        }
       
        public function 
    pushMainToThreadPacket(string $pStr): void {
            
    $this->mInternalQueue[]  = $pStr;
        }
       
        public function 
    readMainToThreadPacket() {
            return 
    $this->mInternalQueue->shift();
        }
       
        public function 
    pushThreadToMainPacket(string $pStr): void {
            
    $this->mExtrenalQueue[] = $pStr;
        }
       
        public function 
    getInternalQueueSize(): int {
            return 
    count($this->mInternalQueue);
        }
       
        public function 
    readThreadToMainPacket() {
            return 
    $this->mExtrenalQueue->shift();
        }
       
        public function 
    isShutdown(): bool {
            return 
    $this->mShutdown;
        }
       
        public function 
    shutdown(): void {
            
    $this->mShutdown true;
        }
       
        public function 
    getPort(): int {
            return 
    $this->mPort;
        }
       
        public function 
    getInterface(): string {
            return 
    $this->mInterface;
        }
       
        public function 
    getLogger(): \ThreadedLogger {
            return 
    $this->mLogger;
        }
       
        public function 
    isGarbage(): bool {
            return 
    parent::isGarbage();
        }
       
        public function 
    getThreadName(): string {
            return 
    "HavenClient";
        }
    }
    Already registering it, still throwing the error
     
    Last edited: Apr 4, 2019
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.