From 455040407c031d33129808462d42414c577863b4 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 26 Jul 2011 12:02:50 +0200 Subject: [PATCH] added P10_Channel.class.php and recv_burst --- Uplink/P10_Channel.class.php | 127 ++++++++++++++++++++++++++++++++++ Uplink/P10_ModeSets.class.php | 43 +++++++++++- Uplink/P10_User.class.php | 16 +++++ Uplink/Uplink.class.php | 49 +++++++++++++ 4 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 Uplink/P10_Channel.class.php diff --git a/Uplink/P10_Channel.class.php b/Uplink/P10_Channel.class.php new file mode 100644 index 0000000..efe960d --- /dev/null +++ b/Uplink/P10_Channel.class.php @@ -0,0 +1,127 @@ +name = $name; + $this->modes = new P10_ChannelModeSet($this); + self::$static_channels[strtolower($name)] = $this; + } + + public function getName() { + return $this->name; + } + + public function getModes() { + return $this->modes; + } + + public function setTopic($topic) { + $this->topic = $topic; + } + + public function getTopic() { + return $this->topic; + } + + public function joinUser($user) { + $this->users[$user->getNumeric()] = $user; + $this->userPrivs[$user->getNumeric()] = 0; + $user->addChannel($this); + } + + public function burstUser($user, $opped, $voiced) { + $this->users[$user->getNumeric()] = $user; + $this->userPrivs[$user->getNumeric()] = ($opped ? self::USERPRIV_OPED : 0) | ($voiced ? self::USERPRIV_VOICE : 0); + $user->addChannel($this); + } + + public function quitUser($user) { + if(array_key_exists($user->getNumeric(), $this->users)) { + unset($this->users[$user->getNumeric()]); + unset($this->userPrivs[$user->getNumeric()]); + //$user->delChannel($this) is not necessary because the user quits (the whole Object gets removed later) + } else { + trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING); + } + } + + public function partUser($user) { + if(array_key_exists($user->getNumeric(), $this->users)) { + unset($this->users[$user->getNumeric()]); + unset($this->userPrivs[$user->getNumeric()]); + $user->delChannel($this); + } else { + trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING); + } + } + + public function getUserPrivs($user) { + if(array_key_exists($user->getNumeric(), $this->users)) { + return $this->userPrivs[$user->getNumeric()]; + } else + return 0; + } + + public function setUserPrivs($user, $privs) { + if(array_key_exists($user->getNumeric(), $this->users)) { + $this->userPrivs[$user->getNumeric()] = $privs; + } + } + +} + +?> \ No newline at end of file diff --git a/Uplink/P10_ModeSets.class.php b/Uplink/P10_ModeSets.class.php index 83611b8..264a53f 100644 --- a/Uplink/P10_ModeSets.class.php +++ b/Uplink/P10_ModeSets.class.php @@ -69,13 +69,18 @@ class P10_ChannelModeSet { "D" => self::MODE_TYPE_D, "d" => self::MODE_TYPE_D, "R" => self::MODE_TYPE_D, - "z" => self::MODE_TYPE_D + "z" => self::MODE_TYPE_D, + + //special behavior + "o" => self::MODE_TYPE_B, + "v" => self::MODE_TYPE_B ); private static $modevalues = null; private $modeflags = 0; private $modeparams = array(); + private $channel; - public function __construct($modes) { + public function __construct($channel) { if(self::$modevalues == null) { //build modevalues array $flag = 1; @@ -85,7 +90,7 @@ class P10_ChannelModeSet { $flag <<= 1; } } - $this->parseModes($modes); + $this->channel = $channel; } public function parseModes($modes) { @@ -109,6 +114,7 @@ class P10_ChannelModeSet { $this->modeparams[$mode] = $args[$c++]; } } + return $c-1; } public function setModes($modes, $returndiff = false) { @@ -133,6 +139,18 @@ class P10_ChannelModeSet { trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING); continue; } + if($mode == "o" || $mode == "v") { + if($this->setPrivs($add, $mode, $args[$c++])) { + if($returndiff && $add) { + $modestradd .= $mode; + $paramstradd .= " ".$args[$c-1]; + } else if($returndiff && !$add) { + $modestrdel .= $mode; + $paramstrdel .= " ".$args[$c-1]; + } + } + continue; + } $flag = self::$modevalues[$mode]; if($add) { if($returndiff && !($this->modeflags & $flag)) { @@ -167,6 +185,25 @@ class P10_ChannelModeSet { } } + private function setPrivs($add, $mode, $user) { + $user = P10_User::getUserByNum($user); + if($user == null) { + trigger_error("Tried to set privs on a User that does not exist.", E_USER_ERROR); + return; + } + $privs = $this->channel->getUserPrivs($user); + $privFlag = 0; + if($mode == "o") $privFlag = P10_Channel::USERPRIV_OPED; + if($mode == "v") $privFlag = P10_Channel::USERPRIV_VOICE; + if(!($add xor ($privs & $privFlag))) + return false; + if($add) $privs |= $privFlag; + else $privs &= ~$privFlag; + $this->channel->setUserPrivs($user, $privs); + return true; + + } + public function getModeString() { $modestr = "+"; $paramstr = ""; diff --git a/Uplink/P10_User.class.php b/Uplink/P10_User.class.php index a05f40b..83169bf 100644 --- a/Uplink/P10_User.class.php +++ b/Uplink/P10_User.class.php @@ -64,6 +64,7 @@ class P10_User { private $connect_time; private $modes; private $realname; + private $channels; public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) { $this->nick = $nick; @@ -121,6 +122,21 @@ class P10_User { public function quit($reason) { $this->server->delUser($this); + foreach($this->channels as $channel) { + $channel->quitUser($this); + } + } + + public function addChannel($channel) { + $this->channels[strtolower($channel->getName())] = $channel; + } + + public function delChannel($channel) { + if(array_key_exists(strtolower($channel->getName()), $this->channels)) { + unset($this->channels[strtolower($channel->getName())]); + } else { + trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING); + } } } diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index 7cd1d77..5c86c95 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -52,6 +52,7 @@ 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_Channel.class.php"); require_once("P10_ModeSets.class.php"); class Uplink { @@ -205,6 +206,9 @@ class Uplink { case "Q": $this->recv_quit($from, $arguments); break; + case "B": + $this->recv_burst($from, $arguments); + break; //default default: //unknown cmd @@ -335,6 +339,51 @@ class Uplink { $user->quit($args[0]); } + private function recv_burst($from, $args) { + //AK B #aide 1292621006 +tn ALAMH:o + $name = $args[0]; + $create_time = $args[1]; + $channel = P10_Channel::getChannelByName($name); + if($name == null) + $channel = new P10_Channel($name); + $modes = $channel->getModes(); + $userstr = $args[count($args)-1]; + $modeparamcount = count($args)-3; + if($userstr[0] == "%") { + //ban list + $banlist = explode(" ", substr($userstr, 1)); + foreach($banlist as $ban) { + //TODO: save bans + } + $userstr = $args[count($args)-2]; + $modeparamcount--; + } + $users = explode(":",$userstr); + $isop = false; $isvoice = false; + foreach($users as $user) { + $uexp = explode(":", $user); + if(strlen($uexp[0]) != 6) { + trigger_error("burst parse error: '".$uexp[0]."' is not an user numeric.", E_USER_ERROR); + return; + } + if(count($uexp) > 1) { + $isop = false; + $isvoice = false; + for($i = 0; $i < strlen($uexp[1]); $i++) { + if($uexp[1][0] == "@") $isop = true; + if($uexp[1][0] == "+") $isvoice = true; + } + } + $user = P10_User::getUserByNum($uexp[0]); + if($user == null) { + trigger_error("burst parse error: cant find User '".$uexp[0]."'.", E_USER_ERROR); + return; + } + $channel->burstUser($user, $isop, $isvoice); + } + $modes->parseModes(implode(array_slice($args, 2, $modeparamcount))); + } + /******************************************************************************************** * SERVER FUNCTIONS * ********************************************************************************************/ -- 2.20.1