added recv_join & recv_part
[PHP-P10.git] / Uplink / Uplink.class.php
index 6908ab7a0d5fb987eaa7aff54e3d2b7b58528f9f..cf9b34fab94a767b8dd228802eaa59b9d27cf49f 100644 (file)
@@ -214,6 +214,13 @@ class Uplink {
                        case "B":
                                $this->recv_burst($from, $arguments);
                                break;
+                       case "J":
+                       case "C":
+                               $this->recv_join($from, $arguments);
+                               break;
+                       case "L":
+                               $this->recv_part($from, $arguments);
+                               break;
                //default
                        default:
                                //unknown cmd
@@ -358,6 +365,7 @@ class Uplink {
                $channel = P10_Channel::getChannelByName($name);
                if($channel == null)
                        $channel = new P10_Channel($name);
+               $channel->setCreateTime($create_time);
                $modes = $channel->getModes();
                $userstr = $args[count($args)-1];
                $modeparamcount = count($args)-3;
@@ -370,6 +378,10 @@ class Uplink {
                        $userstr = $args[count($args)-2];
                        $modeparamcount--;
                }
+               if($userstr[0] == "+") { //MODE String
+                       $modeparamcount++;
+                       $userstr = "";
+               }
                $users = explode(",",$userstr);
                $isop = false; $isvoice = false;
                foreach($users as $user) {
@@ -396,6 +408,30 @@ class Uplink {
                $modes->parseModes(implode(array_slice($args, 2, $modeparamcount)));
        }
        
+       private function recv_join($from, $args) {
+               $user = P10_User::getUserByNum($from);
+               if($user == null) {
+                       trigger_error("Server tries to join an user that does not exist or was not found on recv_join.", E_USER_ERROR);
+                       return;
+               }
+               $channel = P10_Channel::getChannelByName($args[0]);
+               if($channel == null)
+                       $channel = new P10_Channel($args[0]);
+               $channel->joinUser($user);
+       }
+       
+       private function recv_part($from, $args) {
+               $user = P10_User::getUserByNum($from);
+               if($user == null) {
+                       trigger_error("Server tries to part an user that does not exist or was not found on recv_join.", E_USER_ERROR);
+                       return;
+               }
+               $channel = P10_Channel::getChannelByName($args[0]);
+               if($channel == null)
+                       $channel = new P10_Channel($args[0]);
+               $channel->partUser($user, $args[1]);
+       }
+       
        /********************************************************************************************
         *                                     SERVER FUNCTIONS                                     *
         ********************************************************************************************/
@@ -412,6 +448,57 @@ class Uplink {
                        $realname = $user->getRealname();
                        $this->send("N", $nick, $connect_time, $ident, $host, $modes, $ip, $numeric, $realname);
                }
+               foreach(P10_Channel::getChannels() as $channel) {
+                       $sorted_users = array('ov' => array(), 'o' => array(), 'v' => array(), '-' => array());
+                       $local_users = false;
+                       foreach($channel->getUsers() as $user) {
+                               if(substr($user->getNumeric(), 0, 2) != $this->server->getNumeric()) continue; //skip users that are not on the local server
+                               $privs = $channel->getUserPrivs($user);
+                               $strPrivs = "";
+                               if(($privs & P10_Channel::USERPRIV_OPED)) $strPrivs .= "o";
+                               if(($privs & P10_Channel::USERPRIV_VOICE)) $strPrivs .= "v";
+                               if($strPrivs == "") $strPrivs = "-";
+                               $local_users = true;
+                               $sorted_users[$strPrivs][] = $user;
+                       }
+                       if(!$local_users) continue;
+                       $userStr = "";
+                       foreach($sorted_users['-'] as $user) {
+                               if($userStr != "") $userStr.=",";
+                               $userStr .= $user->getNumeric();
+                       }
+                       foreach($sorted_users['ov'] as $i => $user) {
+                               if($userStr != "") $userStr.=",";
+                               $userStr .= $user->getNumeric();
+                               if($i == 0) $userStr .= ":ov";
+                       }
+                       foreach($sorted_users['o'] as $i => $user) {
+                               if($userStr != "") $userStr.=",";
+                               $userStr .= $user->getNumeric();
+                               if($i == 0) $userStr .= ":o";
+                       }
+                       foreach($sorted_users['v'] as $i => $user) {
+                               if($userStr != "") $userStr.=",";
+                               $userStr .= $user->getNumeric();
+                               if($i == 0) $userStr .= ":v";
+                       }
+                       $banString = "";
+                       //TODO: Build ban String
+                       $burstString = "";
+                       $modeString = $channel->getModes()->getModeString();
+                       if($modeString != "+") {
+                               $burstString .= $modeString;
+                       }
+                       if($userStr != "") {
+                               if($burstString != "") $burstString .= " ";
+                               $burstString .= $userStr;
+                       }
+                       if($banString != "") {
+                               if($burstString != "") $burstString .= " ";
+                               $burstString .= ":%".$banString;
+                       }
+                       $this->send("B", $channel->getName(), $channel->getCreateTime(), $burstString);
+               }
                $this->send("EB");
        }