2 /********************************* PHP-P10 ******************************
3 * P10 uplink class by pk910 (c)2011 pk910 *
4 ************************************************************************
7 * PHP-P10 is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with PHP-P10; if not, write to the Free Software Foundation, *
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 ************************************************************************
23 * Uplink/P10_Server.class.php
25 * This class represents a IRC Server
27 ************************************************************************
30 * static P10_Server getServerByNum(String $numeric)
31 * searches and returns the Server with the provided Numeric
33 * __construct(String $name, String $numeric, P10_Server $parent_server, int $start_time, $link_time, $description)
34 * *** nothing to say here ***
36 * void disconnectServer(bool $linked_only = false)
37 * DISCONNECT EVENT (if $linked_only is true, only the Servers connected to the actual Server get disconnected.)
40 * returns the Numeric of the Server
43 * returns the Name of the Server
45 * String getStartTime()
46 * returns the startup time of the Server
48 * String getLinkTime()
49 * returns the link time of the Server
51 * String getDescription()
52 * returns the Description of the Server
54 * void addServer(P10_Server $server)
55 * adds a Server to the server's "slave" list
57 * void delServer(P10_Server $server)
58 * removes a Server to the server's "slave" list
62 private static $static_servers = array();
64 public static getServerByNum($numeric) {
65 if(array_key_exists($numeric, self::$static_servers)) {
66 return self::$static_servers[$numeric];
74 private $parent_server;
78 private $servers = array(); //all Servers connected to this Server
79 private $users = array(); //all Users connected to this Server
81 public function __construct($name, $numeric, $parent_server, $start_time, $link_time, $description) {
83 $this->numeric = $numeric;
84 $this->parent_server = $parent_server;
85 $this->start_time = $start_time;
86 $this->link_time = $link_time;
87 $this->description = $description;
89 self::$static_servers[$numeric] = $this;
92 public function disconnectServer($linked_only = false) {
94 if($this->parent_server) {
95 $this->parent_server->delServer($this);
97 $this->disconnectUsers();
98 unset(self::$static_servers[$this->numeric]);
100 foreach($this->servers as $server) {
101 $server->disconnectServer();
105 public function disconnectUsers() {
106 //disconnect all Users connected to the actual Server
107 foreach($this->users as $user) {
108 $user->quit("*.net *.split");
112 public function getNumeric() {
113 return $this->numeric;
116 public function getName() {
120 public function getStartTime() {
121 return $this->start_time;
124 public function getLinkTime() {
125 return $this->link_time;
128 public function getDescription() {
129 return $this->description;
132 public function addServer($server) {
133 $this->servers[$server->getNumeric()] = $server;
136 public function delServer($server) {
137 if(array_key_exists($server->getNumeric(), $this->servers)) {
138 unset($this->servers[$server->getNumeric()]);
140 trigger_error("Tried to remove a Server, that does NOT exist.", E_USER_WARNING);
144 public function addUser($user) {
145 $this->users[$user->getNumeric()] = $user;
148 public function delUser($user) {
149 if(array_key_exists($user->getNumeric(), $this->users)) {
150 unset($this->users[$user->getNumeric()]);
152 trigger_error("Tried to remove a User, that does NOT exist.", E_USER_WARNING);