PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/html/import/import_playerstuff.php

https://github.com/graywh/utstats
PHP | 186 lines | 141 code | 31 blank | 14 comment | 22 complexity | 5296137769945e0ec28ab48a97c9709e MD5 | raw file
  1. <?php
  2. include_once("includes/geoip.inc");
  3. $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
  4. // Get the unique ID of this player.
  5. // Create a new one if he has none yet.
  6. $r_pid = small_query("SELECT id, country, banned FROM uts_pinfo WHERE name = '$playername'");
  7. if ($r_pid) {
  8. $pid = $r_pid['id'];
  9. $pid_country = $r_pid['country'];
  10. $playerbanned = ($r_pid['banned'] == 'Y') ? true : false;
  11. } else {
  12. mysql_query("INSERT INTO uts_pinfo SET name = '$playername'") or die(mysql_error());
  13. $pid = mysql_insert_id();
  14. $pid_country = false;
  15. $playerbanned = false;
  16. }
  17. $playerid2pid[$playerid] = $pid;
  18. // Do we import banned players?
  19. if ($playerbanned and $import_ban_type == 2) return;
  20. // Did the player do first blood?
  21. IF($playerid == $firstblood) {
  22. $upd_firstblood = "UPDATE uts_match SET firstblood = '$pid' WHERE id = $matchid";
  23. mysql_query($upd_firstblood) or die(mysql_error());
  24. }
  25. // Get player's IP
  26. $q_playerip = small_query("SELECT INET_ATON(col4) AS ip FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'IP' and col3 = '$playerid' ORDER BY id ASC LIMIT 0,1");
  27. $playerip = ($q_playerip) ? $q_playerip['ip'] : 0;
  28. if (empty($playerip)) $playerip = 0;
  29. // Map the IP to a country
  30. $playercountry = strtolower(geoip_country_code_by_addr($gi,long2ip($playerip)));
  31. if ($playercountry != $pid_country)
  32. {
  33. mysql_query("UPDATE uts_pinfo SET country = '$playercountry' WHERE id = '$pid'") or die(mysql_error());
  34. }
  35. // Get Sprees and Head Shots
  36. $q_spree_dbl = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_dbl' AND col3 = '$playerid'");
  37. $q_spree_mult = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_mult' AND col3 = '$playerid'");
  38. $q_spree_ult = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_ult' AND col3 = '$playerid'");
  39. $q_spree_mon = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_mon' AND col3 = '$playerid'");
  40. $q_spree_kill = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_kill' AND col3 = '$playerid'");
  41. $q_spree_rampage = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_rampage' AND col3 = '$playerid'");
  42. $q_spree_dom = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_dom' AND col3 = '$playerid'");
  43. $q_spree_uns = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_uns' AND col3 = '$playerid'");
  44. $q_spree_god = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'spree' AND col2 = 'spree_god' AND col3 = '$playerid'");
  45. $q_headshots = small_count("SELECT id FROM uts_temp_$uid WHERE col1 = 'headshot' AND col2 = '$playerid'");
  46. // Get Count of Pickups
  47. $sql_player7 = "SELECT col2, COUNT(col2) AS pu_count FROM uts_temp_$uid WHERE col1 = 'item_get' AND col3 = $playerid GROUP BY col2";
  48. $q_player7 = mysql_query($sql_player7);
  49. $pu_pads = 0;
  50. $pu_armour = 0;
  51. $pu_keg = 0;
  52. $pu_belt = 0;
  53. $pu_amp = 0;
  54. $pu_invis = 0;
  55. $pu_boots = 0;
  56. while ($r_player7 = mysql_fetch_array($q_player7)) {
  57. // Cycle through pickups and see what the player got
  58. IF ($r_player7[col2] == "Thigh Pads") { $pu_pads = $r_player7[pu_count]; }
  59. IF ($r_player7[col2] == "Body Armor") { $pu_armour = $r_player7[pu_count]; }
  60. IF ($r_player7[col2] == "Super Health Pack") { $pu_keg = $r_player7[pu_count]; }
  61. IF ($r_player7[col2] == "ShieldBelt") { $pu_belt = $r_player7[pu_count]; }
  62. IF ($r_player7[col2] == "Damage Amplifier") { $pu_amp = $r_player7[pu_count]; }
  63. IF ($r_player7[col2] == "Invisibility") { $pu_invis = $r_player7[pu_count]; }
  64. IF ($r_player7[col2] == "AntiGrav Boots") { $pu_boots = $r_player7[pu_count]; }
  65. }
  66. // Get ping information
  67. $r_player9 = small_query("SELECT MIN(col4 * 1) AS lowping, MAX(col4 * 1) AS highping, AVG(col4 * 1) AS avgping FROM uts_temp_$uid WHERE col1 = 'Player' AND col2 = 'Ping' AND col3 = $playerid AND col4 > 0");
  68. $lowping = $r_player9[lowping];
  69. $highping = $r_player9[highping];
  70. $avgping = (int)$r_player9[avgping];
  71. // People who join at the end error the import, this stops it
  72. IF ($lowping == NULL) { $lowping = 0; }
  73. IF ($highping == NULL) { $highping = 0; }
  74. IF ($avgping == NULL) { $avgping = 0; }
  75. // Get accuracy, ttl etc
  76. $r_acc = 0;
  77. $r_deaths = 0;
  78. $r_efficiency = 0;
  79. $r_frags = 0;
  80. $r_kills = 0;
  81. $r_teamkills = 0;
  82. $r_suicides = 0;
  83. $r_tos = 0;
  84. $r_ttl = 0;
  85. $q_acc = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'accuracy' AND col3 = $playerid");
  86. $q_deaths = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'deaths' AND col3 = $playerid");
  87. $q_kills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'kills' AND col3 = $playerid");
  88. $q_teamkills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'teamkills' AND col3 = $playerid");
  89. $q_efficiency = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'efficiency' AND col3 = $playerid");
  90. $q_suicides = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'suicides' AND col3 = $playerid");
  91. $q_tos = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'time_on_server' AND col3 = $playerid");
  92. $q_ttl = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'ttl' AND col3 = $playerid");
  93. $q_score = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'score' AND col3 = $playerid");
  94. IF ($teamgame == "True") {
  95. $r_kills = $q_kills[col4];
  96. $r_teamkills = $q_teamkills[col4];
  97. }
  98. IF ($teamgame == "False") {
  99. $r_kills = $q_kills[col4] + $q_teamkills[col4];
  100. $r_teamkills = 0;
  101. }
  102. $r_acc = get_dp($q_acc[col4]);
  103. $r_efficiency = get_dp($q_efficiency[col4]);
  104. $r_deaths = $q_deaths[col4];
  105. $r_suicides = $q_suicides[col4];
  106. $r_frags = $r_kills-$r_suicides-$r_teamkills;
  107. $r_tos = get_dp($q_tos[col4]);
  108. $r_ttl = get_dp($q_ttl[col4]);
  109. $r_score = $q_score[col4];
  110. // Get "real" TTL
  111. $r_ttl = $r_tos / ($r_deaths + $r_suicides + 1);
  112. // Generate player record
  113. $sql_playerid = " INSERT
  114. INTO uts_player
  115. SET matchid = '$matchid',
  116. playerid = '$playerid',
  117. pid = '$pid',
  118. team = '$playerteam',
  119. gid = '$gid',
  120. insta = '$gameinsta',
  121. country = '$playercountry',
  122. ip = '$playerip',
  123. headshots = '$q_headshots',
  124. spree_double = '$q_spree_dbl',
  125. spree_multi = '$q_spree_mult',
  126. spree_ultra = '$q_spree_ult',
  127. spree_monster = '$q_spree_mon',
  128. spree_kill = '$q_spree_kill',
  129. spree_rampage = '$q_spree_rampage',
  130. spree_dom = '$q_spree_dom',
  131. spree_uns = '$q_spree_uns',
  132. spree_god = '$q_spree_god',
  133. pu_pads = '$pu_pads',
  134. pu_armour = '$pu_armour',
  135. pu_keg = '$pu_keg',
  136. pu_belt = '$pu_belt',
  137. pu_amp = '$pu_amp',
  138. pu_invis = '$pu_invis',
  139. pu_boots = '$pu_boots',
  140. lowping = '$lowping',
  141. highping = '$highping',
  142. avgping = '$avgping',
  143. accuracy = '$r_acc',
  144. frags = '$r_frags',
  145. deaths = '$r_deaths',
  146. kills = '$r_kills',
  147. suicides = '$r_suicides',
  148. teamkills = '$r_teamkills',
  149. eff = '$r_efficiency',
  150. gametime = '$r_tos',
  151. ttl = '$r_ttl',
  152. gamescore= '$r_score'";
  153. $q_playerid = mysql_query($sql_playerid) or die(mysql_error());
  154. $playerecordid = mysql_insert_id();
  155. ?>