Guest User

Untitled

a guest
Jun 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. <?php
  2.  
  3. /* USER EDITABLE AREA */
  4.  
  5. # Insert the MySQL database information in here.
  6. $dbusername = "" ;
  7. $dbhostname = "" ;
  8. $dbpassword = "" ;
  9. $database = "" ;
  10.  
  11. # Insert the messages in here that the console should say in-game once a player was found (or not).
  12. # You can use $name , $guid and $team within the text, it should get replaced automatically.
  13. $msgpass = "^1<^3SQHub^1>^7 Player ^3$name ^7(^5$guid^7) is assigned to ^2$team" ;
  14. $msgfail = "^1<^3SQHub^1>^7 Unable to identify ^3$name" ;
  15.  
  16. /***************************************************************************************/
  17. /*** DO NOT EDIT ANYTHING UNDER THIS LINE UNLESS YOU'RE SURE ABOUT WHAT YOU'RE DOING ***/
  18. /***************************************************************************************/
  19.  
  20. # Functions
  21.  
  22. function delcodcolor($str) {
  23. do {
  24. $str = preg_replace("/\^\d/", "", $str) ;
  25. }
  26. while(preg_match("/\^\d/", $str)) ;
  27. return $str ;
  28. }
  29.  
  30. # Check whether all fields in the session are set.
  31. if(isset($_POST["ip"]) && isset($_POST["port"]) && isset($_POST["rcon"])) {
  32. $error = false ;
  33.  
  34. if(!preg_match("/[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}/", $_POST["ip"])) {
  35. $error = true ;
  36. }
  37. if(!preg_match("/[\d]{4,5}/", $_POST["port"])) {
  38. $error = true ;
  39. }
  40. if(!preg_match("/[\w\d]{0,16}/", $_POST["rcon"])) {
  41. $error = true ;
  42. }
  43. if($error) {
  44. die("Please go <a href='javascript:history.go(-1);'>back</a>.") ;
  45. }
  46.  
  47. echo "Retreived configuration info<br />" ;
  48.  
  49. # Load rcon into a variable for easier handling
  50. $rcon = $_POST["rcon"] ;
  51.  
  52. # Open a connection to the MySQL server
  53. $sql = mysql_connect($dbhostname, $dbusername, $dbpassword) ;
  54. if(!$sql) {
  55. session_destroy() ;
  56. die("Could not connect to the MySQL server: " . mysql_error()) ;
  57. }
  58. mysql_select_db($database, $sql) ;
  59. echo "Connected to the MySQL database<br />" ;
  60.  
  61. # Open a connection to the game server
  62. $sock = fsockopen("udp://" . $_POST["ip"], intval($_POST["port"]), $re, $errstr, 5) ;
  63. if(!$sock) {
  64. session_destroy() ;
  65. die("Could not connect to the game server: " . $errstr) ;
  66. }
  67. socket_set_timeout($sock, 5) ;
  68. echo "Connected to the game server<br />" ;
  69.  
  70. # Load the PB list from the game server into an array
  71. fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" pb_sv_plist") ;
  72. $plist = fread($sock, 1) ;
  73. $sockstat = socket_get_status($sock) ;
  74. while($sockstat["unread_bytes"]) {
  75. $plist .= fread ($sock, 2048) ;
  76. $sockstat = socket_get_status($sock) ;
  77. }
  78. $plist = preg_replace("/[ ]{2,}/", " ", str_replace("print\n", "", str_replace(chr(0xFF), "", $plist))) ;
  79. if(strstr($plist, "valid password.") {
  80. die("Invalid rcon password.") ;
  81. }
  82. $temp = explode("\n", $plist) ;
  83. $temp = explode(" ", $temp[0]) ;
  84. $prefix = "" ;
  85. for($i = 0 ; $i < count($temp) - 14 ; $i++) {
  86. $prefix .= $temp[$i] . " " ;
  87. }
  88. $plist = str_replace($prefix, "", $plist) ;
  89. unset($temp, $prefix) ;
  90. $plexp = explode("\n", $plist) ;
  91. if(count($plexp) <= 2) {
  92. die("Error: no players connected / script failure") ;
  93. }
  94. $players = array() ;
  95. for($i = 1 ; $i < count($plexp) - 1 ; $i++) {
  96. $boom1 = explode(" ", $plexp) ;
  97. $boom2 = explode("\"", $plexp) ;
  98. $players[preg_replace("/\(.*?\)/", "", $boom1[1])] = delcodcolor($boom2[1]) ;
  99. }
  100. echo "Retrieved player list<br />" ;
  101.  
  102. # Parse it all
  103. foreach($players as $guid => $name) {
  104. $knownlist = mysql_query("SELECT * FROM members WHERE PB_GUID='" . $guid . "'") ;
  105. $data = mysql_fetch_array($knownlist) ;
  106. if(!$data) {
  107. fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" say " . $msgfail) ;
  108. $del = fread($sock, 1) ;
  109. $sockstat = socket_get_status($sock) ;
  110. while($sockstat["unread_bytes"]) {
  111. $del .= fread ($sock, 2048) ;
  112. $sockstat = socket_get_status($sock) ;
  113. }
  114. unset($del) ;
  115. echo "Player $name ($guid) not assigned" ;
  116. }
  117. else {
  118. $teamid = mysql_fetch_array(mysql_query("SELECT teamid FROM membersteams WHERE memberid='" . $data["ID"] . "' AND ladderid='4'")) ;
  119. $teamx = mysql_fetch_array(mysql_query("SELECT name FROM teams WHERE id='" . $teamid["$teamid"] . "'")) ;
  120. $team = $teamx["name"] ;
  121. fwrite($sock, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0xFF) . "rcon \"" . $rcon . "\" say " . $msgpass) ;
  122. $del = fread($sock, 1) ;
  123. $sockstat = socket_get_status($sock) ;
  124. while($sockstat["unread_bytes"]) {
  125. $del .= fread ($sock, 2048) ;
  126. $sockstat = socket_get_status($sock) ;
  127. }
  128. unset($del) ;
  129. echo "Player $name ($guid) assigned to $team" ;
  130. }
  131. # Sleep once per player
  132. sleep(1) ;
  133. }
  134.  
  135. # It's all done now.
  136. mysql_close($sql) ;
  137. fclose($sock) ;
  138. echo "All done." ;
  139. }
  140. else {
  141. ?>
  142. <html>
  143. <head>
  144. <title>Auto-assignation</title>
  145. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  146. </head>
  147. <body>
  148. <form method='post'>
  149. IP: <input name='ip' type='text' /><br />
  150. Port: <input name='port' type='text' /><br />
  151. Rcon pass: <input name='rcon' type='password' /><br />
  152. <input type='submit' value='I like Squealer!' />
  153. </form>
  154. </body>
  155. </html>
  156. <?php
  157. }
  158. ?>
Add Comment
Please, Sign In to add comment