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_User.class.php
22 * This class represents a IRC User
27 private static $static_users = array();
29 public static function getUserByNum($numeric) {
30 if(array_key_exists($numeric, self::$static_users)) {
31 return self::$static_users[$numeric];
36 public static function getUserByNick($nick) {
37 $nick = strtolower($nick);
38 foreach(self::$static_users as $user) {
39 if(strtolower($user->getNick()) == $nick) {
46 public static function getAllUsers() {
47 return self::$static_users;
57 private $connect_time;
60 private $channels = array();
63 public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
65 $this->numeric = $numeric;
66 $this->server = $server;
67 $this->connect_time = $connect_time;
68 $this->ident = $ident;
71 $this->realname = $realname;
72 $this->modes = $modes;
73 $server->addUser($this);
74 self::$static_users[$numeric] = $this;
77 public function getNumeric() {
78 return $this->numeric;
81 public function getServer() {
85 public function setNick($nick) {
89 public function getNick() {
93 public function setIdent($ident) {
94 $this->ident = $ident;
97 public function getIdent() {
101 public function getHost() {
105 public function getIP() {
109 public function getConnectTime() {
110 return $this->connect_time;
113 public function getModes() {
117 public function getRealname() {
118 return $this->realname;
121 public function setAway($away) {
125 public function getAway() {
129 public function isAway() {
130 return ($this->away != null);
133 public function quit($reason) {
134 $this->server->delUser($this);
135 unset(self::$static_users[$this->numeric]);
136 foreach($this->channels as $channel) {
137 $channel->quitUser($this);
141 public function addChannel($channel) {
142 $this->channels[strtolower($channel->getName())] = $channel;
145 public function delChannel($channel) {
146 if(array_key_exists(strtolower($channel->getName()), $this->channels)) {
147 unset($this->channels[strtolower($channel->getName())]);
149 trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING);
153 public function getChannels() {
154 return $this->channels;
157 public function getChannelCount() {
158 return count($this->channels);
161 public function isOnChannel($channel) {
162 return array_key_exists(strtolower($channel->getName()),$this->channels);