diff --git a/bot.php b/bot.php index e22b14b..c09839f 100644 --- a/bot.php +++ b/bot.php @@ -53,9 +53,8 @@ fputs($socket, "USER Badge-" . $rand . " 0 * :DC29 Badge Bot\n"); fputs($socket, "JOIN #theSignal\n"); // Join channel - - fputs($socket, "PRIVMSG #theSignal :!req " . $rand . " " . $myCode . "\n"); +echo "[+] announced arrival: ".$rand."\n"; // Force an endless while while (1) { @@ -78,23 +77,28 @@ chr(10), chr(13) ), '', $ex[3]); - if ($command == ":!req" && isset($ex[4]) && isset($ex[5]) && $ex[4] <> "" && $ex[5] <> "") { - // 4 = bot name, 5 = their code - if(!in_array($ex[4], $collected)){ // not already added their code - $response = get_code($ex[5]); - if(preg_match("/^[0-9A-Fa-f]{32}/", $response)){ // valid code back - fputs($socket, "PRIVMSG #theSignal :!rsp " . $ex[4] . " " . $response . "\n"); - array_push($collected, $ex[4]); // add to replied array - $myCode = get_own_code(); - fputs($socket, "PRIVMSG #theSignal :!req " . $rand . " " . $myCode . "\n"); - - } - } + if ($command == ":!req") { + if(isset($ex[4]) && $ex[4] <> ""){ // bot name + if(isset($ex[5]) && $ex[5] <> ""){ // code + if(!in_array($ex[4], $collected)){ // not already added this bot + $response = get_code($ex[5]); + if(preg_match("/^[0-9A-Fa-f]{32}/", $response)){ // valid code back + echo "[+] computing for ".$ex[4]."\n"; + fputs($socket, "PRIVMSG #theSignal :!rsp " . $ex[4] . " " . $response . "\n"); + array_push($collected, $ex[4]); // add to replied array + $myCode = get_own_code(); + fputs($socket, "PRIVMSG #theSignal :!req " . $rand . " " . $myCode . "\n"); + echo "[+] replied to ".$ex[4]."\n"; + }else{echo "[-] invalid code\n";} + }else{echo "[-] already exchanged\n";} + }else{echo "[-] no code\n";} + }else{echo "[-] no name\n";} } if ($command == ":!rsp") { if ($ex[4] == $rand && isset($ex[5]) && $ex[5] <> ""){ // response is for this bot get_code($ex[5]); - } + echo "[+] got response from ".$ex[4]."\n"; + }else{echo "[-] not for me\n";} } } }