· 10 years ago · Feb 13, 2016, 12:45 AM
1<?php
2
3/**
4 *
5 * Welcome to the main file of the Q9 Services!
6 * @author Arie - #Arie on QuakeNet!
7 *
8 */
9
10require_once("config.php");
11require_once("db.php");
12
13$db = new dbAbstraction($mysql['type']);
14$db->connect($mysql['user'], $mysql['pass'], $mysql['name']);
15
16$main = new functions($db, $config, $bots);
17
18class functions {
19
20 // Basic connecting parts of this function, plus in the connectServices function have been made by some dude who made the PHP fishbot. Rest is made by #Arie on QuakeNet.
21 public function __construct($db, $config, $bots) {
22 $this->db = $db;
23 $this->config = $config;
24 $this->bots = $bots;
25
26 printf("PID: %s\n",posix_getpid());
27 $this->Socket = @fsockopen($this->config['server'],$this->config['port'],$ErrNr,$ErrStr);
28 if (!$this->Socket) {
29 $tmp = sprintf("\n\nProblems with connecting to %s:%s\nErrorNr.: %s\nErrStr.: %s\n\n",$this->config['server'],$this->config['port'],$ErrNr,$ErrStr);
30 die ($tmp);
31 }
32
33 $Time = time();
34 $tmp = sprintf('PASS :%s',$this->config['password']);
35 $this->SendRaw($tmp,1);
36 $tmp = sprintf('SERVER %s 1 %s %s J10 %s]]] +s :%s',$this->config['cline'],$Time,$Time,$this->config['numeric'],$this->config['servicename']);
37 $this->SendRaw($tmp,1);
38 $this->loadCommands();
39 $this->getAuths();
40 $this->getChanlevs();
41 $this->gethelps();
42 $this->getWelcomes();
43 $tmp = sprintf('%s EB',$this->config['numeric']);
44 $this->SendRaw($tmp,1);
45 $this->Counter =0;
46
47 if ($this->config['debug']) {
48 printf("Bot sended his own information to the server, waiting for respond.\n");
49 @ob_flush();
50 }
51
52 $this->Idle();
53 }
54
55 private function connectServices() {
56 if (is_array($this->bots)) {
57 foreach ($this->bots as $moo => $mrr) {
58 if (empty($this->bots[$moo]['connected'])) {
59 $tmp = sprintf('%s N %s 1 %s %s %s %s B]AAAB %s :%s',$this->config['numeric'],$this->bots[$moo]['nickname'],time(),$this->bots[$moo]['ident'],$this->bots[$moo]['vhost'],$this->bots[$moo]['botmodes'],$this->bots[$moo]['snumeric'],$this->bots[$moo]['servicename']);
60 $this->SendRaw($tmp,1);
61 $this->bots[$moo]['connected'] = true;
62 $modes = explode(" ", $this->bots[$moo]['botmodes']);
63 if ($moo == 'google') $modes[0] = '+orX';
64
65 $auth = $this->bots[$moo]['auth'];
66 $num = $this->bots[$moo]['snumeric'];
67 $this->user[$this->bots[$moo]['snumeric']] = array(
68 'server' => $this->config['servicename'],
69 'nick' => $this->bots[$moo]['nickname'],
70 'numeric' => $this->bots[$moo]['snumeric'],
71 'ctime' => time(),
72 'ident' => $this->bots[$moo]['ident'],
73 'host' => $this->bots[$moo]['vhost'],
74 'modes' => $modes[0],
75 'auth' => $auth,
76 );
77 if ($auth) $this->auth[strtolower($auth)]['users'][] = $num;
78 $this->nick[strtolower($this->bots[$moo]['nickname'])] = $this->bots[$moo]['snumeric'];
79 }
80 }
81 }
82 else print "Some error in the config!";
83 $this->joinChannels();
84 $this->getVersions();
85 }
86
87 private function Idle() {
88 /* Checking the incoming information */
89 while (!feof($this->Socket)) {
90 $this->Get = fgets($this->Socket,512);
91 if (!empty($this->Get)) {
92 $Args = explode(" ",$this->Get);
93 if ($Args[0] == 'SERVER') $this->saveMainServer($Args);
94 $Cmd = trim($Args[1]);
95 switch ($Cmd) {
96 case "EB": /* End of Burst */
97 $this->EA();
98 $this->serverEndB($Args);
99 break;
100 case "SQ":
101 $this->squitServer($Args);
102 break;
103 case "G": /* Ping .. Pong :) */
104 $this->Pong($Args);
105 break;
106 case "B":
107 $this->saveChannels($Args);
108 break;
109 case "S":
110 $this->saveServer($Args);
111 break;
112 case "N":
113 $this->saveUsers($Args);
114 break;
115 case "P":
116 $this->pmParse($Args,$this->Get);
117 break;
118 case "I":
119 $this->invite($Args,$this->Get);
120 break;
121 case "O":
122 $this->noticeParse($Args,$this->Get);
123 break;
124 case "M":
125 $this->modeChange($Args);
126 break;
127 case "OM":
128 $this->modeChange($Args);
129 break;
130 case "CM":
131 $this->clearMode($Args);
132 break;
133 case "J":
134 $this->joinChan($Args);
135 break;
136 case "K":
137 $this->kickUser($Args);
138 break;
139 case "C":
140 $this->createChan($Args);
141 break;
142 case "L":
143 $this->leaveChan($Args);
144 break;
145 case "Q":
146 $this->quitUser($Args);
147 break;
148 case "D":
149 $this->killedUser($Args);
150 break;
151 case "W":
152 $this->sWhois($Args);
153 break;
154 case "AC":
155 $this->authUser($Args);
156 break;
157 }
158 }
159 }
160 }
161
162 public $chan;
163 public $user;
164 public $nick;
165 public $email;
166 public $auth;
167 public $chanlev;
168 public $rchanlev;
169 public $helps;
170 public $server;
171 public $schan;
172 public $pchan;
173 public $lchan;
174 public $versions;
175 public $versionallow;
176 public $authflood;
177 public $command;
178 public $welcome;
179
180 private function saveData($sender) {
181
182 $auth = $this->getAuth($sender);
183
184 if ($auth) {
185
186 if (is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
187
188 print_r($this->server);
189
190 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving chanlevs...', 1);
191 $this->db->query("
192 TRUNCATE TABLE chanlevs
193 ");
194 if (is_array($this->chanlev)) {
195 foreach ($this->chanlev as $moo => $mee) {
196 if (is_array($mee)) {
197 foreach (array_keys($mee) as $key) {
198 $id = $this->auth[strtolower($key)]['id'];
199 if ($id) {
200 $this->db->query("
201 INSERT INTO chanlevs
202 VALUES ('$moo', '$id', '$mee[$key]')
203 ");
204 }
205 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :No id for '.$moo.' - '.$mee[$key], 1);
206 }
207 }
208 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: chanlevs is no array. #2', 1);
209 }
210 }
211 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: chanlevs is no array. #1', 1);
212
213
214 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving helptopics...', 1);
215 $this->db->query("
216 TRUNCATE TABLE helps
217 ");
218 if (is_array($this->helps)) {
219 foreach ($this->helps as $tag => $answer) {
220 $tag = $this->db->escape($tag);
221 $answer = $this->db->escape($answer);
222 if ($tag && $answer) {
223 $this->db->query("
224 INSERT INTO helps
225 VALUES ($tag, $answer)
226 ");
227 }
228 }
229 }
230 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: helps is no array. #1', 1);
231
232 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving welcomes...', 1);
233 $this->db->query("
234 TRUNCATE TABLE welcomes
235 ");
236 if (is_array($this->welcome)) {
237 foreach ($this->welcome as $chan => $moo) {
238 if (is_array($moo)) {
239 foreach (array_keys($moo) as $service) {
240 if ($chan && $moo && $service) {
241 $chan2 = $this->db->escape($chan);
242 $service2 = $this->db->escape($service);
243 $message2 = $this->db->escape($moo[$service]);
244 $this->db->query("
245 INSERT INTO welcomes
246 VALUES ($chan2, $service2, $message2)
247 ");
248 }
249 }
250 }
251 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: welcomes is no array. #2', 1);
252 }
253 }
254 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: welcomes is no array. #1', 1);
255
256 $this->helps[strtolower($row['tag'])] = $row['answer'];
257
258
259 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving auths...', 1);
260 $this->db->query("
261 TRUNCATE TABLE auths
262 ");
263 if (is_array($this->auth)) {
264 foreach ($this->auth as $moo => $mee) {
265 $id = $this->db->escape($mee['id']);
266 if ($mee['password']) $pass = $this->db->escape($mee['password']);
267 else unset($pass);
268 $ctime = $this->db->escape($mee['ctime']);
269 $userflags = $this->db->escape($mee['userflags']);
270 $email = $this->db->escape($mee['email']);
271 if ($mee['name']) $name = $this->db->escape($mee['name']);
272 else unset($name);
273 if ($name && $pass) {
274 $this->db->query("
275 INSERT INTO auths
276 VALUES ($id, $name, $pass, $ctime, $userflags, $email)
277 ");
278 }
279 }
280 }
281 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: auths is no array. #1', 1);
282
283 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving channel information...', 1);
284 $this->db->query("
285 TRUNCATE TABLE channels
286 ");
287 if (is_array($this->schan)) {
288 foreach ($this->schan as $moo => $mee) {
289 $name = $this->db->escape($moo);
290 if (is_array($mee)) {
291 foreach (array_keys($mee) as $key) {
292 $flags = $this->db->escape($this->schan[$moo][$key]['flags']);
293 $topic = $this->db->escape($this->schan[$moo][$key]['topic']);
294 $owner = $this->db->escape($key);
295 $suspended = $this->db->escape($this->schan[$moo][$key]['suspended']);
296 $autolimit = $this->db->escape($this->schan[$moo][$key]['autolimit']);
297 $this->db->query("
298 INSERT INTO channels
299 VALUES ($name, $flags, $topic, $owner, $suspended, $autolimit)
300 ");
301 }
302 }
303 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: channels is no array. #2', 1);
304 }
305 }
306 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: channels is no array. #1', 1);
307
308 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Saving versions...', 1);
309 $this->db->query("
310 TRUNCATE TABLE versions
311 ");
312 if (is_array($this->versions)) {
313 foreach ($this->versions as $moo => $mee) {
314 $ip = $this->db->escape($moo);
315 if (is_array($mee)) {
316 foreach (array_keys($mee) as $key) {
317 $version = $this->db->escape($mee[$key]);
318 $this->db->query("
319 INSERT INTO versions
320 VALUES ($ip, $version)
321 ");
322 }
323 }
324 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: versions is no array. #2', 1);
325 }
326 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Done.', 1);
327 }
328 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Error: versions is no array. #1', 1);
329 }
330 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use save.', 1);
331 }
332 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use save.', 1);
333 }
334
335 private function sWhois($argz) {
336 foreach ($argz as $arg) {
337 $args[] = trim($arg);
338 }
339
340 $sender = $args[0];
341 $bot = $this->botToName(str_replace(':', '', $args[3]));
342 $bot = $this->numtoBot($bot);
343 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :More information about me can be found at www.netirc.eu.', 1);
344 }
345
346 private function authUser($argz) {
347 foreach ($argz as $arg) {
348 $args[] = trim($arg);
349 }
350
351 // if the user is authed in a bugged way.. (like by old Qnet Q version ;-))
352 if (is_numeric(strpos($args[3], ':'))) {
353 for ($i = 0; $i <= strlen($args[3]); $i++) {
354 $cur = $args[3]{$i};
355 if ($cur == ':') break;
356 else $auth .= $cur;
357 }
358 }
359 else $auth = $args[3];
360
361 $this->user[$args[2]]['auth'] = $auth;
362
363 $auth = strtolower($auth);
364
365 $this->auth[$auth]['users'][] = $args[2];
366
367 if (is_array($this->rchanlev[$auth])) {
368 foreach ($this->rchanlev[$auth] as $chan => $flags) {
369 $curc = $flags;
370 if ($curc) {
371 if (is_numeric(strpos($curc, 'a'))) {
372 if (is_numeric(strpos($curc, 'o'))) {
373 if ($this->user[$args[2]]['channels'][$chan] == 'voiced') {
374 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +o '.$args[2], 1);
375 $this->setStatus($args[2], $chan, 'opvoiced');
376 }
377 elseif ($this->user[$args[2]]['channels'][$chan] == 'regged') {
378 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +o '.$args[2], 1);
379 $this->setStatus($args[2], $chan, 'opped');
380 }
381 }
382 elseif (is_numeric(strpos($curc, 'v'))) {
383 if ($this->user[$args[2]]['channels'][$chan] == 'regged') {
384 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +v '.$args[2], 1);
385 $this->setStatus($args[2], $chan, 'voiced');
386 }
387 }
388 }
389 if (is_numeric(strpos($curc, 'i')))
390 $this->SendRaw($this->bots['c']['snumeric'].' I '.$this->user[$args[2]]['nick'].' '.$chan, 1);
391 }
392 }
393 }
394 }
395
396 private function inviteuser($argz) {
397 foreach ($argz as $arg) {
398 $args[] = trim($arg);
399 }
400 $sender = $args[0];
401 $channel = strtolower($args[4]);
402 $auth = $this->getAuth($sender);
403 if ($auth) {
404 if ($channel) {
405 $curc = $this->chanlev[$channel][$auth];
406 if (is_numeric(strpos($curc, 'i')) || is_numeric(strpos($curc, 'o')) || is_numeric(strpos($curc, 'm')) || is_numeric(strpos($curc, 'n')) ) {
407 $this->SendRaw($this->bots['c']['snumeric'].' I '.$this->user[$sender]['nick'].' '.$channel, 1);
408 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
409 }
410 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$channel.' to use invite.', 1);
411 }
412 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' invite <#channel>', 1);
413 }
414 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :invite is only available to authed users.', 1);
415 }
416
417 private function getAuthsOfEmail($email) {
418 if (is_array($this->email[$email])) {
419 foreach ($this->email[$email] as $auth) {
420 $ret .=
421'Auth: '.$auth.'
422Password: '.$this->auth[strtolower($auth)]['password']."\n";
423 }
424 return $ret;
425 }
426 }
427
428 private function reqpasswd($argz) {
429 foreach ($argz as $arg) {
430 $args[] = trim($arg);
431 }
432
433 $sender = $args[0];
434 $email = strtolower($args[4]);
435
436 if ($email) {
437 if ($this->email[$email]) {
438 $bericht =
439'Hello '.$email.',
440
441You or someone else requested the username and password for your e-mail adres. You can use the data below to login to '.$this->bots['c']['nickname'].'.
442
443'.$this->getAuthsOfEmail($email).'
444
445This message whas automaticaly generated by '.$this->bots['c']['nickname'].' on '.$this->config['network'].'.';
446 mail($email, 'Your '.$this->bots['c']['nickname'].' password', $bericht, 'From: "GamersINC Services" <Q@Service2.gamersinc.org>');
447 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :An e-mail has been send to '.$email.'.', 1);
448 }
449 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :That e-mail adres is not matching any auth.', 1);
450 }
451 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' requestpassword user@mymailhost.xx', 1);
452 }
453
454 private function op($argz) {
455 foreach ($argz as $arg) {
456 $args[] = trim($arg);
457 }
458
459 $sender = $args[0];
460 $channel = strtolower($args[4]);
461 $auth = $this->getAuth($sender);
462
463 if (trim($args[5])) {
464 $moo = 'moo';
465 unset($args[0]);
466 unset($args[1]);
467 unset($args[2]);
468 unset($args[3]);
469 unset($args[4]);
470 }
471
472 if ($auth) {
473 if ($channel) {
474 if ($this->chanlev[$channel]) {
475 $curc = $this->chanlev[$channel][$auth];
476 if ($moo == 'moo') {
477 if ((is_numeric(strpos($curc, 'm')) || is_numeric(strpos($curc, 'n'))) || (is_numeric(strpos($this->getAuthlevel($auth), 'd')))) {
478 foreach ($args as $nick) {
479 $user = $this->nick[strtolower($nick)];
480 if ($this->chan[$channel]['users'][$user]) {
481 if ($this->user[$user]['channels'][$channel] == 'voiced') {
482 $this->setStatus($user, $channel, 'opvoiced');
483 $opnicks[] = $user;
484 }
485 elseif ($this->user[$user]['channels'][$channel] == 'regged') {
486 $this->setStatus($user, $channel, 'opped');
487 $opnicks[] = $user;
488 }
489 }
490 }
491 if ($opnicks) {
492 $count = count($opnicks);
493 for ($i = 0,$y = 0; $i <= $count; $i++) {
494 $som = $i / 6;
495 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
496 for ($x = 0; $x <= 5; $x++)
497 unset($opnicks[$x]);
498 $y++;
499 }
500 $nicks2op[$y] .= ' '.$opnicks[$i];
501 }
502 foreach ($nicks2op as $oprow) {
503 $moo = explode(' ', $oprow);
504 $count = count($moo);
505 for ($i = 0; $i <= $count; $i++) {
506 $oc .= 'o';
507 }
508 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +'.$oc.' '.trim($oprow), 1);
509 unset($oc);
510 }
511 }
512 else {
513 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :No nick\'s to op. (Already opped or not in the channel)', 1);
514 return;
515 }
516
517 }
518 }
519
520 elseif (is_numeric(strpos($curc, 'o')) || is_numeric(strpos($curc, 'm')) || is_numeric(strpos($curc, 'n')) || is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
521 if ($this->user[$sender]['channels'][$channel] == 'voiced') {
522 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +o '.$sender, 1);
523 $this->setStatus($sender, $channel, 'opvoiced');
524 }
525 elseif ($this->user[$sender]['channels'][$channel] == 'regged') {
526 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +o '.$sender, 1);
527 $this->setStatus($sender, $channel, 'opped');
528 }
529 }
530 else {
531 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$channel.' to use op.', 1);
532 return;
533 }
534 }
535 else {
536 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$channel.' is unknown or suspended.', 1);
537 return;
538 }
539 }
540
541 else {
542 if (is_array($this->auth[$auth]['channels'])) {
543 foreach ($this->auth[$auth]['channels'] as $chan => $flags) {
544 if ($this->user[$sender]['channels'][$chan]) {
545 if (is_numeric(strpos($flags, 'o')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($flags, 'n'))) {
546 if ($this->user[$sender]['channels'][$chan] == 'voiced') {
547 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +o '.$sender, 1);
548 $this->setStatus($sender, $chan, 'opvoiced');
549 }
550 elseif ($this->user[$sender]['channels'][$chan] == 'regged') {
551 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +o '.$sender, 1);
552 $this->setStatus($sender, $chan, 'opped');
553 }
554 }
555 }
556 }
557 }
558 }
559 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
560 }
561 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :op is only available to authed users.', 1);
562 }
563
564 private function voice($argz) {
565 foreach ($argz as $arg) {
566 $args[] = trim($arg);
567 }
568
569 $sender = $args[0];
570 $channel = strtolower($args[4]);
571 $auth = $this->getAuth($sender);
572
573 if (trim($args[5])) {
574 $moo = 'moo';
575 unset($args[0]);
576 unset($args[1]);
577 unset($args[2]);
578 unset($args[3]);
579 unset($args[4]);
580 }
581
582 if ($auth) {
583 if ($channel) {
584 if ($this->chanlev[$channel]) {
585 $curc = $this->chanlev[$channel][$auth];
586 if ($moo == 'moo') {
587 if ((is_numeric(strpos($curc, 'm')) || is_numeric(strpos($curc, 'n'))) || (is_numeric(strpos($this->getAuthlevel($auth), 'd')))) {
588 foreach ($args as $nick) {
589 $user = $this->nick[strtolower($nick)];
590 if ($this->chan[$channel]['users'][$user]) {
591 if ($this->user[$user]['channels'][$channel] == 'opped') {
592 $this->setStatus($user, $channel, 'opvoiced');
593 $opnicks[] = $user;
594 }
595 elseif ($this->user[$user]['channels'][$channel] == 'regged') {
596 $this->setStatus($user, $channel, 'voiced');
597 $opnicks[] = $user;
598 }
599 }
600 }
601 if ($opnicks) {
602 $count = count($opnicks);
603 for ($i = 0,$y = 0; $i <= $count; $i++) {
604 $som = $i / 6;
605 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
606 for ($x = 0; $x <= 5; $x++)
607 unset($opnicks[$x]);
608 $y++;
609 }
610 $nicks2op[$y] .= ' '.$opnicks[$i];
611 }
612 foreach ($nicks2op as $oprow) {
613 $moo = explode(' ', $oprow);
614 $count = count($moo);
615 for ($i = 0; $i <= $count; $i++) {
616 $oc .= 'v';
617 }
618 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +'.$oc.' '.trim($oprow), 1);
619 unset($oc);
620 }
621 }
622 else {
623 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :No nick\'s to voice (Already voiced or not in the channel).', 1);
624 return;
625 }
626
627 }
628 }
629
630 elseif (is_numeric(strpos($curc, 'o')) || is_numeric(strpos($curc, 'v')) || is_numeric(strpos($curc, 'm')) || is_numeric(strpos($curc, 'n')) || is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
631 if ($this->user[$sender]['channels'][$channel] == 'opped') {
632 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +v '.$sender, 1);
633 $this->setStatus($sender, $channel, 'opvoiced');
634 }
635 elseif ($this->user[$sender]['channels'][$channel] == 'regged') {
636 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +v '.$sender, 1);
637 $this->setStatus($sender, $channel, 'voiced');
638 }
639 }
640 else {
641 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$channel.' to use voice.', 1);
642 return;
643 }
644 }
645 else {
646 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$channel.' is unknown or suspended.', 1);
647 return;
648 }
649 }
650
651 else {
652 foreach ($this->auth[$auth]['channels'] as $chan => $flags) {
653 if ($this->user[$sender]['channels'][$chan]) {
654 if (is_numeric(strpos($flags, 'v') || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($flags, 'n')))) {
655 if ($this->user[$sender]['channels'][$chan] == 'opped') {
656 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +v '.$sender, 1);
657 $this->setStatus($sender, $chan, 'opvoiced');
658 }
659 elseif ($this->user[$sender]['channels'][$chan] == 'regged') {
660 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +v '.$sender, 1);
661 $this->setStatus($sender, $chan, 'voiced');
662 }
663 }
664 }
665 }
666 }
667 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
668 }
669 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :op is only available to authed users.', 1);
670 }
671
672
673 private function setWelcome($argz) {
674 foreach ($argz as $arg) {
675 $args[] = trim($arg);
676 }
677
678 $sender = $args[0];
679 $chan = strtolower($args[4]);
680 $user = strtolower($args[5]);
681 for ($i = 1; $i <= strlen($args[3]); $i++) {
682 $command .= $args[3]{$i};
683 }
684 $auth = $this->getAuth($args[0]);
685
686 if ($auth) {
687 $count = count($args);
688 for ($i = 5; $i <= $count; $i++) {
689 $welcome .= ' '.$args[$i];
690 }
691 $welcome = trim($welcome);
692 if ($chan) {
693
694 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
695 $flags = $this->chanlev[$chan][$auth];
696 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
697 if ($welcome) {
698 $this->welcome[$chan]['c'] = $welcome;
699 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done. Welcome message for '.$chan.': '.$welcome, 1);
700 }
701 else {
702 $bericht = $this->getWelcome($chan, 'c');
703 if ($bericht) $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Welcome message for '.$chan.': '.$bericht, 1);
704 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :No message for '.$chan.'.', 1);
705 }
706 }
707 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use autolimit.', 1);
708 }
709 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
710 }
711 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' welcome <#channel> [message]', 1);
712 }
713 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
714 }
715
716
717 private function autolimit($argz) {
718 foreach ($argz as $arg) {
719 $args[] = trim($arg);
720 }
721
722 $sender = $args[0];
723 $chan = strtolower($args[4]);
724 $user = strtolower($args[5]);
725 for ($i = 1; $i <= strlen($args[3]); $i++) {
726 $command .= $args[3]{$i};
727 }
728 $auth = $this->getAuth($args[0]);
729
730 if ($auth) {
731
732 $setlimit = strtolower($args[5]);
733 if ($chan) {
734
735 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
736 $flags = $this->chanlev[$chan][$auth];
737 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
738 if ($setlimit) {
739 for ($i = 0; $i <= strlen($setlimit); $i++) {
740 $cur = $setlimit{$i};
741 if (is_numeric($cur))
742 $limit .= $cur;
743 }
744 if ($limit > 500) $limit = 500;
745 $this->schan[$chan]['c']['autolimit'] = $limit;
746 if (is_numeric(strpos($this->schan[$chan]['c']['flags'], 'c'))) $this->setLimit($chan);
747 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
748 if ($limit)
749 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Current autolimit setting on '.$chan.': '.$limit, 1);
750 }
751 else {
752 $limit = $this->schan[$chan]['c']['autolimit'];
753 if (!$limit) $limit = 'none';
754 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Current autolimit setting on '.$chan.': '.$limit, 1);
755 }
756 }
757 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use autolimit.', 1);
758 }
759 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
760 }
761 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' autolimit <#channel> [#increase]', 1);
762 }
763 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
764 }
765
766 private function whois($argz) {
767 foreach ($argz as $arg) {
768 $args[] = trim($arg);
769 }
770
771 $sender = $args[0];
772 $user = strtolower($args[4]);
773 for ($i = 1; $i <= strlen($args[3]); $i++) {
774 $command .= $args[3]{$i};
775 }
776 $auth = $this->getAuth($args[0]);
777
778 if ($auth) {
779 if ($user) {
780 if (strpos($user, '#') === 0 && strlen($user) > 1) {
781 $len = strlen($user);
782 for ($i = 1; $i <= $len; $i++)
783 $ruser .= $user{$i};
784 $uauth = $this->auth[$ruser]['name'];
785 }
786 if (!$uauth) $wuser = $this->nick[$user];
787 if ($wuser || $uauth) {
788 if (!$uauth) $uauth = $this->user[$wuser]['auth'];
789 $lauth = strtolower($uauth);
790 if ($lauth) {
791 foreach ($this->auth[$lauth]['users'] as $uzer) {
792 $accusers .= ' '.$this->user[$uzer]['nick'];
793 }
794 $accusers = trim($accusers);
795 if (!$accusers) $accusers = '(none)';
796
797 if (strpos($args[4], '#') === 0) $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :-Information for account '.$uauth.'-----', 1);
798 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :-Information for user '.$user.' (using account '.$uauth.')-----', 1);
799 if ($sender == $wuser || $this->isOper($sender)) {
800 $chanlevs = $this->getComChanlevs($uauth, $uauth);
801 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User ID : '.$this->auth[$lauth]['id'], 1);
802 $this->whoisStaff($sender, $uauth);
803 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User flags : +'.$this->auth[$lauth]['userflags'], 1);
804 if ($accusers) $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Account users : '.$accusers, 1);
805 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User created : '.$this->timetodate($this->auth[$lauth]['ctime']), 1);
806 if ($this->user[$wuser]) $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Last user@host : '.$this->user[$wuser]['ident'].'@'.$this->user[$wuser]['host'], 1);
807 if ($chanlevs) {
808 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel Flags', 1);
809 foreach ($chanlevs as $chan => $status) {
810 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$status, 1);
811 }
812 }
813 }
814 else {
815 $chanlevs = $this->getComChanlevs($uauth, $auth);
816 if ($accusers) $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Account users : '.$accusers, 1);
817 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User created : '.$this->timetodate($this->auth[$lauth]['ctime']), 1);
818 $this->whoisStaff($sender, $uauth);
819 if ($chanlevs) {
820 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel Flags', 1);
821 foreach ($chanlevs as $chan => $status) {
822 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$status, 1);
823 }
824 }
825
826 }
827 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :End of list.', 1);
828 }
829 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
830 }
831 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Unknown user '.$user.'.', 1);
832 }
833 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' whois <user>', 1);
834 }
835 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
836 }
837
838 private function whoisStaff($sender, $uauth) {
839 $level = $this->getAuthlevel($uauth);
840 if (is_numeric(strpos($level, 'a')))
841 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Network Staff : IRC Administrator', 1);
842
843 elseif (is_numeric(strpos($level, 'o')))
844 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Network Staff : IRC Operator', 1);
845
846 elseif (is_numeric(strpos($level, 'h')))
847 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Network Staff : Helper', 1);
848
849 if (is_numeric(strpos($level, 'd')))
850 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Network Staff : Developer', 1);
851 }
852
853 private function getComChanlevs($auth1, $auth2) {
854 $rauth = strtolower($auth1);
855 $rauth2 = strtolower($auth2);
856 $spaces = ' ';
857 foreach ($this->rchanlev[$rauth] as $chan => $flags) {
858 if ($this->chanlev[$chan][$rauth2]) {
859 $cur = substr_replace($spaces, $chan, 1, strlen($chan));
860 $cur .= '+'.$flags;
861 $ret[$chan] = $cur;
862 }
863 }
864 return $ret;
865 }
866
867 private function requestspamscan($argz) {
868 foreach ($argz as $arg) {
869 $args[] = trim($arg);
870 }
871
872 $sender = $args[0];
873 $chan = strtolower($args[4]);
874 $user = strtolower($args[5]);
875 $bot = 'r';
876 for ($i = 1; $i <= strlen($args[3]); $i++) {
877 $command .= $args[3]{$i};
878 }
879 $auth = $this->getAuth($args[0]);
880
881 if (!$this->nick['s']) {
882 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :S is currently offline. Try again later.', 1);
883 return;
884 }
885
886 if ($auth) {
887 if ($chan) {
888 if (!$this->user[$this->nick['s']]['channels'][$chan]) {
889 if ($this->chan[$chan]) {
890 $status = $this->user[$sender]['channels'][$chan];
891 if ($status == 'opped' || $status == 'opvoiced') {
892 if ($this->schan[$chan]['c'] || $this->user[$this->nick['l']]['channels'][$chan]) {
893 $ctime = $this->chan[$chan]['cdate'];
894 $verschil = time() - $ctime;
895 if ($verschil >= 43200) {
896 if (count($this->chan[$chan]['users']) >= 18) {
897 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Requirements met, S added.', 1);
898 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->nick['s'].' :join '.$chan, 1);
899 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->config['debug_channel'].' :Added S to '.$chan, 1);
900 }
901 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not meet the requirements to request S. (see somefaqurl)', 1);
902 }
903 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Your channel is too new. Try again later.', 1);
904 }
905 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :There is no channel service on that channel.', 1);
906 }
907 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You must be op\'d on the channel to request a service.', 1);
908 }
909 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :No such channel.', 1);
910 }
911 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :S is already on that channel.', 1);
912 }
913 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' spamscan <#channel>', 1);
914 }
915 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
916 }
917 private function requestbot($argz) {
918 foreach ($argz as $arg) {
919 $args[] = trim($arg);
920 }
921
922 $sender = $args[0];
923 $chan = strtolower($args[4]);
924 $user = strtolower($args[5]);
925 $bot = 'r';
926 for ($i = 1; $i <= strlen($args[3]); $i++) {
927 $command .= $args[3]{$i};
928 }
929 $auth = $this->getAuth($args[0]);
930
931 if ($auth) {
932 if ($chan) {
933 $susp = $this->schan[$chan]['c']['suspended'];
934 if (!$susp) {
935 if (!$this->schan[$chan]['c']) {
936 if ($this->chan[$chan]) {
937 $status = $this->user[$sender]['channels'][$chan];
938 if ($status == 'opped' || $status == 'opvoiced') {
939 $ctime = $this->chan[$chan]['cdate'];
940 $verschil = time() - $ctime;
941 if ($verschil >= 300) {
942 if (count($this->chan[$chan]['users']) >= 3) {
943 $this->joinService($chan, 'c');
944 $this->chanlev[$chan][$auth] = 'amnov';
945 $this->rchanlev[$auth][$chan] = 'amnov';
946 $this->schan[$chan]['c']['flags'] = 'j';
947 $this->schan[$chan]['c']['moo'] = 'mo';
948 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Requirements met, '.$this->bots['c']['nickname'].' added.', 1);
949 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->nick['l'].' :delchan '.$chan, 1);
950 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->config['debug_channel'].' :Added '.$this->bots['c']['nickname'].' to '.$chan, 1);
951 }
952 elseif (count($this->chan[$chan]['users']) >= 4) {
953 if ($this->user[$this->nick['l']]['channels'][$chan]) {
954 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not meet the requirements to request '.$this->bots['c']['nickname'].' and you have L already. (see somefaqurl)', 1);
955 return;
956 }
957 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->nick['l'].' :addchan '.$chan.' #'.$auth, 1);
958 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Requirements met, L added.', 1);
959 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$this->config['debug_channel'].' :Added L to '.$chan, 1);
960 }
961 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not meet the requirements to request '.$this->bots['c']['nickname'].' or L. (see somefaqurl)', 1);
962 }
963 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Your channel is too new. Try again later.', 1);
964 }
965 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You must be op\'d on the channel to request a service.', 1);
966 }
967 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :No such channel.', 1);
968 }
969 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :'.$this->bots['c']['nickname'].' is already on that channel.', 1);
970 }
971 else {
972 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Error: You are not allowed to request a service to this channel.', 1);
973 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Reason: '.$susp, 1);
974 }
975 }
976 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' requestbot <#channel>', 1);
977 }
978 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
979 }
980
981 private function bandel($argz) {
982 foreach ($argz as $arg) {
983 $args[] = trim($arg);
984 }
985
986 $sender = $args[0];
987 $chan = strtolower($args[4]);
988 $user = strtolower($args[5]);
989 for ($i = 1; $i <= strlen($args[3]); $i++) {
990 $command .= $args[3]{$i};
991 }
992 $auth = $this->getAuth($args[0]);
993
994 if ($auth) {
995
996 $bandel = strtolower($args[5]);
997 if ($chan) {
998
999 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
1000 $flags = $this->chanlev[$chan][$auth];
1001 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
1002 if ($bandel) {
1003 if ($this->chan[$chan]['bans']) {
1004 foreach ($this->chan[$chan]['bans'] as $bnr => $ban) {
1005 if ($ban == $bandel) {
1006 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' -b '.$ban, 1);
1007 unset($this->chan[$chan]['bans'][$bnr]);
1008 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
1009 return;
1010 }
1011 }
1012 }
1013 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Can\'t find ban '.$bandel.' on '.$chan.'.', 1);
1014 }
1015 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' bandel <#channel> <ban>', 1);
1016 }
1017 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use bandel.', 1);
1018 }
1019 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
1020 }
1021 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' bandel <#channel> <ban>', 1);
1022 }
1023 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
1024 }
1025
1026 private function newpass($argz) {
1027 foreach ($argz as $arg) {
1028 $args[] = trim($arg);
1029 }
1030
1031 $sender = $args[0];
1032 $auth = $this->getAuth($args[0]);
1033
1034 $oldpass = $args[4];
1035 $newpass1 = $args[5];
1036 $newpass2 = $args[6];
1037 if ($auth) {
1038 if ($oldpass && $newpass1 && $newpass2) {
1039 if ($oldpass == $this->auth[$auth]['password']) {
1040 if ($newpass1 == $newpass2) {
1041 if (strlen($newpass1) > 2) {
1042 $this->auth[$auth]['password'] = $newpass1;
1043 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done. Password saved.', 1);
1044 }
1045 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :New password to short.', 1);
1046 }
1047 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :New passwords do not match.', 1);
1048 }
1049 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Incorrect password.', 1);
1050 }
1051 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' newpass <oldpassword> <newpassword> <newpassword>', 1);
1052 }
1053 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
1054 }
1055
1056 private function listauths($argz) {
1057 foreach ($argz as $arg) {
1058 $args[] = trim($arg);
1059 }
1060
1061 $sender = $args[0];
1062 if ($this->isOper($sender)) {
1063 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :I have '.count($this->auth).' auths in my database.', 1);
1064 }
1065 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access to use users.', 1);
1066 }
1067
1068 private function banlist($argz) {
1069 foreach ($argz as $arg) {
1070 $args[] = trim($arg);
1071 }
1072
1073 $sender = $args[0];
1074 $chan = strtolower($args[4]);
1075 $user = strtolower($args[5]);
1076 for ($i = 1; $i <= strlen($args[3]); $i++) {
1077 $command .= $args[3]{$i};
1078 }
1079 $auth = $this->getAuth($args[0]);
1080
1081 if ($auth) {
1082
1083 if ($chan) {
1084
1085 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
1086 $flags = $this->chanlev[$chan][$auth];
1087 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
1088 if (count($this->chan[$chan]['bans']) >= 1) {
1089 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Registered bans on '.$chan.':', 1);
1090 $i = 1;
1091 foreach ($this->chan[$chan]['bans'] as $m00 => $test) {
1092 if ($test) {
1093 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :#'.$i.' '.$test, 1);
1094 $i++;
1095 }
1096 }
1097 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :End of list.', 1);
1098 }
1099 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :No bans on '.$chan.'.', 1);
1100 }
1101 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use banlist.', 1);
1102 }
1103 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
1104 }
1105 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' banlist <#channel>', 1);
1106 }
1107 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
1108 }
1109
1110 private function deopall($argz) {
1111 foreach ($argz as $arg) {
1112 $args[] = trim($arg);
1113 }
1114
1115 $sender = $args[0];
1116 $chan = strtolower($args[4]);
1117 $user = strtolower($args[5]);
1118 for ($i = 1; $i <= strlen($args[3]); $i++) {
1119 $command .= $args[3]{$i};
1120 }
1121 $auth = $this->getAuth($args[0]);
1122
1123 if ($auth) {
1124
1125 if ($chan) {
1126
1127 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
1128 $flags = $this->chanlev[$chan][$auth];
1129 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
1130 //$this->deopusers($chan);
1131 }
1132 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use deopall.', 1);
1133 }
1134 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
1135 }
1136 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' deopall <#channel>', 1);
1137 }
1138 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
1139 }
1140
1141 private function banclear($argz) {
1142 foreach ($argz as $arg) {
1143 $args[] = trim($arg);
1144 }
1145
1146 $sender = $args[0];
1147 $chan = strtolower($args[4]);
1148 $user = strtolower($args[5]);
1149 for ($i = 1; $i <= strlen($args[3]); $i++) {
1150 $command .= $args[3]{$i};
1151 }
1152 $auth = $this->getAuth($args[0]);
1153
1154 if ($auth) {
1155
1156 if ($chan) {
1157
1158 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
1159 $flags = $this->chanlev[$chan][$auth];
1160 if (is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
1161 if (!$limit) $limit = 'none';
1162 $this->SendRaw($this->config['numeric'].' CM '.$chan.' b', 1);
1163 $count = count($this->chan[$chan]['bans']);
1164 unset($this->chan[$chan]['bans']);
1165 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$count.' bans removed from channel.', 1);
1166 }
1167 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use banclear.', 1);
1168 }
1169 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
1170 }
1171 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' banclear <#channel>', 1);
1172 }
1173 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
1174 }
1175
1176
1177 private function serverEndB($argz) {
1178 foreach ($argz as $arg) {
1179 $args[] = trim($arg);
1180 }
1181 //print_r($args);
1182
1183 foreach ($this->server as $server => $moo) {
1184 if ($server == $args[0]) {
1185 $this->connectServices();
1186 if (is_array($moo)){
1187 foreach (array_keys($moo) as $key) {
1188 $this->server[$server][$key]['eb'] = 'eb';
1189 }
1190 }
1191 }
1192 else {
1193 foreach (array_keys($moo) as $key) {
1194 if ($key == $args[0])
1195 $this->server[$server][$key]['eb'] = 'eb';
1196 }
1197 }
1198 }
1199 }
1200
1201 private function squitServer($argz) {
1202 foreach ($argz as $arg) {
1203 $args[] = trim($arg);
1204 }
1205
1206 foreach ($this->server as $server => $moo) {
1207 if (is_array($moo)){
1208 foreach (array_keys($moo) as $key) {
1209 if ($this->server[$server][$key]['name'] == $args[2]) {
1210 $i = 0;
1211 foreach ($this->user as $user => $info) {
1212 if ($this->user[$user]['server'] == $key) {
1213 //$this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :User: '.$this->user[$user]['nick'].' ('.$user.')', 1);
1214 unset($this->nick[strtolower($this->user[$user]['nick'])]);
1215 $this->removeUserChannels($user);
1216 unset($this->user[$user]);
1217 $i++;
1218 }
1219 }
1220 if ($i) $xtra = ' ['.$i.'] users gone.';
1221 $this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :server ['.$this->server[$server][$key]['name'].'] squitted.'.$xtra, 1);
1222
1223 $totaal += $i;
1224
1225 if (is_array($this->server[$key])) {
1226 print_r($this->server[$key]);
1227 $i = 0;
1228 foreach (array_keys($this->server[$key]) as $snum) {
1229 foreach ($this->user as $user => $info) {
1230 if ($this->user[$user]['server'] == $snum) {
1231 $this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :User: '.$this->user[$user]['nick'].' ('.$user.')', 1);
1232 unset($this->nick[strtolower($this->user[$user]['nick'])]);
1233 $this->removeUserChannels($user);
1234 unset($this->user[$user]);
1235 $i++;
1236 }
1237 }
1238 $totaal += $i;
1239 if ($i) $xtra = ' ['.$i.'] users gone.';
1240 if ($totaal > $i) $xtra = ' ['.$i.'] users gone, total: '.$totaal;
1241 $this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :server ['.$this->server[$server][$key]['name'].'] squitted.'.$xtra, 1);
1242 }
1243 }
1244 }
1245 }
1246 }
1247 }
1248 }
1249 private function saveServer($argz) {
1250 foreach ($argz as $arg) {
1251 $args[] = trim($arg);
1252 }
1253
1254 $snum = $args[0];
1255 $name = $args[2];
1256 $hop = $args[3];
1257 $start = $args[4];
1258 $link = $args[5];
1259 $prot = $args[6];
1260 $num = $args[7];
1261 $mode = $args[8];
1262
1263 for ($i = 0; $i <= 1; $i++) {
1264 $ownnum .= $args[7]{$i};
1265 }
1266
1267 unset($args[0]);
1268 unset($args[1]);
1269 unset($args[2]);
1270 unset($args[3]);
1271 unset($args[4]);
1272 unset($args[5]);
1273 unset($args[6]);
1274 unset($args[7]);
1275 unset($args[8]);
1276
1277 foreach ($args as $arg) {
1278 $dec .= ' '.$arg;
1279 }
1280 $dec = trim($dec);
1281 for ($i = 1; $i <= strlen($dec); $i++) {
1282 $descr .= $dec{$i};
1283 }
1284
1285 if (!$snum) $snum = $ownnum;
1286
1287 $this->server[$snum][$ownnum] = array(
1288 'name' => $name,
1289 'hop' => $hop,
1290 'start' => $start,
1291 'link' => $link,
1292 'prot' => $prot,
1293 'num' => $num,
1294 'mode' => $mode,
1295 'descr' => $descr
1296 );
1297 }
1298
1299 private function saveMainServer($argz) {
1300
1301 foreach ($argz as $arg) {
1302 $args[] = trim($arg);
1303 }
1304
1305 for ($i = 0; $i <= 1; $i++) {
1306 $tot .= $args[6]{$i};
1307 }
1308
1309 $argb[0] = $tot;
1310 $argb[1] = 'S';
1311
1312 $i = 0;
1313 foreach ($args as $arg) {
1314 $o = $i - 1;
1315 $argb[$i] = $args[$o];
1316 $i++;
1317 }
1318 $argb[11] = $args[10];
1319
1320 $this->saveServer($argb);
1321 }
1322
1323 private function quitUser($argz) {
1324 foreach ($argz as $arg) {
1325 $args[] = trim($arg);
1326 }
1327
1328 $this->removeUserChannels($args[0]);
1329
1330 $nick = $args[0];
1331 unset($args[0]);
1332 unset($args[1]);
1333 foreach ($args as $arg) {
1334 $reason .= ' '.$arg;
1335 }
1336 $reason = trim($reason);
1337 for ($i = 1; $i <= strlen($reason); $i++) {
1338 $treason .= $reason{$i};
1339 }
1340
1341 $this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :user ['.$this->user[$nick]['nick'].'] has quitted ['.$treason.']', 1);
1342 unset($this->user[$nick]['nick']);
1343 $this->removeUserChannels($nick);
1344 unset($this->user[$nick]);
1345 }
1346
1347 private function killedUser($argz) {
1348 foreach ($argz as $arg) {
1349 $args[] = trim($arg);
1350 }
1351
1352 foreach ($this->bots as $moo => $mrr) {
1353 if ($args[2] == $mrr['snumeric']) {
1354 $this->SendRaw($this->config['numeric'].' P '.$this->config['debug_channel'].' :Service '.$mrr['nickname'].' has been killed by '.$this->user[$args[0]]['nick'].'.. connecting the service aganin.', 1);
1355 $this->bots[$moo]['connected'] = false;
1356 $this->connectServices();
1357 $nvm = true;
1358 }
1359 }
1360 if (!$nvm) {
1361 $nick = $args[0];
1362 $victim = $args[2];
1363
1364 unset($args[0]);
1365 unset($args[1]);
1366 unset($args[2]);
1367 unset($args[3]);
1368
1369 foreach ($args as $arg) {
1370 $reason .= ' '.$arg;
1371 }
1372
1373 $tmp = $this->Return_Substrings($reason, '(', ')');
1374 $killreason = ':Killed: ['.$tmp[0].'] by ['.$this->user[$nick]['nick'].']';
1375 $sending[] = $victim;
1376 $sending[] = 'Q';
1377 $sending[] = $killreason;
1378 $this->quitUser($sending);
1379 }
1380
1381 //if ($args[2] == )
1382 }
1383
1384 private function kickUser($argz) {
1385 foreach ($argz as $arg) {
1386 $args[] = trim($arg);
1387 }
1388 $this->removeUserChannels($args[3], $args[2]);
1389
1390 $bot = $this->numtoBot($args[3]);
1391 if ($bot) {
1392 $this->SendRaw($this->bots[$bot]['snumeric'].' L '.$args[2], 0);
1393 if ($bot == 'google') {
1394 $this->leaveService($bot, $args[2]);
1395 unset($this->schan[strtolower($args[2])][$bot]);
1396 return;
1397 }
1398 $this->joinService($args[2], $bot);
1399 }
1400
1401 }
1402
1403 private function joinChan($argz) {
1404 foreach ($argz as $arg) {
1405 $args[] = trim($arg);
1406 }
1407 if (is_numeric(strpos($args[2], ','))) {
1408 $moo = explode(',', $args[2]);
1409 foreach ($moo as $channel) {
1410 $mee[] = $args[0];
1411 $mee[] = $args[1];
1412 $mee[] = $channel;
1413 $mee[] = $args[3];
1414 $this->joinChan2($mee);
1415 unset($mee);
1416 }
1417 }
1418 else $this->joinChan2($argz);
1419 }
1420
1421 private function createChan($argz) {
1422 foreach ($argz as $arg) {
1423 $args[] = trim($arg);
1424 }
1425 if (is_numeric(strpos($args[2], ','))) {
1426 $moo = explode(',', $args[2]);
1427 print_r($moo);
1428 print_r($args[2]);
1429 foreach ($moo as $channel) {
1430 $mee[] = $args[0];
1431 $mee[] = $args[1];
1432 $mee[] = $channel;
1433 $mee[] = $args[3];
1434 $this->createChan2($mee);
1435 unset($mee);
1436 }
1437 }
1438 else $this->createChan2($argz);
1439 }
1440
1441 private function joinChan2($argz) {
1442 foreach ($argz as $arg) {
1443 $args[] = trim($arg);
1444 }
1445 $channel = strtolower($args[2]);
1446 $sender = $args[0];
1447
1448 if ($channel == '0') {
1449 $this->removeUserChannels($args[0]);
1450 unset($this->user[$args[0]]['channels']);
1451 return;
1452 }
1453
1454 if ($this->schan[$channel]['c'] && !isset($this->schan[$channel]['c']['suspended'])) {
1455
1456 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'e'))) {
1457 if ($this->kickMatched($channel, $sender) == true) return;
1458 }
1459
1460
1461 $auth = $this->getAuth($args[0]);
1462 $flags = $this->chanlev[$channel][$auth];
1463 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'k')) && !$flags && !$this->isOper($sender) && !is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
1464
1465 if ($this->user[$args[0]]['auth']) $ban = '*!*@'.$this->user[$args[0]]['auth'].'.'.$this->config['vhost'];
1466 else $ban = '*!'.$this->user[$args[0]]['ident'].'@'.$this->user[$args[0]]['host'];
1467
1468 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +b '.$ban, 1);
1469
1470 $this->chan[$channel]['bans'] [] = $ban;
1471
1472 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$args[0].' :Authorised users only.', 1);
1473 return;
1474 }
1475
1476
1477 if ($flags) {
1478 if (is_numeric(strpos($flags, 'b')) && !$this->isOper($sender) && !is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
1479 $ban = '*!*@'.$this->user[$args[0]]['auth'].'.'.$this->config['vhost'];
1480 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +b '.$ban, 1);
1481 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$args[0].' :Banned.', 1);
1482 $this->chan[$channel]['bans'][] = $ban;
1483 return;
1484 }
1485 elseif (is_numeric(strpos($flags, 'a'))) {
1486 if (is_numeric(strpos($flags, 'o'))) {
1487 $this->setStatus($sender, $channel, 'opped');
1488 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +o '.$args[0], 1);
1489 }
1490 elseif (is_numeric(strpos($flags, 'v'))) {
1491 $this->setStatus($sender, $channel, 'voiced');
1492 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +v '.$args[0], 1);
1493 }
1494 }
1495 }
1496 if (!$this->user[$args[0]]['channels'][$channel]) {
1497 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'v')) && $this->user[$args[0]]['channels'][$channel] != 'opped') {
1498 $this->setStatus($sender, $channel, 'voiced');
1499 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +v '.$args[0], 1);
1500 }
1501 else $this->setStatus($sender, $channel, 'regged');
1502 }
1503 }
1504 else $this->setStatus($sender, $channel, 'regged');
1505
1506
1507 $this->welcomeuser($channel, $sender, 'c');
1508 if ($this->isGchan($channel)) $this->welcomeuser($channel, $sender, 'g');
1509 }
1510
1511 private function welcomeuser($chan, $sender, $service) {
1512 if ($service == 'c') {
1513 if (!$this->schan[$channel][$service]['suspended'] && is_numeric(strpos($this->schan[$chan]['c']['flags'], 'w'))) {
1514 $bericht = $this->welcome[$chan][$service];
1515 if (strlen($bericht) > 0) $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :['.$chan.'] '.$bericht, 1);
1516 }
1517 }
1518 else {
1519 if (!$this->schan[$channel][$service]['suspended'] && $this->schan[$channel][$service]) {
1520 $bericht = $this->welcome[$chan][$service];
1521 if (strlen($bericht) > 0) $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :['.$chan.'] '.$bericht, 1);
1522 }
1523 }
1524 }
1525
1526 private function getWelcome($chan, $service) {
1527 $bericht = $this->welcome[$chan][$service];
1528 if ($bericht) return $bericht;
1529 else return false;
1530 }
1531
1532 private function createChan2($argz) {
1533 foreach ($argz as $arg) {
1534 $args[] = trim($arg);
1535 }
1536
1537 $channel = strtolower($args[2]);
1538
1539 $auth = $this->getAuth($args[0]);
1540 $flags = $this->chanlev[$channel][$auth];
1541
1542 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'k')) && !$flags && !is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
1543 $this->joinService($channel, 'c');
1544 $this->pchan[$channel] = time();
1545
1546
1547 if ($this->user[$args[0]]['auth']) $ban = '*!*@'.$this->user[$args[0]]['auth'].'.'.$this->config['vhost'];
1548 else $ban = '*!'.$this->user[$args[0]]['ident'].'@'.$this->user[$args[0]]['host'];
1549
1550 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +b '.$ban, 1);
1551
1552 $this->chan[$channel]['bans'] [] = $ban;
1553
1554 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$args[0].' :Authorised users only.', 1);
1555 return;
1556 }
1557
1558
1559 if ($flags) {
1560 if (is_numeric(strpos($flags, 'b'))) {
1561 $this->joinService($channel, 'c');
1562 $this->pchan[$channel] = time();
1563
1564 $ban = $this->user[$args[0]]['auth'].'.'.$this->config['vhost'];
1565 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' +b '.$ban, 1);
1566 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$args[0].' :Banned.', 1);
1567 $this->chan[$channel]['bans'][] = $ban;
1568 return;
1569 }
1570 elseif (is_numeric(strpos($flags, 'o')) || is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'm'))) {
1571 $this->setStatus($args[0], $channel, 'opped');
1572 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'j'))) $this->joinService($channel, 'c');
1573 }
1574 elseif (is_numeric(strpos($flags, 'v'))) {
1575 $this->joinService($channel, 'c');
1576 $this->pchan[$channel] = time();
1577
1578 $this->setStatus($args[0], $channel, 'voiced');
1579 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' -o+v '.$args[0].' '.$args[0], 1);
1580 }
1581 }
1582 else {
1583 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'v')) && $this->user[$args[0]]['channels'][$channel] != 'opped') {
1584 $this->joinService($channel, 'c');
1585 $this->pchan[$channel] = time();
1586
1587 $this->setStatus($args[0], $channel, 'voiced');
1588 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' -o+v '.$args[0].' '.$args[0], 1);
1589 }
1590 elseif (!$this->user[$args[0]]['channels'][$channel] && $this->schan[$channel]) {
1591 $this->joinService($channel, 'c');
1592 $this->pchan[$channel] = time();
1593
1594 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' -o '.$args[0], 1);
1595 $this->setStatus($args[0], $channel, 'regged');
1596 }
1597 else $this->setStatus($args[0], $channel, 'opped');
1598 }
1599 $this->chan[$channel]['cdate'] = $args[3];
1600 }
1601
1602 private function modek($channel, $service) {
1603 $numeric = $this->bots[$service]['snumeric'];
1604 if ($this->user[$numeric]['channels'][$channel])
1605 return $this->bots[$service]['snumeric'];
1606 else return $this->config['numeric'];
1607 }
1608
1609 private function leaveChan($argz) {
1610 foreach ($argz as $arg) {
1611 $args[] = trim($arg);
1612 }
1613
1614 $channel = strtolower($args[2]);
1615 if ($this->user[$args[0]]['channels'][$channel]) {
1616 $this->removeUserChannels($args[0], $channel);
1617 unset($this->user[$args[0]]['channels'][$channel]);
1618 }
1619
1620 if (is_array($this->chan[$channel]['users'])) {
1621 foreach ($this->chan[$channel]['users'] as $user => $status) {
1622 if ($status) $moo++;
1623 }
1624 if ($moo < 1) {
1625 unset($this->chan[$channel]);
1626 }
1627 }
1628 else {
1629 unset($this->chan[$channel]);
1630 //print_r($this->chan[$channel]);
1631 //print "\n1: $channel\n";
1632 }
1633 //print "\n2: $channel\n";
1634 }
1635
1636 private function clearMode($argz) {
1637 foreach ($argz as $arg) {
1638 $args[] = trim($arg);
1639 }
1640
1641 $channel = strtolower($args[2]);
1642
1643 for ($i = 0; $i < strlen($args[3]); $i++) {
1644 $cur = $args[3]{$i};
1645 if ($cur == 'o') {
1646 foreach ($this->chan[$channel]['users'] as $user => $status) {
1647 $mayb = $this->numtoBot($user);
1648 $mayb2 = $this->bots[$mayb]['snumeric'];
1649 if ($user == $mayb2) {
1650 $deopusers[] = $mayb2;
1651 $this->setStatus($mayb2, $channel, 'opped');
1652 }
1653 else {
1654 if ($status == 'opped') {
1655 $this->setStatus($user, $channel, 'regged');
1656 }
1657 if ($status == 'opvoiced')
1658 $this->setStatus($user, $channel, 'voiced');
1659 }
1660 }
1661 if (is_array($deopusers)) {
1662 $count = count($deopusers);
1663 for ($a = 0,$y = 0; $a <= $count; $a++) {
1664 $som = $a / 6;
1665 if ($a !== 0 && !is_numeric(strpos($som, '.'))) {
1666 for ($x = 0; $x <= 5; $x++)
1667 unset($deopusers[$x]);
1668 $y++;
1669 }
1670 $nicks2op[$y] .= ' '.$deopusers[$a];
1671 }
1672 foreach ($nicks2op as $oprow) {
1673 $moo = trim($oprow);
1674 $moo = explode(' ', $oprow);
1675 $count = count($moo);
1676 for ($a = 1; $a < $count; $a++) {
1677 $oc .= 'o';
1678 }
1679 $this->SendRaw($this->config['numeric'].' M '.$channel.' +'.$oc.' '.trim($oprow), 1);
1680 unset($oc);
1681 }
1682 }
1683 if (!$this->schan[$channel]['c']['suspended'] && is_numeric(strpos($this->schan[$channel]['c']['flags'], 'p'))) {
1684 $this->opAllC($channel);
1685 }
1686 }
1687 if ($cur == 'v') {
1688 foreach ($this->chan[$channel]['users'] as $user => $status) {
1689 if ($status == 'voiced') {
1690 $this->setStatus($user, $channel, 'regged');
1691 }
1692 if ($status == 'opvoiced')
1693 $this->setStatus($user, $channel, 'opped');
1694 }
1695 }
1696 if ($cur == 'p') {
1697 $this->chan[$channel]['modes'] = str_replace('p', '', $this->chan[$channel]['modes']);
1698 }
1699 if ($cur == 'n') {
1700 $this->chan[$channel]['modes'] = str_replace('n', '', $this->chan[$channel]['modes']);
1701 }
1702 if ($cur == 't') {
1703 $this->chan[$channel]['modes'] = str_replace('t', '', $this->chan[$channel]['modes']);
1704 }
1705 if ($cur == 'r') {
1706 $this->chan[$channel]['modes'] = str_replace('r', '', $this->chan[$channel]['modes']);
1707 }
1708 if ($cur == 'D') {
1709 $this->chan[$channel]['modes'] = str_replace('D', '', $this->chan[$channel]['modes']);
1710 }
1711 if ($cur == 'd') {
1712 $this->chan[$channel]['modes'] = str_replace('d', '', $this->chan[$channel]['modes']);
1713 }
1714 if ($cur == 'c') {
1715 $this->chan[$channel]['modes'] = str_replace('c', '', $this->chan[$channel]['modes']);
1716 }
1717 if ($cur == 'C') {
1718 $this->chan[$channel]['modes'] = str_replace('C', '', $this->chan[$channel]['modes']);
1719 }
1720 if ($cur == 'N') {
1721 $this->chan[$channel]['modes'] = str_replace('N', '', $this->chan[$channel]['modes']);
1722 }
1723 if ($cur == 'u') {
1724 $this->chan[$channel]['modes'] = str_replace('u', '', $this->chan[$channel]['modes']);
1725 }
1726 if ($cur == 's') {
1727 $this->chan[$channel]['modes'] = str_replace('s', '', $this->chan[$channel]['modes']);
1728 }
1729 if ($cur == 'm') {
1730 $this->chan[$channel]['modes'] = str_replace('m', '', $this->chan[$channel]['modes']);
1731 }
1732 if ($cur == 'i') {
1733 $this->chan[$channel]['modes'] = str_replace('i', '', $this->chan[$channel]['modes']);
1734 }
1735 if ($cur == 'k') {
1736 $this->chan[$channel]['modes'] = str_replace('k', '', $this->chan[$channel]['modes']);
1737 $this->chan[$channel]['key'] = '';
1738 }
1739 if ($cur == 'b') {
1740 unset($this->chan[$channel]['bans']);
1741 }
1742 if ($cur == 'l') {
1743 $this->chan[$channel]['modes'] = str_replace('l', '', $this->chan[$channel]['modes']);
1744 $this->chan[$channel]['limit'] = '';
1745 }
1746 }
1747
1748 }
1749
1750 private function setStatus($numeric, $channel, $status) {
1751 //print "n: $numeric | c: $channel | s: $status\n";
1752 $this->chan[$channel]['users'][$numeric] = $status;
1753 $this->user[$numeric]['channels'][$channel] = $status;
1754 }
1755
1756 private function removeUserChannels($numeric, $channel = false) {
1757 if ($channel) {
1758 unset($this->user[$numeric]['channels'][$channel]);
1759 unset($this->chan[$channel]['users'][$numeric]);
1760 $sends[] = $numeric;
1761 $sends[] = 'L';
1762 $sends[] = $channel;
1763 $this->leaveChan($sends);
1764 }
1765 else {
1766 if (is_array($this->user[$numeric]['channels'])) {
1767 foreach ($this->user[$numeric]['channels'] as $chan => $status) {
1768 unset($this->user[$numeric]['channels'][$chan]);
1769 unset($this->chan[$chan]['users'][$numeric]);
1770 $sends[] = $numeric;
1771 $sends[] = 'L';
1772 $sends[] = $chan;
1773 $this->leaveChan($sends);
1774 unset($sends);
1775 }
1776 }
1777 }
1778 }
1779
1780 private function modeChange($argz) {
1781
1782 foreach ($argz as $arg) {
1783 $args[] = trim($arg);
1784 }
1785
1786 $channel = strtolower($args[2]);
1787
1788 if (strpos($channel, '#') === 0) {
1789 $tel = 3;
1790 for ($i = 0; $i <= strlen($args[3]); $i++) {
1791 $cur = $args[3]{$i};
1792 //print "cur: $cur\n";
1793
1794 if ($cur == '-') $mode = $cur;
1795 if ($cur == '+') $mode = $cur;
1796
1797 if ($cur == 'l') {
1798 if ($mode == '+') {
1799 $tel++;
1800 $this->chan[$channel]['limit'] = $args[$tel];
1801 }
1802 elseif ($mode == '-') $this->chan[$channel]['limit'] = '';
1803 }
1804 if ($cur == 'k') {
1805 $tel++;
1806 if ($mode == '+') $this->chan[$channel]['key'] = $args[$tel];
1807 elseif ($mode == '-') $this->chan[$channel]['key'] = '';
1808 }
1809 if ($cur == 'o') {
1810 $tel++;
1811 if ($mode == '+') {
1812 if (!$this->schan[$channel]['c']['suspended'] && !$this->isOper($args[0]) && is_numeric(strpos($this->schan[$channel]['c']['flags'], 'b'))) {
1813 if (!$this->isOper($args[$tel])) {
1814 $auth = $this->user[$args[$tel]]['auth'];
1815 if (!is_numeric(strpos($chanlev, 'o')) || !is_numeric(strpos($chanlev, 'm')) || !is_numeric(strpos($chanlev, 'n'))) {
1816 $dops .= ' '.$args[$tel];
1817 }
1818 }
1819 }
1820 else {
1821 if ($this->user[$args[$tel]]['channels'][$channel] == 'voiced')
1822 $this->setStatus($args[$tel], $channel, 'opvoiced');
1823
1824 else $this->setStatus($args[$tel], $channel, 'opped');
1825 }
1826 }
1827 elseif ($mode == '-') {
1828 foreach ($this->bots as $moo => $mrr) {
1829 if ($this->bots[$moo]['snumeric'] == $args[$tel]) {
1830 $this->SendRaw($this->config['numeric'].' M '.$channel.' +o '.$this->bots[$moo]['snumeric'], 1);
1831 $halt = 'moo';
1832 }
1833 }
1834 if (!$halt) {
1835 if (!$this->schan[$channel]['c']['suspended'] && is_numeric(strpos($this->schan[$channel]['c']['flags'], 'p'))) {
1836 $auth = $this->user[$args[$tel]]['auth'];
1837 $chanlev = $this->chanlev[$channel][strtolower($auth)];
1838 if (is_numeric(strpos($chanlev, 'o')) || is_numeric(strpos($chanlev, 'm')) || is_numeric(strpos($chanlev, 'n'))) {
1839 $ops .= ' '.$args[$tel];
1840 }
1841 else {
1842 if ($this->user[$args[$tel]]['channels'][$channel] == 'opvoiced')
1843 $this->setStatus($args[$tel], $channel, 'voiced');
1844 else $this->setStatus($args[$tel], $channel, 'regged');
1845 }
1846 }
1847 else {
1848 if ($this->user[$args[$tel]]['channels'][$channel] == 'opvoiced')
1849 $this->setStatus($args[$tel], $channel, 'voiced');
1850 else $this->setStatus($args[$tel], $channel, 'regged');
1851 }
1852 }
1853 }
1854 }
1855 if ($cur == 'v') {
1856 $tel++;
1857 if ($mode == '+') {
1858 if ($this->user[$args[$tel]]['channels'][$channel] == 'opped')
1859 $this->setStatus($args[$tel], $channel, 'opvoiced');
1860
1861 else $this->setStatus($args[$tel], $channel, 'voiced');
1862 }
1863 elseif ($mode == '-') {
1864 if (empty($this->user[$args[$tel]]['channels'][$channel]) == 'opped')
1865 $this->setStatus($args[$tel], $channel, 'opped');
1866
1867 else $this->setStatus($args[$tel], $channel, 'regged');
1868 }
1869 }
1870
1871 if ($cur == 'b') {
1872 $tel++;
1873 if ($mode == '+') {
1874 $this->chan[$channel]['bans'][] = $args[$tel];
1875 if (is_numeric(strpos($this->schan[$channel]['c']['flags'], 'e')))
1876 $this->kickBanneds($channel, $args[$tel]);
1877 }
1878
1879 if ($mode == '-') {
1880 foreach ($this->chan[$channel]['bans'] as $m00 => $test) {
1881 if ($test == $args[$tel]) {
1882 unset($this->chan[$channel]['bans'][$m00]);
1883 }
1884 }
1885 }
1886 }
1887 else {
1888 $moden = array('i','m','n','p','s','t','r','D','d','c','C','N','u');
1889
1890 foreach ($moden as $m00 => $moo) {
1891 if ($mode == '-')
1892 if ($moo == $cur) $this->chan[$channel]['modes'] = str_replace($moo, '', $this->chan[$channel]['modes']);
1893
1894 if ($mode == '+')
1895 if ($moo == $cur) $this->chan[$channel]['modes'] .= $moo;
1896 }
1897 }
1898 unset($moo);
1899 }
1900 if ($dops) {
1901 $dops = trim($dops);
1902 $dops2 = explode(' ', $dops);
1903 $aantal = count($dops2);
1904 for ($i = 0; $i < $aantal; $i++) {
1905 $dos .= 'o';
1906 }
1907 }
1908 if ($ops) {
1909 $ops = trim($ops);
1910 $ops2 = explode(' ', $ops);
1911 $aantal = count($ops2);
1912 for ($i = 0; $i < $aantal; $i++) {
1913 $os .= 'o';
1914 }
1915 }
1916 if ($ops || $dops) {
1917 $this->SendRaw($this->modek($channel, 'c').' M '.$channel.' -'.$dos.'+'.$os.' '.$dops.' '.$ops, 1);
1918 unset($dops);
1919 unset($ops);
1920 unset($dos);
1921 unset($os);
1922 }
1923 }
1924
1925 else {
1926
1927 $user = $args[2];
1928 $tel = 3;
1929 $m00 = $this->user[$this->nick[strtolower($user)]];
1930 for ($i = 0; $i <= strlen($args[3]); $i++) {
1931 $cur = $args[3]{$i};
1932
1933 if ($cur == '-') $mode = $cur;
1934 if ($cur == '+') $mode = $cur;
1935
1936 $moden = array('i','o','w','g','k','x','n','I','r','X','R');
1937
1938 foreach ($moden as $m33 => $moo) {
1939 if ($moo == $cur) {
1940 if ($mode == '+')
1941 $this->user[$m00['numeric']]['modes'] .= $cur;
1942
1943 elseif ($mode == '-')
1944 $this->user[$m00['numeric']]['modes'] = str_replace($cur, '', $this->user[$m00['numeric']]['modes']);
1945 }
1946 }
1947 if ($cur == 'h') {
1948 $tel++;
1949 if ($mode == '+') {
1950 $this->user[$m00['numeric']]['sethost'] = $args[$tel];
1951 if (!is_numeric(strpos($this->user[$m00['numeric']]['modes'], 'h')))
1952 $this->user[$m00['numeric']]['modes'] .= $cur;
1953 }
1954 elseif ($mode == '-') {
1955 $this->user[$m00['numeric']]['sethost'] = '';
1956 $this->user[$m00['numeric']]['modes'] = str_replace($cur, '', $this->user[$m00['numeric']]['modes']);
1957 }
1958 }
1959 }
1960 }
1961 }
1962
1963 private function kickBanneds($channel, $ban) {
1964 if ($ban == '*!*@*') return;
1965 $uban = $ban;
1966 $ban = '`'.$ban.'`';
1967 $vat = $this->Return_Substrings($ban, '`', '@');
1968 $vat = $vat[0];
1969 $aat = str_replace($vat, '', $ban);
1970 $aat = str_replace('`', '', $aat);
1971
1972 $vat = $this->banReg($vat);
1973 $aat = $this->banReg($aat);
1974 $vat = '^'.$vat;
1975 foreach ($this->chan[$channel]['users'] as $numeric => $status) {
1976 if (!$this->isOper($numeric)) {
1977 $host = $this->user[$numeric]['host'];
1978 $maa = $this->user[$numeric]['nick'].'!'.$this->user[$numeric]['ident'];
1979
1980
1981 if (eregi($aat,'@'.$host) && eregi($vat,$maa)) {
1982 $victim = true;
1983 }
1984
1985 $shost = $this->user[$numeric]['sethost'];
1986 if ($shost) {
1987 if (eregi($aat,'@'.$shost) && eregi($vat,$maa)) {
1988 $victim = true;
1989 }
1990 }
1991
1992 if ($this->user[$numeric]['auth']) {
1993 $host = $this->user[$numeric]['auth'].'.'.$this->config['vhost'];
1994 if (eregi($aat,'@'.$host) && eregi($vat,$maa)) {
1995 $victim = true;
1996 }
1997 }
1998
1999 if ($victim == true)
2000 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$numeric.' :Banned.', 1);
2001
2002 unset($victim);
2003 }
2004 }
2005 }
2006
2007 private function kickMatched($channel, $numeric) {
2008 if (count($this->chan[$channel]['bans']) >= 1) {
2009 foreach ($this->chan[$channel]['bans'] as $nummer => $ban) {
2010 if ($this->ifbanmatch($ban, $numeric)) {
2011 $this->SendRaw($this->modek($channel, 'c').' K '.$channel.' '.$numeric.' :Banned.', 1);
2012 $nvm = true;
2013 }
2014 }
2015 }
2016 if ($nvm) return true;
2017 else return false;
2018 }
2019
2020 private function banReg($mask) {
2021 $mask = str_replace('[', '\[', $mask);
2022 $mask = str_replace(']', '\]', $mask);
2023 $mask = str_replace('.', '\.', $mask);
2024 $mask = str_replace('?', '.', $mask);
2025 $mask = str_replace(':', '\:', $mask);
2026 $mask = str_replace('^', '\^', $mask);
2027 $mask = str_replace('$', '\$', $mask);
2028 $mask = str_replace('(', '\(', $mask);
2029 $mask = str_replace(')', '\)', $mask);
2030 $mask = str_replace('{', '\{', $mask);
2031 $mask = str_replace('}', '\}', $mask);
2032 $mask = str_replace('*', '(.*)', $mask);
2033 return $mask;
2034 }
2035
2036 private function ifbanmatch($ban, $numeric) {
2037 $uban = $ban;
2038 $ban = '`'.$ban.'`';
2039 $vat = $this->Return_Substrings($ban, '`', '@');
2040 $vat = $vat[0];
2041 $aat = str_replace($vat, '', $ban);
2042 $aat = str_replace('`', '', $aat);
2043
2044 $aat = $this->banReg($aat);
2045 $vat = $this->banReg($vat);
2046
2047 $vat = '^'.$vat;
2048 if (!$this->isOper($numeric)) {
2049 $host = $this->user[$numeric]['host'];
2050 $maa = $this->user[$numeric]['nick'].'!'.$this->user[$numeric]['ident'];
2051 if (eregi($aat,'@'.$host) && eregi($vat,$maa))
2052 $victim = true;
2053
2054 $host = $this->user[$numeric]['sethost'];
2055 if (eregi($aat,'@'.$host) && eregi($vat,$maa))
2056 $victim = true;
2057
2058 print_r($this->user[$numeric]);
2059 if ($this->user[$numeric]['auth']) {
2060 $host = $this->user[$numeric]['auth'].'.'.$this->config['vhost'];
2061 if (eregi($aat,'@'.$host) && eregi($vat,$maa))
2062 $victim = true;
2063 }
2064
2065 if ($victim == true)
2066 return true;
2067 else return false;
2068 }
2069 }
2070
2071 private function noticeParse($argz) {
2072 foreach ($argz as $arg) {
2073 $args[] = trim($arg);
2074 }
2075 if ($args[3] == ':VERSION')
2076 $this->saveVersions($args);
2077 }
2078
2079 private function isGchan($chan) {
2080 if ($this->user[$this->bots['g']['snumeric']]['channels'][$chan]) return true;
2081 return false;
2082 }
2083
2084 private function isGooglechan($chan) {
2085 if ($this->user[$this->bots['google']['snumeric']]['channels'][$chan]) return true;
2086 return false;
2087 }
2088
2089 private function invite($args,$Line) {
2090 if (strtolower($args[2]) == strtolower($this->bots['google']['nickname'])) {
2091 $chan2 = trim($args[3]);
2092 $chan2 = strtolower('#'.$chan2);
2093 for ($i = 1; $i <= strlen($chan2); $i++) {
2094 $chan .= $chan2{$i};
2095 }
2096 $chan = strtolower($chan);
2097 if (!$this->isGooglechan($chan)) {
2098 $this->joinService($chan, 'google');
2099 $argz[] = $this->bots['google']['snumeric'];
2100 $argz[] = 'J';
2101 $argz[] = $chan;
2102 $this->joinChan2($argz);
2103
2104 $this->SendRaw($this->bots['google']['snumeric'].' P '.$chan.' :ACTION googles for '.$this->user[$args[0]]['nick'].'.', 1);
2105 $this->SendRaw($this->bots['google']['snumeric'].' P '.$chan.' :ACTION found '.rand().' results.', 1);
2106 $this->schan[$chan]['google']['moo'] = 'mo';
2107
2108 }
2109 }
2110 }
2111
2112 private function pmParse($args,$Line) {
2113
2114 $msg = explode(":",$Line,2);
2115 $msg = strtolower(trim($msg[1]));
2116
2117 $parts = explode(" ",$msg);
2118
2119 $sender = $args[0];
2120
2121 $snd = trim($parts[1]);
2122 $dnd = trim($parts[2]);
2123
2124 if ($this->isGchan(strtolower($args[2]))) {
2125 $this->helps($args);
2126 }
2127 if ($this->isGooglechan(strtolower($args[2]))) {
2128 $this->google($args);
2129 }
2130
2131 // ms commands
2132 if ($args[2] == $this->bots['ms']['snumeric']) {
2133
2134 if ($msg == 'showcommands') {
2135 $this->showcommands($sender, 'ms');
2136 }
2137
2138 elseif ($msg == 'showchannels') {
2139 $this->showChannels($sender);
2140 }
2141
2142 elseif ($parts[0] == 'channel') {
2143 $this->getChannelinfo($sender, $snd);
2144 }
2145
2146 elseif ($parts[0] == 'save') {
2147 $this->saveData($sender);
2148 }
2149
2150 elseif ($parts[0] == 'whois') {
2151 $this->getUserinfo($sender, $snd);
2152 }
2153 elseif ($parts[0] == 'stats') {
2154 $this->countusers($sender);
2155 }
2156 elseif ($parts[0] == 'userlist') {
2157 $this->userlist($sender);
2158 }
2159 elseif ($parts[0] == 'kickall') {
2160 $this->kickAll($sender, $args);
2161 }
2162 /*elseif ($parts[0] == 'VERSION') {
2163 $this->saveVersions($args);
2164 }*/
2165 else {
2166 if ($parts[0] != 'addchan' && $parts[0] != 'suspend' && $parts[0] != 'unsuspend' && $parts[0] != 'delchan' && $parts[0] != 'banflood' && $parts[0] != 'rejoin' && $parts[0] != 'rejoinall')
2167 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Unknown command.', 1);
2168 }
2169 }
2170 // ms end
2171
2172 if ($parts[0] == 'addchan') {
2173 $this->addChan($args);
2174 }
2175 elseif ($parts[0] == 'banflood') {
2176 $this->banflood($args);
2177 }
2178 elseif ($parts[0] == 'suspend') {
2179 $this->suspendChan($args);
2180 }
2181 elseif ($parts[0] == 'unsuspend') {
2182 $this->unsuspendChan($args);
2183 }
2184 elseif ($parts[0] == 'delchan') {
2185 $this->delChan($args);
2186 }
2187 elseif ($parts[0] == 'rejoin') {
2188 $this->rejoin($args);
2189 }
2190 elseif ($parts[0] == 'rejoinall') {
2191 $this->rejoinall($args);
2192 }
2193
2194 // chanserv commands
2195 if ($args[2] == $this->bots['c']['snumeric']) {
2196 if ($msg == 'showcommands') {
2197 $this->showcommands($sender, 'c');
2198 }
2199 elseif ($parts[0] == 'chanlev') {
2200 $this->changeChanlev($args);
2201 }
2202 elseif ($parts[0] == 'hello') {
2203 //$this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Command disabled.', 1);
2204 //return;
2205 $this->hello($args);
2206 }
2207 elseif ($parts[0] == 'users') {
2208 $this->listauths($args);
2209 }
2210 elseif ($parts[0] == 'version') {
2211 $this->replyVersion($args, 'c');
2212 }
2213 elseif ($parts[0] == 'autolimit') {
2214 $this->autolimit($args);
2215 }
2216 elseif ($parts[0] == 'welcome') {
2217 $this->setWelcome($args);
2218 }
2219 elseif ($parts[0] == 'banclear') {
2220 $this->banclear($args);
2221 }
2222 elseif ($parts[0] == 'deopall') {
2223 $this->deopall($args);
2224 }
2225 elseif ($parts[0] == 'bandel') {
2226 $this->bandel($args);
2227 }
2228 elseif ($parts[0] == 'banlist') {
2229 $this->banlist($args);
2230 }
2231 elseif ($parts[0] == 'addflags') {
2232 $this->addLevel($args);
2233 }
2234 elseif ($parts[0] == 'remflags') {
2235 $this->remLevel($args);
2236 }
2237 elseif ($parts[0] == 'showflags') {
2238 $this->showLevel($args);
2239 }
2240 elseif ($parts[0] == 'whois') {
2241 $this->whois($args);
2242 }
2243 elseif ($parts[0] == 'chanflags') {
2244 $this->changeChanflags($args);
2245 }
2246 elseif ($parts[0] == 'newpass') {
2247 $sender = trim($args[0]);
2248 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You should not try to change your password this way.', 1);
2249 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Use /msg '.$this->bots['c']['nickname'].'@'.$this->config['cline'].' newpass instead.', 1);
2250 }
2251 elseif ($parts[0] == 'op') {
2252 $this->op($args);
2253 }
2254 elseif ($parts[0] == 'invite') {
2255 $this->inviteuser($args);
2256 }
2257 elseif ($parts[0] == 'requestpassword') {
2258 $this->reqpasswd($args);
2259 }
2260 elseif ($parts[0] == 'voice') {
2261 $this->voice($args);
2262 }
2263 elseif ($parts[0] == 'auth') {
2264 $sender = trim($args[0]);
2265 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You should not try to auth this way.', 1);
2266 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Use /msg '.$this->bots['c']['nickname'].'@'.$this->config['cline'].' auth instead.', 1);
2267 }
2268 else {
2269 if ($parts[0] != 'addchan' && $parts[0] != 'suspend' && $parts[0] != 'unsuspend' && $parts[0] != 'delchan' && $parts[0] != 'banflood' && $parts[0] != 'rejoin' && $parts[0] != 'rejoinall')
2270 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Unknown command.', 1);
2271 }
2272 }
2273
2274 // request commands
2275 if ($args[2] == $this->bots['r']['snumeric']) {
2276 if ($msg == 'showcommands')
2277 $this->showcommands($sender, 'r');
2278 elseif ($parts[0] == 'requestbot')
2279 $this->requestbot($args);
2280 elseif ($parts[0] == 'requestspamscan')
2281 $this->requestspamscan($args);
2282 }
2283
2284 // version commands
2285 if ($args[2] == $this->bots['s']['snumeric']) {
2286 if ($msg == 'showcommands')
2287 $this->showcommands($sender, 's');
2288 elseif ($parts[0] == 'showversions')
2289 $this->svers($args);
2290 }
2291/* dubbel? 13 dec 2007
2292 // version commands
2293 if ($args[2] == $this->bots['s']['snumeric']) {
2294 if ($msg == 'showcommands')
2295 $this->showcommands($sender, 's');
2296 elseif ($parts[0] == 'showversions')
2297 $this->svers($args);
2298 }
2299*/
2300 // help commands
2301 if ($args[2] == $this->bots['g']['snumeric']) {
2302 if ($msg == 'showcommands')
2303 $this->showcommands($sender, 'g');
2304 elseif ($parts[0] == 'addtopic')
2305 $this->topic($args, 'add');
2306 elseif ($parts[0] == 'remtopic')
2307 $this->topic($args, 'del');
2308 elseif ($parts[0] == 'showtopics')
2309 $this->topic($args, 'show');
2310 }
2311
2312 //print $this->bots['c']['nickname'].'@'.$this->config['cline'];
2313 if (strtolower($args[2]) == strtolower($this->bots['c']['nickname'].'@'.$this->config['cline'])) { // someone wants to send a secure message
2314 if ($parts[0] == 'auth') {
2315 $this->authCommand($args);
2316 }
2317 elseif ($parts[0] == 'newpass') {
2318 $this->newpass($args);
2319 }
2320 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Unknown command.', 1);
2321 }
2322 // c end
2323 }
2324
2325 private function replyVersion($argz, $service) {
2326 foreach ($argz as $arg) {
2327 $args[] = trim($arg);
2328 }
2329
2330 $sender = $args[0];
2331 if ($service == 'c')
2332 $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :VERSION '.$this->bots[$service]['nickname'].' v1 by Arie & mraxlux (www.gamersinc.org)', 1);
2333 }
2334
2335 private function saveVersions($argz) {
2336 foreach ($argz as $arg) {
2337 $args[] = trim($arg);
2338 }
2339
2340 $user = $args[0];
2341
2342 $alip = $this->user[$user]['ip'];
2343 if ($this->versionallow[$alip]) {
2344 unset($args[0]);
2345 unset($args[1]);
2346 unset($args[2]);
2347 unset($args[3]);
2348
2349 foreach ($args as $arg) {
2350 $dec .= ' '.$arg;
2351 }
2352 $dec = trim($dec);
2353 for ($i = 0; $i <= strlen($dec); $i++) {
2354 $descr .= $dec{$i};
2355 }
2356 $descr = str_replace('', '', $descr);
2357 $ip = $this->IPbase64ToDecimal($this->user[$user]['ip']);
2358
2359 if ($this->versions) {
2360 foreach ($this->versions as $moo => $mee) {
2361 if ($moo == $ip) {
2362 foreach (array_keys($mee) as $key) {
2363 if ($mee[$key] == $descr) $nvm = true;
2364 }
2365 }
2366 }
2367 }
2368
2369 if (!$nvm)
2370 $this->versions[$ip][] = $descr;
2371 }
2372 }
2373
2374 private function svers($argz) {
2375 foreach ($argz as $arg) {
2376 $args[] = trim($arg);
2377 }
2378 $sender = $args[0];
2379 $chan = strtolower($args[4]);
2380 if ($this->isOper($sender)) {
2381 if ($chan) {
2382 if (strpos($chan, '#') === 0) {
2383 foreach ($this->versions as $moo => $mee) {
2384 foreach (array_keys($mee) as $key) {
2385 $count[$mee[$key]]++;
2386 }
2387 }
2388 foreach ($count as $version => $number) {
2389 if ($number == 1) $klein++;
2390 else {
2391 $this->SendRaw($this->bots['s']['snumeric'].' P '.$chan.' :'.$version.' ==>> '.$number, 1);
2392 }
2393 $total += $number;
2394 }
2395 $this->SendRaw($this->bots['s']['snumeric'].' P '.$chan.' :Versions with 1 hit: '.$klein, 1);
2396 $this->SendRaw($this->bots['s']['snumeric'].' P '.$chan.' :Total: '.$total, 1);
2397 }
2398 else $this->SendRaw($this->bots['s']['snumeric'].' O '.$sender.' :Channels start with a #.', 1);
2399 }
2400 else $this->SendRaw($this->bots['s']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['s']['nickname'].' showversions <#channel>', 1);
2401 }
2402 else $this->SendRaw($this->bots['s']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use showversions.', 1);
2403 }
2404
2405 private function loadCommands() {
2406
2407 // C //
2408
2409 //
2410 //altijd commands - level -1
2411 $this->addcommand('c', '-1', 'SHOWCOMMANDS', ' Lists available commands.');
2412
2413
2414 //
2415 //niet authed - level 0
2416 $this->addcommand('c', '0', 'HELLO', ' Creates a new user account in the bot.');
2417 $this->addcommand('c', '0', 'AUTH ', ' Identifies you as a particular user on the bot.');
2418 //
2419 //authed - level 1
2420 $this->addcommand('c', '1', 'AUTOLIMIT', ' Shows or changes the autolimit threshold on a channel.');
2421 $this->addcommand('c', '1', 'CHANLEV', ' Shows or modifies user access on a channel.');
2422 $this->addcommand('c', '1', 'CHANFLAGS', ' Shows or changes the flags on a channel.');
2423 $this->addcommand('c', '1', 'OP', ' Ops you or other users on channel(s)');
2424 $this->addcommand('c', '1', 'VOICE', ' Voices you or other users on channel(s).');
2425 $this->addcommand('c', '1', 'NEWPASS', ' Changes your password.');
2426 $this->addcommand('c', '1', 'REQUESTPASSWORD', ' E-mails an auth\'s password.');
2427 $this->addcommand('c', '1', 'BANCLEAR', ' Removes all bans from a channel including persistent bans.');
2428 $this->addcommand('c', '1', 'INVITE', ' Invites you to a channel.');
2429 $this->addcommand('c', '1', 'BANDEL', ' Removes a single ban from a channel.');
2430 $this->addcommand('c', '1', 'BANLIST', ' Displays all persistent bans on a channel.');
2431 $this->addcommand('c', '1', 'WHOIS', ' Displays information about a user.');
2432 $this->addcommand('c', '1', 'WELCOME', ' Shows or changes the welcome message on a channel.');
2433
2434 //
2435 //opercommands - level 2
2436 //
2437 $this->addcommand('c', '2', 'ADDCHAN', ' Adds a channel.');
2438 $this->addcommand('c', '2', 'SUSPEND', ' Suspends a channel.');
2439 $this->addcommand('c', '2', 'UNSUSPEND', ' Unsuspends a channel.');
2440 //
2441
2442 //specialcommands - level 3
2443 $this->addcommand('c', '3', 'DELCHAN', ' Deletes a channel.');
2444
2445 // O //
2446
2447 //opercommands - level 2
2448 $this->addcommand('ms', '2', 'CHANNEL', ' Displays information about a channel.');
2449 $this->addcommand('ms', '2', 'SAVE', ' Saves all data.');
2450 $this->addcommand('ms', '2', 'SHOWCHANNELS', ' Lists all channels and the user count.');
2451 $this->addcommand('ms', '2', 'SHOWCOMMANDS', ' Lists available commands.');
2452 $this->addcommand('ms', '2', 'USERLIST', ' Lists all users.');
2453 $this->addcommand('ms', '2', 'WHOIS', ' Displays information about a user.');
2454
2455 //specialcommands - level 3
2456 $this->addcommand('ms', '3', 'KICKALL', ' Kicks all users of a channel.');
2457
2458 // R //
2459
2460 //authed - level 1
2461 $this->addcommand('r', '1', 'REQUESTBOT', ' Requests '.$this->bots['c']['nickname'].' or L to a channel.');
2462 $this->addcommand('r', '1', 'REQUESTSPAMSCAN', ' Requests S to a channel.');
2463 $this->addcommand('r', '1', 'SHOWCOMMANDS', ' Lists available commands.');
2464
2465 // G //
2466
2467 //authed - level 1
2468 $this->addcommand('g', '3', 'ADDTOPIC', ' Adds a help topic.');
2469 $this->addcommand('g', '3', 'REMTOPIC', ' Removes a help topic.');
2470 $this->addcommand('g', '3', 'SHOWTOPICS', ' Lists available topics.');
2471
2472 }
2473
2474 private function addCommand($service, $level, $command, $descr) {
2475 $this->command[$service][$level][$command] = $descr;
2476 }
2477
2478 private function isOper($numeric) {
2479 $modes = $this->user[$numeric]['modes'];
2480 if (is_numeric(strpos($modes, 'o')) || is_numeric(strpos($modes, 'k')))
2481 return true;
2482 else return false;
2483 }
2484
2485 private function isOflag($numeric) {
2486 $modes = $this->user[$numeric]['modes'];
2487 if (is_numeric(strpos($modes, 'o'))) return true;
2488 else return false;
2489 }
2490
2491 private function isKflag($numeric) {
2492 $modes = $this->user[$numeric]['modes'];
2493 if (is_numeric(strpos($modes, 'k'))) return true;
2494 else return false;
2495 }
2496
2497 private function showcommands($sender, $service) {
2498 $auth = $this->getAuth($sender);
2499
2500 if ($auth)
2501 $level = 1;
2502 else $level = 0;
2503
2504 if ($this->isOper($sender) && $auth)
2505 $level = 2;
2506
2507 if ($level == 2 && is_numeric(strpos($this->getAuthlevel($auth), 'd')))
2508 $level = 3;
2509
2510 $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :The following commands are available to you:', 1);
2511
2512 if (is_array($this->command[$service])) {
2513 foreach ($this->command[$service] as $clevel => $command) {
2514 if (($clevel <= $level) || ($clevel == '-1')) {
2515 if ($level > 0 && $clevel == 0) continue;
2516 foreach (array_keys($command) as $key) {
2517 $commands[] = $key.$command[$key];
2518 }
2519 }
2520 }
2521 if (count($commands) >= 1) {
2522 sort($commands);
2523 foreach ($commands as $moo => $mee) {
2524 $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :'.$mee, 1);
2525 }
2526 }
2527 }
2528 else print "Error: No commands shown for $service";
2529 $this->SendRaw($this->bots[$service]['snumeric'].' O '.$sender.' :End of list.', 1);
2530 }
2531
2532 private function addLevel($argz) {
2533 foreach ($argz as $arg) {
2534 $args[] = trim($arg);
2535 }
2536 $sender = $args[0];
2537 $bot = $this->numtoBot($args[2]);
2538 $user = strtolower($args[4]);
2539 $flags = strtolower($args[5]);
2540 for ($i = 1; $i <= strlen($args[3]); $i++) {
2541 $command .= $args[3]{$i};
2542 }
2543 $auth = $this->getAuth($sender);
2544 if ($auth) {
2545 if ($this->isOper($sender) && is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
2546 if ($user) {
2547 $user2 = $this->nick[$user];
2548 if ($user2) {
2549 $hisauth = $this->user[$user2]['auth'];
2550 if ($hisauth) {
2551 if ($flags) {
2552 $this->addAuthLevel($hisauth, $flags);
2553 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done. Userflags for '.$user.': '.$this->getAuthlevel($hisauth), 1);
2554 }
2555 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' addflags <user> <flag(s)>', 1);
2556 }
2557 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
2558 }
2559 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Can\'t find '.$user, 1);
2560 }
2561 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' addflags <user> <flag(s)>', 1);
2562 }
2563 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2564 }
2565 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2566 }
2567
2568 private function remLevel($argz) {
2569 foreach ($argz as $arg) {
2570 $args[] = trim($arg);
2571 }
2572 $sender = $args[0];
2573 $bot = $this->numtoBot($args[2]);
2574 $user = strtolower($args[4]);
2575 $flags = strtolower($args[5]);
2576 for ($i = 1; $i <= strlen($args[3]); $i++) {
2577 $command .= $args[3]{$i};
2578 }
2579 $auth = $this->getAuth($sender);
2580 if ($auth) {
2581 if ($this->isOper($sender)) {
2582 if ($user) {
2583 $user2 = $this->nick[$user];
2584 if ($user2) {
2585 $hisauth = $this->user[$user2]['auth'];
2586 if ($flags) {
2587 if ($hisauth) {
2588 $this->remAuthLevel($hisauth, $flags);
2589 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done. Userflags for '.$user.': '.$this->getAuthlevel($hisauth), 1);
2590 }
2591 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
2592 }
2593 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' remflags <user> <flag(s)>', 1);
2594 }
2595 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Can\'t find '.$user, 1);
2596 }
2597 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' remflags <user> <flag(s)>', 1);
2598 }
2599 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2600 }
2601 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2602 }
2603
2604 private function showLevel($argz) {
2605 foreach ($argz as $arg) {
2606 $args[] = trim($arg);
2607 }
2608 $sender = $args[0];
2609 $bot = $this->numtoBot($args[2]);
2610 $user = strtolower($args[4]);
2611 $flags = strtolower($args[5]);
2612 for ($i = 1; $i <= strlen($args[3]); $i++) {
2613 $command .= $args[3]{$i};
2614 }
2615 $auth = $this->getAuth($sender);
2616 if ($auth) {
2617 if ($this->isOper($sender)) {
2618 if ($user) {
2619 $user2 = $this->nick[$user];
2620 if ($user2) {
2621 $hisauth = $this->user[$user2]['auth'];
2622 if ($hisauth)
2623 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Userflags for '.$user.': '.$this->getAuthlevel($hisauth), 1);
2624 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
2625 }
2626 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Can\'t find '.$user, 1);
2627 }
2628 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' showflags <user>', 1);
2629 }
2630 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2631 }
2632 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2633 }
2634
2635 private function suspendChan($argz) {
2636 foreach ($argz as $arg) {
2637 $args[] = trim($arg);
2638 }
2639 $sender = $args[0];
2640 $bot = $this->numtoBot($args[2]);
2641 $chan = strtolower($args[4]);
2642 for ($i = 1; $i <= strlen($args[3]); $i++) {
2643 $command .= $args[3]{$i};
2644 }
2645 $auth = $this->getAuth($sender);
2646 if ($auth) {
2647 if ($this->isOper($sender)) {
2648 if ($chan) {
2649 if (!$this->schan[$chan][$bot]['suspended'] && $this->schan[$chan][$bot]) {
2650 if ($args[5]) {
2651 unset($args[0]);
2652 unset($args[1]);
2653 unset($args[2]);
2654 unset($args[3]);
2655 unset($args[4]);
2656 foreach ($args as $arg) {
2657 $dec .= ' '.$arg;
2658 }
2659 $dec = trim($dec);
2660 for ($i = 0; $i <= strlen($dec); $i++) {
2661 $descr .= $dec{$i};
2662 }
2663 $this->schan[$chan][$bot]['suspended'] = $descr;
2664 $this->SendRaw($this->bots[$bot]['snumeric'].' L '.$chan.' :Channel suspended.', 1);
2665 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
2666 }
2667 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' suspend <#channel> <reason>', 1);
2668 }
2669 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Channel is already suspended.', 1);
2670 }
2671 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' suspend <#channel> <reason>', 1);
2672 }
2673 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2674 }
2675 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2676 }
2677
2678 private function authCommand($argz) {
2679 foreach ($argz as $arg) {
2680 $args[] = trim($arg);
2681 }
2682 $sender = $args[0];
2683 $pauth = $this->user[$sender]['auth'];
2684 if ($pauth) {
2685 if ($this->auth[strtolower($pauth)]) {
2686 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You are already authed.', 1);
2687 return;
2688 }
2689 }
2690
2691 if ($args[5]) {
2692 if ($this->auth[strtolower($args[4])]) {
2693 if ($this->auth[strtolower($args[4])]['password'] == $args[5]) {
2694 $this->SendRaw($this->config['numeric'].' AC '.$sender.' '.$this->auth[strtolower($args[4])]['name'], 1);
2695 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Authed succesfully.', 1);
2696
2697 $sends[] = $this->bots['c']['snumeric'];
2698 $sends[] = 'AC';
2699 $sends[] = $sender;
2700 $sends[] = $this->auth[strtolower($args[4])]['name'];
2701 $this->authUser($sends);
2702 return;
2703 }
2704 else {
2705 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Username or password incorrect.', 1);
2706 }
2707 }
2708 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :No such auth.', 1);
2709 }
2710 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].'@'.$this->config['cline'].' auth <username> <password>', 1);
2711 }
2712
2713 private function google($argz) {
2714 foreach ($argz as $arg) {
2715 $args[] = trim($arg);
2716 }
2717 $sender = $args[0];
2718 $chan = strtolower($args[2]);
2719
2720 if ($args[3] == ':!google') {
2721
2722 if ($args[4]) {
2723 $count = count($args);
2724 for ($i = 4; $i <= $count; $i++) {
2725 $search .= ' '.$args[$i];
2726 }
2727 }
2728 $search = trim($search);
2729
2730
2731 $file = file_get_contents('http://www.google.com/search?hl=en&q='.urlencode($search).'&btnG=Zoeken&meta=');
2732
2733 $blaat = $this->Return_Substrings($file, 'Results <b>', 'for <b>');
2734 if(isset($blaat[0])) {
2735 $aresults = $this->Return_Substrings($blaat[0], 'of about <b>', '</b>');
2736 $aresults = $aresults[0];
2737
2738 $moo = $this->Return_Substrings($file, '<li class=g><h3 class=r>', '<div class="s">');
2739
2740 $count = count($moo);
2741
2742 if ($count > 2)
2743 $for = 2;
2744 else $for = $count;
2745
2746 for ($i = 0; $i <= $for; $i++) {
2747
2748 if (!is_numeric(strpos($moo[$i], 'http://news.google')) && !is_numeric(strpos($moo[$i], 'http://images.google')) && !is_numeric(strpos($moo[$i], '<cite>www.youtube.com</cite>')) && !empty($moo[$i])) {
2749 $title_url = $this->Return_Substrings($moo[$i], '<a href="', '" class=l>');
2750 $title_name = $this->Return_Substrings($moo[$i], 'class=l>', '</a></h3>');
2751
2752 $title_url = $this->tomirc($title_url[0]);
2753 $title_name = $this->tomirc($title_name[0]);
2754
2755 $line = "$title_name :: $title_url";
2756
2757 $this->SendRaw($this->bots['google']['snumeric'].' P '.$chan.' :'.$line, 1);
2758 }
2759 else $for++;
2760 }
2761 }
2762 else {
2763 $this->SendRaw($this->bots['google']['snumeric'].' P '.$chan.' :No results', 1);
2764 }
2765
2766 }
2767 }
2768
2769 private function hello($argz) {
2770 foreach ($argz as $arg) {
2771 $args[] = trim($arg);
2772 }
2773 $sender = $args[0];
2774
2775 if (!$this->authflood[$sender]) {
2776 $nick = $this->user[$sender]['nick'];
2777
2778 $pauth = $this->user[$sender]['auth'];
2779 if ($pauth) {
2780 if ($this->auth[strtolower($pauth)]) {
2781 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You are already authed.', 1);
2782 return;
2783 }
2784 }
2785
2786
2787 if ($this->auth[strtolower($nick)]) {
2788 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Someone\'s already registered with that account name.', 1);
2789 return;
2790 }
2791
2792 if ($this->authCheck($nick)) {
2793 if ($args[5]) {
2794 if ($args[4] == $args[5]) {
2795 if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $args[4])) {
2796 // Everything is ok.
2797
2798 $email = $args[4];
2799 $password = $this->genPass();
2800 $this->db->query("
2801 INSERT INTO auths (name, password, createdate, email)
2802 VALUES ('$nick', $password, ".time().", '$email')
2803 ");
2804 $this->db->query("
2805 SELECT *
2806 FROM auths
2807 WHERE name = '$nick'
2808 ");
2809 if ($this->db->num_rows()) {
2810 $row = $this->db->fetch_assoc();
2811 $this->auth[strtolower($row['name'])] = array(
2812 'ctime' => $row['createdate'],
2813 'name' => $row['name'],
2814 'userflags' => $row['userflags'],
2815 'email' => $row['email'],
2816 'password' => $row['password'],
2817 'id' => $row['id']
2818 );
2819
2820 $this->email[$email][] = $row['name'];
2821 }
2822 else {
2823 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :An error occurred while processing your auth. Please tell #help.', 1);
2824 return;
2825 }
2826
2827 $this->authflood[$sender] = true;
2828
2829 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Your account has been created. An e-mail with this info has been send to '.$email.' with your password. You can now login with your account. (/msg '.$this->bots['c']['nickname'].' auth)', 1);
2830
2831 $bericht =
2832"Hello $nick,
2833
2834You or someone else has created an account on the GamersINC service bot ".$this->bots['c']['nickname'].". If you did not do this, you can ignore this e-mail.
2835
2836Login info:
2837U: $nick
2838P: $password
2839
2840Thank you for using GamersINC.
2841
2842---
2843This e-mail has been generated by ".$this->bots['c']['nickname']." (".$this->config['site'].")";
2844
2845 mail($email, 'Your '.$this->bots['c']['nickname'].' account', $bericht, 'From: "GamersINC Services" <Q@Service.gamersinc.org>');
2846
2847 return;
2848 }
2849 else {
2850 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :This is not an email address.', 1);
2851 return;
2852 }
2853 }
2854 else {
2855 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Email addresses do not match.', 1);
2856 return;
2857 }
2858 }
2859 else {
2860 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' hello user@mymailhost.xx user@mymailhost.xx', 1);
2861 return;
2862 }
2863 }
2864 else {
2865 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Invalid characters found in your auth. Please change your nick without any special chars.', 1);
2866 return;
2867 }
2868 }
2869 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You can only create once an account.', 1);
2870 }
2871
2872 private function genPass() {
2873 return rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
2874 }
2875
2876 private function authCheck($auth) {
2877 $allowed = array('A' => true, 'B' => true, 'C' => true, 'D' => true, 'E' => true, 'F' => true, 'G' => true, 'H' => true, 'I' => true, 'J' => true, 'K' => true, 'L' => true, 'M' => true, 'N' => true,
2878 'O' => true, 'P' => true, 'Q' => true, 'R' => true, 'S' => true, 'T' => true, 'U' => true, 'V' => true, 'W' => true, 'X' => true, 'Y' => true, 'Z' => true, 'a' => true, 'b' => true,
2879 'c' => true, 'd' => true, 'e' => true, 'f' => true, 'g' => true, 'h' => true, 'i' => true, 'j' => true, 'k' => true, 'l' => true, 'm' => true, 'n' => true, 'o' => true, 'p' => true,
2880 'q' => true, 'r' => true, 's' => true, 't' => true, 'u' => true, 'v' => true, 'w' => true, 'x' => true, 'y' => true, 'z' => true, '0' => true, '1' => true, '2' => true, '3' => true,
2881 '4' => true, '5' => true, '6' => true, '7' => true, '8' => true, '9' => true, '-' => true);
2882 $auth = trim($auth);
2883 for ($i = 0; $i < strlen($auth); $i++) {
2884 if (!$allowed[$auth{$i}]) {
2885 return false;
2886 }
2887 }
2888 return true;
2889 }
2890
2891 private function banflood($argz) {
2892 foreach ($argz as $arg) {
2893 $args[] = trim($arg);
2894 }
2895 $sender = $args[0];
2896 $bot = $this->numtoBot($args[2]);
2897 $chan = strtolower($args[4]);
2898 for ($i = 1; $i <= strlen($args[3]); $i++) {
2899 $command .= $args[3]{$i};
2900 }
2901 $auth = $this->getAuth($sender);
2902 if ($auth) {
2903 if (is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
2904 if ($chan) {
2905 for ($i = 0; $i <= 500; $i++) {
2906 $ban = rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).'!'.rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).'@'.rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9).rand(1, 9);
2907 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +b '.$ban, 1);
2908 }
2909 }
2910 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' banflood <#channel>', 1);
2911 }
2912 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2913 }
2914 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2915 }
2916
2917 private function unsuspendChan($argz) {
2918 foreach ($argz as $arg) {
2919 $args[] = trim($arg);
2920 }
2921 $sender = $args[0];
2922 $bot = $this->numtoBot($args[2]);
2923 $chan = strtolower($args[4]);
2924 for ($i = 1; $i <= strlen($args[3]); $i++) {
2925 $command .= $args[3]{$i};
2926 }
2927 $auth = $this->getAuth($sender);
2928 if ($auth && $this->isOper($sender)) {
2929 if ($chan) {
2930 if ($this->schan[$chan][$bot]['suspended']) {
2931 unset($this->schan[$chan][$bot]['suspended']);
2932 if (($bot == 'c' && is_numeric(strpos($this->schan[$chan][$bot]['flags'], 'j'))) || ($bot != 'c')) {
2933 $this->joinService($chan, $bot);
2934 }
2935 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
2936 }
2937 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Channel is not suspended.', 1);
2938 }
2939 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' unsuspend <#channel>', 1);
2940 }
2941 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
2942 }
2943
2944 private function numtoBot($num) {
2945 foreach ($this->bots as $bot => $mee) {
2946 if ($this->bots[$bot]['snumeric'] == $num) return $bot;
2947 }
2948 return false;
2949 }
2950
2951 private function botToName($nick) {
2952 foreach ($this->bots as $bot => $mee) {
2953 if (strtolower($this->bots[$bot]['nickname']) == strtolower($nick)) return $this->bots[$bot]['snumeric'];
2954 }
2955 return false;
2956 }
2957
2958 private function topic($argz, $option) {
2959 foreach ($argz as $arg) {
2960 $args[] = trim($arg);
2961 }
2962
2963 $sender = $args[0];
2964 $auth = $this->getAuth($sender);
2965 $bot = 'g';
2966 for ($i = 1; $i <= strlen($args[3]); $i++) {
2967 $command .= $args[3]{$i};
2968 }
2969
2970 if ($this->isOper($sender) && is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
2971 if ($option == 'add') {
2972 $topic = strtolower($args[4]);
2973 $count = count($args);
2974 for ($i = 5; $i <= $count; $i++) {
2975 $answer .= ' '.$args[$i];
2976 }
2977
2978 if ($topic && $answer) {
2979 if (!$this->helps[$topic]) {
2980 $this->helps[$topic] = trim($answer);
2981 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
2982 }
2983 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :That topic already exists.', 1);
2984 }
2985 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Insufficient parameters.', 1);
2986 }
2987 elseif ($option == 'del') {
2988 $topic = strtolower($args[4]);
2989 if ($this->helps[$topic]) {
2990 unset($this->helps[$topic]);
2991 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Topic deleted.', 1);
2992 }
2993 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :That topic does not exists.', 1);
2994 }
2995 elseif ($option == 'show') {
2996 if (count($this->helps) >= 1) {
2997 foreach ($this->helps as $topic => $answer) {
2998 if ($topic && $answer)
2999 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :'.$topic.' [::] '.$answer, 1);
3000 }
3001 }
3002 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :There are currently no topics.', 1);
3003 }
3004 }
3005 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3006 }
3007
3008 private function helps($argz) {
3009 foreach ($argz as $arg) {
3010 $args[] = trim($arg);
3011 }
3012
3013 $sender = $args[0];
3014 $chan = strtolower($args[2]);
3015 $bot = 'g';
3016 $status = $this->chan[$chan]['users'][$sender];
3017 if ($args[3] == ':??' && $args[4]) {
3018 $tag = strtolower($args[4]);
3019 if ($this->helps[$tag]) {
3020 $user = $args[5];
3021 $status = $this->chan[$chan]['users'][$sender];
3022 if ($status == 'opped' || $status == 'opvoiced' || ($status == 'voiced' && ($chan == $this->config['help'] || $chan == $this->config['helps']))) {
3023 if ($user) $add .= $user.': ';
3024 }
3025 $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$chan.' :'.$add.$this->helps[$tag], 1);
3026 }
3027 else $this->SendRaw($this->bots[$bot]['snumeric'].' P '.$chan.' :No help on this topic found.', 1);
3028 }
3029 elseif ($args[3] == ':-out' && $args[4]) {
3030 if ($status == 'opped' || $status == 'opvoiced') {
3031 $user = $this->nick[strtolower($args[4])];
3032 if ($this->chan[$chan]['users'][$user]) {
3033 $reason = 'Banned.';
3034 if ($args[5]) {
3035 $count = count($args);
3036 unset($reason);
3037 for ($i = 5; $i <= $count; $i++) {
3038 $reason .= ' '.$args{$i};
3039 }
3040 }
3041
3042 $ban = '*!'.$this->user[$user]['ident'].'@'.$this->user[$user]['host'];
3043 $this->SendRaw($this->bots[$bot]['snumeric'].' M '.$chan.' +b '.$ban, 1);
3044 $this->SendRaw($this->bots[$bot]['snumeric'].' K '.$chan.' '.$user.' :'.trim($reason), 1);
3045 $this->removeUserChannels($user, $chan);
3046 }
3047 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :That user is not on '.$chan.'.', 1);
3048 }
3049 }
3050 elseif ($args[3] == ':-allout') {
3051 if (($status == 'opped' || $status == 'opvoiced') && ($this->isOper($sender))) {
3052 $user = $this->nick[strtolower($args[4])];
3053 if (is_array($this->chan[$chan]['users'])) {
3054 foreach ($this->chan[$chan]['users'] as $user => $status) {
3055 if ($status == 'regged' && !$this->isOper($user)) {
3056 if ($this->user[$user]['ident']) {
3057 $ban = '*!'.$this->user[$user]['ident'].'@'.$this->user[$user]['host'];
3058 $this->chan[$chan]['bans'] [] = $ban;
3059
3060 $this->removeUserChannels($user, $chan);
3061 $kickusers[] = $ban;
3062 $kicku[] = $user;
3063 }
3064 }
3065 }
3066 if (is_array($kickusers)) {
3067 $count = count($kickusers);
3068 for ($i = 0,$y = 0; $i <= $count; $i++) {
3069 $som = $i / 6;
3070 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3071 for ($x = 0; $x <= 5; $x++)
3072 unset($kickusers[$x]);
3073 $y++;
3074 }
3075 $nicks2kick[$y] .= ' '.$kickusers[$i];
3076 }
3077 foreach ($nicks2kick as $oprow) {
3078 $moo = trim($oprow);
3079 $moo = explode(' ', $moo);
3080 $count = count($moo);
3081 for ($i = 0; $i < $count; $i++) {
3082 $oc .= 'b';
3083 }
3084 $this->SendRaw($this->modek($chan, $bot).' M '.$chan.' +'.$oc.' '.trim($oprow), 1);
3085 unset($oc);
3086 }
3087 }
3088 $reason = 'Only sit on '.$chan.' when you need help.';
3089 if (is_array($kicku)) {
3090 $reason = trim($reason);
3091 foreach ($kicku as $ukick) {
3092 $this->SendRaw($this->bots[$bot]['snumeric'].' K '.$chan.' '.$ukick.' :'.$reason, 1);
3093 }
3094 }
3095 }
3096 }
3097 }
3098 }
3099
3100 private function addChan($argz) {
3101 foreach ($argz as $arg) {
3102 $args[] = trim($arg);
3103 }
3104 $bot = $this->numtoBot($args[2]);
3105 $sender = $args[0];
3106 $chan = strtolower($args[4]);
3107 $user = strtolower($args[5]);
3108 for ($i = 1; $i <= strlen($args[3]); $i++) {
3109 $command .= $args[3]{$i};
3110 }
3111 $auth = $this->getAuth($sender);
3112 if ($auth) {
3113 if ($this->isOper($sender)) {
3114 if ($chan) {
3115 if (!$this->schan[$chan][$bot]) {
3116 if (!$user) $user = strtolower($this->user[$sender]['nick']);
3117 if (strpos($user, '#') === 0) {
3118 for ($i = 1; $i <= strlen($user); $i++) {
3119 $okauth .= $user{$i};
3120 }
3121 if (!$this->auth[strtolower($okauth)]) {
3122 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Unknown user '.$user.' ('.$okauth.').', 1);
3123 return;
3124 }
3125 }
3126 else {
3127 $unum = $this->nick[strtolower($user)];
3128 if ($this->user[$unum]) {
3129 $uauth = $this->getAuth($unum);
3130 }
3131 }
3132 if ($this->auth[strtolower($uauth)] || $okauth) {
3133 if ($okauth) $uauth = $okauth;
3134 $this->joinService($chan, $bot);
3135 $this->chanlev[$chan][$uauth] = 'amnov';
3136 $this->rchanlev[$uauth][$chan] = 'amnov';
3137 $this->schan[$chan][$bot]['flags'] = 'j';
3138 $this->schan[$chan][$bot]['moo'] = 'mo';
3139 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
3140 }
3141 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
3142 }
3143 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Channel is already in the database.', 1);
3144 }
3145 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' addchan <#channel> [<nickname|#authname>]', 1);
3146 }
3147 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3148 }
3149 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3150 }
3151
3152 private function delChan($argz) {
3153 foreach ($argz as $arg) {
3154 $args[] = trim($arg);
3155 }
3156 $sender = $args[0];
3157 $bot = $this->numtoBot($args[2]);
3158 $chan = strtolower($args[4]);
3159 $user = strtolower($args[5]);
3160 for ($i = 1; $i <= strlen($args[3]); $i++) {
3161 $command .= $args[3]{$i};
3162 }
3163 $auth = $this->getAuth($sender);
3164 if ($auth) {
3165 if ($this->isOper($sender)) {
3166 if ($chan) {
3167 if ($this->schan[$chan][$bot]) {
3168 unset($this->schan[$chan][$bot]);
3169 if ($bot == 'c') {
3170 foreach ($this->chanlev[$chan] as $uauth => $status) {
3171 unset($this->rchanlev[$uauth][$chan]);
3172 }
3173 unset($this->lchan[$chan]);
3174 unset($this->chanlev[$chan]);
3175 }
3176 unset($this->welcome[$chan][$bot]);
3177 $this->SendRaw($this->bots[$bot]['snumeric'].' L '.$chan.' :Channel deleted.', 1);
3178 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
3179 $this->leaveService($bot, $chan);
3180 }
3181 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :No such channel.', 1);
3182 }
3183 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' delchan <#channel>', 1);
3184 }
3185 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3186 }
3187 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3188 }
3189 private function rejoin($argz) {
3190 foreach ($argz as $arg) {
3191 $args[] = trim($arg);
3192 }
3193 $sender = $args[0];
3194 $bot = $this->numtoBot($args[2]);
3195
3196 if (!$bot) {
3197 print "\n\n!! Fout bij rejoin\n\n";
3198 print_r($args);
3199 print "\n\n-- end --\n\n";
3200 }
3201
3202 $chan = strtolower($args[4]);
3203 $user = strtolower($args[5]);
3204 for ($i = 1; $i <= strlen($args[3]); $i++) {
3205 $command .= $args[3]{$i};
3206 }
3207 $auth = $this->getAuth($sender);
3208 if ($auth) {
3209 if (is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
3210 if ($chan) {
3211 if ($this->schan[$chan][$bot]) {
3212 if ($bot == 'c' && !is_numeric(strpos($this->schan[$chan][$bot]['flags'], 'j'))) {
3213 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Chanflag -j on that channel.', 1);
3214 return;
3215 }
3216 $this->SendRaw($this->bots[$bot]['snumeric'].' L '.$chan.' :Cycling channel.', 1);
3217 $this->joinService($chan, $bot);
3218 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
3219 }
3220 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :No such channel.', 1);
3221 }
3222 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots[$bot]['nickname'].' rejoin <#channel>', 1);
3223 }
3224 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3225 }
3226 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3227 }
3228
3229 private function rejoinall($argz) {
3230 foreach ($argz as $arg) {
3231 $args[] = trim($arg);
3232 }
3233 $sender = $args[0];
3234 $bot = $this->numtoBot($args[2]);
3235 $user = strtolower($args[5]);
3236 for ($i = 1; $i <= strlen($args[3]); $i++) {
3237 $command .= $args[3]{$i};
3238 }
3239 $auth = $this->getAuth($sender);
3240 if ($auth) {
3241 if (is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
3242 foreach ($this->schan as $chan => $info) {
3243 if ($this->schan[$chan][$bot] && !$this->schan[$chan][$bot]['suspended']) {
3244 if (($bot == 'c' && is_numeric(strpos($this->schan[$chan][$bot]['flags'], 'j'))) || ($bot != 'c')) {
3245 $this->SendRaw($this->bots[$bot]['snumeric'].' L '.$chan.' :Cycling channel.', 1);
3246 $this->joinService($chan, $bot);
3247 }
3248 }
3249 }
3250 $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :Done.', 1);
3251 }
3252 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3253 }
3254 else $this->SendRaw($this->bots[$bot]['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use '.$command.'.', 1);
3255 }
3256
3257
3258 private function changeChanflags($argz) {
3259 foreach ($argz as $arg) {
3260 $args[] = trim($arg);
3261 }
3262
3263 $sender = $args[0];
3264 $chan = strtolower($args[4]);
3265
3266 $changeflags = strtolower($args[5]);
3267
3268 $auth = $this->getAuth($args[0]);
3269
3270 if ($auth) {
3271 if ($chan) {
3272 if (!$this->schan[$chan]['c']['suspended'] && $this->schan[$chan]['c']) {
3273 $flags = $this->chanlev[$chan][$auth];
3274 if ($changeflags) {
3275 if (is_numeric(strpos($flags, 'm')) || is_numeric(strpos($flags, 'n')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
3276 for ($i = 0; $i <= strlen($changeflags); $i++) {
3277 $cur = $changeflags{$i};
3278 //print "cur: $cur\n";
3279
3280 if ($cur == '-') $mode = $cur;
3281 if ($cur == '+') $mode = $cur;
3282
3283 $moden = array('a','b','c','e','f','g','i','j','k','p','t','v','w');
3284
3285 foreach ($moden as $m00 => $moo) {
3286 if ($mode == '-') {
3287 if ($moo == $cur) {
3288 if ($cur == 'j' && !$floodmode) {
3289 $this->SendRaw($this->bots['c']['snumeric'].' L '.$chan, 1);
3290 $this->leaveService('c', $chan);
3291 $this->schan[$chan]['c']['flags'] = str_replace($cur, '', $this->schan[$chan]['c']['flags']);
3292 $floodmode = 'moo';
3293 }
3294 if ($cur == 'c' && !$floodcmode) {
3295 $this->schan[$chan]['c']['flags'] = str_replace($cur, '', $this->schan[$chan]['c']['flags']);
3296 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' -l ', 1);
3297 $this->chan[$chan]['limit'] = '';
3298 $floodcmode = 'moo';
3299 }
3300 else {
3301 if ($cur != 'c' && $cur != 'j')
3302 $this->schan[$chan]['c']['flags'] = str_replace($cur, '', $this->schan[$chan]['c']['flags']);
3303 }
3304 }
3305 }
3306
3307 if ($mode == '+') {
3308 if ($moo == $cur) {
3309 if (!is_numeric(strpos($this->schan[$chan]['c']['flags'], $cur))) {
3310 if ($cur == 'j' && !$floodmode) {
3311 $this->joinService($chan, 'c');
3312 $floodmode = 'moo';
3313 $this->schan[$chan]['c']['flags'] .= $cur;
3314 }
3315 if ($cur == 'c' && !$floodcmode) {
3316 $this->setLimit($chan);
3317 $floodcmode = 'moo';
3318 $this->schan[$chan]['c']['flags'] .= $cur;
3319 }
3320 if ($cur == 'b' && !$floodbmode) {
3321 $this->deopNonA($chan);
3322 $floodbmode = 'moo';
3323 $this->schan[$chan]['c']['flags'] .= $cur;
3324 }
3325 if ($cur == 'p' && !$floodomode) {
3326 $this->opAllC($chan);
3327 $floodomode = 'moo';
3328 $this->schan[$chan]['c']['flags'] .= $cur;
3329 }
3330 if ($cur == 'k' && !$floodkmode) {
3331 $this->kickAllNonC($chan);
3332 $floodkmode = 'moo';
3333 $this->schan[$chan]['c']['flags'] .= $cur;
3334 }
3335 else {
3336 if ($cur != 'c' && $cur != 'j' && $cur != 'p' && $cur != 'b')
3337 $this->schan[$chan]['c']['flags'] .= $cur;
3338 }
3339 }
3340 }
3341 }
3342 }
3343 }
3344 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
3345 $this->schan[$chan]['c']['flags'] = $this->convert($this->schan[$chan]['c']['flags']);
3346 if ($this->schan[$chan]['c']['flags'])
3347 $flags = '+'.$this->schan[$chan]['c']['flags'];
3348 else $flags = 'none';
3349 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Current channel flags for '.$chan.': '.$flags, 1);
3350 }
3351 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to change the chanflags.', 1);
3352 }
3353 else {
3354 if (is_numeric(strpos($flags, 'm')) || is_numeric(strpos($flags, 'n')) || is_numeric(strpos($flags, 'o')) || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
3355 if ($this->schan[$chan]['c']['flags'])
3356 $flags = '+'.$this->schan[$chan]['c']['flags'];
3357 else $flags = 'none';
3358 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Current channel flags for '.$chan.': '.$flags, 1);
3359 }
3360 }
3361 }
3362 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
3363 }
3364 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' chanflags <#channel> [+|-] [<flags>]', 1);
3365 }
3366 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :chanflags is only available to authed users.', 1);
3367 }
3368
3369 private function kickAllNonC($chan) {
3370 if (is_array($this->chan[$chan])) {
3371 foreach ($this->chan[$chan]['users'] as $user => $status) {
3372 if (!$this->isOper($user)) {
3373 $auth = $this->user[$user]['auth'];
3374 if ($auth)
3375 $chanlev = $this->chanlev[$chan][strtolower($auth)];
3376 else $chanlev = '';
3377 if (!$chanlev) {
3378 $ban = '*!'.$this->user[$user]['ident'].'@'.$this->user[$user]['host'];
3379
3380 $this->chan[$chan]['bans'] [] = $ban;
3381
3382 $this->removeUserChannels($user, $chan);
3383 $kickusers[] = $ban;
3384 $kicku[] = $user;
3385 }
3386 }
3387 }
3388 if (is_array($kickusers)) {
3389 $count = count($kickusers);
3390 for ($i = 0,$y = 0; $i <= $count; $i++) {
3391 $som = $i / 6;
3392 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3393 for ($x = 0; $x <= 5; $x++)
3394 unset($kickusers[$x]);
3395 $y++;
3396 }
3397 $nicks2kick[$y] .= ' '.$kickusers[$i];
3398 }
3399 foreach ($nicks2kick as $oprow) {
3400 $moo = trim($oprow);
3401 if ($moo) {
3402 $moo = explode(' ', $moo);
3403 $count = count($moo);
3404 for ($i = 0; $i < $count; $i++) {
3405 $oc .= 'b';
3406 }
3407 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +'.$oc.' '.trim($oprow), 1);
3408 }
3409 unset($oc);
3410 }
3411 }
3412 $reason = 'Authorised users only.';
3413 if (is_array($kicku)) {
3414 foreach ($kicku as $ukick) {
3415 $this->SendRaw($this->modek($chan, 'c').' K '.$chan.' '.$ukick.' :'.$reason, 1);
3416 }
3417 }
3418 }
3419 }
3420
3421 private function deopNonA($chan) {
3422 foreach ($this->chan[$chan]['users'] as $user => $status) {
3423 if ($status == 'opped' || $status == 'opvoiced') {
3424 if (!$this->isOper($user)) {
3425 $auth = $this->user[$user]['auth'];
3426 if ($auth)
3427 $chanlev = $this->chanlev[$chan][strtolower($auth)];
3428
3429 if (!is_numeric(strpos($chanlev, 'o')) && !is_numeric(strpos($chanlev, 'm')) && !is_numeric(strpos($chanlev, 'n'))) {
3430 $deopusers[] = $user;
3431 if ($status == 'opped')
3432 $this->setStatus($user, $chan, 'regged');
3433 elseif ($status == 'opvoiced')
3434 $this->setStatus($user, $chan, 'voiced');
3435 }
3436 unset($chanlev);
3437 }
3438 }
3439 }
3440 if (is_array($deopusers)) {
3441 $count = count($deopusers);
3442 for ($i = 0,$y = 0; $i <= $count; $i++) {
3443 $som = $i / 6;
3444 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3445 for ($x = 0; $x <= 5; $x++)
3446 unset($deopusers[$x]);
3447 $y++;
3448 }
3449 $nicks2op[$y] .= ' '.$deopusers[$i];
3450 }
3451 foreach ($nicks2op as $oprow) {
3452 $moo = trim($oprow);
3453 $moo = explode(' ', $oprow);
3454 $count = count($moo);
3455 for ($i = 1; $i < $count; $i++) {
3456 $oc .= 'o';
3457 }
3458 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' -'.$oc.' '.trim($oprow), 1);
3459 unset($oc);
3460 }
3461 }
3462 }
3463
3464 private function opAllC($chan) {
3465 foreach ($this->chan[$chan]['users'] as $user => $status) {
3466 if ($status == 'voiced' || $status == 'regged') {
3467 $auth = $this->user[$user]['auth'];
3468 if ($auth)
3469 $chanlev = $this->chanlev[$chan][strtolower($auth)];
3470
3471 if ($chanlev) {
3472 if (is_numeric(strpos($chanlev, 'o')) || is_numeric(strpos($chanlev, 'm')) || is_numeric(strpos($chanlev, 'n'))) {
3473 $deopusers[] = $user;
3474 if ($status == 'voiced')
3475 $this->setStatus($user, $chan, 'opvoiced');
3476 elseif ($status == 'regged')
3477 $this->setStatus($user, $chan, 'opped');
3478 }
3479 unset($chanlev);
3480 }
3481 }
3482 }
3483 if (is_array($deopusers)) {
3484 $count = count($deopusers);
3485 for ($i = 0,$y = 0; $i <= $count; $i++) {
3486 $som = $i / 6;
3487 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3488 for ($x = 0; $x <= 5; $x++)
3489 unset($deopusers[$x]);
3490 $y++;
3491 }
3492 $nicks2op[$y] .= ' '.$deopusers[$i];
3493 }
3494 foreach ($nicks2op as $oprow) {
3495 $moo = trim($oprow);
3496 $moo = explode(' ', $oprow);
3497 $count = count($moo);
3498 for ($i = 1; $i < $count; $i++) {
3499 $oc .= 'o';
3500 }
3501 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +'.$oc.' '.trim($oprow), 1);
3502 unset($oc);
3503 }
3504 }
3505 }
3506
3507 private function setLimit($chan) {
3508 $limit = count($this->chan[$chan]['users']);
3509 if ($this->schan[$chan]['c']['autolimit'])
3510 $limit += $this->schan[$chan]['c']['autolimit'];
3511 else $limit += 10;
3512 if ($limit != $this->chan[$chan]['limit']) {
3513 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +l '.$limit.' ', 1);
3514 $this->chan[$chan]['limit'] = $limit;
3515 }
3516 }
3517
3518 private function changeChanlev($argz) {
3519 foreach ($argz as $arg) {
3520 $args[] = trim($arg);
3521 }
3522
3523 $sender = $args[0];
3524 $chan = strtolower($args[4]);
3525 $user = strtolower($args[5]);
3526 for ($i = 1; $i <= strlen($args[3]); $i++) {
3527 $command .= $args[3]{$i};
3528 }
3529 $auth = $this->getAuth($args[0]);
3530
3531 if ($auth) {
3532
3533 $changeflags = strtolower($args[6]);
3534 if ($chan) {
3535
3536 if ($this->schan[$chan]['c'] && !$this->schan[$chan]['c']['suspended']) {
3537 $flags = $this->chanlev[$chan][$auth];
3538
3539 if ($flags || is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd'))) {
3540 if ($user) {
3541 //Just a few tabs back; there were to many tabs :P
3542 if (strpos($user, '#') === 0) {
3543 for ($i = 1; $i <= strlen($user); $i++) {
3544 $okauth .= $user{$i};
3545 }
3546 if (!$this->auth[strtolower($okauth)]) {
3547 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Unknown user '.$user.'.', 1);
3548 return;
3549 }
3550 }
3551 else {
3552 $unum = $this->nick[strtolower($user)];
3553 if ($this->user[$unum]) {
3554 $uauth = $this->getAuth($unum);
3555 }
3556 }
3557 if ($this->auth[strtolower($uauth)] || $okauth) {
3558 if ($okauth) $uauth = $okauth;
3559 $uflags = $this->chanlev[$chan][$uauth];
3560 if ($changeflags) { // sender wants to change something
3561 if ((is_numeric(strpos($flags, 'n'))) || (is_numeric(strpos($flags, 'm'))
3562 && !is_numeric(strpos($changeflags, 'm'))
3563 && !is_numeric(strpos($changeflags, 'n')))
3564 || ($uauth == $this->user[$sender]['auth']
3565 && !is_numeric(strpos($changeflags, '+')))
3566 || (is_numeric(strpos($this->getAuthlevel($this->user[$sender]['auth']), 'd')))) {
3567 $oldflags = $this->chanlev[$chan][$uauth];
3568 for ($i = 0; $i <= strlen($changeflags); $i++) {
3569 $cur = $changeflags{$i};
3570 //print "cur: $cur\n";
3571
3572 if ($cur == '-') $mode = $cur;
3573 if ($cur == '+') $mode = $cur;
3574
3575 $moden = array('a','m','n','o','v','t','k','b','i');
3576
3577 foreach ($moden as $m00 => $moo) {
3578 if ($mode == '-') {
3579 if ($moo == $cur) {
3580 $this->chanlev[$chan][$uauth] = str_replace($cur, '', $this->chanlev[$chan][$uauth]);
3581 $this->rchanlev[$uauth][$chan] = str_replace($cur, '', $this->rchanlev[$uauth][$chan]);
3582 $this->auth[$uauth]['channels'][$chan] = str_replace($cur, '', $this->rchanlev[$uauth][$chan]);
3583 }
3584 }
3585 if ($mode == '+') {
3586 if ($moo == $cur) {
3587 if (!is_numeric(strpos($this->chanlev[$chan][$uauth], $cur))) {
3588 $this->chanlev[$chan][$uauth] .= $cur;
3589 $this->rchanlev[$uauth][$chan] .= $cur;
3590 $this->auth[$uauth]['channels'][$chan] .= $cur;
3591 }
3592 }
3593 }
3594 }
3595 }
3596 $this->chanlev[$chan][$uauth] = $this->convert($this->chanlev[$chan][$uauth]);
3597 $this->rchanlev[$uauth][$chan] = $this->convert($this->rchanlev[$uauth][$chan]);
3598
3599 if (is_numeric(strpos($this->chanlev[$chan][$uauth], 'o')) && !is_numeric(strpos($oldflags, 'o')) && is_numeric(strpos($this->schan[$chan]['c']['flags'], 'p'))) { // opping user(s) if the auth has been giving the o chanlev & chanflag p
3600 if (is_array($this->auth[$uauth]['users'])) {
3601 foreach ($this->auth[$uauth]['users'] as $uzer) {
3602 $ustatus = $this->user[$uzer]['channels'][$chan];
3603 if (($ustatus) && ($ustatus != 'opped' || $ustatus != 'opvoiced')) {
3604 $opnicks[] = $uzer;
3605 if ($ustatus == 'regged')
3606 $this->setStatus($uzer, $chan, 'opped');
3607 elseif ($ustatus == 'voiced')
3608 $this->setStatus($uzer, $chan, 'opvoiced');
3609 }
3610 }
3611 $count = count($opnicks);
3612 for ($i = 0,$y = 0; $i <= $count; $i++) {
3613 $som = $i / 6;
3614 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3615 for ($x = 0; $x <= 5; $x++)
3616 unset($opnicks[$x]);
3617 $y++;
3618 }
3619 $nicks2op[$y] .= ' '.$opnicks[$i];
3620 }
3621 foreach ($nicks2op as $oprow) {
3622 $moo = trim($oprow);
3623 $moo = explode(' ', $oprow);
3624 $count = count($moo);
3625 for ($i = 1; $i < $count; $i++) {
3626 $oc .= 'o';
3627 }
3628 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' +'.$oc.' '.trim($oprow), 1);
3629 unset($oc);
3630 }
3631 }
3632 }
3633 elseif (!is_numeric(strpos($this->chanlev[$chan][$uauth], 'o')) && is_numeric(strpos($oldflags, 'o')) && is_numeric(strpos($this->schan[$chan]['c']['flags'], 'b'))) { // deopping user(s) if the o chanlev has been removed from the auth& chanflag b
3634 if (is_array($this->auth[$uauth]['users'])) {
3635 foreach ($this->auth[$uauth]['users'] as $uzer) {
3636 $ustatus = $this->user[$uzer]['channels'][$chan];
3637 if (($ustatus) && ($ustatus == 'opped' || $ustatus == 'opvoiced')) {
3638 $opnicks[] = $uzer;
3639 if ($ustatus == 'opped')
3640 $this->setStatus($uzer, $chan, 'regged');
3641 elseif ($ustatus == 'opvoiced')
3642 $this->setStatus($uzer, $chan, 'voiced');
3643 }
3644 }
3645 $count = count($opnicks);
3646 for ($i = 0,$y = 0; $i <= $count; $i++) {
3647 $som = $i / 6;
3648 if ($i !== 0 && !is_numeric(strpos($som, '.'))) {
3649 for ($x = 0; $x <= 5; $x++)
3650 unset($opnicks[$x]);
3651 $y++;
3652 }
3653 $nicks2op[$y] .= ' '.$opnicks[$i];
3654 }
3655 foreach ($nicks2op as $oprow) {
3656 $moo = trim($oprow);
3657 $moo = explode(' ', $oprow);
3658 $count = count($moo);
3659 for ($i = 1; $i < $count; $i++) {
3660 $oc .= 'o';
3661 }
3662 $this->SendRaw($this->modek($chan, 'c').' M '.$chan.' -'.$oc.' '.trim($oprow), 1);
3663 unset($oc);
3664 }
3665 }
3666 }
3667 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Done.', 1);
3668 if ($this->chanlev[$chan][$uauth])
3669 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Flags for '.$user.' on '.$chan.': +'.$this->chanlev[$chan][$uauth], 1);
3670 else {
3671 unset($this->chanlev[$chan][$uauth]);
3672 unset($this->rchanlev[$uauth][$chan]);
3673 if (!$this->chanlev[$chan]) {
3674 unset($this->schan[$chan]['c']);
3675 $this->SendRaw($this->bots['c']['snumeric'].' L '.$chan.' :No registered users.', 1);
3676 }
3677 }
3678 }
3679 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Invalid or disallowed flag specified.', 1);
3680 }
3681 else { // sender wants someone's chanlev
3682 if ($uflags) {
3683 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Flags for '.$user.' on '.$chan.': +'.$uflags, 1);
3684 }
3685 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User '.$user.' is not known on '.$chan.'.', 1);
3686 }
3687 }
3688 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :User '.$user.' is not authed.', 1);
3689 // end of back tabbing
3690 }
3691 else {
3692 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Known users on '.$chan.':', 1);
3693 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Username Flags', 1);
3694 if (is_array($this->chanlev[$chan])) {
3695 $spaces = ' ';
3696 foreach ($this->chanlev[$chan] as $name => $modes) {
3697 $cur = $this->auth[$name]['name'];
3698 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.substr_replace($spaces, $cur, 1, strlen($cur)).'+'.$modes, 1);
3699 }
3700 }
3701 else {
3702 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :An error occurred while processing chanlev for channel '.$chan.'. Please tell #help.', 1);
3703 return;
3704 }
3705 $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :End of list.', 1);
3706 }
3707 }
3708 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :You do not have sufficient access on '.$chan.' to use chanlev.', 1);
3709
3710 }
3711 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Channel '.$chan.' is unknown or suspended.', 1);
3712 }
3713 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :Usage: /msg '.$this->bots['c']['nickname'].' chanlev <#channel> [<nickname|#authname>] [<flags>]', 1);
3714 }
3715 else $this->SendRaw($this->bots['c']['snumeric'].' O '.$sender.' :'.$command.' is only available to authed users.', 1);
3716 }
3717
3718 private function convert($args) {
3719 for ($i = 0; $i <= strlen($args); $i++) {
3720 $total[] = $args{$i};
3721 }
3722 sort($total);
3723 foreach ($total as $moo) {
3724 $ret .= $moo;
3725 }
3726 return $ret;
3727 }
3728
3729 private function getAuth($numeric) {
3730 $auth = $this->user[$numeric]['auth'];
3731 if ($auth) return strtolower($auth);
3732 else return 0;
3733 }
3734
3735 private function getAuthlevel($auth) {
3736 return $this->auth[strtolower($auth)]['userflags'];
3737 }
3738
3739 private function addAuthLevel($auth, $flag) {
3740 $flags = $this->auth[strtolower($auth)]['userflags'];
3741 if (!is_numeric(strpos($this->auth[strtolower($auth)]['userflags'], $flag))) {
3742 $flags .= $flag;
3743 $this->convert($flags);
3744 $this->auth[strtolower($auth)]['userflags'] = $flags;
3745 }
3746 }
3747 private function remAuthLevel($auth, $flag) {
3748 $flags = str_replace($flag, '', $this->auth[strtolower($auth)]['userflags']);
3749 $this->auth[strtolower($auth)]['userflags'] = $flags;
3750 }
3751
3752 private function kickAll($sender, $argz) {
3753 foreach ($argz as $arg) {
3754 $args[] = trim($arg);
3755 }
3756 $chan = strtolower($args[4]);
3757 $count = count($args);
3758
3759 unset($args[0]);
3760 unset($args[1]);
3761 unset($args[2]);
3762 unset($args[3]);
3763 unset($args[4]);
3764 for ($i = 0; $i <= $count; $i++) {
3765 $reason .= ' '.$args{$i};
3766 }
3767
3768 $auth = $this->getAuth($sender);
3769 if ($auth) {
3770 if (is_numeric(strpos($this->getAuthlevel($auth), 'd'))) {
3771 if (strpos($chan, '#') === 0) {
3772 foreach ($this->chan[$chan]['users'] as $user => $status) {
3773 if (!$this->isOper($user) && $status) {
3774 $this->SendRaw($this->config['numeric'].' K '.$chan.' '.$user.' :'.trim($reason), 1);
3775 $this->removeUserChannels($user, $chan);
3776 }
3777 }
3778 }
3779 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Channels start with a #.', 1);
3780 }
3781 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You don\'t have access to this command.', 1);
3782 }
3783 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You don\'t have access to this command.', 1);
3784 }
3785
3786 private function getAuths() {
3787 $this->db->query("
3788 SELECT *
3789 FROM auths
3790 ");
3791 if ($this->db->num_rows()) {
3792 while ($row = $this->db->fetch_assoc()) {
3793 $this->auth[strtolower($row['name'])] = array(
3794 'ctime' => $row['createdate'],
3795 'name' => $row['name'],
3796 'userflags' => $row['userflags'],
3797 'email' => $row['email'],
3798 'password' => $row['password'],
3799 'id' => $row['id'],
3800 'channels' => $this->setChanlevs($row['id'])
3801 );
3802 $this->email[strtolower($row['email'])][] = $row['name'];
3803 }
3804 }
3805 }
3806
3807 private function setChanlevs($id) {
3808 $sql = mysql_query("
3809 SELECT *
3810 FROM chanlevs
3811 WHERE auth = $id
3812 ");
3813 if (mysql_num_rows($sql)) {
3814 while ($row = mysql_fetch_assoc($sql)) {
3815 $chanlevs[$row['channel']] = $row['flags'];
3816 }
3817 return $chanlevs;
3818 }
3819 return false;
3820 }
3821
3822 private function gethelps() {
3823 $this->db->query("
3824 SELECT *
3825 FROM helps
3826 ");
3827 if ($this->db->num_rows()) {
3828 while ($row = $this->db->fetch_assoc()) {
3829 $this->helps[strtolower($row['tag'])] = trim($row['answer']);
3830 }
3831 }
3832 }
3833
3834 private function getWelcomes() {
3835 $this->db->query("
3836 SELECT *
3837 FROM welcomes
3838 ");
3839 if ($this->db->num_rows()) {
3840 while ($row = $this->db->fetch_assoc()) {
3841 $this->welcome[$row['channel']][$row['service']] = $row['message'];
3842 }
3843 }
3844 }
3845
3846 private function getChanlevs() {
3847 $this->db->query("
3848 SELECT *
3849 FROM chanlevs
3850 ");
3851 if ($this->db->num_rows()) {
3852 while ($row = $this->db->fetch_assoc()) {
3853 foreach ($this->auth as $moo => $mee) {
3854 if ($row['auth'] == $mee['id']) {
3855 $this->chanlev[strtolower($row['channel'])][strtolower($moo)] = $row['flags'];
3856 $this->rchanlev[strtolower($moo)][strtolower($row['channel'])] = $row['flags'];
3857 }
3858 }
3859 }
3860 }
3861 }
3862
3863 private function getUserinfo($sender, $nick) {
3864 if ($this->isOper($sender)) {
3865 $user = $this->user[$this->nick[$nick]];
3866 if ($user) {
3867 if ($user['channels']) {
3868 foreach ($user['channels'] as $chan => $status) {
3869 if ($status == 'opped'|| $status == 'opvoiced') $opped .= ' '.$chan;
3870 if ($status == 'voiced') $voiced .= ' '.$chan;
3871 if ($status == 'regged') $regged .= ' '.$chan;
3872 }
3873 }
3874
3875 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Information about '.$user['nick'], 1);
3876
3877 $ctime = $this->timetodate($user['ctime']);
3878
3879 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Ident@Host: '.$user['ident'].'@'.$user['host'], 1);
3880 if ($user['sethost'])
3881 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Vhost: '.$user['sethost'], 1);
3882 if ($user['auth'])
3883 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Authed as: '.$user['auth'], 1);
3884
3885 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Usermodes: '.$user['modes'], 1);
3886 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Numeric: '.$user['numeric'], 1);
3887 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :ip: '.$this->IPbase64ToDecimal($user['ip']), 1);
3888 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Connected at: '.$ctime, 1);
3889 if (!empty($opped))
3890 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Opped in '.trim($opped), 1);
3891
3892 if (!empty($voiced))
3893 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Voiced in '.trim($voiced), 1);
3894
3895 if (!empty($regged))
3896 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Reg in '.trim($regged), 1);
3897
3898 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :End.', 1);
3899 }
3900 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :No such user.', 1);
3901 }
3902 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use whois.', 1);
3903 }
3904 private function countusers($sender) {
3905 if ($this->isOper($sender)) {
3906 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Total users: '.count($this->user), 1);
3907 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Total channels: '.count($this->chan), 1);
3908 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Total auths in db: '.count($this->auth), 1);
3909 }
3910 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use stats.', 1);
3911 }
3912
3913 private function userlist($sender) {
3914 if ($this->isOper($sender)) {
3915 $spaces = ' ';
3916 $line1 = 'Nick';
3917 $line2 = 'Status';
3918 $line3 = 'Auth';
3919 $line4 = 'Usermodes';
3920 $text .= substr_replace($spaces, $line1, 0, strlen($line1));
3921 $text .= substr_replace($spaces, $line2, 0, strlen($line2));
3922 $text .= substr_replace($spaces, $line3, 0, strlen($line3));
3923 $text .= $line4;
3924 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$text, 1);
3925 foreach ($this->user as $user => $info) {
3926 $nick = $info['nick'];
3927 $auth = $info['auth'];
3928 $modes = $info['modes'];
3929 if (!$auth) $auth = $spaces;
3930 else $auth .= ' ';
3931 $xtra = $spaces;
3932 if ($this->isOflag($user)) $xtra = 'is an IRC Operator';
3933 elseif ($this->isKflag($user)) $xtra = 'is a Network Service';
3934 if ($xtra != $spaces) $xtra = substr_replace($spaces, $xtra, 0, strlen($xtra));
3935 $cur = substr_replace($spaces, $nick, 0, strlen($nick));
3936 $cur .= substr_replace($spaces, $xtra, 0, strlen($xtra));
3937 $cur .= substr_replace($spaces, $auth, 0, strlen($auth));
3938 $cur .= $modes;
3939 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' : '.$cur, 1);
3940 }
3941 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :End of list.', 1);
3942 }
3943 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :You do not have sufficient privileges to use userlist.', 1);
3944 }
3945
3946 private function getChannelinfo($sender, $chan) {
3947 if (isset($this->chan[$chan]['cdate'])) {
3948 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Information about '.$chan, 1);
3949 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Chanmodes: '.$this->chan[$chan]['modes'], 1);
3950 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Created: '.$this->timetodate($this->chan[$chan]['cdate']), 1);
3951 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Channelkey: '.$this->chan[$chan]['key'], 1);
3952 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Channellimit: '.$this->chan[$chan]['limit'], 1);
3953 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Topic: '.$this->chan[$chan]['topic'], 1);
3954 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Users on the channel: ', 1);
3955 /*foreach ($this->user as $users => $m00) {
3956 if ($m00['channels'][$chan] == 'opped' || $m00['channels'][$chan] == 'opvoiced') {
3957 $opped .= '@'.$m00['nick'].' ';
3958 print_r($this->user[$users]); print '('.$users.')';
3959 }
3960 if ($m00['channels'][$chan] == 'voiced') $voiced .= '+'.$m00['nick'].' ';
3961 if ($m00['channels'][$chan] == 'regged') $regged .= $m00['nick'].' ';
3962 }*/
3963 foreach ($this->chan[$chan]['users'] as $user => $status) {
3964 //print 'chan: '.$chan.' '.$this->user[$user]['nick'].' is '.$status."($user])\n";
3965 if ($status == 'opped' || $status == 'opvoiced') {
3966 $opped .= '@'.$this->user[$user]['nick'].' ';
3967 //print_r($this->user[$users]); print '('.$users.')';
3968 }
3969 if ($status == 'voiced') $voiced .= '+'.$this->user[$user]['nick'].' ';
3970 if ($status == 'regged') $regged .= $this->user[$user]['nick'].' ';
3971 }
3972 if (!empty($opped)) $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$opped, 1);
3973 if (!empty($voiced)) $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$voiced, 1);
3974 if (!empty($regged)) $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$regged, 1);
3975 if (count($this->chan[$chan]['bans']) >= 1) {
3976 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :Channel bans: ', 1);
3977 foreach ($this->chan[$chan]['bans'] as $m00 => $test) {
3978 if ($test) $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$test, 1);
3979 }
3980 }
3981 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :End.', 1);
3982 }
3983 else $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :No such channel.', 1);
3984 }
3985
3986 private function showChannels($sender) {
3987 foreach ($this->chan as $chan => $mee) {
3988 $var = count($this->chan[$chan]['users']);
3989 $count[$var.' '.$chan] = "$chan - $var";
3990 }
3991 sort($count);
3992 foreach ($count as $channel)
3993 $this->SendRaw($this->bots['ms']['snumeric'].' O '.$sender.' :'.$channel,0);
3994 }
3995
3996 private function joinChannels() {
3997 $this->db->query("
3998 SELECT *
3999 FROM channels
4000 ");
4001 while ($row = $this->db->fetch_assoc()) {
4002 $channel = strtolower($row['name']);
4003 $this->schan[$channel][strtolower($row['owner'])]['flags'] = strtolower($row['flags']);
4004 $this->schan[$channel][strtolower($row['owner'])]['topic'] = $row['topic'];
4005 if (is_numeric(strpos($row['flags'], 'c')) && !$row['suspended']) {
4006 $autolimit = $row['autolimit'];
4007 if ($autolimit) {
4008 $time = time();
4009 $this->lchan[$channel] = $time += 120;
4010 }
4011 }
4012 if ($row['autolimit'])
4013 $this->schan[$channel][strtolower($row['owner'])]['autolimit'] = $row['autolimit'];
4014
4015 if ((strtolower($row['owner']) == 'c' && is_numeric(strpos($this->schan[$channel]['c']['flags'], 'j'))) && (!$row['suspended'])) {
4016 $this->joinService($row['name'], strtolower($row['owner']));
4017 }
4018 elseif (strtolower($row['owner']) != 'c')
4019 $this->joinService($row['name'], strtolower($row['owner']));
4020
4021 if ($row['suspended']) {
4022 $this->schan[$channel][strtolower($row['owner'])]['suspended'] = $row['suspended'];
4023 }
4024 $this->schan[$channel][strtolower($row['owner'])]['moo'] = 'mo';
4025 }
4026 }
4027 private function joinService($channel, $service) {
4028 $this->SendRaw($this->bots[$service]['snumeric'].' J '.$channel, 1);
4029 if ($service != 'google') {
4030 $this->SendRaw($this->config['numeric'].' M '.$channel.' +o '.$this->bots[$service]['snumeric'], 1);
4031 $this->setStatus($this->bots[$service]['snumeric'], $channel, 'opped');
4032 }
4033 else $this->setStatus($this->bots[$service]['snumeric'], $channel, 'regged');
4034 }
4035
4036 private function getVersions() {
4037 $this->db->query("
4038 SELECT *
4039 FROM versions
4040 ");
4041 while ($row = $this->db->fetch_assoc()) {
4042 if (is_array($this->versions[$row['ip']])) {
4043 foreach ($this->versions[$row['ip']] as $moo => $mee) {
4044 if ($mee == $row['version']) $nvm = true;
4045 }
4046 }
4047 if (!$nvm) $this->versions[$row['ip']][] = $row['version'];
4048 unset($nvm);
4049 }
4050 }
4051
4052 private function killUser($numeric, $reason) {
4053 $this->SendRaw($this->bots['c']['snumeric'].' D '.$numeric.' :'.$this->config['snumeric'].' ('.$reason.')', 1);
4054 $sending[] = $numeric;
4055 $sending[] = 'Q';
4056 $sending[] = ':'.$reason;
4057 $this->quitUser($sending);
4058 }
4059
4060 private function saveUsers($args) {
4061 if (isset($args[4])) {
4062 $server = $args[0];
4063 $nick = $args[2];
4064 if ($args[4] == 0) $connectedtime = time();
4065 else $connectedtime = $args[4];
4066 $ident = $args[5];
4067 $host = $args[6];
4068 if (strpos($args[7], '+') === 0) {
4069 $modes = $args[7];
4070 $num = $args[9];
4071 $ip = $args[8];
4072 }
4073 else {
4074 $modes = '+';
4075 $num = $args[8];
4076 $ip = $args[7];
4077 }
4078 $sethost = 0;
4079 $auth = 0;
4080 if (strpos($modes, 'h') && strpos($modes, 'r')) {
4081 $sethost = $args[9];
4082 $auth = $args[8];
4083 $num = $args[11];
4084 $ip = $args[10];
4085 }
4086 if (strpos($modes, 'r') && strpos($modes, 'h') === false) {
4087 $auth = $args[8];
4088 $num = $args[10];
4089 $ip = $args[9];
4090 }
4091 if (strpos($modes, 'r') === false && strpos($modes, 'h')) {
4092 $sethost = $args[8];
4093 $num = $args[10];
4094 $ip = $args[9];
4095 }
4096
4097 /*
4098 if (strlen($args[2]) == 2 && is_numeric(strpos($args[2], 'Q')) && !$this->isOper($args[0])) {
4099 $this->killUser($num, 'No, You\'re not a service.');
4100 return;
4101 }
4102 */
4103
4104 if ($auth && is_numeric(strpos($auth, ':'))) {
4105 for ($i = 0; $i <= strlen($auth); $i++) {
4106 $cur = $auth{$i};
4107 if ($cur == ':') break;
4108 else $tussenauth .= $cur;
4109 }
4110 $auth = $tussenauth;
4111 }
4112
4113 $this->user[$num] = array(
4114 'server' => $server,
4115 'numeric' => $num,
4116 'ctime' => $connectedtime,
4117 'ident' => $ident,
4118 'host' => $host,
4119 'modes' => $modes,
4120 'sethost' => $sethost,
4121 'ip' => $ip,
4122 'auth' => $auth
4123 );
4124 $this->setNick($num, $nick);
4125 if ($auth) $this->auth[strtolower($auth)]['users'][] = $num;
4126
4127 foreach ($this->server as $server2 => $moo) {
4128 if (is_array($moo)) {
4129 foreach (array_keys($moo) as $key) {
4130 if ($key == $server) {
4131 if ($this->server[$server2][$server]['eb'])
4132 $nserver = $this->server[$server2][$server]['name'];
4133 }
4134 }
4135 }
4136 }
4137
4138 if (isset($nserver)) {
4139 $this->SendRaw($this->bots['ms']['snumeric'].' P '.$this->config['debug_channel'].' :user ['.$nick.'] ['.$ident.'@'.$host.'] has connected on ['.$nserver.']', 1);
4140 $this->SendRaw($this->bots['s']['snumeric'].' P '.$num.' :VERSION', 1);
4141 $this->versionallow[$ip] = true;
4142 }
4143 }
4144 else {
4145 /*
4146 if (strlen($args[2]) == 2 && is_numeric(strpos($args[2], 'Q')) && !$this->isOper($args[0])) {
4147 $this->killUser($args[0], 'No, You\'re not a service.');
4148 }
4149 */
4150 $this->setNick($args[0], $args[2]);
4151 }
4152 }
4153
4154 private function setNick($numeric, $newnick) {
4155 $oldnick = $this->user[$numeric]['nick'];
4156 if ($oldnick) unset($this->nick[strtolower($oldnick)]);
4157 $this->nick[strtolower($newnick)] = $numeric;
4158 $this->user[$numeric]['nick'] = $newnick;
4159 }
4160
4161 private function parseBan($ban, $chan) {
4162 if (!empty($ban)) {
4163 $chan = strtolower($chan);
4164 if (strpos($ban, ':%') === 0) $ban = str_replace(':%', '', $ban);
4165 $this->chan[$chan]['bans'][] = $ban;
4166 }
4167 }
4168
4169 private function saveChannels($argz) {
4170
4171 foreach ($argz as $arg) {
4172 $args[] = trim($arg);
4173 }
4174
4175 if (strpos($args[4], ':') === 0) {
4176 $aantal = count($args);
4177 for ($i = 4; $i <= $aantal; $i++) {
4178 $ban = $args[$i];
4179 if (is_numeric(strpos($ban, '@')))
4180 $bans[] = $ban;
4181 }
4182 $mauw = true;
4183 }
4184
4185
4186 $chan = strtolower(trim($args[2]));
4187
4188 if (is_array($this->chan[$chan]['users'])) {
4189 if (array_count_values($this->chan[$chan]['users']) > 0) {
4190 //print_r($this->chan[$args[2]]['users']);
4191 $channel = true;
4192 }
4193 }
4194
4195
4196 foreach ($this->server as $server2 => $moo) {
4197 if (is_array($moo)) {
4198 foreach (array_keys($moo) as $key2) {
4199 if ($key2 == $server) {
4200 if ($this->server[$server2][$server]['eb'])
4201 $nserver = $this->server[$server2][$server]['name'];
4202 }
4203 }
4204 }
4205 }
4206
4207 $check = true;
4208
4209 if ($channel) { // channel already exists (so probably another server is connecting)
4210 if ($this->chan[$chan]['cdate'] < $args[3]) { // the new server is introducing a channel wich was created earlyer then ours, so known channel + user information will be resetted.
4211 $reset = true;
4212 print 'resetted '.$args[2];
4213 $flags = $this->schan[$chan]['c']['flags'];
4214 unset($this->chan[$chan]);
4215 if ($flags) $this->schan[$chan]['c']['flags'] = $flags;
4216 foreach ($this->user as $users => $m00) {
4217 $bot = $this->numtoBot($m00['num']);
4218 if ($bot && $bot != 'google') {
4219 $this->SendRaw($this->config['numeric'].' M '.$chan.' +o '.$this->bots[$bot]['snumeric'], 1);
4220 $this->setStatus($this->bots[$service]['snumeric'], $chan, 'opped');
4221 }
4222 elseif ($m00['channels'][$chan])
4223 $this->setStatus($m00['numeric'], $chan, 'regged');
4224 }
4225 }
4226 else $check = false;
4227 }
4228
4229 if (!$mauw) {
4230 if (strpos($args[4], '+') === 0) {
4231 $modes = str_replace('+', '', $args[4]);
4232 $tlimit = strpos($args[4], 'l');
4233 $tkey = strpos($args[4], 'k');
4234 if (is_numeric($tkey) && is_numeric($tlimit)) {
4235 $users = $args[7];
4236 if (is_integer(strpos($args[8], ':%'))) {
4237 $aantal = count($args);
4238 for ($i = 8; $i <= $aantal; $i++) {
4239 $ban = $args[$i];
4240 if (is_numeric(strpos($ban, '@')))
4241 $bans[] = $ban;
4242
4243 }
4244 }
4245 if ($tlimit < $tkey) {
4246 $key = $args[6];
4247 $limit = $args[5];
4248 }
4249 if ($tlimit > $tkey) {
4250 $key = $args[5];
4251 $limit = $args[6];
4252 }
4253 }
4254 elseif (is_numeric(strpos($args[4], 'l')) && strpos($args[4], 'k') === false) {
4255 $limit = $args[5];
4256 $users = $args[6];
4257 if (is_integer(strpos($args[7], ':%'))) {
4258 $aantal = count($args);
4259 for ($i = 7; $i <= $aantal; $i++) {
4260 $ban = $args[$i];
4261 if (is_numeric(strpos($ban, '@')))
4262 $bans[] = $ban;
4263 }
4264 }
4265 }
4266 elseif (strpos($args[4], 'l') === false && is_numeric(strpos($args[4], 'k'))) {
4267 $key = $args[5];
4268 $users = $args[6];
4269 if (is_integer(strpos($args[7], ':%'))) {
4270 $aantal = count($args);
4271 for ($i = 7; $i <= $aantal; $i++) {
4272 $ban = $args[$i];
4273 if (is_numeric(strpos($ban, '@')))
4274 $bans[] = $ban;
4275 }
4276 }
4277 }
4278 else {
4279 $users = $args[5];
4280 if (is_integer(strpos($args[6], ':%'))) {
4281 $aantal = count($args);
4282 for ($i = 6; $i <= $aantal; $i++) {
4283 $ban = $args[$i];
4284 if (is_numeric(strpos($ban, '@')))
4285 $bans[] = $ban;
4286 }
4287 }
4288 }
4289 }
4290 else {
4291 $modes = '+';
4292 $users = $args[4];
4293 if (is_integer(strpos($args[5], ':%'))) {
4294 $aantal = count($args);
4295 for ($i = 5; $i <= $aantal; $i++) {
4296 $ban = $args[$i];
4297 if (is_numeric(strpos($ban, '@')))
4298 $bans[] = $ban;
4299 }
4300 }
4301 }
4302 $args[2] = strtolower($args[2]);
4303 $flags = $this->schan[$args[2]]['c']['flags'];
4304
4305 if ($check == true) {
4306 $this->chan[$args[2]] = array(
4307 'cdate' => $args[3],
4308 'modes' => $modes,
4309 'limit' => $limit,
4310 'key' => $key,
4311 'flags' => $flags,
4312 );
4313 }
4314 $loop = strlen($users) + 2;
4315 for ($i = 0; $i <= $loop; $i++) {
4316 $cur = $users{$i};
4317 if ($cur == ',' || $i == $loop) {
4318 unset ($startstate);
4319 if (!$state) {
4320 $statesay = 'regged';
4321 }
4322 if ($state == ':ov') $statesay = 'opvoiced';
4323 if ($state == ':o') $statesay = 'opped';
4324 if ($state == ':v') $statesay = 'voiced';
4325 if ($statesay == 'opped' || $statesay == 'opvoiced' || $statesay == 'voiced' || ($statesay == 'regged' || $reset)) {
4326 $this->setStatus($curnum, $args[2], $statesay);
4327 //print "\n\n".$this->user[$curnum]['nick']." ".$args[2]." $startstate\n\n";
4328 }
4329 unset($curnum);
4330 }
4331 else unset($endnum);
4332
4333 if ($cur == ':') {
4334 $startstate = 'on';
4335 unset($state);
4336 }
4337
4338 if ($startstate) {
4339 $state .= $cur;
4340 }
4341
4342 if ($cur != ',' && !$startstate) {
4343 $curnum .= $cur;
4344 }
4345 }
4346 if ($bans) {
4347 $i = 0;
4348 foreach ($bans as $maa) {
4349 if (is_numeric(strpos($maa,'@'))) {
4350 if ($i == 0) $maa = str_replace(':%', '', $maa);
4351 $i++;
4352 $this->parseBan($maa, trim($args[2]));
4353 }
4354 }
4355 }
4356 }
4357 }
4358
4359 private function EA() {
4360 /* End of Burst received */
4361 /* [get] AB EB */
4362 if (empty($this->EB)) {
4363 $tmp = sprintf('%s EA',$this->config['numeric']);
4364 $this->SendRaw($tmp,1);
4365 $this->EB = TRUE;
4366 }
4367 }
4368
4369 private function leaveService($service, $channel) {
4370 /*$sends[] = $this->bots[$service]['snumeric'];
4371 $sends[] = 'L';
4372 $sends[] = $channel;
4373 $this->leaveChan($sends);*/
4374 $this->removeUserChannels($this->bots[$service]['snumeric'], $channel);
4375 }
4376
4377 private function Pong($Args) {
4378
4379 // parting known empty channels //
4380
4381 foreach ($this->schan as $chan => $info) {
4382 $count = count($this->chan[$chan]['users']);
4383 foreach (array_keys($info) as $key) {
4384 if ($count == 1) {
4385 if ($key == 'c' || $key == 'google') {
4386
4387 if (($key == 'c' && $this->user[$this->bots[$key]['snumeric']]['channels'][$chan]) || ($key == 'google')) {
4388 $this->SendRaw($this->bots[$key]['snumeric'].' L '.$chan, 1);
4389 $this->leaveService($key, $chan);
4390 }
4391
4392 if ($key == 'google')
4393 unset($this->schan[strtolower($chan)][$key]);
4394
4395 $this->leaveService($this->bots[$key]['snumeric'], $chan);
4396 $this->removeUserChannels($this->bots[$key]['snumeric'], $chan);
4397 }
4398 }
4399 }
4400 }
4401
4402 // paring end //
4403
4404 // Channel limit //
4405
4406 if ($this->lchan) {
4407 foreach ($this->lchan as $channel => $time) {
4408 $tijd = time();
4409 if ($time <= $tijd) {
4410 $this->setLimit($channel);
4411 }
4412 }
4413 }
4414
4415 // limit end //
4416
4417
4418
4419 /* The server pinged us, we have to pong him back */
4420 /* [get] AB G !1061145822.928732 fish.go.moh.yes 1061145822.928732 */
4421 $this->Counter++;
4422 if ($this->Counter >= $this->PingPongs) {
4423 //$this->SaveChannels();
4424 $this->Counter=0; /* Putting it on zer0, for a new save/count */
4425 }
4426 $tmp = sprintf('%s Z %s',$this->config['numeric'],$Args[2]);
4427 $this->SendRaw($tmp,0);
4428 if ($this->DeBug) {
4429 printf("Ping Pong?!\n");
4430 @ob_flush();
4431 }
4432 }
4433
4434 private function timer($i, $todo) {
4435 $tijd = time();
4436 while ($tijd != $i) {
4437 $tijd = time();
4438 if ($i == $time) $todo;
4439 }
4440 }
4441
4442
4443 private function SendRaw($Line,$Show) {
4444 /* This sends information to the server */
4445 /*if ($this->DeBug && $Show) {
4446 printf("[send]: %s\n",$Line);
4447 @ob_flush();
4448 }*/
4449 fputs($this->Socket,$Line."\r\n");
4450 printf("[send]: %s\n",$Line);
4451 }
4452
4453
4454 public function timetodate($time)
4455 {
4456 $date = date("w j n Y G i", $time);
4457 $t = time() - 60*60*24*3 ;
4458 $date = explode (" ", $date);
4459 $date[0] = $dagen[$date[0]];
4460 $maand = $date[2];
4461 $date[2] = $maanden[$date[2]];
4462 if ($date[1] < 10) $date[1] = "0".$date[1];
4463 if ($maand < 10) $maand = "0".$maand;
4464 $date = $date[1]."-".$maand."-".$date[3];
4465 return $date;
4466 }
4467
4468 public function Return_Substrings($text, $sopener, $scloser) {
4469 $result = array();
4470
4471 $noresult = substr_count($text, $sopener);
4472 $ncresult = substr_count($text, $scloser);
4473
4474 if ($noresult < $ncresult)
4475 $nresult = $noresult;
4476 else
4477 $nresult = $ncresult;
4478
4479 unset($noresult);
4480 unset($ncresult);
4481
4482 for ($i=0;$i<$nresult;$i++)
4483 {
4484 $pos = strpos($text, $sopener) + strlen($sopener);
4485
4486 $text = substr($text, $pos, strlen($text));
4487
4488 $pos = strpos($text, $scloser);
4489
4490 $result[] = substr($text, 0, $pos);
4491
4492 $text = substr($text, $pos + strlen($scloser), strlen($text));
4493 }
4494
4495 return $result;
4496 }
4497
4498 private function IPbase64ToDecimal($base64)
4499 {
4500 $ip = $this->base64Todecimal($base64);
4501 $iphex = dechex($ip);
4502 $part0 = substr($iphex,0,2);
4503 $part0 = hexdec($part0);
4504
4505 $part1 = substr($iphex,2,2);
4506 $part1 = hexdec($part1);
4507
4508 $part2 = substr($iphex,4,2);
4509 $part2 = hexdec($part2);
4510
4511 $part3 = substr($iphex,6,2);
4512 $part3 = hexdec($part3);
4513 return $part0 . "." . $part1 . "." . $part2 . "." . $part3;
4514 }
4515
4516
4517 private function base64Todecimal($Base64)
4518 {
4519 $b64chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
4520 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
4521 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
4522 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
4523 '4', '5', '6', '7', '8', '9', '[', ']');
4524 for ($i = 0; $i < strlen($Base64); $i++)
4525 {
4526 $cur = $Base64{$i};
4527 for ($j = 0; $j < 64; $j++)
4528 if ($b64chars[$j] == $cur) $num = $j;
4529 $pow = strlen($Base64) - $i - 1;
4530 $pow = pow(64,$pow);
4531 $result += $num * $pow;
4532 }
4533 return $result;
4534 }
4535
4536 private function tomirc($text) {
4537 $text = str_replace('<b>', '', $text);
4538 $text = str_replace('</b>', '', $text);
4539 $text = str_replace('<u>', '', $text);
4540 $text = str_replace('</u>', '', $text);
4541 $text = str_replace('<em>', '', $text);
4542 $text = str_replace('</em>', '', $text);
4543 return $text;
4544 }
4545}