2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011-2012 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_HALFOP = 0x0002;
58 const USERPRIV_VOICE = 0x0004;
59 private $userPrivs = array();
61 public function __construct($name) {
63 $this->modes = new P10_ChannelModeSet($this);
64 $this->create_time = time();
65 self::$static_channels[strtolower($name)] = $this;
68 public function getName() {
72 public function getModes() {
76 public function setTopic($topic) {
77 $this->topic = $topic;
80 public function getTopic() {
84 public function setCreateTime($time) {
85 $this->create_time = $time;
88 public function getCreateTime() {
89 return $this->create_time;
92 public function joinUser($user) {
93 $this->users[$user->getNumeric()] = $user;
94 $this->userPrivs[$user->getNumeric()] = 0;
95 $user->addChannel($this);
98 public function burstUser($user, $opped, $halfopped, $voiced) {
99 $this->users[$user->getNumeric()] = $user;
100 $this->userPrivs[$user->getNumeric()] = ($opped ? self::USERPRIV_OPED : 0) | ($halfopped ? self::USERPRIV_HALFOP : 0) | ($voiced ? self::USERPRIV_VOICE : 0);
101 $user->addChannel($this);
104 private function checkChannel() {
105 if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
106 unset(self::$static_channels[strtolower($this->name)]); //drop empty channel
110 public function quitUser($user) {
111 if(array_key_exists($user->getNumeric(), $this->users)) {
112 unset($this->users[$user->getNumeric()]);
113 unset($this->userPrivs[$user->getNumeric()]);
114 //$user->delChannel($this) is not necessary because the user quits (the whole Object gets removed later)
115 $this->checkChannel();
117 trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
121 public function partUser($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);
126 $this->checkChannel();
128 trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
132 public function getUserPrivs($user) {
133 if(array_key_exists($user->getNumeric(), $this->users)) {
134 return $this->userPrivs[$user->getNumeric()];
139 public function setUserPrivs($user, $privs) {
140 if(array_key_exists($user->getNumeric(), $this->users)) {
141 $this->userPrivs[$user->getNumeric()] = $privs;
145 public function getUserCount() {
146 return count($this->users);
149 public function getUsers() {