require_once("P10_User.class.php");
require_once("P10_Channel.class.php");
require_once("P10_ModeSets.class.php");
+require_once("EventHandler.interface.php");
class Uplink {
private $client;
private $settings = array();
private $server;
+ private $eventHandler = null;
const FLAG_P10SESSION = 0x0001; //connection is in P10 mode (server is connected)
const FLAG_SECURITY_QUIT = 0x0002; //local connection abort because of security issues
if(!$this->client->connected()) {
if(($this->flags & self::FLAG_P10SESSION)) {
//Server got disconnected
- $this->server->disconnectServer(true);
+ $this->server->disconnectServer($this->eventHandler, true);
$this->flags &= ~self::FLAG_P10SESSION;
}
$host = $this->getSetting("host");
$this->setSetting("their_password", $password);
}
+ public function setEventHandler($event_handler) {
+ if(!is_a($event_handler, "EventHandler")) {
+ trigger_error((is_object($event_handler) ? get_class($event_handler) : gettype($event_handler))." is NOT a valid EventHandler.", E_USER_ERROR);
+ return;
+ }
+ $this->eventHandler = $event_handler;
+ }
+
private function setSetting($setting, $value) {
$this->settings[$setting] = $value;
}
case "B":
$this->recv_burst($from, $arguments);
break;
+ case "J":
+ case "C":
+ $this->recv_join($from, $arguments);
+ break;
+ case "L":
+ $this->recv_part($from, $arguments);
+ break;
//default
default:
//unknown cmd
$new_server = new P10_Server($args[0], substr($args[5],0,2), $this->server, $args[2], $args[3], $args[7]);
$this->server->addServer($new_server);
$this->flags |= self::FLAG_P10SESSION | self::FLAG_BURST_PENDING;
+ if($this->eventHandler)
+ $this->eventHandler->event_server($new_server, !($this->flags & self::FLAG_CONNECTED));
} else {
//another server got a new slave server ^^
$server = P10_Server::getServerByNum($from);
}
$new_server = new P10_Server($args[0], substr($args[5],0,2), $server, $args[2], $args[3], $args[7]);
$server->addServer($new_server);
+ if($this->eventHandler)
+ $this->eventHandler->event_server($new_server, !($this->flags & self::FLAG_CONNECTED));
}
}
trigger_error("Server tries to change the nick of an user that does not exist or was not found on recv_nick.", E_USER_ERROR);
return;
}
- $nick->setNick($args[0]);
+ if($this->eventHandler)
+ $this->eventHandler->event_nick($user, $args[0]);
+ $user->setNick($args[0]);
} else {
//New User
$numeric = $args[count($args)-2];
$modes = new P10_UserModeSet($modes);
$ip = Numerics::parseIP($args[count($args)-3]);
$realname = $args[count($args)-1];
- new P10_User($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes);
+ $user = new P10_User($nick, $numeric, $server, $connect_time, $ident, $host, $ip, $realname, $modes);
+ if($this->eventHandler)
+ $this->eventHandler->event_connect($user, !($this->flags & self::FLAG_CONNECTED));
}
}
trigger_error("Server (".$args[0].") not found.", E_USER_ERROR);
return;
}
- $server->disconnectServer();
+ $server->disconnectServer($this->eventHandler);
}
private function recv_quit($from, $args) {
trigger_error("Server tries to quit an user that does not exist or was not found on recv_quit.", E_USER_ERROR);
return;
}
+ if($this->eventHandler)
+ $this->eventHandler->event_quit($user, $args[1]);
$user->quit($args[0]);
}
$channel = P10_Channel::getChannelByName($name);
if($channel == null)
$channel = new P10_Channel($name);
+ $channel->setCreateTime($create_time);
$modes = $channel->getModes();
$userstr = $args[count($args)-1];
$modeparamcount = count($args)-3;
return;
}
$channel->burstUser($user, $isop, $isvoice);
+ if($this->eventHandler)
+ $this->eventHandler->event_join($user, $channel, true);
}
$modes->parseModes(implode(array_slice($args, 2, $modeparamcount)));
}
+ private function recv_join($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to join an user that does not exist or was not found on recv_join.", E_USER_ERROR);
+ return;
+ }
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ $channel->joinUser($user);
+ if($this->eventHandler)
+ $this->eventHandler->event_join($user, $channel, false);
+ }
+
+ private function recv_part($from, $args) {
+ $user = P10_User::getUserByNum($from);
+ if($user == null) {
+ trigger_error("Server tries to part an user that does not exist or was not found on recv_join.", E_USER_ERROR);
+ return;
+ }
+ $channel = P10_Channel::getChannelByName($args[0]);
+ if($channel == null)
+ $channel = new P10_Channel($args[0]);
+ if($this->eventHandler)
+ $this->eventHandler->event_part($user, $channel, $args[1]);
+ $channel->partUser($user);
+ }
+
/********************************************************************************************
* SERVER FUNCTIONS *
********************************************************************************************/