Another year is about to end... So we have to update these damn copyright information :P
[PHP-P10.git] / Uplink / P10_User.class.php
index 83169bfe4ada43fa419ec21df9d51a8cdc92e0dc..752e8be6f856cc1ca0680447c5d948cb3b7b3d63 100644 (file)
@@ -1,22 +1,19 @@
 <?php
-/********************************* PHP-P10 ******************************
- *    P10 uplink class by pk910   (c)2011 pk910                         *
- ************************************************************************
- *                          Version 2 (OOP)                             *
+/******************************* PHP-P10 v2 *****************************
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)                       *
  *                                                                      *
- * PHP-P10 is free software; you can redistribute it and/or modify      *
+ * This program is free software: you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or    *
+ * the Free Software Foundation, either version 3 of the License, or    *
  * (at your option) any later version.                                  *
- *                                                                      *
+ *                                                                      * 
  * This program is distributed in the hope that it will be useful,      *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
  * GNU General Public License for more details.                         *
  *                                                                      *
  * You should have received a copy of the GNU General Public License    *
- * along with PHP-P10; if not, write to the Free Software Foundation,   *
- * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  *                                                                      *
  ************************************************************************
  * 
  *
  * This class represents a IRC User
  *
- ************************************************************************
- * accessable methods:
- *
- * static P10_User getUserByNum(String $numeric) 
- *     searches and returns the User with the provided Numeric
- *
- * __construct(String $nick, String $numeric, P10_Server $server, int $connect_time, String $ident, String $realname, P10_ModeSet $modes)
- *     *** nothing to say here ***
- *
  */
 
 class P10_User {
        private static $static_users = array();
        
        public static function getUserByNum($numeric) {
-               if(array_key_exists($numeric, self::$static_servers)) {
-                       return self::$static_servers[$numeric];
+               if(array_key_exists($numeric, self::$static_users)) {
+                       return self::$static_users[$numeric];
                }
                return NULL;
        }
@@ -55,8 +43,13 @@ class P10_User {
                return NULL;
        }
        
+       public static function getAllUsers() {
+               return self::$static_users;
+       }
+       
        
        private $numeric;
+       private $server;
        private $nick;
        private $ident;
        private $host;
@@ -64,7 +57,8 @@ class P10_User {
        private $connect_time;
        private $modes;
        private $realname;
-       private $channels;
+       private $channels = array();
+       private $away = null;
        
        public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
                $this->nick = $nick;
@@ -84,6 +78,10 @@ class P10_User {
                return $this->numeric;
        }
        
+       public function getServer() {
+               return $this->server;
+       }
+       
        public function setNick($nick) {
                $this->nick = $nick;
        }
@@ -120,8 +118,21 @@ class P10_User {
                return $this->realname;
        }
        
+       public function setAway($away) {
+               $this->away = $away;
+       }
+       
+       public function getAway() {
+               return $this->away;
+       }
+       
+       public function isAway() {
+               return ($this->away != null);
+       }
+       
        public function quit($reason) {
                $this->server->delUser($this);
+               unset(self::$static_users[$this->numeric]);
                foreach($this->channels as $channel) {
                        $channel->quitUser($this);
                }
@@ -138,6 +149,18 @@ class P10_User {
                        trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING);
                }
        }
+       
+       public function getChannels() {
+               return $this->channels;
+       }
+       
+       public function getChannelCount() {
+               return count($this->channels);
+       }
+       
+       public function isOnChannel($channel) {
+               return array_key_exists(strtolower($channel->getName()),$this->channels);
+       }
 }
 
 ?>
\ No newline at end of file