finished first "alpha" version of PHP-P10 v2
[PHP-P10.git] / Uplink / Uplink.class.php
index 037d4633170c904026ee89f5f144e87294f52c94..14585f6901fc5a7b11b253ad7a97b299c1143358 100644 (file)
@@ -142,6 +142,15 @@ class Uplink {
                }
        }
        
+       public function shutdown() {
+               if($this->client->connected()) {
+                       if(($this->flags & self::FLAG_P10SESSION)) {
+                               $this->send("SQ", "Shutdown requested.");
+                       }
+                       $this->client->disconnect();
+               }
+       }
+       
        public function setUplinkHost($host, $port, $ssl = false, $bind = null) {
                $this->setSetting("host", $host);
                $this->setSetting("port", $port);
@@ -330,7 +339,7 @@ class Uplink {
                        $this->server->addServer($new_server);
                        $this->flags |= self::FLAG_P10SESSION | self::FLAG_BURST_PENDING;
                        if($this->eventHandler)
-                               $this->eventHandler->event_server($new_server, !($this->flags & self::FLAG_CONNECTED));
+                               $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED));
                } else {
                        //another server got a new slave server ^^
                        $server = P10_Server::getServerByNum($from);
@@ -341,7 +350,7 @@ class Uplink {
                        $new_server = new P10_Server($args[0], substr($args[5],0,2), $server, $args[2], $args[3], $args[7]);
                        $server->addServer($new_server);
                        if($this->eventHandler)
-                               $this->eventHandler->event_server($new_server, !($this->flags & self::FLAG_CONNECTED));
+                               $this->eventHandler->event_newserver($new_server, !($this->flags & self::FLAG_CONNECTED));
                }
        }
        
@@ -443,6 +452,7 @@ class Uplink {
                $users = explode(",",$userstr);
                $isop = false; $isvoice = false;
                foreach($users as $user) {
+                       if($user == "") continue;
                        $uexp = explode(":", $user);
                        if(strlen($uexp[0]) != 5) {
                                trigger_error("burst parse error: '".$uexp[0]."' is not an user numeric.", E_USER_ERROR);
@@ -533,7 +543,7 @@ class Uplink {
                        return;
                }
                if($this->eventHandler) {
-                       if($args[0] == "#") {
+                       if($args[0][0] == "#") {
                                $channel = P10_Channel::getChannelByName($args[0]);
                                if($channel == null)
                                        $channel = new P10_Channel($args[0]);
@@ -556,7 +566,7 @@ class Uplink {
                        return;
                }
                if($this->eventHandler) {
-                       if($args[0] == "#") {
+                       if($args[0][0] == "#") {
                                $channel = P10_Channel::getChannelByName($args[0]);
                                if($channel == null)
                                        $channel = new P10_Channel($args[0]);
@@ -727,6 +737,7 @@ class Uplink {
                        $numeric = substr($this->server->getNumeric(),0,2).Numerics::intToNum($this->last_local_numeric, 3);
                }
                $this->last_local_numeric++;
+               $modes = new P10_UserModeSet($modes);
                $user = new P10_User($nick, $numeric, $this->server, time(), $ident, $host, $ip, $realname, $modes);
                if(($this->flags & self::FLAG_CONNECTED)) {
                        $ip = Numerics::numericFromIP($user->getIP());
@@ -755,7 +766,7 @@ class Uplink {
                }
        }
        
-       public function join($user, $chanName) {
+       public function join($user, $chanName, $privs = 0) {
                if(!is_a($user, "P10_User") || !($user->getServer() === $this->server))
                        return ERR_INVALID_USER;
                if($chanName[0] != "#")
@@ -766,6 +777,15 @@ class Uplink {
                $channel->joinUser($user);
                if(($this->flags & self::FLAG_CONNECTED))
                        $this->send("J", $user->getNumeric(), $chanName, time(), 0);
+               if($privs != 0) {
+                       $channel->setUserPrivs($user, $privs);
+                       if(($this->flags & self::FLAG_CONNECTED)) {
+                               $modestr = "+".(($privs & P10_Channel::USERPRIV_OPED) ? "o" : "").(($privs & P10_Channel::USERPRIV_VOICE) ? "v" : "");
+                               $modestr .= (($privs & P10_Channel::USERPRIV_OPED) ? " ".$user->getNumeric() : "");
+                               $modestr .= (($privs & P10_Channel::USERPRIV_VOICE) ? " ".$user->getNumeric() : "");
+                               $this->send("OM", $user->getNumeric(), $chanName, $modestr);
+                       }
+               }
                if($this->eventHandler)
                        $this->eventHandler->event_join($user, $channel, false);
        }