PageRenderTime 93ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/html/pages/admin/plm.php

https://github.com/graywh/utstats
PHP | 329 lines | 264 code | 41 blank | 24 comment | 48 complexity | db058437d5846159c2851e34b2a50446 MD5 | raw file
  1. <?php
  2. if (empty($import_adminkey) or isset($_REQUEST['import_adminkey']) or $import_adminkey != $adminkey) die('bla');
  3. $debug = 0; // This enables debug messages
  4. /*
  5. ** This function merges two playerss
  6. ** @var $mplayer1 : The player to merge to
  7. ** @var $mplayer2 : The player who gets merged into mplayer 1
  8. ** @return null
  9. */
  10. function merge_players($mplayer1, $mplayer2) {
  11. $mp1name = small_query("SELECT name FROM uts_pinfo WHERE id = $mplayer1");
  12. $mp2name = small_query("SELECT name FROM uts_pinfo WHERE id = $mplayer2");
  13. mysql_query("DELETE FROM uts_pinfo WHERE id = $mplayer2") or die(mysql_error());
  14. mysql_query("UPDATE uts_player SET pid = $mplayer1 WHERE pid = $mplayer2") or die(mysql_error());
  15. mysql_query("UPDATE uts_weaponstats SET pid = $mplayer1 WHERE pid = $mplayer2") or die(mysql_error());
  16. mysql_query("DELETE FROM uts_weaponstats WHERE pid = $mplayer2") or die(mysql_error());
  17. mysql_query("DELETE FROM uts_weaponstats WHERE matchid='0' AND pid = '$mplayer1'") or die(mysql_error());
  18. $q_weaponstats = mysql_query("SELECT weapon, SUM(kills) AS kills, SUM(shots) AS shots, SUM(hits) as hits, SUM(damage) as damage, AVG(acc) AS acc FROM uts_weaponstats WHERE pid = '$mplayer1' GROUP BY weapon") or die(mysql_error());
  19. while ($r_weaponstats = mysql_fetch_array($q_weaponstats)) {
  20. mysql_query("INSERT INTO uts_weaponstats SET matchid='0', pid='$mplayer1', weapon='${r_weaponstats['weapon']}', kills='${r_weaponstats['kills']}', shots='${r_weaponstats['shots']}', hits='${r_weaponstats['hits']}', damage='${r_weaponstats['damage']}', acc='${r_weaponstats['acc']}'") or die(mysql_error());
  21. }
  22. mysql_query("UPDATE uts_match SET firstblood = $mplayer1 WHERE firstblood = $mplayer2") or die(mysql_error());
  23. mysql_query("UPDATE uts_rank SET pid = $mplayer2 WHERE pid= $mplayer1") or die(mysql_error());
  24. $sql_nrank = "SELECT SUM(time) AS time, pid, gid, AVG(rank) AS rank, AVG(prevrank) AS prevrank, SUM(matches) AS matches FROM uts_rank WHERE pid = $mplayer2 GROUP BY pid, gid";
  25. $q_nrank = mysql_query($sql_nrank) or die(mysql_error());
  26. while ($r_nrank = mysql_fetch_array($q_nrank)) {
  27. mysql_query("INSERT INTO uts_rank SET time = '$r_nrank[time]', pid = $mplayer1, gid = $r_nrank[gid], rank = '$r_nrank[rank]', prevrank = '$r_nrank[prevrank]', matches = $r_nrank[matches]") or die(mysql_error());
  28. }
  29. mysql_query("DELETE FROM uts_rank WHERE pid = $mplayer2") or die(mysql_error());
  30. }
  31. // If debugmode is on, get start time
  32. if($debug) {
  33. $time = microtime();
  34. $time = explode(' ', $time);
  35. $time = $time[1] + $time[0];
  36. $begintime = $time;
  37. }
  38. // Print header & links
  39. echo '<P><B>Player merging tool</B></P>';
  40. echo "<P><A href=admin.php?key=".$adminkey."&action=plm>Merge ip's</A> - <A href=admin.php?key=".$adminkey."&action=plm&onlyrange=true>Merge ip's, limited on range</A> - <A href=admin.php?key=".$adminkey."&action=plm&manignore=true>Manage ignored ip's</A> - <A href=admin.php?key=".$adminkey."&action=plm&manignore=true&onlyrange=true>Manage ignored ip's - only range</A><BR><BR></P>";
  41. // CASE: MANAGE IGNORED IPS
  42. if($_GET['manignore'] == "true") {
  43. if($_POST['submit'] == "Remove from ignored list") {
  44. echo "<P><B>Stopped ignore ip's</B></P>";
  45. foreach($_POST as $key=>$value) {
  46. if($key !='submit') {
  47. $key = mysql_real_escape_string(str_replace("_",".",$key));
  48. $query = "DELETE FROM uts_ignoreips WHERE ip = (INET_ATON('".$key."'))";
  49. mysql_query($query) or die(mysql_error());
  50. echo "<br>$key";
  51. }
  52. }
  53. } else if($_GET['onlyrange'] == "true") {
  54. if($_POST['submit'] == "Confirm") {
  55. echo '<P><B>Ignored ip\'s in range '.htmlentities($_POST['from']).' to '.htmlentities($_POST['to']).'</B><br><I>If you want to stop ignoring some ip\'s, because for example you accidently ignored these, check these and press the button at the lower end to confirm this</I></P>';
  56. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm&manignore=true" target="_blank">';
  57. $from = mysql_real_escape_string($_POST['from']);
  58. $to = mysql_real_escape_string($_POST['to']);
  59. $ignore_ips = mysql_query("SELECT ip FROM uts_ignoreips WHERE ip >= INET_ATON('$from') AND ip <= INET_ATON('$to') ORDER BY ip ASC");
  60. if(mysql_num_rows($ignore_ips) > 0) {
  61. while ($r_pipcheck = mysql_fetch_array($ignore_ips)) {
  62. $playerip = $r_pipcheck[ip];
  63. $trueplayerip = long2ip($playerip);
  64. $pidcount = $r_pipcheck[pidcount];
  65. echo "<br><input type=checkbox name=$trueplayerip> <b>$trueplayerip</b>";
  66. // Query for player names and ids associated to that ip during the cycle
  67. $sql_pcheck = "SELECT pi.id, pi.name, pi.country, p.pid, p.ip FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  68. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  69. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  70. echo '<br><a class="darkhuman" href="admin.php?key='.$adminkey.'&amp;action=pinfo&amp;pid='.$r_pcheck[pid].'">'.FormatPlayerName($r_pcheck[country], $r_pcheck['pid'], $r_pcheck['name']).'</a> ';
  71. }
  72. echo '<br />';
  73. }
  74. echo '<BR><INPUT TYPE="SUBMIT" VALUE="Remove from ignored list" NAME="submit"></FORM>';
  75. } else {
  76. echo "<BR><P>No ignored ip's found</P>";
  77. }
  78. } else {
  79. echo "<P><B>Ignored ip's in range: Enter range to filter on</B></P>";
  80. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm&manignore=true&onlyrange=true">';
  81. echo '<BR>Ranging from <INPUT TYPE="TEXT" NAME="from" SIZE="20" VALUE="0.0.0.0"> to <INPUT TYPE="TEXT" NAME="to" SIZE="20" VALUE="255.255.255.255">';
  82. echo '<BR><BR><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Confirm"></FORM>';
  83. }
  84. } else {
  85. echo '<P><B>Ignored ip\'s</B><br><I>If you want to stop ignoring some ip\'s, because for example you accidently ignored these, check these and press the button at the lower end to confirm this</I></P>';
  86. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm&manignore=true" target="_blank">';
  87. $ignore_ips = mysql_query("SELECT ip FROM uts_ignoreips ORDER BY ip ASC");
  88. if(mysql_num_rows($ignore_ips) > 0) {
  89. while ($r_pipcheck = mysql_fetch_array($ignore_ips)) {
  90. $playerip = $r_pipcheck[ip];
  91. $trueplayerip = long2ip($playerip);
  92. $pidcount = $r_pipcheck[pidcount];
  93. echo "<br><input type=checkbox name=$trueplayerip> <b>$trueplayerip</b>";
  94. // Query for player names and ids associated to that ip during the cycle
  95. $sql_pcheck = "SELECT pi.id, pi.name, pi.country, p.pid, p.ip FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  96. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  97. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  98. echo '<br><a class="darkhuman" href="admin.php?key='.$adminkey.'&amp;action=pinfo&amp;pid='.$r_pcheck[pid].'">'.FormatPlayerName($r_pcheck[country], $r_pcheck['pid'], $r_pcheck['name']).'</a> ';
  99. }
  100. echo '<br />';
  101. }
  102. echo '<BR><INPUT TYPE="SUBMIT" VALUE="Remove from ignored list" NAME="submit"></FORM>';
  103. } else {
  104. echo "<BR><P>No ignored ip's found</P>";
  105. }
  106. }
  107. // CASE: IGNORE SUBMITTED IP'S
  108. } else if($_POST['submit'] == "ignore") {
  109. echo "<P><B>Ignored ips</B></P>";
  110. foreach($_POST as $key=>$value) {
  111. if($key !='submit') {
  112. $key = mysql_real_escape_string(str_replace("_",".",$key));
  113. $query = "INSERT INTO uts_ignoreips (ip) VALUES (INET_ATON('".$key."'))";
  114. mysql_query($query) or die(mysql_error());
  115. echo "<br>$key";
  116. }
  117. }
  118. echo "<br>";
  119. // CASE: SHOW NICKS WITH GIVEN SHARED IP
  120. } else if(substr($_POST['submit'],0,8) == "merge - ") {
  121. echo "<P><B>Merge nicks with shared ip</B></P>";
  122. $ip = mysql_real_escape_string(str_replace("_",".",substr($_POST['submit'],8)));
  123. $sql_pipcheck = "SELECT ip, COUNT(DISTINCT pid) AS pidcount FROM uts_player WHERE ip = INET_ATON('$ip') GROUP BY ip ORDER BY ip ASC";
  124. $q_pipcheck = mysql_query($sql_pipcheck) or die(mysql_error());
  125. while ($r_pipcheck = mysql_fetch_array($q_pipcheck)) {
  126. $playerip = $r_pipcheck[ip];
  127. $trueplayerip = long2ip($playerip);
  128. $pidcount = $r_pipcheck[pidcount];
  129. // If there is more than one pid associated to an IP ...
  130. IF ($pidcount > 1 ) {
  131. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm">';
  132. echo "<br><b>$trueplayerip</b>";
  133. // Query for player names and ids associated to that ip during the cycle
  134. $sql_pcheck = "SELECT pi.id, pi.name, pi.country, p.pid, p.ip FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  135. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  136. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  137. echo '<br><a class="darkhuman" href="./?p=pinfo&amp;pid='.$r_pcheck[pid].'">'.FormatPlayerName($r_pcheck[country], $r_pcheck['pid'], $r_pcheck['name']).'</a> ';
  138. $options .= '<OPTION value="'.$r_pcheck[pid].'">'.$r_pcheck['name'].'</OPTION>';
  139. }
  140. echo '<br><br>Merge to: <SELECT NAME="merge_to">'.$options.'</SELECT>';
  141. echo "<br><INPUT TYPE=\"hidden\" NAME=\"ip\" VALUE=\"$ip\"><INPUT TYPE=\"SUBMIT\" VALUE=\"Player merge\" NAME=\"submit\"></FORM>";
  142. echo '<br />';
  143. }
  144. }
  145. // CASE: MERGE NICKS WITH SHARED IP
  146. } else if($_POST['submit'] == "Player merge") {
  147. echo "<P><B>Merging nicks with shared ip</B></P>";
  148. $ip = mysql_real_escape_string(str_replace("_",".",$_POST['ip']));
  149. $merge_to_pid = mysql_real_escape_string($_POST['merge_to']);
  150. $sql_pipcheck = "SELECT ip, COUNT(DISTINCT pid) AS pidcount FROM uts_player WHERE ip = INET_ATON('$ip') GROUP BY ip ORDER BY ip ASC";
  151. $q_pipcheck = mysql_query($sql_pipcheck) or die(mysql_error());
  152. while ($r_pipcheck = mysql_fetch_array($q_pipcheck)) {
  153. $playerip = $r_pipcheck[ip];
  154. $trueplayerip = long2ip($playerip);
  155. $pidcount = $r_pipcheck[pidcount];
  156. // If there is more than one pid associated to an IP ...
  157. IF ($pidcount > 1 ) {
  158. echo "<b>$trueplayerip</b><br><br>merge:<br>";
  159. // Query for player names and ids associated to that ip during the cycle
  160. $sql_pcheck = "SELECT p.pid FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  161. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  162. $i=0;
  163. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  164. if($r_pcheck['pid'] != $merge_to_pid) {
  165. $pid_from[$i] = $r_pcheck['pid'];
  166. echo $pid_from[$i].'<br>';
  167. $i++;
  168. }
  169. }
  170. echo '<br />merge to: '.$merge_to_pid;
  171. }
  172. }
  173. if($debug) echo "<br> -- started merging";
  174. for($j=0;$j<count($pid_from);$j++) {
  175. merge_players($merge_to_pid, $pid_from[$j]);
  176. }
  177. if($debug) echo "<br> -- merging ended";
  178. // CASE: SHOW ALL IP'S LINKED TO MORE THAN ONE NICK - ONLY RANGE
  179. } else if($_GET['onlyrange'] == "true") {
  180. if($_POST['submit'] == "Confirm") {
  181. echo "<P><B>Showing all ip's in range ".htmlentities($_POST['from'])." to ".htmlentities($_POST['to'])."</B><br><I>If you want to ignore some ip's, because for example different but unrelated nicks are associated with it, check these and press the button at the lower end to confirm this</I></P>";
  182. $from = mysql_real_escape_string($_POST['from']);
  183. $to = mysql_real_escape_string($_POST['to']);
  184. $ignore_ips = mysql_query("SELECT ip FROM uts_ignoreips WHERE ip >= INET_ATON('$from') AND ip <= INET_ATON('$to')");
  185. $extended_query = "WHERE ip >= INET_ATON('$from') AND ip <= INET_ATON('$to')";
  186. $i=0;
  187. while($ignore_ips_array = mysql_fetch_array($ignore_ips)) {
  188. $ip = $ignore_ips_array[0];
  189. $extended_query .= " AND ";
  190. $extended_query .= "ip <> '".$ip."'";
  191. $i++;
  192. }
  193. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm" target="_blank">';
  194. // Query for list of unique ips and player ids
  195. $sql_pipcheck = "SELECT ip, COUNT(DISTINCT pid) AS pidcount FROM uts_player ".$extended_query." GROUP BY ip ORDER BY ip ASC";
  196. $q_pipcheck = mysql_query($sql_pipcheck) or die(mysql_error());
  197. if(mysql_num_rows($q_pipcheck) > 0) {
  198. while ($r_pipcheck = mysql_fetch_array($q_pipcheck)) {
  199. $playerip = $r_pipcheck[ip];
  200. $trueplayerip = long2ip($playerip);
  201. $pidcount = $r_pipcheck[pidcount];
  202. // If there is more than one pid associated to an IP ...
  203. IF ($pidcount > 1 ) {
  204. echo "<br><input type=checkbox name=$trueplayerip> <b>$trueplayerip</b>";
  205. // Query for player names and ids associated to that ip during the cycle
  206. $sql_pcheck = "SELECT pi.id, pi.name, pi.country, p.pid, p.ip FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  207. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  208. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  209. echo '<br><a class="darkhuman" href="admin.php?key='.$adminkey.'&amp;action=pinfo&amp;pid='.$r_pcheck[pid].'">'.FormatPlayerName($r_pcheck[country], $r_pcheck['pid'], $r_pcheck['name']).'</a> ';
  210. }
  211. echo "<br><INPUT TYPE=\"SUBMIT\" VALUE=\"merge - $trueplayerip\" NAME=\"submit\">";
  212. echo '<br />';
  213. }
  214. }
  215. echo '<BR><INPUT TYPE="SUBMIT" VALUE="ignore" NAME="submit"></FORM>';
  216. } else {
  217. echo "<P><BR>No ip's found with more than one nick linked to it and which are not ignored and are in this range</P>";
  218. }
  219. } else {
  220. echo "<P><B>Showing all ip's in range - Enter range to filter on</B></P>";
  221. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm&onlyrange=true">';
  222. echo '<BR>Ranging from <INPUT TYPE="TEXT" NAME="from" SIZE="20" VALUE="0.0.0.0"> to <INPUT TYPE="TEXT" NAME="to" SIZE="20" VALUE="255.255.255.255">';
  223. echo '<BR><BR><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Confirm"></FORM>';
  224. }
  225. // CASE: SHOW ALL IP'S LINKED TO MORE THAN ONE NICK
  226. } else {
  227. echo "<P><B>IP's linked with more than one nick</B><br><I>If you want to ignore some ip's, because for example different but unrelated nicks are associated with it, check these and press the button at the lower end to confirm this</I></P>";
  228. $ignore_ips = mysql_query("SELECT ip FROM uts_ignoreips");
  229. $extended_query = "";
  230. $i=0;
  231. while($ignore_ips_array = mysql_fetch_array($ignore_ips)) {
  232. $ip = $ignore_ips_array[0];
  233. if($i==0)
  234. $extended_query = " WHERE ";
  235. else
  236. $extended_query .= " AND ";
  237. $extended_query .= "ip <> '".$ip."'";
  238. $i++;
  239. }
  240. echo '<FORM METHOD="POST" ACTION="admin.php?key='.$adminkey.'&action=plm" target="_blank">';
  241. // Query for list of unique ips and player ids
  242. $sql_pipcheck = "SELECT ip, COUNT(DISTINCT pid) AS pidcount FROM uts_player ".$extended_query." GROUP BY ip ORDER BY ip ASC";
  243. $q_pipcheck = mysql_query($sql_pipcheck) or die(mysql_error());
  244. if(mysql_num_rows($q_pipcheck) > 0) {
  245. while ($r_pipcheck = mysql_fetch_array($q_pipcheck)) {
  246. $playerip = $r_pipcheck[ip];
  247. $trueplayerip = long2ip($playerip);
  248. $pidcount = $r_pipcheck[pidcount];
  249. // If there is more than one pid associated to an IP ...
  250. IF ($pidcount > 1 ) {
  251. echo "<br><input type=checkbox name=$trueplayerip> <b>$trueplayerip</b>";
  252. // Query for player names and ids associated to that ip during the cycle
  253. $sql_pcheck = "SELECT pi.id, pi.name, pi.country, p.pid, p.ip FROM uts_pinfo AS pi, uts_player AS p WHERE pi.id = p.pid AND p.ip = $playerip GROUP BY pi.id, pi.name, p.pid, p.ip, pi.country";
  254. $q_pcheck = mysql_query($sql_pcheck) or die(mysql_error());
  255. while ($r_pcheck = mysql_fetch_array($q_pcheck)) {
  256. echo '<br><a class="darkhuman" href="admin.php?key='.$adminkey.'&amp;action=pinfo&amp;pid='.$r_pcheck[pid].'">'.FormatPlayerName($r_pcheck[country], $r_pcheck['pid'], $r_pcheck['name']).'</a> ';
  257. }
  258. echo "<br><INPUT TYPE=\"SUBMIT\" VALUE=\"merge - $trueplayerip\" NAME=\"submit\">";
  259. echo '<br />';
  260. }
  261. }
  262. echo '<BR><INPUT TYPE="SUBMIT" VALUE="ignore" NAME="submit"></FORM>';
  263. } else {
  264. echo "<P><BR>No ip's found with more than one nick linked to it and which are not ignored</P>";
  265. }
  266. }
  267. // If debugmode is on, determine end time & output execution time
  268. if($debug) {
  269. $time = microtime();
  270. $time = explode(" ", $time);
  271. $time = $time[1] + $time[0];
  272. $endtime = $time;
  273. $totaltime = ($endtime - $begintime);
  274. echo "<br>execution time: $totaltime";
  275. }
  276. ?>