2 /********************************* PHP-P10 ******************************
3 * P10 uplink class by pk910 (c)2011 pk910 *
4 ************************************************************************
7 * PHP-P10 is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with PHP-P10; if not, write to the Free Software Foundation, *
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 ************************************************************************
23 * Uplink/P10_Channel.class.php
25 * This class represents a IRC Channel
27 ************************************************************************
30 * static P10_User getChannelByName(String $name)
31 * searches and returns the Channel with the provided name
33 * __construct(String $name)
34 * *** nothing to say here ***
39 private static $static_channels = array();
41 public static function getChannelByName($name) {
42 $name = strtolower($name);
43 if(array_key_exists($name, self::$static_channels)) {
44 return self::$static_channels[$name];
49 public static function getChannels() {
50 return self::$static_channels;
53 public static function getChannelCount() {
54 return count(self::$static_channels);
57 public static function recheckAllChannels() {
58 foreach(self::$static_channels as $channel) {
59 $channel->checkChannel();
67 private $users = array();
68 const USERPRIV_OPED = 0x0001;
69 const USERPRIV_VOICE = 0x0002;
70 private $userPrivs = array();
72 public function __construct($name) {
74 $this->modes = new P10_ChannelModeSet($this);
75 $this->create_time = time();
76 self::$static_channels[strtolower($name)] = $this;
79 public function getName() {
83 public function getModes() {
87 public function setTopic($topic) {
88 $this->topic = $topic;
91 public function getTopic() {
95 public function setCreateTime($time) {
96 $this->create_time = $time;
99 public function getCreateTime() {
100 return $this->create_time;
103 public function joinUser($user) {
104 $this->users[$user->getNumeric()] = $user;
105 $this->userPrivs[$user->getNumeric()] = 0;
106 $user->addChannel($this);
109 public function burstUser($user, $opped, $voiced) {
110 $this->users[$user->getNumeric()] = $user;
111 $this->userPrivs[$user->getNumeric()] = ($opped ? self::USERPRIV_OPED : 0) | ($voiced ? self::USERPRIV_VOICE : 0);
112 $user->addChannel($this);
115 private function checkChannel() {
116 if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
117 unset(self::$static_channels[strtolower($this->name)]); //drop empty channel
121 public function quitUser($user) {
122 if(array_key_exists($user->getNumeric(), $this->users)) {
123 unset($this->users[$user->getNumeric()]);
124 unset($this->userPrivs[$user->getNumeric()]);
125 //$user->delChannel($this) is not necessary because the user quits (the whole Object gets removed later)
126 $this->checkChannel();
128 trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
132 public function partUser($user) {
133 if(array_key_exists($user->getNumeric(), $this->users)) {
134 unset($this->users[$user->getNumeric()]);
135 unset($this->userPrivs[$user->getNumeric()]);
136 $user->delChannel($this);
137 $this->checkChannel();
139 trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
143 public function getUserPrivs($user) {
144 if(array_key_exists($user->getNumeric(), $this->users)) {
145 return $this->userPrivs[$user->getNumeric()];
150 public function setUserPrivs($user, $privs) {
151 if(array_key_exists($user->getNumeric(), $this->users)) {
152 $this->userPrivs[$user->getNumeric()] = $privs;
156 public function getUserCount() {
157 return count($this->users);
160 public function getUsers() {