X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=Uplink%2FP10_Server.class.php;h=465fa3c00d97a830779a26981724ee3dda3f7b2d;hb=e59e78694524537f0bd03782c777cc097b435e3d;hp=1603e4c84722a6455b7187e001a0e254addcab2f;hpb=64245b7638b8ac32229ccc67856b45a6b79afd35;p=PHP-P10.git diff --git a/Uplink/P10_Server.class.php b/Uplink/P10_Server.class.php index 1603e4c..465fa3c 100644 --- a/Uplink/P10_Server.class.php +++ b/Uplink/P10_Server.class.php @@ -55,19 +55,38 @@ * 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; @@ -76,6 +95,7 @@ class P10_Server { private $link_time; private $description; private $servers = array(); //all Servers connected to this Server + private $users = array(); //all Users connected to this Server public function __construct($name, $numeric, $parent_server, $start_time, $link_time, $description) { $this->name = $name; @@ -88,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); } @@ -97,12 +119,15 @@ class P10_Server { unset(self::$static_servers[$this->numeric]); } foreach($this->servers as $server) { - $server->disconnectServer(); + $server->disconnectServer($eventHandler); } } public function disconnectUsers() { //disconnect all Users connected to the actual Server + foreach($this->users as $user) { + $user->quit("*.net *.split"); + } } public function getNumeric() { @@ -136,6 +161,22 @@ class P10_Server { trigger_error("Tried to remove a Server, that does NOT exist.", E_USER_WARNING); } } + + public function addUser($user) { + $this->users[$user->getNumeric()] = $user; + } + + public function delUser($user) { + if(array_key_exists($user->getNumeric(), $this->users)) { + unset($this->users[$user->getNumeric()]); + } else { + 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