finished Server Handshake (script should be able to connect to another server now)
authorpk910 <philipp@zoelle1.de>
Tue, 26 Jul 2011 04:55:03 +0000 (06:55 +0200)
committerpk910 <philipp@zoelle1.de>
Tue, 26 Jul 2011 04:55:03 +0000 (06:55 +0200)
Uplink/P10Formatter.class.php
Uplink/P10_Server.class.php
Uplink/Uplink.class.php

index d280bf212b8f09827a300c0322e6668725444272..66bf379a505ba162e466536f2f5bee2d89ace48d 100644 (file)
@@ -36,7 +36,7 @@ class P10Formatter {
        
        private static $commands = array(
                "PASS"   => "PASS :%s",
-               "SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s :%s",
+               "SERVER" => "SERVER %s 1 %s %s J10 %s]]] +s6 :%s",
                "ERROR"  => "ERROR :%s"
        );
        
index a2144cb28a8fc440db8b0ff8d06d6c39b4b2b0d2..1603e4c84722a6455b7187e001a0e254addcab2f 100644 (file)
  * String getNumeric()
  *     returns the Numeric of the Server
  *
+ * String getName()
+ *     returns the Name of the Server
+ *
+ * String getStartTime()
+ *     returns the startup time of the Server
+ *
+ * String getLinkTime()
+ *     returns the link time of the Server
+ *
+ * String getDescription()
+ *     returns the Description of the Server
+ *
  * void addServer(P10_Server $server)
  *     adds a Server to the server's "slave" list
  *
@@ -97,6 +109,22 @@ class P10_Server {
                return $this->numeric;
        }
        
+       public function getName() {
+               return $this->name;
+       }
+       
+       public function getStartTime() {
+               return $this->start_time;
+       }
+       
+       public function getLinkTime() {
+               return $this->link_time;
+       }
+       
+       public function getDescription() {
+               return $this->description;
+       }
+       
        public function addServer($server) {
                $this->servers[$server->getNumeric()] = $server;
        }
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);