2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
20 * Uplink/P10_Channel.class.php
22 * This class represents a IRC Channel
27 private static $static_channels = array();
29 public static function getChannelByName($name) {
30 $name = strtolower($name);
31 if(array_key_exists($name, self::$static_channels)) {
32 return self::$static_channels[$name];
37 public static function getChannels() {
38 return self::$static_channels;
41 public static function getChannelCount() {
42 return count(self::$static_channels);
45 public static function recheckAllChannels() {
46 foreach(self::$static_channels as $channel) {
47 $channel->checkChannel();
55 private $users = array();
56 const USERPRIV_OPED = 0x0001;
57 const USERPRIV_VOICE = 0x0002;
58 private $userPrivs = array();
60 public function __construct($name) {
62 $this->modes = new P10_ChannelModeSet($this);
63 $this->create_time = time();
64 self::$static_channels[strtolower($name)] = $this;
67 public function getName() {
71 public function getModes() {
75 public function setTopic($topic) {
76 $this->topic = $topic;
79 public function getTopic() {
83 public function setCreateTime($time) {
84 $this->create_time = $time;
87 public function getCreateTime() {
88 return $this->create_time;
91 public function joinUser($user) {
92 $this->users[$user->getNumeric()] = $user;
93 $this->userPrivs[$user->getNumeric()] = 0;
94 $user->addChannel($this);
97 public function burstUser($user, $opped, $voiced) {
98 $this->users[$user->getNumeric()] = $user;
99 $this->userPrivs[$user->getNumeric()] = ($opped ? self::USERPRIV_OPED : 0) | ($voiced ? self::USERPRIV_VOICE : 0);
100 $user->addChannel($this);
103 private function checkChannel() {
104 if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
105 unset(self::$static_channels[strtolower($this->name)]); //drop empty channel
109 public function quitUser($user) {
110 if(array_key_exists($user->getNumeric(), $this->users)) {
111 unset($this->users[$user->getNumeric()]);
112 unset($this->userPrivs[$user->getNumeric()]);
113 //$user->delChannel($this) is not necessary because the user quits (the whole Object gets removed later)
114 $this->checkChannel();
116 trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
120 public function partUser($user) {
121 if(array_key_exists($user->getNumeric(), $this->users)) {
122 unset($this->users[$user->getNumeric()]);
123 unset($this->userPrivs[$user->getNumeric()]);
124 $user->delChannel($this);
125 $this->checkChannel();
127 trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
131 public function getUserPrivs($user) {
132 if(array_key_exists($user->getNumeric(), $this->users)) {
133 return $this->userPrivs[$user->getNumeric()];
138 public function setUserPrivs($user, $privs) {
139 if(array_key_exists($user->getNumeric(), $this->users)) {
140 $this->userPrivs[$user->getNumeric()] = $privs;
144 public function getUserCount() {
145 return count($this->users);
148 public function getUsers() {