new way for dev
[irbot.git] / main.php
blob63c334666cc44596c4d3a36f19a40eaf379abccf
1 #!/usr/bin/php
2 <?php
3 /**
4 * This file is part of IrBot, irc robot.
5 * Copyright (C) 2007 Bellière Ludovic
7 * This program 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 3 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 this program. If not, see <http://www.gnu.org/licenses/>.
20 * $Id: main.php 28 2008-01-19 17:17:01Z xrogaan $
23 define('BASE_DIR',dirname(__FILE__).'/');
25 require_once('./config.php');
26 require_once('./sources/functions.inc.php');
28 debug(true);
29 //set_error_handler('myErrorHandler');
31 require_once('source/Registry.php');
32 Zend_Registry::registerAutoload();
34 require_once('./sources/main-class.inc.php');
35 require_once('./sources/irc-class.inc.php');
36 require_once('./sources/Plugins.php');
37 require_once('./sources/tick-class.inc.php');
38 require_once('./sources/TextFormat-class.inc.php');
40 echo <<<EOF
42 IrBot Copyright (C) 2007 Bellière Ludovic
43 This program comes with ABSOLUTELY NO WARRANTY;
44 This is free software, and you are welcome to redistribute it
45 under certain conditions; for details see <http://www.gnu.org/licenses/>.
48 EOF;
50 // searching for command line option
51 if (isset($argv[1])) {
52 $i=1;
53 while (isset($argv[$i])) {
54 $val = false;
55 $option = $argv[$i];
56 if (substr_count($option,'=') === 1) {
57 list($option,$val) = explode('=',$option);
60 if (!$val && ($option != '-h' && $option != '--help')) {
61 $i++;
62 $val = $argv[$i];
65 switch ($option) {
66 case '-h':case '--help':
67 echo "
68 ./main.php [options]
70 Options :
71 -s Equivalent to --server=name
72 -p Equivalent to --port=number
73 -c Equivalent to --channel=#name
74 -n Equivalent to --nick=name
75 -i Equivalent to --ip=number
76 -d Equivalent to --domain=HOST
77 -a Equivalent to --password=pwd
78 --server=name
79 IRC server to connect (default: ".IRC_SERVER.")
80 --port=number
81 Port to use (default: ".IRC_PORT.")
82 --channel=#value
83 Channel to join (default: ".IRC_CHANNEL.")
84 --nick=nickname
85 Nick of the bot (default: ".IRC_PSEUDO.")
86 --ip=xxx.xxx.xxx.xxx
87 Local ip (default: ".IRC_IP.")
88 --domain=HOST
89 Local domain (default: ".IRC_DOMAIN.")
90 --password=pwd
91 Server password (default: ".IRC_PASSWORD.")
93 $stop = true;
94 break;
95 case '-s':case '--server':
96 bot::$server = $val;
97 break;
98 case '-p':case '--port':
99 bot::$port = (int) $val;
100 break;
101 case '-c':case '--channel':
102 bot::$channel = $val;
103 break;
104 case '-n':case '--nick':
105 bot::$myBotName = $val;
106 break;
107 case '-i':case '--ip':
108 if (ereg("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}",$val)) {
109 bot::$ip = $val;
110 } else {
111 echo "The ip adress entered is wrong.\nUsing default ip instead : ".IRC_IP."\n";
113 break;
114 case '-d':case '--domain':
115 bot::$domain = $val;
116 break;
117 case '-a':case '--password':
118 bot::$connection_password = $val;
119 break;
120 default:
121 break;
123 $i++;
125 if (isset($stop)) {
126 die();
130 if (!isset(bot::$server)) bot::$server = IRC_SERVER;
131 if (!isset(bot::$port)) bot::$port = (int) IRC_PORT;
132 if (!isset(bot::$channel)) bot::$channel = IRC_CHANNEL;
133 if (!isset(bot::$myBotName)) bot::$myBotName = IRC_PSEUDO;
134 if (!isset(bot::$ip)) bot::$ip = IRC_IP;
135 if (!isset(bot::$domain)) bot::$domain = IRC_DOMAIN;
136 if (!isset(bot::$connection_password)) bot::$connection_password = IRC_PASSWORD;
138 $MainProc = bot::GetInstance();
139 while (1) {
141 // On charge les plugins que l'on souhaite
142 $MainProc->plugins->load_plugin('sample');
143 $MainProc->plugins->load_plugin('jet');
145 // On lance le bot
146 try {
147 $MainProc -> launch();
148 } catch (Exception $e) {
149 switch($e->getCode()) {
150 case 0:
151 echo $e->getMessage()."\n";
152 echo "Process terminating...\n";
153 die("EOL from client\n");
154 break 2;
155 case 1: // SIGHUP restart
156 echo $e->getMessage()."\n";
157 echo "Process restarting ...\n\n";
158 continue 2;
159 case 3: // SIGQUIT
160 die("EOL from user...\n");
161 break 2;