From 64245b7638b8ac32229ccc67856b45a6b79afd35 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 26 Jul 2011 06:55:03 +0200 Subject: [PATCH] finished Server Handshake (script should be able to connect to another server now) --- Uplink/P10Formatter.class.php | 2 +- Uplink/P10_Server.class.php | 28 ++++++++++++++++++++++++++++ Uplink/Uplink.class.php | 15 +++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Uplink/P10Formatter.class.php b/Uplink/P10Formatter.class.php index d280bf2..66bf379 100644 --- a/Uplink/P10Formatter.class.php +++ b/Uplink/P10Formatter.class.php @@ -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" ); diff --git a/Uplink/P10_Server.class.php b/Uplink/P10_Server.class.php index a2144cb..1603e4c 100644 --- a/Uplink/P10_Server.class.php +++ b/Uplink/P10_Server.class.php @@ -39,6 +39,18 @@ * 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; } diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index c9de410..0dd6df9 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -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); -- 2.20.1