-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
80 lines (62 loc) · 2.15 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/************************************************************
* icarus v1.0-beta -- an IRC framework for PHP *
* Author: rintaun - Matthew J. Lanigan <[email protected]> *
* *
* Copyright 2011 Matthew J. Lanigan. *
* See LICENSE file for licensing restrictions *
************************************************************/
if (!defined('_ICARUS_')) die('This script may not be invoked directly.' . "\n");
abstract class Client extends EventHandler {
private $sid = "";
private $config;
public $modules = array();
final public function __construct($name, $config)
{
$this->config = $config;
if ((!isset($config['server'])) || (!isset($config['port'])))
_die("Client %s: Didnt get a server or port value!", $name);
$SH = SocketHandler::getInstance();
$this->sid = $SH->createSocket($config['server'], $config['port'], $this);
$this->loadModules();
$this->_create($name, $config);
}
final public function __destruct()
{
$this->_destroy();
}
public function loadModules()
{
if ((isset($this->config['module'])) && (is_array($this->config['module'])))
foreach ($this->config['module'] AS $key => $entry)
{
$keyinfo = explode(":", $key);
$type = 'Module_' . $keyinfo[0];
$name = (isset($keyinfo[1])) ? $keyinfo[1] : "";
if (file_exists($GLOBALS['modulesdir'] . $type . '.php'))
{
require_once($GLOBALS['modulesdir'] . $type . '.php');
$this->modules[] = new $type($this, $name, $this->config['module'][$key]);
}
else
_log(L_WARNING, '%s: could not find %s', get_called_class(), $type);
}
}
public function read($sid, $data)
{
// $sid is, admittedly, pretty irrelevant at the moment,
// but it could come in handy later.
$this->parse($data);
}
public function write($format)
{
if (strlen($format) == 0) return;
$SH = SocketHandler::getInstance();
$args = func_get_args();
array_unshift($args, $this->sid);
call_user_func_array(array($SH, 'send'), $args);
}
abstract function parse($data);
abstract function _create($name, $config);
abstract function _destroy();
}