Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.01 KB | None | 0 0
  1. <?php
  2. /***************
  3. ** Deactivate HLstatsX ranking for banned players
  4. ** and reactivate them if unbanned
  5. ** Supports SourceBans, AMXBans, Beetlesmod, Globalban, MySQL Banning*
  6. ** by Jannik 'Peace-Maker' Hartung
  7. ** http://www.sourcebans.net/, http://www.wcfan.de/
  8.  
  9. ** This program is free software; you can redistribute it and/or
  10. ** modify it under the terms of the GNU General Public License
  11. ** as published by the Free Software Foundation; either version 2
  12. ** of the License, or (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22. **
  23. **
  24. ** Version 1.3: Added MySQL Banning support
  25. ** Version 1.2: Added more error handling
  26. ** Version 1.1: Fixed banned players not marked as banned, if a previous ban was unbanned
  27. ** Version 1.0: Initial Release
  28. ***************/
  29.  
  30. /*****************************
  31. /***MAKE YOUR CONFIGURATION***
  32. /********SETTINGS IN**********
  33. /******hlstatsxban.cfg********
  34. /***** DON'T EDIT BELOW ******
  35. /*****************************/
  36.  
  37. require("hlstatsxban.cfg");
  38.  
  39. if (!extension_loaded('mysqli')) {
  40.     die("This script requires the MySQLi extension to be enabled.  Consult your administrator, or edit your php.ini file, to enable this extension.");
  41. }
  42.  
  43. $usesb = (SB_HOST == ""||SB_PORT == ""||SB_USER == ""||SB_PASS == ""||SB_NAME == ""||SB_PREFIX == ""?false:true);
  44. $useamx = (AMX_HOST == ""||AMX_PORT == ""||AMX_USER == ""||AMX_PASS == ""||AMX_NAME == ""||AMX_PREFIX == ""?false:true);
  45. $usebm = (BM_HOST == ""||BM_PORT == ""||BM_USER == ""||BM_PASS == ""||BM_NAME == ""||BM_PREFIX == ""?false:true);
  46. $usegb = (GB_HOST == ""||GB_PORT == ""||GB_USER == ""||GB_PASS == ""||GB_NAME == ""||GB_PREFIX == ""?false:true);
  47. $usemb = (MB_HOST == ""||MB_PORT == ""||MB_USER == ""||MB_PASS == ""||MB_NAME == ""||MB_PREFIX == ""?false:true);
  48. $hlxready = (HLX_HOST == ""||HLX_PORT == ""||HLX_USER == ""||HLX_PASS == ""||empty($hlxdbs)||HLX_PREFIX == ""?false:true);
  49.  
  50. if (!$hlxready || (!$usesb && !$useamx && !$usebm && !$usegb && !$usemb))
  51.     die('[-] Please type your database information for HLstatsX and at least for one other ban database.');
  52.  
  53. $bannedplayers = array();
  54. $unbannedplayers = array();
  55.  
  56. //------------------------------
  57. // SourceBans Part
  58. //------------------------------
  59. if ($usesb)
  60. {
  61.     // Connect to the SourceBans database.
  62.     $con = new mysqli(SB_HOST, SB_USER, SB_PASS, SB_NAME, SB_PORT);
  63.     if (mysqli_connect_error()) die('[-] Can\'t connect to SourceBans Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  64.    
  65.     print("[+] Successfully connected to SourceBans database. Retrieving bans now.\n");
  66.    
  67.     // Get permanent banned players
  68.     $bcnt = 0;
  69.     if ($bans = $con->query("SELECT `authid` FROM `".SB_PREFIX."_bans` WHERE `RemoveType` IS NULL AND `length` = 0")) {
  70.          while ($banned = $bans->fetch_assoc()) {
  71.              if(!in_array($banned["authid"], $bannedplayers)) {
  72.                   $bannedplayers[] = $banned["authid"];
  73.                   ++$bcnt;
  74.              }
  75.          }
  76.     }
  77.     else {
  78.         die('[-] Error retrieving banned players: ' . $con->error);
  79.     }
  80.  
  81.        
  82.    
  83.     // Read unbanned players
  84.     $ubcnt = 0;
  85.     if ($unbans = $con->query("SELECT `authid` FROM `".SB_PREFIX."_bans` WHERE `RemoveType` IS NOT NULL AND `RemovedOn` IS NOT NULL")) {
  86.         while ($unbanned = $unbans->fetch_assoc()) {
  87.              if(!in_array($unbanned["authid"], $bannedplayers) && !in_array($unbanned["authid"], $unbannedplayers)) {
  88.                   $unbannedplayers[] = $unbanned["authid"];
  89.                   ++$ubcnt;
  90.              }
  91.         }
  92.     }
  93.     else {
  94.         die('[-] Error retrieving unbanned players: ' . $con->error);
  95.     }
  96.  
  97.     $con->close();
  98.     print("[+] Retrieved ".$bcnt." banned and ".$ubcnt." unbanned players from SourceBans.\n");
  99. }
  100.  
  101. //------------------------------
  102. // AMXBans Part
  103. //------------------------------
  104. if ($useamx)
  105. {
  106.     // Connect to the AMXBans database.
  107.     $con = new mysqli(AMX_HOST, AMX_USER, AMX_PASS, AMX_NAME, AMX_PORT);
  108.     if (mysqli_connect_error()) die('[-] Can\'t connect to AMXBans Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  109.  
  110.     print("[+] Successfully connected to AMXBans database. Retrieving bans now.\n");
  111.    
  112.     // Get permanent banned players
  113.     $bcnt = 0;
  114.     if ($bans = $con->query("SELECT `player_id` FROM `".AMX_PREFIX."_bans` WHERE `ban_length` = 0")) {
  115.         while ($banned = $bans->fetch_assoc()) {
  116.             if(!in_array($banned["player_id"], $bannedplayers))
  117.             {
  118.                 $bannedplayers[] = $banned["player_id"];
  119.                 ++$bcnt;
  120.             }
  121.         }
  122.     } else {
  123.         die('[-] Error retrieving banned players: ' . $con->error);
  124.     }
  125.    
  126.  
  127.     // Read unbanned players
  128.     $ubcnt = 0;
  129.     // Handles (apparently) pre-6.0 version DB or lower
  130.     if ($unbans = $con->query("SELECT `player_id` FROM `".AMX_PREFIX."_banhistory` WHERE `ban_length` = 0")) {
  131.         while ($unbanned = $unbans->fetch_assoc()) {
  132.             if(!in_array($unbanned["player_id"], $bannedplayers) && !in_array($unbanned["player_id"], $unbannedplayers))
  133.             {
  134.                 $unbannedplayers[] = $unbanned["player_id"];
  135.                 ++$ubcnt;
  136.             }
  137.         }      
  138.     }
  139.     // Handles (apparently) 6.0 version DB or higher
  140.     else if ($unbans = $con->query("SELECT `player_id` FROM `".AMX_PREFIX."_bans` WHERE `expired` = 1")) {
  141.         while ($unbanned = $unbans->fetch_assoc()) {
  142.             if(!in_array($unbanned["player_id"], $bannedplayers) && !in_array($unbanned["player_id"], $unbannedplayers))
  143.             {
  144.                 $unbannedplayers[] = $unbanned["player_id"];
  145.                 ++$ubcnt;
  146.             }
  147.         }
  148.     } else {
  149.         die('[-] Error retrieving unbanned players: ' . $con->error);
  150.     }
  151.    
  152.  
  153.     $con->close();
  154.     print("[+] Retrieved ".$bcnt." banned and ".$ubcnt." unbanned players from AMXBans.\n");
  155. }
  156.  
  157. //------------------------------
  158. // Beetlesmod Part
  159. //------------------------------
  160. if ($usebm)
  161. {
  162.     // Connect to the Beetlesmod database.
  163.     $con = new mysqli(BM_HOST, BM_USER, BM_PASS, BM_NAME, BM_PORT);
  164.     if (mysqli_connect_error()) die('[-] Can\'t connect to Beetlesmod Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  165.  
  166.     print("[+] Successfully connected to Beetlesmod database. Retrieving bans now.\n");
  167.  
  168.     // Get permanent banned players
  169.     $bcnt = 0;
  170.     if ($bans = $con->query("SELECT `steamid` FROM `".BM_PREFIX."_bans` WHERE `Until` IS NULL")) {
  171.         while ($banned = $bans->fetch_assoc()) {
  172.             if(!in_array($banned["steamid"], $bannedplayers))
  173.             {
  174.                 $bannedplayers[] = $banned["steamid"];
  175.                 ++$bcnt;
  176.             }
  177.         }
  178.     } else {
  179.         die('[-] Error retrieving banned players: ' . $con->error);
  180.     }
  181.    
  182.  
  183.     // Read unbanned players
  184.     $ubcnt = 0;
  185.     if ($unbans = $con->query("SELECT `steamid` FROM `".BM_PREFIX."_bans` WHERE `Until` IS NULL AND `Remove` = 0")) {
  186.         while ($unbanned = $unbans->fetch_assoc()) {
  187.             if(!in_array($unbanned["steamid"], $bannedplayers) && !in_array($unbanned["steamid"], $unbannedplayers))
  188.             {
  189.                 $unbannedplayers[] = $unbanned["steamid"];
  190.                 ++$ubcnt;
  191.             }
  192.         }
  193.     } else {
  194.         die('[-] Error retrieving unbanned players: ' . $con->error);
  195.     }
  196.    
  197.  
  198.     $con->close();
  199.     print("[+] Retrieved ".$bcnt." banned and ".$ubcnt." unbanned players from Beetlesmod.\n");
  200. }
  201.  
  202. //------------------------------
  203. // Globalban Part
  204. //------------------------------
  205. if ($usegb)
  206. {
  207.     // Connect to the Globalban database.
  208.     $con = new mysqli(GB_HOST, GB_USER, GB_PASS, GB_NAME, GB_PORT);
  209.     if (mysqli_connect_error()) die('[-] Can\'t connect to Globalban Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  210.  
  211.     print("[+] Successfully connected to Globalban database. Retrieving bans now.\n");
  212.  
  213.     // Get permanent banned players
  214.     $bcnt = 0;
  215.     if ($bans = $con->query("SELECT `steam_id` FROM `".GB_PREFIX."_ban` WHERE `active` = 1 AND `pending` = 0 AND `length` = 0")) {
  216.         while ($banned = $bans->fetch_assoc()) {
  217.             if(!in_array($banned["steam_id"], $bannedplayers))
  218.             {
  219.                 $bannedplayers[] = $banned["steam_id"];
  220.                 ++$bcnt;
  221.             }
  222.         }
  223.     } else {
  224.         die('[-] Error retrieving banned players: ' . $con->error);
  225.     }
  226.    
  227.  
  228.     // Read unbanned players
  229.     $ubcnt = 0;
  230.     if ($unbans = $con->query("SELECT `steam_id` FROM `".GB_PREFIX."_ban` WHERE `active` = 0 AND `pending` = 0 AND `length` = 0")) {
  231.         while ($unbanned = $unbans->fetch_assoc()) {
  232.             if(!in_array($unbanned["steam_id"], $bannedplayers) && !in_array($unbanned["steam_id"], $unbannedplayers))
  233.             {
  234.                 $unbannedplayers[] = $unbanned["steam_id"];
  235.                 ++$ubcnt;
  236.             }
  237.         }
  238.     } else {
  239.         die('[-] Error retrieving unbanned players: ' . $con->error);
  240.     }
  241.    
  242.  
  243.     $con->close();
  244.     print("[+] Retrieved ".$bcnt." banned and ".$ubcnt." unbanned players from Globalban.\n");
  245. }
  246.  
  247. //------------------------------
  248. // MySQL Banning Part
  249. //------------------------------
  250. if ($usemb)
  251. {
  252.     // Connect to the MySQL Banning database.
  253.     $con = new mysqli(MB_HOST, MB_USER, MB_PASS, MB_NAME, MB_PORT);
  254.     if (mysqli_connect_error()) die('[-] Can\'t connect to MySQL Banning Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  255.  
  256.     print("[+] Successfully connected to MySQL Banning database. Retrieving bans now.\n");
  257.  
  258.     // Get permanent banned players
  259.     $bcnt = 0;
  260.     if ($bans = $con->query("SELECT `steam_id` FROM `".MB_PREFIX."_bans` WHERE `ban_length` = 0")) {
  261.         while ($banned = $bans->fetch_assoc()) {
  262.             if(!in_array($banned["steam_id"], $bannedplayers))
  263.             {
  264.                 $bannedplayers[] = $banned["steam_id"];
  265.                 ++$bcnt;
  266.             }
  267.         }
  268.     } else {
  269.         die('[-] Error retrieving banned players: ' . $con->error);
  270.     }
  271.    
  272.  
  273.     /****** SM MySQL Banning doesn't provide a ban history AFAIK ******/
  274.    
  275.     // Read unbanned players
  276.     // $ubcnt = 0;
  277.     // if ($unbans = $con->query("SELECT `steam_id` FROM `".MB_PREFIX."_bans` WHERE `ban_length` = 0")) {
  278.         // while ($unbanned = $unbans->fetch_assoc()) {
  279.             // if(!in_array($unbanned["steam_id"], $bannedplayers) && !in_array($unbanned["steam_id"], $unbannedplayers))
  280.             // {
  281.                 // $unbannedplayers[] = $unbanned["steam_id"];
  282.                 // ++$ubcnt;
  283.             // }
  284.         // }
  285.     // } else {
  286.     // die('[-] Error retrieving unbanned players: ' . $con->error);
  287.     //}
  288.  
  289.     $con->close();
  290.     //print("[+] Retrieved ".$bcnt." banned and ".$ubcnt." unbanned players from MySQL Banning.\n");
  291.     print("[+] Retrieved ".$bcnt." banned players from MySQL Banning.\n");
  292. }
  293.  
  294. //------------------------------
  295. // HLstatsX Part
  296. //------------------------------
  297.  
  298. if(empty($bannedplayers) && empty($unbannedplayers))
  299.     die('[-] Nothing to change. Exiting.');
  300.  
  301. $bannedsteamids="''";
  302. $unbannedsteamids="''";
  303.  
  304. if(!empty($bannedplayers))
  305. {
  306.     $bannedsteamids = "'";
  307.     foreach ($bannedplayers as $steamid)
  308.     {
  309.         $steamid = preg_replace('/^STEAM_[0-9]+?\:/i','',$steamid);
  310.         $bannedsteamids .= $steamid."','";
  311.     }
  312.     $bannedsteamids .= preg_replace('/\,\'$/','',$steamid);
  313.     $bannedsteamids .= "'";
  314. }
  315.  
  316. if(!empty($unbannedplayers))
  317. {
  318.     $unbannedsteamids = "'";
  319.     foreach ($unbannedplayers as $steamid)
  320.     {
  321.         $steamid = preg_replace('/^STEAM_[0-9]+?\:/i','',$steamid);
  322.         $unbannedsteamids .= $steamid."','";
  323.     }
  324.     $unbannedsteamids .= preg_replace('/\,\'$/','',$steamid);
  325.     $unbannedsteamids .= "'";
  326. }
  327.  
  328. // Connection to DB
  329. $hlxcon = new mysqli(HLX_HOST, HLX_USER, HLX_PASS, '', HLX_PORT);
  330. if (mysqli_connect_error()) die('[-] Can\'t connect to HLstatsX Database (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
  331.  
  332. print("[+] Successfully connected to HLstatsX database server. Updating players...\n");
  333. // Loop through all hlstatsx databases
  334. foreach ($hlxdbs as $hlxdb)
  335. {
  336.     $unbancnt = $bancnt = 0;
  337.     $hlxcon->select_db($hlxdb);
  338.     // Hide all banned players
  339.     if ($hlxban = $hlxcon->query("UPDATE `".HLX_PREFIX."_Players` SET `hideranking` = 2 WHERE `hideranking` < 4 AND `playerId` IN (SELECT `playerId` FROM `".HLX_PREFIX."_PlayerUniqueIds` WHERE `uniqueId` IN (".$bannedsteamids."));")) {
  340.         $bancnt = ($hlxcon->affected_rows?$hlxcon->affected_rows:0);
  341.     }
  342.     else {
  343.     die('[-] Error hiding banned players: ' . $hlxcon->error);
  344.     }
  345.  
  346.     // Show all unbanned players
  347.     if ($hlxunban = $hlxcon->query("UPDATE `".HLX_PREFIX."_Players` SET `hideranking` = 0 WHERE `hideranking` = 2 AND `playerId` IN (SELECT `playerId` FROM `".HLX_PREFIX."_PlayerUniqueIds` WHERE `uniqueId` IN (".$unbannedsteamids."));")) {
  348.         $unbancnt = ($hlxcon->affected_rows?$hlxcon->affected_rows:0);
  349.        
  350.         if ($bancnt>0||$unbancnt>0) {
  351.              print("[+] ".$hlxdb.": ".$bancnt." players were marked as banned, ".$unbancnt." players were reenabled again.\n");
  352.         }
  353.         else {
  354.              print("[-] ".$hlxdb.": No player changed.\n");
  355.         }
  356.     }
  357.     else {
  358.          die('[-] Error showing unbanned players: ' . $hlxcon->error);
  359.     }
  360. }
  361. $hlxcon->close();
  362. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement