--- /dev/null
+<?php
+/********************************* PHP-P10 ******************************
+ * P10 uplink class by pk910 (c)2011 pk910 *
+ ************************************************************************
+ * Version 2 (OOP) *
+ * *
+ * PHP-P10 is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with PHP-P10; if not, write to the Free Software Foundation, *
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
+ * *
+ ************************************************************************
+ *
+ * Uplink/P10_Channel.class.php
+ *
+ * This class represents a IRC Channel
+ *
+ ************************************************************************
+ * accessable methods:
+ *
+ * static P10_User getChannelByName(String $name)
+ * searches and returns the Channel with the provided name
+ *
+ * __construct(String $name)
+ * *** nothing to say here ***
+ *
+ */
+
+class P10_Channel {
+ private static $static_channels = array();
+
+ public static function getChannelByName($name) {
+ $name = strtolower($name);
+ if(array_key_exists($name, self::$static_channels)) {
+ return self::$static_channels[$name];
+ }
+ return NULL;
+ }
+
+
+ private $name;
+ private $topic;
+ private $modes;
+ private $users = array();
+ const USERPRIV_OPED = 0x0001;
+ const USERPRIV_VOICE = 0x0002;
+ private $userPrivs = array();
+
+ public function __construct($name) {
+ $this->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
"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;
$flag <<= 1;
}
}
- $this->parseModes($modes);
+ $this->channel = $channel;
}
public function parseModes($modes) {
$this->modeparams[$mode] = $args[$c++];
}
}
+ return $c-1;
}
public function setModes($modes, $returndiff = false) {
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)) {
}
}
+ 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 = "";
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;
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);
+ }
}
}
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 {
case "Q":
$this->recv_quit($from, $arguments);
break;
+ case "B":
+ $this->recv_burst($from, $arguments);
+ break;
//default
default:
//unknown cmd
$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 *
********************************************************************************************/