552c3e45fc63e7c09a7263c728857b87e0a7fce1
[PHP-P10.git] / Uplink / P10_User.class.php
1 <?php
2 /********************************* PHP-P10 ******************************
3  *    P10 uplink class by pk910   (c)2011 pk910                         *
4  ************************************************************************
5  *                          Version 2 (OOP)                             *
6  *                                                                      *
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.                                  *
11  *                                                                      *
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.                         *
16  *                                                                      *
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.       *
20  *                                                                      *
21  ************************************************************************
22  * 
23  *  Uplink/P10_User.class.php
24  *
25  * This class represents a IRC User
26  *
27  ************************************************************************
28  * accessable methods:
29  *
30  * static P10_User getUserByNum(String $numeric) 
31  *     searches and returns the User with the provided Numeric
32  *
33  * __construct(String $nick, String $numeric, P10_Server $server, int $connect_time, String $ident, String $realname, P10_ModeSet $modes)
34  *     *** nothing to say here ***
35  *
36  */
37
38 class P10_User {
39         private static $static_users = array();
40         
41         public static function getUserByNum($numeric) {
42                 if(array_key_exists($numeric, self::$static_users)) {
43                         return self::$static_users[$numeric];
44                 }
45                 return NULL;
46         }
47         
48         public static function getUserByNick($nick) {
49                 $nick = strtolower($nick);
50                 foreach(self::$static_users as $user) {
51                         if(strtolower($user->getNick()) == $nick) {
52                                 return $user;
53                         }
54                 }
55                 return NULL;
56         }
57         
58         public static function getAllUsers() {
59                 return self::$static_users;
60         }
61         
62         
63         private $numeric;
64         private $server;
65         private $nick;
66         private $ident;
67         private $host;
68         private $ip;
69         private $connect_time;
70         private $modes;
71         private $realname;
72         private $channels = array();
73         private $away = null;
74         
75         public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
76                 $this->nick = $nick;
77                 $this->numeric = $numeric;
78                 $this->server = $server;
79                 $this->connect_time = $connect_time;
80                 $this->ident = $ident;
81                 $this->host = $host;
82                 $this->ip = $ip;
83                 $this->realname = $realname;
84                 $this->modes = $modes;
85                 $server->addUser($this);
86                 self::$static_users[$numeric] = $this;
87         }
88         
89         public function getNumeric() {
90                 return $this->numeric;
91         }
92         
93         public function getServer() {
94                 return $this->server;
95         }
96         
97         public function setNick($nick) {
98                 $this->nick = $nick;
99         }
100         
101         public function getNick() {
102                 return $this->nick;
103         }
104         
105         public function setIdent($ident) {
106                 $this->ident = $ident;
107         }
108         
109         public function getIdent() {
110                 return $this->ident;
111         }
112         
113         public function getHost() {
114                 return $this->host;
115         }
116         
117         public function getIP() {
118                 return $this->ip;
119         }
120         
121         public function getConnectTime() {
122                 return $this->connect_time;
123         }
124         
125         public function getModes() {
126                 return $this->modes;
127         }
128         
129         public function getRealname() {
130                 return $this->realname;
131         }
132         
133         public function setAway($away) {
134                 $this->away = $away;
135         }
136         
137         public function getAway() {
138                 return $this->away;
139         }
140         
141         public function isAway() {
142                 return ($this->away != null);
143         }
144         
145         public function quit($reason) {
146                 $this->server->delUser($this);
147                 unset(self::$static_users[$this->numeric]);
148                 foreach($this->channels as $channel) {
149                         $channel->quitUser($this);
150                 }
151         }
152         
153         public function addChannel($channel) {
154                 $this->channels[strtolower($channel->getName())] = $channel;
155         }
156         
157         public function delChannel($channel) {
158                 if(array_key_exists(strtolower($channel->getName()), $this->channels)) {
159                         unset($this->channels[strtolower($channel->getName())]);
160                 } else {
161                         trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING);
162                 }
163         }
164         
165         public function getChannels() {
166                 return $this->channels;
167         }
168         
169         public function getChannelCount() {
170                 return count($this->channels);
171         }
172         
173         public function isOnChannel($channel) {
174                 return array_key_exists(strtolower($channel->getName()),$this->channels);
175         }
176 }
177
178 ?>