From 8fc32c585446865b73c89859c35d1387fadbf9af Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 26 Jul 2011 08:31:23 +0200 Subject: [PATCH] added recv_nick and P10_User --- Uplink/Numerics.class.php | 31 +++++++++ Uplink/P10_ModeSets.class.php | 41 +++++++++++ Uplink/P10_Server.class.php | 16 +++++ Uplink/P10_User.class.php | 127 ++++++++++++++++++++++++++++++++++ Uplink/Uplink.class.php | 63 ++++++++++++++++- 5 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 Uplink/P10_ModeSets.class.php create mode 100644 Uplink/P10_User.class.php diff --git a/Uplink/Numerics.class.php b/Uplink/Numerics.class.php index 55db209..4727dcf 100644 --- a/Uplink/Numerics.class.php +++ b/Uplink/Numerics.class.php @@ -32,6 +32,9 @@ * * static int numToInt(String $numeric) * returns the integer value, the numeric represents + * + * static String parseIP(String $numeric) + * parses an IP Address in numeric format */ class Numerics { @@ -78,6 +81,34 @@ class Numerics { return $int; } + public static function parseIP($numeric) { + if(strlen($numeric) == 6) { //IPv4 + $value = self::numToInt($numeric); + $ip = array(); + $ip[0] = ($value & 0xff000000) >> 24; + $ip[1] = ($value & 0x00ff0000) >> 16; + $ip[2] = ($value & 0x0000ff00) >> 8; + $ip[3] = ($value & 0x000000ff); + return implode(".", $ip); + } else { //IPv6 + $ip = array(); + for($i = 0; $i < strlen($numeric);) { + if($numeric[$i] == "_") { + $rightBlocks = (strlen($numeric) - ($i + 1)) / 3; + $skipCount = 8 - count($ip) - $rightBlocks; + for($j = 0; $j < $skipBlocks; $j++) { + $ip[] = "0"; + } + } else { + $value = self::numToInt($numeric[$i].$numeric[$i+1].$numeric[$i+2]); + $ip[] = dechex($value); + $i += 3; + } + } + return implode(":", $ip); + } + } + } ?> \ No newline at end of file diff --git a/Uplink/P10_ModeSets.class.php b/Uplink/P10_ModeSets.class.php new file mode 100644 index 0000000..4d0af7d --- /dev/null +++ b/Uplink/P10_ModeSets.class.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/Uplink/P10_Server.class.php b/Uplink/P10_Server.class.php index 1603e4c..41bf281 100644 --- a/Uplink/P10_Server.class.php +++ b/Uplink/P10_Server.class.php @@ -76,6 +76,7 @@ class P10_Server { private $link_time; private $description; private $servers = array(); //all Servers connected to this Server + private $users = array(); //all Users connected to this Server public function __construct($name, $numeric, $parent_server, $start_time, $link_time, $description) { $this->name = $name; @@ -103,6 +104,9 @@ class P10_Server { public function disconnectUsers() { //disconnect all Users connected to the actual Server + foreach($this->users as $user) { + $user->quit("*.net *.split"); + } } public function getNumeric() { @@ -136,6 +140,18 @@ class P10_Server { trigger_error("Tried to remove a Server, that does NOT exist.", E_USER_WARNING); } } + + public function addUser($user) { + $this->users[$user->getNumeric()] = $user; + } + + public function delUser($user) { + if(array_key_exists($user->getNumeric(), $this->users)) { + unset($this->users[$user->getNumeric()]); + } else { + trigger_error("Tried to remove a User, that does NOT exist.", E_USER_WARNING); + } + } } ?> \ No newline at end of file diff --git a/Uplink/P10_User.class.php b/Uplink/P10_User.class.php new file mode 100644 index 0000000..bdc84e3 --- /dev/null +++ b/Uplink/P10_User.class.php @@ -0,0 +1,127 @@ +getNick()) == $nick) { + return $user; + } + } + return NULL; + } + + + private $numeric; + private $nick; + private $ident; + private $host; + private $ip; + private $connect_time; + private $modes; + private $realname; + + public __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) { + $this->nick = $nick; + $this->numeric = $numeric; + $this->server = $server; + $this->connect_time = $connect_time; + $this->ident = $ident; + $this->host = $host; + $this->ip = $ip; + $this->realname = $realname; + $this->modes = $modes; + $server->addUser($this); + self::$static_users[$numeric] = $this; + } + + public function getNumeric() { + return $this->numeric; + } + + public function setNick($nick) { + $this->nick = $nick; + } + + public function getNick() { + return $this->nick; + } + + public function setIdent($ident) { + $this->ident = $ident; + } + + public function getIdent() { + return $this->ident; + } + + public function getHost() { + return $this->host; + } + + public function getIP() { + return $this->ip; + } + + public function getConnectTime() { + return $this->connect_time; + } + + public function getModes() { + return $this->modes; + } + + public function getRealname() { + return $this->realname; + } + + public function quit($reason) { + $this->server->delUser($this); + } +} + +?> \ No newline at end of file diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index 2dee4da..e7b8e9c 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -50,6 +50,9 @@ require_once("Client.class.php"); require_once("Numerics.class.php"); require_once("P10Formatter.class.php"); +require_once("P10_Server.class.php"); +require_once("P10_User.class.php"); +require_once("P10_ModeSets.class.php"); class Uplink { private $client = new Client(); @@ -59,6 +62,7 @@ class Uplink { const FLAG_P10SESSION = 0x0001; //connection is in P10 mode (server is connected) const FLAG_SECURITY_QUIT = 0x0002; //local connection abort because of security issues const FLAG_NOT_CONNECTABLE = 0x0004; //remote server is not connectable + const FLAG_BURST_PENDING = 0x0008; //we still have to burst private $flags = 0; public function __construct() { @@ -185,6 +189,12 @@ class Uplink { case "G": $this->recv_ping($from, $arguments); break; + case "N": + $this->recv_nick($from, $arguments); + break; + case "EB": + $this->recv_end_of_burst($from, $arguments); + break; //default default: //unknown cmd @@ -234,7 +244,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; + $this->flags |= self::FLAG_P10SESSION | self::FLAG_BURST_PENDING; } else { //another server got a new slave server ^^ $server = P10_Server::getServerByNum($from); @@ -251,6 +261,57 @@ class Uplink { $this->send("Z", $args[0]); //simply PONG } + private function recv_nick($from, $args) { + //[recv] AM N Zer0n|IRPG 2 1292194168 ~Zer0n c04D8C5.localIP +oiwgrftx Zer0n Zer0n.admin.WebGamesNet AKBNjF AMAAj :Zer0n IRPG - Will never answer here. + if(count($args) == 2) { + //Nick change + $user = P10_User::getUserByNum($from); + if($user == null) { + trigger_error("Server tries to change the nick of an user that does not exist or was not found on recv_nick.", E_USER_ERROR); + return; + } + $nick->setNick($args[0]); + } else { + //New User + $numeric = $args[count($args)-2]; + $nick = $args[0]; + $server = P10_Server::getServerByNum($from); + if($server == null) { + trigger_error("Server (".$from.") the User (".$nick.") is coming from does not exist or was not found on recv_nick.", E_USER_ERROR); + return; + } + if(substr($numeric,0,2) != $from) { + trigger_error("A Server (".$from.") tries to connect a User with an invalid User numeric ('".$numeric."' does not belong to the Server)", E_USER_WARNING); + } + $connect_time = $args[2]; + $ident = $args[3]; + $host = $args[4]; + $modes = implode(" ",array_slice($args, 5, count($args)-8)); + $modes = new UserModeSet($modes); + $ip = Numerics::parseIP($args[count($args)-3]); + $realname = $args[count($args)-1]; + new P10_User($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes); + } + } + + private function recv_end_of_burst($from, $args) { + if(($this->flags & self::FLAG_BURST_PENDING)) { + $this->burst(); + $this->send("EA"); + $this->flags &= ~self::FLAG_BURST_PENDING; + } + } + + + + /******************************************************************************************** + * SERVER FUNCTIONS * + ********************************************************************************************/ + + private function burst() { + $this->send("EB"); + } + } ?> \ No newline at end of file -- 2.20.1