+<?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