finished Server Handshake (script should be able to connect to another server now)
[PHP-P10.git] / Uplink / Uplink.class.php
index c9de4102de829d949f599e781311dc8db3ae50bf..0dd6df9cca21dd1525ddef145f247009dea6ee24 100644 (file)
@@ -73,6 +73,10 @@ class Uplink {
                $self_numeric = $this->getSetting("numeric");
                $self_name = $this->getSetting("name");
                $self_description = $this->getSetting("description");
+               if(!$self_numeric || !$self_name) {
+                       trigger_error("Server Settings missing.", E_USER_ERROR);
+                       return;
+               }
                $this->server = new P10_Server($self_name, $self_numeric, null, time(), time(), $self_description);
        }
        
@@ -99,10 +103,11 @@ class Uplink {
                        $state = $this->client->connect($host, $port, $this->getSettings("bind"), $this->getSettings("ssl"), $this->getSettings("recv_timeout"));
                        if(!$state) {
                                usleep($this->getSetting("recv_timeout") / 1000);
-                               $flags |= self::FLAG_NOT_CONNECTABLE;
+                               $this->flags |= self::FLAG_NOT_CONNECTABLE;
                                return;
                        }
                        $this->flags = 0;
+                       $this->loginServer();
                }
                //try to receive new data from the Uplink
                $lines = $this->client->recv();
@@ -147,13 +152,18 @@ class Uplink {
                }
        }
        
+       private function loginServer() {
+               $password = $this->getSetting("password");
+               $this->send("PASS", $password);
+               $this->send("SERVER", $this->server->getName(), $this->server->getStartTime(), $this->server->getLinkTime(), $this->server->getNumeric(), $this->server->getDescription());
+       }
+       
        private function parseLine($line) {
                $highExplode = explode(" :", $line, 2);
                $tokens = explode(" ", $highExplode[0]);
                if(count($highExplode) > 1)
                        $tokens[] = $highExplode[1];
                $cmdPos = (($this->flags & self::FLAG_P10SESSION) ? 1 : 0);
-               if($tokens[0] == "ERROR") $cmdPos = 0; //override
                if($cmdPos == 1) $from = $tokens[0];
                else $from = null;
                $arguments = array_slice($tokens, $cmdPos + 1);
@@ -217,6 +227,7 @@ class Uplink {
                        }
                        $new_server = new P10_Server($args[0], substr($args[5],0,2), $this->server, $args[2], $args[3], $args[7]);
                        $this->server->add_server($new_server);
+                       $this->flags |= self::FLAG_P10SESSION;
                } else {
                        //another server got a new slave server ^^
                        $server = P10_Server::getServerByNum($from);