/
Icarus.php
126 lines (98 loc) · 2.95 KB
/
Icarus.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/************************************************************
* icarus v1.0-beta -- an IRC framework for PHP *
* Author: rintaun - Matthew J. Lanigan <rintaun@gmail.com> *
* *
* Copyright 2011 Matthew J. Lanigan. *
* See LICENSE file for licensing restrictions *
************************************************************/
declare(ticks=1);
ini_set('memory_limit', '16M');
define('_ICARUS_', TRUE);
$location = __FILE__;
require_once("inc/includes.php");
final class Icarus extends Singleton
{
private $running = FALSE;
private $servers = array();
public $clients = array();
protected function _create()
{
// as soon as we start, we want to initialize Configurator
// and parse the config file. MUST HAVE CONFIGS
Configurator::getInstance();
}
public function start()
{
$c = Configurator::getInstance();
$l = Logger::getInstance();
if (isset($c->config['logfile']))
$l->setLogfile($c->config['logfile']);
if ((!isset($c->config['debugmode'])) || ($c->config['debugmode'] == "false"))
$l->debug(FALSE);
elseif (is_numeric($c->config['debugmode']))
$l->debug($c->config['debugmode']);
elseif ($c->config['debugmode'] == "true")
$l->debug(3);
else
$l->debug(FALSE);
if (isset($c->config['die']))
_die("Icarus: read the config file!");
$this->loadClients();
$this->loadServers();
$this->running = TRUE;
$SH = SocketHandler::getInstance();
$SH->loop();
}
private function loadClients()
{
$c = Configurator::getInstance();
if ((isset($c->config['client'])) && (is_array($c->config['client'])))
foreach ($c->config['client'] AS $key => $entry)
{
$keyinfo = explode(":", $key);
$type = 'Client_' . $keyinfo[0];
$name = (isset($keyinfo[1])) ? $keyinfo[1] : "";
if (file_exists($GLOBALS['clientsdir'] . $type . '.php'))
{
require_once($GLOBALS['clientsdir'] . $type . '.php');
new $type($name, $c->config['client'][$key]);
}
else
_log(L_WARNING, 'Loader: could not find %s', $type);
}
}
private function loadServers()
{
$c = Configurator::getInstance();
if ((isset($c->config['server'])) && (is_array($c->config['server'])))
foreach ($c->config['server'] AS $key => $entry)
{
$keyinfo = explode(":", $key);
$type = 'Server_' . $keyinfo[0];
$name = (isset($keyinfo[1])) ? $keyinfo[1] : "";
if (file_exists($GLOBALS['serversdir'] . $type . '.php'))
{
require_once($GLOBALS['serversdir'] . $type . '.php');
$server = new $type($name, $c->config['client'][$key]);
}
else
_log(L_WARNING, 'Loader: could not find %s', $type);
}
}
public function end()
{
$SH = SocketHandler::getInstance();
$SH->interrupt();
$this->running = FALSE;
}
public function isRunning()
{
return $this->running;
}
protected function _destroy()
{
}
}
// and now we need the core program, heh!
require_once("inc/core.php");