Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* USER EDITABLE AREA */
- # Insert the MySQL database information in here.
- $dbusername = "" ;
- $dbhostname = "" ;
- $dbpassword = "" ;
- $database = "" ;
- # Insert the messages in here that the console should say in-game once a player was found (or not).
- # You can use $name , $guid and $team within the text, it should get replaced automatically.
- $msgpass = "^1<^3SQHub^1>^7 Player ^3$name ^7(^5$guid^7) is assigned to ^2$team" ;
- $msgfail = "^1<^3SQHub^1>^7 Unable to identify ^3$name" ;
- /***************************************************************************************/
- /*** DO NOT EDIT ANYTHING UNDER THIS LINE UNLESS YOU'RE SURE ABOUT WHAT YOU'RE DOING ***/
- /***************************************************************************************/
- # Functions
- function delcodcolor($str) {
- do {
- $str = preg_replace("/\^\d/", "", $str) ;
- }
- while(preg_match("/\^\d/", $str)) ;
- return $str ;
- }
- # Check whether all fields in the session are set.
- if(isset($_POST["ip"]) && isset($_POST["port"]) && isset($_POST["rcon"])) {
- $error = false ;
- if(!preg_match("/[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}/", $_POST["ip"])) {
- $error = true ;
- }
- if(!preg_match("/[\d]{4,5}/", $_POST["port"])) {
- $error = true ;
- }
- if(!preg_match("/[\w\d]{0,16}/", $_POST["rcon"])) {
- $error = true ;
- }
- if($error) {
- die("Please go <a href='javascript:history.go(-1);'>back</a>.") ;
- }
- echo "Retreived configuration info<br />" ;
- # Load rcon into a variable for easier handling
- $rcon = $_POST["rcon"] ;
- # Open a connection to the MySQL server
- $sql = mysql_connect($dbhostname, $dbusername, $dbpassword) ;
- if(!$sql) {
- session_destroy() ;
- die("Could not connect to the MySQL server: " . mysql_error()) ;
- }
- mysql_select_db($database, $sql) ;
- echo "Connected to the MySQL database<br />" ;
- # Open a connection to the game server
- $sock = fsockopen("udp://" . $_POST["ip"], intval($_POST["port"]), $re, $errstr, 5) ;
- if(!$sock) {
- session_destroy() ;
- die("Could not connect to the game server: " . $errstr) ;
- }
- socket_set_timeout($sock, 5) ;
- echo "Connected to the game server<br />" ;
- # Load the PB list from the game server into an array
- fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" pb_sv_plist") ;
- $plist = fread($sock, 1) ;
- $sockstat = socket_get_status($sock) ;
- while($sockstat["unread_bytes"]) {
- $plist .= fread ($sock, 2048) ;
- $sockstat = socket_get_status($sock) ;
- }
- $plist = preg_replace("/[ ]{2,}/", " ", str_replace("print\n", "", str_replace(chr(0xFF), "", $plist))) ;
- if(strstr($plist, "valid password.") {
- die("Invalid rcon password.") ;
- }
- $temp = explode("\n", $plist) ;
- $temp = explode(" ", $temp[0]) ;
- $prefix = "" ;
- for($i = 0 ; $i < count($temp) - 14 ; $i++) {
- $prefix .= $temp[$i] . " " ;
- }
- $plist = str_replace($prefix, "", $plist) ;
- unset($temp, $prefix) ;
- $plexp = explode("\n", $plist) ;
- if(count($plexp) <= 2) {
- die("Error: no players connected / script failure") ;
- }
- $players = array() ;
- for($i = 1 ; $i < count($plexp) - 1 ; $i++) {
- $boom1 = explode(" ", $plexp) ;
- $boom2 = explode("\"", $plexp) ;
- $players[preg_replace("/\(.*?\)/", "", $boom1[1])] = delcodcolor($boom2[1]) ;
- }
- echo "Retrieved player list<br />" ;
- # Parse it all
- foreach($players as $guid => $name) {
- $knownlist = mysql_query("SELECT * FROM members WHERE PB_GUID='" . $guid . "'") ;
- $data = mysql_fetch_array($knownlist) ;
- if(!$data) {
- fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" say " . $msgfail) ;
- $del = fread($sock, 1) ;
- $sockstat = socket_get_status($sock) ;
- while($sockstat["unread_bytes"]) {
- $del .= fread ($sock, 2048) ;
- $sockstat = socket_get_status($sock) ;
- }
- unset($del) ;
- echo "Player $name ($guid) not assigned" ;
- }
- else {
- $teamid = mysql_fetch_array(mysql_query("SELECT teamid FROM membersteams WHERE memberid='" . $data["ID"] . "' AND ladderid='4'")) ;
- $teamx = mysql_fetch_array(mysql_query("SELECT name FROM teams WHERE id='" . $teamid["$teamid"] . "'")) ;
- $team = $teamx["name"] ;
- fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" say " . $msgpass) ;
- $del = fread($sock, 1) ;
- $sockstat = socket_get_status($sock) ;
- while($sockstat["unread_bytes"]) {
- $del .= fread ($sock, 2048) ;
- $sockstat = socket_get_status($sock) ;
- }
- unset($del) ;
- echo "Player $name ($guid) assigned to $team" ;
- }
- # Sleep once per player
- sleep(1) ;
- }
- # It's all done now.
- mysql_close($sql) ;
- fclose($sock) ;
- echo "All done." ;
- }
- else {
- ?>
- <html>
- <head>
- <title>Auto-assignation</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- </head>
- <body>
- <form method='post'>
- IP: <input name='ip' type='text' /><br />
- Port: <input name='port' type='text' /><br />
- Rcon pass: <input name='rcon' type='password' /><br />
- <input type='submit' value='I like Squealer!' />
- </form>
- </body>
- </html>
- <?php
- }
- ?>
Add Comment
Please, Sign In to add comment