rendered paste body<?php// Remember that the gamemode value is a number, so to get the string do something like:$gamemodes = array( 0 => 'DM', 1 => 'PM', 2 => 'TM', 3 => 'CTF', 4 => 'RM', 5 => 'INF', 6 => 'HTF');$teams = array( 1 => 'Alpha', 2 => 'Bravo', 3 => 'Charlie', 4 => 'Delta', 5 => 'Spectator');function GetInfoForIRC() { // Make sure the REFRESH packet was received if ($info) { // You can now use the $info array to check different stuff from server, check the function for the array's elements $gamemode_str = $gamemodes[$info['gamemode']]; $map_str = $info['map']; if ($gamemode_str = "TM") { $teamscore_str = chr(3)."4Alpha: ".$info['team'][1].chr(3)." Bravo: ".$info['team'][2]." Charlie: ".$info['team'][3]." Delta: ".$info['team'][4]; } else { $teamscore_str = chr(3)."4Alpha: ".$info['team'][1].chr(3)."12 Bravo: ".$info['team'][2]; } $timeleft_str = $info['timeleft']; }}function GetSoldatInfo(&$sock) { if (!$sock) return false; $info = array( 'gamemode' => 0, 'teammode' => false, 'pointmode' => false, 'players' => 0, 'spectators' => 0, 'map' => '', 'timelimit' => 0, 'currenttime' => 0, 'timeleft' => 0, 'limit' => 0, 'player' => array(), 'spectator' => array(), 'team' => array() ); // Temporary array for players $players = array(); for ($i = 0; $i < 32; $i++) { $players[$i] = array( 'name' => '', 'ip' => '', 'id' => 0, 'kills' => 0, 'deaths' => 0, 'team' => 0, 'ping' => 0 ); } // Get player names for ($i = 0; $i < 32; $i++) { $data = fread($sock, 25); $len = ord($data[0]); $players[$i]['name'] = substr($data, 1, $len); } // Get player teams for ($i = 0; $i < 32; $i++) { $data = fread($sock, 1); $players[$i]['team'] = ord($data); } // Get player kills for ($i = 0; $i < 32; $i++) { $data = unpack("v", fread($sock, 2)); $kills = $data[1]; $players[$i]['kills'] = $kills; } // Get player deaths for ($i = 0; $i < 32; $i++) { $data = unpack("v", fread($sock, 2)); $deaths = $data[1]; $players[$i]['deaths'] = $deaths; } // Get player pings for ($i = 0; $i < 32; $i++) { $data = fread($sock, 1); $players[$i]['ping'] = ord($data); } // Get player IDs for ($i = 0; $i < 32; $i++) { $data = fread($sock, 1); $players[$i]['id'] = ord($data); } // Get player IPs for ($i = 0; $i < 32; $i++) { $data = unpack("N", fread($sock, 4)); $players[$i]['ip'] = long2ip($data[1]); } // Get team scores for ($i = 1; $i < 5; $i++) { $data = unpack("v", fread($sock, 2)); $score = $data[1]; $info['team'][$i] = $score; } // Get map name $data = fread($sock, 17); $len = ord($data[0]); $info['map'] = substr($data, 1, $len); // Get time limit & current time, and form timeleft $data = unpack("V", fread($sock, 4)); $timelimit = $data[1]; $info['timelimit'] = $timelimit; $data = unpack("V", fread($sock, 4)); $currenttime = $data[1]; $info['currenttime'] = $timelimit - $currenttime; $timeleft = $currenttime; $temp = (floor($timeleft / 60) % 60); $info['timeleft'] = floor($timeleft / 3600) . ':' . ($temp < 10 ? '0' : '') . $temp; // Get kill limit $data = unpack("v", fread($sock, 2)); $limit = $data[1]; $info['limit'] = $limit; // Get gamestyle $data = fread($sock, 1); $gamestyle = ord($data); $info['gamemode'] = $gamestyle; if ($gamestyle == 2 || $gamestyle == 3 || $gamestyle == 5 || $gamestyle == 6) { $info['teammode'] = true; if ($gamestyle != 2) { $info['pointmode'] = true; } } if ($gamestyle != 2) { if ($gamestyle != 3 && $gamestyle != 5) { unset($info['team'][1]); unset($info['team'][2]); } unset($info['team'][3]); unset($info['team'][4]); } foreach ($players as $player) { if ($player['team'] < 5) { $info['players']++; $info['player'][] = $player; } else if ($player['team'] == 5) { $info['spectators']++; $info['spectator'][] = $player; } } return $info; }$s = @fsockopen("fracs.net", 70000);fputs($s, "drock\n"); fputs($s, "REFRESH\r\n");while($s){ $data = trim(fgets($s)); //check for refresh if($refresh) { if($lastrefresh < (time()-10)) fputs($s, "REFRESH\r\n"); $refresh = false; } else { if(strpos($data, "REFRESH") == true) { $info = GetSoldatInfo($s); $refresh = false; } fwrite($s, "REFRESH\r\n"); $lastrefresh = time(); }}//IRC starts NOW -----------------------------------------------------$host='irc.quakenet.org';$port=6667;$mynickname='R7';// Prevent PHP from stopping the script after 30 secignore_user_abort(TRUE);set_time_limit(0);// Opening the socket to the Quakenet network$socket = fsockopen($host,$port,$errno,$errstr,15);if (!$socket) die("Error: $errstr ($errno)\n");// Send auth infofputs($socket,"USER R7 fracs.net Ruthless :Ruth\n");fputs($socket,"NICK R7\n");$auth = 1;// Force an endless while while (true) { $ircdata=fgets($socket); echo $ircdata; // Separate all data $ex = explode(' ', $ircdata); // Send PONG back to the server if($ex[0] == "PING"){ fputs($socket, "PONG ".$ex[1]."\n"); if ($auth == 1) { sleep(10); fputs($socket, "PRIVMSG Q@CServe.quakenet.org :AUTH Ruthless Xbox360\n"); sleep(1); fputs($socket, "MODE ".$mynickname." +x\n"); sleep(3); $channelfile = "channels.txt"; $channels = file($channelfile); for($c = 0;$c < count($channels);$c++){ fputs($socket, "JOIN ".$channels[$c]."\n"); } $auth = 2; } } if ($ex[1] == "PRIVMSG") { $useraddress=substr($ex[0],1); $nickname=substr($useraddress,0,strpos($useraddress,'!')); $ident=substr($useraddress,strpos($useraddress,'!')+1,-strpos($useraddress,'@')-1); $hostname=substr($useraddress,strpos($useraddress,'@')+1); $channel=$ex[2]; //PM if ($channel=='R7') { $lastnick = $nickname; $to_receive .= ""; for($i = 3;$i < count($ex);$i++){ $to_receive = $to_receive." ".trim($ex[$i]); } $to_receive = substr($to_receive,strpos($to_receive,':',1)+1); fputs($socket, "PRIVMSG #ruth.priv :".chr(2).chr(3)."4<[PM]> ".chr(3).chr(2).chr(3)."12<".$nickname."> ".chr(3).$to_receive."\n"); $to_receive = ""; } } // Say something in the channel $command = trim($ex[3]); //Main channel commands /* if ($channel == "#the.ruthless") { if ($command == ":!sctfl" && !isset($floodtime)) { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2).$nickname.chr(2).chr(3)."7» ".chr(3)."0 would like an SCTFL match\n"); fputs($socket, "PRIVMSG #the.ruthless :".chr(3)."7,1 «".chr(3)."0".chr(2)."The members have been informed.".chr(2).chr(3)."7» ".chr(3)."\n"); $floodtime = time() + 5; } while (isset($floodtime)) { if (time() > $floodtime) { unset($floodtime); } } } */ //Priv Chan commands if ($channel == "#ruth.priv") { if ($command == ":!muffin") { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2)."Muffin Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://u13.net:20000/muffin\n"); } if ($command == ":!server") { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2)."Ruthless Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://208.70.146.121:70000/ruth\n"); } if ($command == ":!OC") { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2)."OC Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://208.70.146.121:41337/newera\n"); } if ($command == ":!deth") { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2)."DETH Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://208.70.146.121:25555/ugapa\n"); } if ($command == ":!LP") { fputs($socket, "PRIVMSG #ruth.priv :".chr(3)."7,1 «".chr(3)."0".chr(2)."LP Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://u13.net:30089/LP\n"); } if ($command == ":!roll") { fputs($socket, "PRIVMSG #ruth.priv : ".$nickname." rolled ".chr(2).rand(0,15).chr(2)."\n"); } if ($command == ":!chans") { fputs($socket, "WHOIS ".$mynickname."\n"); if ($ex[1] == "319") { $curchans .= ""; for($cc = 4;$i < count($ex);$cc++){ $curchans = $curchans." ".trim($ex[$cc]); } $curchans = substr($curchans,strpos($curchans,':',1)+1); $numchans = count($ex) - 4; fputs($socket, "PRIVMSG #ruth.priv :I am in".chr(2).$numchans.chr(2)." channels: ".$curchans."\n"); $curchans = ""; } } if ($command == ":!serv") { fputs($socket, "PRIVMSG ".$ex[4].":".chr(3)."7,1 «".chr(3)."0".chr(2)."Ruthless Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://208.70.146.121:70000/ruth\n"); fputs($socket, "PRIVMSG #ruth.priv :Server info sent to ".$ex[4]."\n"); } if ($command == ":!servlast") { fputs($socket, "PRIVMSG ".$lastnick.":".chr(3)."7,1 «".chr(3)."0".chr(2)."Ruthless Server".chr(2).chr(3)."7» ".chr(3)."0 soldat://208.70.146.121:70000/ruth\n"); fputs($socket, "PRIVMSG #ruth.priv :Server info sent to ".$lastnick."\n"); } if ($command == ":!m" && count($ex) > 4) { //message $to_send .= ""; for($i = 5;$i < count($ex);$i++){ $to_send = $to_send." ".trim($ex[$i]); } fputs($socket, "PRIVMSG ".$ex[4]." :".chr(3)."12<".$nickname.">".chr(3).$to_send."\n"); $to_send = ""; } if ($command == ":!r" && count($ex) > 4) { //reply $to_reply .= ""; for($i = 4;$i < count($ex);$i++){ $to_reply = $to_reply." ".trim($ex[$i]); } fputs($socket, "PRIVMSG ".$lastnick." :".chr(3)."12<".$nickname.">".chr(3).$to_reply."\n"); $to_reply = ""; } //Changes nick if ($command == ":!nick") { fputs($socket, "NICK ".$ex[4]."\n"); $mynickname = $ex[4]; } //Joins channel if ($command == ":!j") { fputs($socket, "JOIN ".$ex[4]." ".$ex[5]."\n"); } //Leaves channel if ($command == ":!p") { fputs($socket, "PART ".$ex[4]." ".$ex[5]."\n"); } if ($command == ":!playing") { fputs($s, "REFRESH\n"); GetInfoForIRC(); fputs($socket, "PRIVMSG #ruth.priv :Gamemode: ".$gamemode_str." Map: ".$map_str." Teamscores: ".$teamscore_str." Timeleft: ".$timeleft_str."\n"); } if ($command == ":!cmd") { $to_server .= ""; for($i = 4;$i < count($ex);$i++){ $to_server = $to_server." ".trim($ex[$i]); } fputs($s, ":".$to_server."\n"); $to_server = ""; } //Auths/+x if ($command == ":!auth") { fputs($socket, "PRIVMSG Q@CServe.quakenet.org :AUTH Ruthless Xbox360\n"); fputs($socket, "MODE ".$mynickname." +x\n"); } // To quit the bot if($command == ":!quit" && $hostname == "Lordrohith-.users.quakenet.org"){ fputs($socket,"QUIT :lolquitmsg\n"); } } }fclose($socket);?>