function users_get_account($nick) { $nick = strtolower(trim($nick)); $users = get_array_bucket(BUCKET_USERS); if (isset($users[$nick]) == True) { if (isset($users[$nick]["account"]) == True) { # TODO: expiry return $users[$nick]["account"]; } } $start = microtime(True); rawmsg("WHOIS {$nick}"); do { $users = get_array_bucket(BUCKET_USERS); if (isset($users[$nick]) == True) { if (isset($users[$nick]["account"]) == True) { return $users[$nick]["account"]; } } else { break; } sleep(1); } while (microtime(True) - $start < 5.0); #return False; return ""; }
function pingpong($data) { $parts = explode(" ", $data); if (count($parts) > 1) { if ($parts[0] == "PING") { rawmsg("PONG " . trim($parts[1])); return True; } } return False; }
return; } $user = users_get_data($nick); if (isset($user["channels"][$dest]) == False) { return; } var_dump($items); return; $timestamp = $items["time"]; $index = "ANTISPAM_DATA_" . $dest . "_" . $nick; $bucket = get_array_bucket($index); if (isset($bucket["timestamps"]) == False) { $bucket["timestamps"] = array(); $bucket["trailings"] = array(); } $bucket["timestamps"][] = $timestamp; $bucket["trailings"][] = $trailing; $n = count($bucket["timestamps"]); if ($n > PREVIOUS_MSG_TRACK) { array_shift($bucket); } set_array_bucket($bucket, $index); if ($n < PREVIOUS_MSG_TRACK) { return; } $delta = $timestamp - $bucket["timestamps"][0]; $trailings = array_count_values($bucket["trailings"]); if ($delta < 5 and count($trailings) == 1) { rawmsg("KICK {$dest} {$nick} :suspected flood"); } #####################################################################################################
term_echo("ERROR CREATING IRC SOCKET"); return; } stream_set_blocking($socket, 0); rawmsg("NICK {$bot_nick}"); rawmsg("USER {$bot_nick} 0host 0server :{$bot_nick}.bot"); #add_minion($bot_nick); while (True) { usleep(100000.0); $data = get_bucket("MINION_CMD_{$bot_nick}"); if ($data != "") { term_echo($data); if (unset_bucket("MINION_CMD_{$bot_nick}") == True) { $items = parse_data($data); if ($items !== False) { rawmsg($data); } else { $tokens = explode(" ", $data); if (count($tokens) == 2 and strtoupper($tokens[0]) == "FORWARD") { $forward = $tokens[1]; term_echo("*** FORWARD SET: ALL DATA WILL BE FORWARDED TO {$forward} ON EXEC BOT HOST NETWORK"); } unset($tokens); } } } $data = fgets($socket); if ($data === False) { continue; } $data = trim($data);
} break; case "~invite": if ($trailing != "") { rawmsg("INVITE {$trailing} :{$dest}"); } break; /*case ".kick": if (($target==$nick) and ($target<>get_bot_nick())) { rawmsg("KICK $dest $target :$nick kicked self"); } break;*/ /*case ".kick": if (($target==$nick) and ($target<>get_bot_nick())) { rawmsg("KICK $dest $target :$nick kicked self"); } break;*/ case "~kick": if ($target != $nick and $target != get_bot_nick()) { rawmsg("KICK {$dest} {$target} :commanded by {$nick}"); } break; case "~topic": if ($trailing != "") { rawmsg("TOPIC {$dest} :{$trailing}"); } break; } #####################################################################################################
function privmsg($destination, $nick, $msg) { global $dest_overrides; if ($destination == "") { term_echo("PRIVMSG: DESTINATION NOT SPECIFIED: nick=\"{$nick}\", msg=\"{$msg}\""); return; } if ($msg == "") { term_echo("PRIVMSG: NO TEXT TO SEND: nick=\"{$nick}\", destination=\"{$destination}\""); return; } $msg = substr($msg, 0, MAX_MSG_LENGTH); if (isset($dest_overrides[$nick][$destination]) == True) { $data = ":" . get_bot_nick() . " PRIVMSG " . $dest_overrides[$nick][$destination] . " :{$msg}"; rawmsg($data); } else { if (substr($destination, 0, 1) == "#") { $data = ":" . get_bot_nick() . " PRIVMSG {$destination} :{$msg}"; rawmsg($data); } else { $data = ":" . get_bot_nick() . " PRIVMSG {$nick} :{$msg}"; rawmsg($data); } } }
##################################################################################################### #exec:~pong|10|0|0|0||INTERNAL|||php scripts/ping.php %%trailing%% %%alias%% #exec:~ping|10|300|0|0||INTERNAL|||php scripts/ping.php %%trailing%% %%alias%% ##################################################################################################### require_once "lib.php"; $trailing = trim($argv[1]); $alias = trim($argv[2]); switch ($alias) { case "~ping": # called every 5 mins (trailing is empty) $t = microtime(True); if (get_bucket(BUCKET_CONNECTION_ESTABLISHED) != "1") { rawmsg("PING {$t}"); return; } $ping = get_bucket("<<PING>>"); $pong = get_bucket("<<PONG>>"); if ($ping != "" and $ping != $pong) { term_echo("==================== PING TIMEOUT DETECTED ===================="); echo "/INTERNAL ~restart-internal\n"; return; } set_bucket("<<PING>>", $t); rawmsg("PING {$t}"); return; case "~pong": # called in response to PONG received (trailing contains timestamp) set_bucket("<<PONG>>", $trailing); return; } #####################################################################################################