PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/html/import/import_pcleanup.php

https://github.com/graywh/utstats
PHP | 201 lines | 169 code | 20 blank | 12 comment | 6 complexity | f90ef3e0ece814b4ba02741d08a7ef18 MD5 | raw file
  1. <?php
  2. $sql_tgame = small_query("SELECT teamgame FROM uts_match WHERE id = $matchid");
  3. IF($sql_tgame == "True") {
  4. $rem_srecord = "DELETE FROM uts_player WHERE matchid = $matchid AND team > 3";
  5. mysql_query($rem_srecord);
  6. }
  7. $cleaned = false;
  8. // Get list of players
  9. $sql_pname = "SELECT pid, name FROM uts_player, uts_pinfo AS pi WHERE matchid = $matchid AND pid = pi.id";
  10. $q_pname = mysql_query($sql_pname);
  11. while ($r_pname = mysql_fetch_array($q_pname)) {
  12. $playername = addslashes($r_pname[name]);
  13. $pid = $r_pname['pid'];
  14. // Check if player has more than 1 record
  15. $q_ids = mysql_query("SELECT playerid FROM uts_player WHERE pid = '$pid' AND matchid = $matchid");
  16. IF (mysql_num_rows($q_ids) > 1) {
  17. $numrecords = mysql_num_rows($q_ids);
  18. echo $r_pname[name] .' ';
  19. // get all the ids this player had
  20. $playerids = array();
  21. while ($r_ids = mysql_fetch_array($q_ids)) {
  22. $playerids[] = $r_ids['playerid'];
  23. }
  24. $r_newplayerid = small_query("SELECT (MAX(playerid) + 1) AS newplayerid FROM uts_player WHERE matchid = $matchid");
  25. $newplayerid = $r_newplayerid['newplayerid'];
  26. // Fix matchcount in ranking table
  27. mysql_query("UPDATE uts_rank SET matches = matches - ". ($numrecords - 1) ." WHERE pid = '$pid' AND gid = '$gid'") or die(mysql_error());
  28. // ***********************
  29. // UPDATE THE KILLS MATRIX
  30. $sql_kmupdate = " SELECT victim,
  31. SUM(kills) AS kills
  32. FROM uts_killsmatrix
  33. WHERE matchid = $matchid
  34. AND killer IN (". implode(",", $playerids) .")
  35. GROUP BY victim;";
  36. $q_kmupdate = mysql_query($sql_kmupdate);
  37. while ($r_kmupdate = mysql_fetch_array($q_kmupdate)) {
  38. mysql_query(" INSERT
  39. INTO uts_killsmatrix
  40. SET matchid = $matchid,
  41. killer = $newplayerid,
  42. victim = ${r_kmupdate['victim']},
  43. kills = ${r_kmupdate['kills']};");
  44. }
  45. $sql_kmupdate = " SELECT killer,
  46. SUM(kills) AS kills
  47. FROM uts_killsmatrix
  48. WHERE matchid = $matchid
  49. AND victim IN (". implode(",", $playerids) .")
  50. GROUP BY killer;";
  51. $q_kmupdate = mysql_query($sql_kmupdate);
  52. while ($r_kmupdate = mysql_fetch_array($q_kmupdate)) {
  53. mysql_query(" INSERT
  54. INTO uts_killsmatrix
  55. SET matchid = $matchid,
  56. killer = ${r_kmupdate['killer']},
  57. victim = $newplayerid,
  58. kills = ${r_kmupdate['kills']};");
  59. }
  60. mysql_query(" DELETE
  61. FROM uts_killsmatrix
  62. WHERE matchid = $matchid
  63. AND (killer IN (". implode(",", $playerids) .")
  64. OR victim IN (". implode(",", $playerids) ."));");
  65. // FINISHED UPDATING THE KILLS MATRiX
  66. // **********************************
  67. // Get non summed information
  68. $r_truepinfo1 = small_query("SELECT insta, pid, team, isabot, country, ip, gid FROM uts_player WHERE pid = '$pid' AND matchid = $matchid LIMIT 0,1");
  69. // Group Player Stuff so we only have 1 player record per match
  70. $r_truepinfo2 = small_query("SELECT
  71. SUM(p.gametime) AS gametime,
  72. SUM(p.gamescore) AS gamescore,
  73. MIN(p.lowping) AS lowping,
  74. MAX(p.highping) AS highping,
  75. AVG(p.avgping) AS avgping,
  76. SUM(p.frags) AS frags,
  77. SUM(p.deaths) AS deaths,
  78. SUM(p.kills) AS kills,
  79. SUM(p.suicides) AS suicides,
  80. SUM(p.teamkills) AS teamkills,
  81. SUM(p.headshots) AS headshots,
  82. (100*SUM(p.kills)/(SUM(p.kills)+SUM(p.deaths)+SUM(p.suicides)+SUM(p.teamkills))) AS eff,
  83. LEAST(ROUND(10000*SUM(w.hits)/SUM(w.shots))/100,100) AS accuracy,
  84. (SUM(p.gametime)/(SUM(p.deaths)+SUM(p.suicides)+COUNT(p.id))) AS ttl,
  85. SUM(p.flag_taken) AS flag_taken,
  86. SUM(p.flag_pickedup) AS flag_pickedup,
  87. SUM(p.flag_dropped) AS flag_dropped,
  88. SUM(p.flag_return) AS flag_return,
  89. SUM(p.flag_capture) AS flag_capture,
  90. SUM(p.flag_cover) AS flag_cover,
  91. SUM(p.flag_seal) AS flag_seal,
  92. SUM(p.flag_assist) AS flag_assist,
  93. SUM(p.flag_kill) AS flag_kill,
  94. SUM(p.dom_cp) AS dom_cp,
  95. SUM(p.dom_pts) AS dom_pts,
  96. SUM(p.ass_obj) AS ass_obj,
  97. SUM(p.spree_double) AS spree_double,
  98. SUM(p.spree_triple) AS spree_triple,
  99. SUM(p.spree_multi) AS spree_multi,
  100. SUM(p.spree_mega) AS spree_mega,
  101. SUM(p.spree_ultra) AS spree_ultra,
  102. SUM(p.spree_monster) AS spree_monster,
  103. SUM(p.spree_kill) AS spree_kill,
  104. SUM(p.spree_rampage) AS spree_rampage,
  105. SUM(p.spree_dom) AS spree_dom,
  106. SUM(p.spree_uns) AS spree_uns,
  107. SUM(p.spree_god) AS spree_god,
  108. SUM(p.pu_pads) AS pu_pads,
  109. SUM(p.pu_armour) AS pu_armour,
  110. SUM(p.pu_keg) AS pu_keg,
  111. SUM(p.pu_invis) AS pu_invis,
  112. SUM(p.pu_belt) AS pu_belt,
  113. SUM(p.pu_amp) AS pu_amp,
  114. SUM(p.pu_boots) AS pu_boots
  115. FROM uts_player AS p, uts_weaponstats AS w
  116. WHERE p.matchid = '$matchid' AND p.pid = '$pid' AND w.matchid = '$matchid' AND w.pid = '$pid' AND w.weapon = 0");
  117. // Remove all of this player's records
  118. $rem_precord = "DELETE FROM uts_player WHERE matchid = '$matchid' AND pid = '$pid'";
  119. mysql_query($rem_precord);
  120. // Add this new record to match
  121. $upd_precord = " INSERT
  122. INTO uts_player
  123. SET matchid = '$matchid',
  124. insta = '${r_truepinfo1['insta']}',
  125. playerid = '$newplayerid',
  126. pid = '$pid',
  127. team = '${r_truepinfo1['team']}',
  128. isabot = '${r_truepinfo1['isabot']}',
  129. country = '${r_truepinfo1['country']}',
  130. ip = '${r_truepinfo1['ip']}',
  131. gid = '${r_truepinfo1['gid']}',
  132. gametime = '${r_truepinfo2['gametime']}',
  133. gamescore = '${r_truepinfo2['gamescore']}',
  134. lowping = '${r_truepinfo2['lowping']}',
  135. highping = '${r_truepinfo2['highping']}',
  136. avgping = '${r_truepinfo2['avgping']}',
  137. frags = '${r_truepinfo2['frags']}',
  138. deaths = '${r_truepinfo2['deaths']}',
  139. kills = '${r_truepinfo2['kills']}',
  140. suicides = '${r_truepinfo2['suicides']}',
  141. teamkills = '${r_truepinfo2['teamkills']}',
  142. headshots = '${r_truepinfo2['headshots']}',
  143. eff = '${r_truepinfo2['eff']}',
  144. accuracy = '${r_truepinfo2['accuracy']}',
  145. ttl = '${r_truepinfo2['ttl']}',
  146. flag_taken = '${r_truepinfo2['flag_taken']}',
  147. flag_dropped = '${r_truepinfo2['flag_dropped']}',
  148. flag_return = '${r_truepinfo2['flag_return']}',
  149. flag_capture = '${r_truepinfo2['flag_capture']}',
  150. flag_cover = '${r_truepinfo2['flag_cover']}',
  151. flag_seal = '${r_truepinfo2['flag_seal']}',
  152. flag_assist = '${r_truepinfo2['flag_assist']}',
  153. flag_kill = '${r_truepinfo2['flag_kill']}',
  154. flag_pickedup = '${r_truepinfo2['flag_pickedup']}',
  155. dom_cp = '${r_truepinfo2['dom_cp']}',
  156. dom_pts = '${r_truepinfo2['dom_pts']}',
  157. ass_obj = '${r_truepinfo2['ass_obj']}',
  158. spree_double = '${r_truepinfo2['spree_double']}',
  159. spree_triple = '${r_truepinfo2['spree_triple']}',
  160. spree_multi = '${r_truepinfo2['spree_multi']}',
  161. spree_mega = '${r_truepinfo2['spree_mega']}',
  162. spree_ultra = '${r_truepinfo2['spree_ultra']}',
  163. spree_monster = '${r_truepinfo2['spree_monster']}',
  164. spree_kill = '${r_truepinfo2['spree_kill']}',
  165. spree_rampage = '${r_truepinfo2['spree_rampage']}',
  166. spree_dom = '${r_truepinfo2['spree_dom']}',
  167. spree_uns = '${r_truepinfo2['spree_uns']}',
  168. spree_god = '${r_truepinfo2['spree_god']}',
  169. pu_pads = '${r_truepinfo2['pu_pads']}',
  170. pu_armour = '${r_truepinfo2['pu_armour']}',
  171. pu_keg = '${r_truepinfo2['pu_keg']}',
  172. pu_invis = '${r_truepinfo2['pu_invis']}',
  173. pu_belt = '${r_truepinfo2['pu_belt']}',
  174. pu_amp = '${r_truepinfo2['pu_amp']}',
  175. pu_boots = '${r_truepinfo2['pu_boots']}';";
  176. mysql_query($upd_precord) or die(mysql_error());
  177. $cleaned = true;
  178. }
  179. }
  180. if ($cleaned and $html) echo "<br />";
  181. ?>