2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
20 * Uplink/P10_Server.class.php
22 * This class represents a IRC Server
27 private static $static_servers = array();
29 public static function getServerByNum($numeric) {
30 if(array_key_exists($numeric, self::$static_servers)) {
31 return self::$static_servers[$numeric];
36 public static function getServerByName($name) {
37 $name = strtolower($name);
38 foreach(self::$static_servers as $server) {
39 if(strtolower($server->getName()) == $name) {
46 public static function getServerCount() {
47 return count(self::$static_servers);
50 public static function getServers() {
51 return self::$static_servers;
57 private $parent_server;
61 private $servers = array(); //all Servers connected to this Server
62 private $users = array(); //all Users connected to this Server
64 public function __construct($name, $numeric, $parent_server, $start_time, $link_time, $description) {
66 $this->numeric = $numeric;
67 $this->parent_server = $parent_server;
68 $this->start_time = $start_time;
69 $this->link_time = $link_time;
70 $this->description = $description;
72 self::$static_servers[$numeric] = $this;
75 public function disconnectServer($eventHandler, $linked_only = false) {
78 $eventHandler->event_squit($this);
79 if($this->parent_server) {
80 $this->parent_server->delServer($this);
82 $this->disconnectUsers();
83 unset(self::$static_servers[$this->numeric]);
85 foreach($this->servers as $server) {
86 $server->disconnectServer($eventHandler);
90 public function disconnectUsers() {
91 //disconnect all Users connected to the actual Server
92 foreach($this->users as $user) {
93 $user->quit("*.net *.split");
97 public function getNumeric() {
98 return $this->numeric;
101 public function getName() {
105 public function getStartTime() {
106 return $this->start_time;
109 public function getLinkTime() {
110 return $this->link_time;
113 public function getDescription() {
114 return $this->description;
117 public function addServer($server) {
118 $this->servers[$server->getNumeric()] = $server;
121 public function delServer($server) {
122 if(array_key_exists($server->getNumeric(), $this->servers)) {
123 unset($this->servers[$server->getNumeric()]);
125 trigger_error("Tried to remove a Server, that does NOT exist.", E_USER_WARNING);
129 public function addUser($user) {
130 $this->users[$user->getNumeric()] = $user;
133 public function delUser($user) {
134 if(array_key_exists($user->getNumeric(), $this->users)) {
135 unset($this->users[$user->getNumeric()]);
137 trigger_error("Tried to remove a User, that does NOT exist.", E_USER_WARNING);
141 public function getUsers() {
145 public function getUserCount() {
146 return count($this->users);