added recv_nick and P10_User
[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 getUserByNum($numeric) {
42                 if(array_key_exists($numeric, self::$static_servers)) {
43                         return self::$static_servers[$numeric];
44                 }
45                 return NULL;
46         }
47         
48         public static 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         
59         private $numeric;
60         private $nick;
61         private $ident;
62         private $host;
63         private $ip;
64         private $connect_time;
65         private $modes;
66         private $realname;
67         
68         public __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
69                 $this->nick = $nick;
70                 $this->numeric = $numeric;
71                 $this->server = $server;
72                 $this->connect_time = $connect_time;
73                 $this->ident = $ident;
74                 $this->host = $host;
75                 $this->ip = $ip;
76                 $this->realname = $realname;
77                 $this->modes = $modes;
78                 $server->addUser($this);
79                 self::$static_users[$numeric] = $this;
80         }
81         
82         public function getNumeric() {
83                 return $this->numeric;
84         }
85         
86         public function setNick($nick) {
87                 $this->nick = $nick;
88         }
89         
90         public function getNick() {
91                 return $this->nick;
92         }
93         
94         public function setIdent($ident) {
95                 $this->ident = $ident;
96         }
97         
98         public function getIdent() {
99                 return $this->ident;
100         }
101         
102         public function getHost() {
103                 return $this->host;
104         }
105         
106         public function getIP() {
107                 return $this->ip;
108         }
109         
110         public function getConnectTime() {
111                 return $this->connect_time;
112         }
113         
114         public function getModes() {
115                 return $this->modes;
116         }
117         
118         public function getRealname() {
119                 return $this->realname;
120         }
121         
122         public function quit($reason) {
123                 $this->server->delUser($this);
124         }
125 }
126
127 ?>