added scripting interfaces (addUser, delUser, join, part, kick, privmsg, notice,...
[PHP-P10.git] / Uplink / P10_User.class.php
index bdc84e3bf157bd2e79430907831a7c782b83fcdc..ac235b140800c4d37c0a4d5177dfa1f3a24df966 100644 (file)
 class P10_User {
        private static $static_users = array();
        
-       public static getUserByNum($numeric) {
-               if(array_key_exists($numeric, self::$static_servers)) {
-                       return self::$static_servers[$numeric];
+       public static function getUserByNum($numeric) {
+               if(array_key_exists($numeric, self::$static_users)) {
+                       return self::$static_users[$numeric];
                }
                return NULL;
        }
        
-       public static getUserByNick($nick) {
+       public static function getUserByNick($nick) {
                $nick = strtolower($nick);
                foreach(self::$static_users as $user) {
                        if(strtolower($user->getNick()) == $nick) {
@@ -57,6 +57,7 @@ class P10_User {
        
        
        private $numeric;
+       private $server;
        private $nick;
        private $ident;
        private $host;
@@ -64,8 +65,9 @@ class P10_User {
        private $connect_time;
        private $modes;
        private $realname;
+       private $channels;
        
-       public __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
+       public function __construct($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes) {
                $this->nick = $nick;
                $this->numeric = $numeric;
                $this->server = $server;
@@ -83,6 +85,10 @@ class P10_User {
                return $this->numeric;
        }
        
+       public function getServer() {
+               return $this->server;
+       }
+       
        public function setNick($nick) {
                $this->nick = $nick;
        }
@@ -121,6 +127,25 @@ class P10_User {
        
        public function quit($reason) {
                $this->server->delUser($this);
+               foreach($this->channels as $channel) {
+                       $channel->quitUser($this);
+               }
+       }
+       
+       public function addChannel($channel) {
+               $this->channels[strtolower($channel->getName())] = $channel;
+       }
+       
+       public function delChannel($channel) {
+               if(array_key_exists(strtolower($channel->getName()), $this->channels)) {
+                       unset($this->channels[strtolower($channel->getName())]);
+               } else {
+                       trigger_error("Tried to remove a Channel, that does NOT exist.", E_USER_WARNING);
+               }
+       }
+       
+       public function isOnChannel($channel) {
+               return array_key_exists(strtolower($channel->getName()),$this->channels);
        }
 }