implemented EventHandler
[PHP-P10.git] / Uplink / P10_Server.class.php
index 41bf281d4c58ede41fd3fc2b90b397986a22a737..465fa3c00d97a830779a26981724ee3dda3f7b2d 100644 (file)
  *     adds a Server to the server's "slave" list
  *
  * void delServer(P10_Server $server)
- *     removes a Server to the server's "slave" list
+ *     removes a Server from the server's "slave" list
+ *
+ * void addUser(P10_User $user)
+ *     adds a User to the server's userlist
+ *
+ * void delUser(P10_User $user)
+ *     removes a User from the server's userlist
+ *
+ * P10_User[] getUsers()
+ *     returns the server's userlist
  */
 
 class P10_Server {
        private static $static_servers = array();
        
-       public static getServerByNum($numeric) {
+       public static function getServerByNum($numeric) {
                if(array_key_exists($numeric, self::$static_servers)) {
                        return self::$static_servers[$numeric];
                }
                return NULL;
        }
        
+       public static function getServerByName($name) {
+               $name = strtolower($name);
+               foreach(self::$static_servers as $server) {
+                       if(strtolower($server->getName()) == $name) {
+                               return $server;
+                       }
+               }
+               return NULL;
+       }
+       
        
        private $name;
        private $numeric;
@@ -89,8 +108,10 @@ class P10_Server {
                self::$static_servers[$numeric] = $this;
        }
        
-       public function disconnectServer($linked_only = false) {
+       public function disconnectServer($eventHandler, $linked_only = false) {
                if(!$linked_only) {
+                       if($eventHandler)
+                               $eventHandler->event_squit($this);
                        if($this->parent_server) {
                                $this->parent_server->delServer($this);
                        }
@@ -98,7 +119,7 @@ class P10_Server {
                        unset(self::$static_servers[$this->numeric]);
                }
                foreach($this->servers as $server) {
-                       $server->disconnectServer();
+                       $server->disconnectServer($eventHandler);
                }
        }
        
@@ -152,6 +173,10 @@ class P10_Server {
                        trigger_error("Tried to remove a User, that does NOT exist.", E_USER_WARNING);
                }
        }
+       
+       public function getUsers() {
+               return $this->users;
+       }
 }
 
 ?>
\ No newline at end of file