+ if($this->eventHandler)
+ $this->eventHandler->event_join($user, $channel, true);
+ }
+ $modes->parseModes(implode(" ", array_slice($args, 2)));
+ }
+
+ 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);
+ if($this->eventHandler)
+ $this->eventHandler->event_join($user, $channel, false);
+ }
+
+ 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]);
+ if($this->eventHandler)
+ $this->eventHandler->event_part($user, $channel, $args[1]);
+ $channel->partUser($user);
+ }
+
+ private function recv_kick($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("An unknown user tries to kick another user on recv_kick.", E_USER_ERROR);
+ return;
+ }
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ $target = P10_User::getUserByNum($args[1]);
+ if($target == null) {
+ trigger_error("Someone tries to kick an user that does not exist or was not found on recv_kick.", E_USER_ERROR);
+ return;
+ }
+ if($this->eventHandler)
+ $this->eventHandler->event_kick($user, $target, $channel, $args[1]);
+ $channel->partUser($user);
+ }
+
+ private function recv_kill($from, $args) {
+ $user = P10_User::getUserByNum($args[0]);
+ if($user == null) {
+ trigger_error("Server tries to kill an user that does not exist or was not found on recv_quit.", E_USER_ERROR);
+ return;
+ }
+ if($this->eventHandler)
+ $this->eventHandler->event_quit($user, "Killed (".$args[1].")");
+ $user->quit($args[1]);
+ }
+
+ private function recv_privmsg($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to send a privmsg from an user that does not exist or was not found on recv_privmsg.", E_USER_WARNING);
+ return;
+ }
+ if($this->eventHandler) {
+ if($args[0][0] == "#") {
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ if(strlen($args[1]) > 0 && $args[1][0] == "\001") {
+ //ctcp
+ $args[1] = substr($args[1],1);
+ if($args[1][strlen($args[1])-1] == "\001")
+ $args[1] = substr($args[1],0,-1);
+ $ctcpexp = explode(" ",$args[1],2);
+ $this->eventHandler->event_chanctcp($user, $channel, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null));
+ } else
+ $this->eventHandler->event_chanmessage($user, $channel, $args[1]);
+ } else if($args[0][0] == "$") {
+ //"multicast"
+ $this->eventHandler->event_privmessage($user, NULL, $args[1]);
+ } else {
+ $targetUser = P10_User::getUserByNum($args[0]);
+ if($targetUser == null) {
+ trigger_error("Server tries to send a privmsg to an user that does not exist or was not found on recv_privmsg.", E_USER_WARNING);
+ return;
+ }
+ if(strlen($args[1]) > 0 && $args[1][0] == "\001") {
+ //ctcp
+ $args[1] = substr($args[1],1);
+ if($args[1][strlen($args[1])-1] == "\001")
+ $args[1] = substr($args[1],0,-1);
+ $ctcpexp = explode(" ",$args[1],2);
+ $this->eventHandler->event_privctcp($user, $targetUser, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null));
+ } else
+ $this->eventHandler->event_privmessage($user, $targetUser, $args[1]);
+ }
+ }
+ }
+
+ private function recv_notice($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to send a notice from an user that does not exist or was not found on recv_notice.", E_USER_WARNING);
+ return;
+ }
+ if($this->eventHandler) {
+ if($args[0][0] == "#") {
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ if(strlen($args[1]) > 0 && $args[1][0] == "\001") {
+ //ctcp
+ $args[1] = substr($args[1],1);
+ if($args[1][strlen($args[1])-1] == "\001")
+ $args[1] = substr($args[1],0,-1);
+ $ctcpexp = explode(" ",$args[1],2);
+ $this->eventHandler->event_chanctcpreply($user, $channel, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null));
+ } else
+ $this->eventHandler->event_channotice($user, $channel, $args[1]);
+ } else if($args[0][0] == "$") {
+ //"multicast"
+ $this->eventHandler->event_privnotice($user, NULL, $args[1]);
+ } else {
+ $targetUser = P10_User::getUserByNum($args[0]);
+ if($targetUser == null) {
+ trigger_error("Server tries to send a notice to an user that does not exist or was not found on recv_notice.", E_USER_WARNING);
+ return;
+ }
+ if(strlen($args[1]) > 0 && $args[1][0] == "\001") {
+ //ctcp
+ $args[1] = substr($args[1],1);
+ if($args[1][strlen($args[1])-1] == "\001")
+ $args[1] = substr($args[1],0,-1);
+ $ctcpexp = explode(" ",$args[1],2);
+ $this->eventHandler->event_privctcpreply($user, $targetUser, strtoupper($ctcpexp[0]), (count($ctcpexp) > 1 ? $ctcpexp[1] : null));
+ } else
+ $this->eventHandler->event_privnotice($user, $targetUser, $args[1]);
+ }
+ }
+ }
+
+ private function recv_whois($from, $args) {
+ /* [get] ACAAF W AX :NetworkServ */
+ $fromUser = P10_User::getUserByNum($from);
+ if($fromUser == null) {
+ trigger_error("Server tries to send a whois from an user that does not exist or was not found on recv_whois.", E_USER_ERROR);
+ return;
+ }
+ $users=explode(",",$args[1]);
+ foreach($users as $nick) {
+ $user = P10_User::getUserByNick($nick);
+ if(!$user) {
+ $this->send("401", $from, $nick);
+ continue;
+ }
+ $nick = $user->getNick();
+ $ident = $user->getIdent();
+ $hostmask = $user->getHost();
+ $modes = $user->getModes();
+ if($modes->hasMode('x')) {
+ if(($fakehost = $modes->hasMode('f'))) {
+ $hostmask = $fakehost;
+ } elseif(($account = $modes->hasMode('r'))) {
+ $hostmask = $account.".".$this->getSetting("his_usermask");
+ }
+ }
+ $realname = $user->getRealname();
+ $this->send("311", $from , $nick, $ident, $hostmask, $realname);
+ if(((!$modes->hasMode('n') && !$modes->hasMode('k')) || $from == $user->getNumeric()) && count($user->getChannels()) != 0) {
+ $channels = "";
+ foreach($user->getChannels() as $channel) {
+ $cmodes = $channel->getModes();
+ $privs = $channel->getUserPrivs($user);
+ if($cmodes->hasMode("s") && !$fromUser->isOnChannel($channel) && $from != $user->getNumeric()) continue;
+ if($cmodes->hasMode("u") && ($privs & (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE)) == 0 && $from != $user->getNumeric()) continue;
+ $chanstr = ($channels == "" ? "" : " ");
+ $prefix = "";
+ if(($privs & P10_Channel::USERPRIV_OPED)) {
+ $prefix = "@";
+ } else if(($privs & P10_Channel::USERPRIV_VOICE)) {
+ $prefix = "+";
+ }
+ $chanstr .= $prefix.$channel->getName();
+ if(strlen($channels) + strlen($chanstr) > 450) {
+ $this->send("319", $from, $nick, $channels);
+ $channels = $prefix.$channel->getName();
+ }
+ }
+ if($channels != "") {
+ $this->send("319", $from, $nick, $channels);
+ }
+ }
+ if($fromUser->getModes()->hasMode("o") || $from == $user->getNumeric() || !$this->getSetting("his_name")) {
+ $this->send("312", $from, $nick, $user->getServer()->getName(), $user->getServer()->getDescription());
+ } else {
+ $this->send("312", $from, $nick, $this->getSetting("his_name"), $this->getSetting("his_desc"));
+ }
+ if($modes->hasMode("o") && (!$modes->hasMode("H") || $fromUser->getModes()->hasMode("o"))) {
+ if($modes->hasMode("S")) {
+ if($modes->hasMode("D"))
+ $this->send("313", $from, $nick, "is a Network Service");
+ else
+ $this->send("313", $from, $nick, "is an illegal Network Service - HACKER!");
+ } else
+ $this->send("313", $from, $nick, "is an IRC Operator");
+ }
+ if(($auth = $modes->hasMode("r"))) {
+ $this->send("330", $from, $nick, $auth);
+ }
+ }
+ $this->send("318", $from, $args[1]);
+ }
+
+ private function recv_away($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to send an away command from an user that does not exist or was not found on recv_away.", E_USER_ERROR);
+ return;
+ }
+ if(count($args) > 0) {
+ $user->setAway($args[0]);
+ if($this->eventHandler)
+ $this->eventHandler->event_away($user, $args[0]);
+ } else {
+ $user->setAway(null);
+ if($this->eventHandler)
+ $this->eventHandler->event_away($user, null);
+ }
+ }
+
+ private function recv_mode($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to send a modechange from an user that does not exist or was not found on recv_mode.", E_USER_ERROR);
+ return;
+ }
+ $modes = implode(" ",array_slice($args,1));
+ if($args[0][0] == "#") {
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ $channel->getModes()->setModes($modes);
+ if($this->eventHandler)
+ $this->eventHandler->event_chanmode($user, $channel, $modes);
+ } else {
+ $targetUser = P10_User::getUserByNick($args[0]);
+ if($targetUser == null) {
+ trigger_error("Server tries to send a mode to an user that does not exist or was not found on recv_mode.", E_USER_ERROR);
+ return;
+ }
+ $targetUser->getModes()->setModes($modes);
+ if($this->eventHandler)
+ $this->eventHandler->event_usermode($targetUser, $modes);