diff --git a/README.md b/README.md index 69a8e04..a961169 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Bot to connect badge to IRC for sharing and validating codes simply git clone this repo + make sure you have the correct interface at top of script (default is /dev/ttyACM0) ```` @@ -23,4 +24,13 @@ ``` (thanks to SkarDude) -the device cannot be busy when running this script, i.e. kill your screen sessions! \ No newline at end of file +the device cannot be busy when running this script, i.e. kill your screen sessions! + +If your badge is generating short hashes this will automagically fix that. + +If you want to see your badge stats type in the IRC channel: + +``` +!stats +``` +(replacing rand with your badge's random ID generated when running the script) \ No newline at end of file diff --git a/README.md b/README.md index 69a8e04..a961169 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Bot to connect badge to IRC for sharing and validating codes simply git clone this repo + make sure you have the correct interface at top of script (default is /dev/ttyACM0) ```` @@ -23,4 +24,13 @@ ``` (thanks to SkarDude) -the device cannot be busy when running this script, i.e. kill your screen sessions! \ No newline at end of file +the device cannot be busy when running this script, i.e. kill your screen sessions! + +If your badge is generating short hashes this will automagically fix that. + +If you want to see your badge stats type in the IRC channel: + +``` +!stats +``` +(replacing rand with your badge's random ID generated when running the script) \ No newline at end of file diff --git a/bot.php b/bot.php index f38c6ae..12e63bb 100644 --- a/bot.php +++ b/bot.php @@ -50,6 +50,46 @@ $fixedCode .= substr($code, 16, strlen($code)); return $fixedCode; } +function get_stats_connected(){ + global $badgeInterface; + $serial = new PhpSerial; + $serial->deviceSet($badgeInterface); + $serial->confBaudRate(9600); + $serial->deviceOpen('w+'); + stream_set_timeout($serial->_dHandle, 3); + $serial->sendMessage("\r\n\r\n5\r\n\r\n"); + $devResponse = $serial->readPort(); + $serial->deviceClose(); + + $toReturn = trim(preg_replace('/\s+/', ' ', $devResponse)); + $toReturn = trim(string_between_two_string($toReturn, 'Number of Badges Connected: ', 'Badge Types')); + //echo $toReturn; // DEBUG + + return $toReturn; +} +function get_stats_signal(){ + global $badgeInterface; + $serial = new PhpSerial; + $serial->deviceSet($badgeInterface); + $serial->confBaudRate(9600); + $serial->deviceOpen('w+'); + stream_set_timeout($serial->_dHandle, 3); + $serial->sendMessage("\r\n\r\n5\r\n\r\n"); + $devResponse = $serial->readPort(); + $serial->deviceClose(); + + $toReturn = trim(preg_replace('/\s+/', ' ', $devResponse)); + $toReturn = trim(string_between_two_string($toReturn, 'Shared the Signal: ', 'Thank you')); + //echo $toReturn; // DEBUG + + return $toReturn; +} +function string_between_two_string($str, $starting_word, $ending_word){ + $subtring_start = strpos($str, $starting_word); + $subtring_start += strlen($starting_word); + $size = strpos($str, $ending_word, $subtring_start) - $subtring_start; + return substr($str, $subtring_start, $size); +} $rand = substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(8/strlen($x)) )),1,8); @@ -59,6 +99,10 @@ if(!isset($myCode) || $myCode == "") die("Please contact 0xRoM on discord for help fixing this issue!"); +$badgeConn = get_stats_connected(); +$badgeSig = get_stats_signal(); +echo "[+] connected: $badgeConn, Sig shared: $badgeSig\n"; + $socket = fsockopen("ice.uplinkcorp.net", 6667); // Send auth info // fputs($socket, "PASS " . $password . "\n"); @@ -105,19 +149,29 @@ $myCode = get_own_code(); $myCode = (strlen($myCode) == 31) ? short_code($myCode) : $myCode; - + 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";} + }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";} + if ($ex[4] == $rand){ // response is for this bot + if(isset($ex[5]) && $ex[5] <> ""){ // code for me + get_code($ex[5]); + echo "[+] got response from ".$ex[4]."\n"; + }else{ echo "[-] no code set\n"; } + }else{ echo "[-] not for me\n"; } + } + if ($command == ":!stats") { + if (trim($ex[4]) === $rand){ // response is for this bot + $badgeConn = get_stats_connected(); + $badgeSig = get_stats_signal(); + echo "[+] connected: $badgeConn, Sig shared: $badgeSig\n"; + fputs($socket, "PRIVMSG #theSignal :Connected = $badgeConn, Sig shared = $badgeSig\n"); + }else{ echo "[-] not for me \n".$ex[4]."\n$rand\n"; } } } }