PageRenderTime 455ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/html/import.php

https://github.com/graywh/utstats
PHP | 824 lines | 750 code | 49 blank | 25 comment | 94 complexity | 5d0c013952aa86e8c6083234985e9f80 MD5 | raw file
  1. <?php
  2. function add_info($name, $value) {
  3. if ($value == '' or $value === NULL) return('');
  4. return(htmlentities($name) ." ". htmlentities($value) ."<br />");
  5. }
  6. ?>
  7. <?php
  8. @ignore_user_abort(true);
  9. @set_time_limit(0);
  10. if (isset($_REQUEST['rememberkey'])) setcookie('uts_importkey', $_REQUEST['key'], time()+60*60*24*30*365);
  11. if (isset($_COOKIE['uts_importkey'])) $adminkey = $_REQUEST['uts_importkey'];
  12. require ("includes/config.php");
  13. require ("includes/functions.php");
  14. $compatible_actor_versions = array('0.4.0', '0.4.1', '0.4.2', 'beta 4.0', 'beta 4.1', 'beta 4.2');
  15. // Get key from web browser
  16. if (isset($_REQUEST['key'])) $adminkey = $_REQUEST['key'];
  17. if (!isset($adminkey)) $adminkey = '';
  18. // Debugging mode?
  19. $debug = isset($_REQUEST['debug']) ? $_REQUEST['debug'] : false;
  20. // Output HTML?
  21. $html = isset($_REQUEST['html']) ? $_REQUEST['html'] : true;
  22. // Were running from the command line (cron-jobs)
  23. if (php_sapi_name() == 'cli' or !isset($_SERVER['SERVER_PORT']) or !$_SERVER['SERVER_PORT']) {
  24. // No password needed when in cli mode.
  25. $adminkey = $import_adminkey;
  26. // There is no time limit when running the cli. And no page to reload :)
  27. $import_reload_after = 0;
  28. // No browser, no HTML
  29. $html = false;
  30. // Chdir to our homedir
  31. if (!empty($import_homedir)) chdir($import_homedir);
  32. }
  33. if ($html) include ("includes/header.php");
  34. if ($html) {
  35. echo'<table border="0" cellpadding="1" cellspacing="2" width="720">
  36. <tr>
  37. <td class="heading" align="center" colspan="2">Importing Latest Log Files</td>
  38. </tr>';
  39. }
  40. IF (empty($import_adminkey)) {
  41. if ($html) echo'<tr><td class="smheading" align="left" width="150">Error:</td><td class="grey" align="left">';
  42. echo "\$import_adminkey not set in config.php!\n";
  43. if ($html) {
  44. echo '</td></tr></table>';
  45. include("includes/footer.php");
  46. }
  47. return;
  48. }
  49. IF (!empty($adminkey) and $adminkey != $import_adminkey) {
  50. if ($html) echo'<tr><td class="smheading" align="left" width="150">Error:</td><td class="grey" align="left">';
  51. echo "Keys do not match\n";
  52. $adminkey = '';
  53. if (!$html) return;
  54. }
  55. IF (empty($adminkey)) {
  56. if (!$html) die('Please provide the adminkey' ."\n");
  57. echo'<tr>
  58. <td class="smheading" align="left" width="150">Enter Admin key:</td>
  59. <td class="grey" align="left"><form NAME="adminkey" ACTION="import.php">
  60. <input TYPE="text" NAME="key" MAXLENGTH="35" SIZE="20" CLASS="searchform">
  61. <input TYPE="submit" VALUE="Submit" CLASS="searchformb">
  62. <input TYPE="checkbox" NAME="rememberkey"> Remember the key
  63. </form></td>
  64. </tr></table>';
  65. include("includes/footer.php");
  66. return;
  67. }
  68. IF (!@is_dir('logs')) {
  69. if ($html) echo'<tr><td class="smheading" align="left" width="150">Error:</td><td class="grey" align="left">';
  70. echo "Can't find the logs directory!\n";
  71. if ($html) echo "<br>";
  72. echo "Current working directory is: ". getcwd() ."\n";
  73. if ($html) echo "<br>";
  74. if (!$html) echo "You forgot to cd to my home directory? Take a look at \$import_homedir in config.php.\n";
  75. if ($html) {
  76. echo '</td></tr></table>';
  77. include("includes/footer.php");
  78. }
  79. return;
  80. }
  81. if ($html) echo'</table><br>';
  82. echo "\n";
  83. $start_time = time();
  84. $files = isset($_REQUEST['files']) ? $_REQUEST['files'] : 0;
  85. $elapsed = isset($_REQUEST['elapsed']) ? $_REQUEST['elapsed'] : 0;
  86. if ($ftp_use and !isset($_GET['no_ftp'])) {
  87. include("includes/ftp.php");
  88. $elapsed = $elapsed - (time() - $start_time);
  89. }
  90. $logdir = opendir('logs');
  91. while (false !== ($filename = readdir($logdir)))
  92. {
  93. // Our (self set) timelimit exceeded => reload the page to prevent srcipt abort
  94. if (!empty($import_reload_after) and $start_time + $import_reload_after <= time()) {
  95. if (!$html) die('Time limit exceeded - unable to reload page (no HTML output)' ."\n");
  96. $elapsed = $elapsed + time() - $start_time;
  97. $target = $PHP_SELF ."?key=". urlencode($adminkey) ."&amp;".str_rand()."=".str_rand()."&amp;no_ftp=1&amp;debug=$debug&amp;files=$files&amp;elapsed=$elapsed";
  98. echo '<meta http-equiv="refresh" content="2;URL='. $target .'">';
  99. echo'<br /><table border="0" cellpadding="1" cellspacing="2" width="720">
  100. <tr>
  101. <td class="heading" align="center" colspan="2">Maximum execution time exeeded; restarting ...</td>
  102. </tr>
  103. </table>';
  104. include("includes/footer.php");
  105. return;
  106. }
  107. $oldfilename = $filename;
  108. $filename = 'logs/' . $filename;
  109. $backupfilename = 'logs/backup/' . $oldfilename;
  110. // UTDC log: Move to logs/utdc/
  111. if ($import_utdc_download_enable
  112. and substr($filename, strlen($filename) - strlen($import_utdc_log_extension)) == $import_utdc_log_extension
  113. and substr($oldfilename, 0, strlen($import_utdc_log_start)) == $import_utdc_log_start) {
  114. if ($import_utdc_log_compress == 'no') $import_utdc_log_compress = 'yes';
  115. if ($html) {
  116. echo'<table class="box" border="0" cellpadding="1" cellspacing="2">
  117. <tr>
  118. <td class="smheading" align="center" height="25" width="550" colspan="2">UTDC log: '.$oldfilename.'</td>
  119. </tr>
  120. <tr>
  121. <td class="smheading" align="left" width="350">';
  122. } else {
  123. echo "UTDC log: $oldfilename:\n";
  124. }
  125. echo 'Moving to logs/utdc/: ';
  126. if ($html) echo '</td><td class="grey" align="left" width="200">';
  127. echo backup_logfile($import_utdc_log_compress, $filename, 'logs/utdc/'.$oldfilename, true) . "\n";
  128. if ($html) echo '</td></tr></table><br />';
  129. echo "\n\n";
  130. unlink($filename);
  131. continue;
  132. }
  133. // AnthChecker log: Move to logs/ac/
  134. if ($import_ac_download_enable
  135. and substr($filename, strlen($filename) - strlen($import_ac_log_extension)) == $import_ac_log_extension
  136. and substr($oldfilename, 0, strlen($import_ac_log_start)) == $import_ac_log_start) {
  137. if ($import_ac_log_compress == 'no') $import_ac_log_compress = 'yes';
  138. if ($html) {
  139. echo'<table class="box" border="0" cellpadding="1" cellspacing="2">
  140. <tr>
  141. <td class="smheading" align="center" height="25" width="550" colspan="2">AC log: '.$oldfilename.'</td>
  142. </tr>
  143. <tr>
  144. <td class="smheading" align="left" width="350">';
  145. } else {
  146. echo "AC log: $oldfilename:\n";
  147. }
  148. echo 'Moving to logs/ac/: ';
  149. if ($html) echo '</td><td class="grey" align="left" width="200">';
  150. echo backup_logfile($import_ac_log_compress, $filename, 'logs/ac/'.$oldfilename, true) . "\n";
  151. if ($html) echo '</td></tr></table><br />';
  152. echo "\n\n";
  153. unlink($filename);
  154. continue;
  155. }
  156. if(substr($filename, strlen($filename) - strlen($import_log_extension)) != $import_log_extension) continue;
  157. if(substr($oldfilename, 0, strlen($import_log_start)) != $import_log_start) continue;
  158. // Create a unique ID
  159. $uid = str_rand();
  160. // Check if there are any logs to do ...
  161. // Create our temp Table
  162. for (;;) {
  163. $sql = "CREATE ". ($import_use_temporary_tables ? 'TEMPORARY ' : '') ."TABLE `uts_temp_$uid` (
  164. `id` mediumint(5) NOT NULL,
  165. `col0` char(20) NOT NULL default '',
  166. `col1` char(120) NOT NULL default '',
  167. `col2` char(120) NOT NULL default '',
  168. `col3` char(120) NOT NULL default '',
  169. `col4` char(120) NOT NULL default '',
  170. KEY `part1` (`col1` (20),`col2` (20)),
  171. KEY `part2` (`col0` (20),`col1` (20),`col2` (20)),
  172. KEY `full` (`col0` (20),`col1` (20),`col2` (20),`col3` (20),`col4` (20))
  173. ) TYPE=". ($import_use_heap_tables ? 'HEAP' : 'MyISAM') .";";
  174. $result = mysql_query($sql);
  175. if ($result) break;
  176. if (mysql_errno() == 1044 and $import_use_temporary_tables) {
  177. echo "<br><strong>WARNING: Unable to create temporary table (". mysql_error() .")<br>";
  178. echo "I'll retry without using MySQL's temporary table feature (see \$import_use_temporary_tables in config.php for details).<br><br></strong>";
  179. $import_use_temporary_tables = false;
  180. continue;
  181. }
  182. die("<br><strong>Unable to create the temporary table - are you allowed to create tables in this database?<br><br></strong>");
  183. }
  184. $id = 0;
  185. if ($html) {
  186. echo'<table class="box" border="0" cellpadding="1" cellspacing="2">
  187. <tr>
  188. <td class="smheading" align="center" height="25" width="550" colspan="2">Importing '.$oldfilename.'</td>
  189. </tr>
  190. <tr>
  191. <td class="smheading" align="left" width="350">';
  192. } else {
  193. echo "Importing $oldfilename:\n";
  194. }
  195. echo 'Creating Temp MySQL Table: ';
  196. if ($html) echo '</td><td class="grey" align="left" width="200">';
  197. echo "uts_temp_$uid\n";
  198. if ($html) echo '</td></tr><tr><td class="smheading" align="left" width="350">';
  199. echo 'Backing Up Log File: ';
  200. if ($html) echo '</td><td class="grey" align="left" width="200">';
  201. // Copy the file to backup folder first
  202. echo backup_logfile($import_log_backup, $filename, $backupfilename, true) . "\n";
  203. if ($html) echo '</td><tr><td class="smheading" align="left" width="350">';
  204. echo 'Player Data Moved to Temp MySQL: ';
  205. if ($html) echo '</td>';
  206. // Create sql for NGLog
  207. $row = 1;
  208. $handle = fopen("$filename", "r");
  209. while (($data = my_fgets($handle, 5000)) !== FALSE) {
  210. if ($debug) debug_output('Raw input ', $data);
  211. $data = preg_replace('/[\x00]/', '', $data);
  212. if ($debug) debug_output('After preg_replace', $data);
  213. $data = explode("\t", $data);
  214. $num = count($data);
  215. $row++;
  216. for ($c=0; $c < 1; $c++) {
  217. $col0 = addslashes($data[0]);
  218. $col1 = addslashes($data[1]);
  219. $col2 = addslashes($data[2]);
  220. $col3 = addslashes($data[3]);
  221. $col4 = addslashes($data[4]);
  222. $col0 = trim($col0, " \n\r");
  223. $col1 = trim($col1, " \n\r");
  224. $col2 = trim($col2, " \n\r");
  225. $col3 = trim($col3, " \n\r");
  226. $col4 = trim($col4, " \n\r");
  227. $id++;
  228. mysql_query("INSERT INTO uts_temp_$uid VALUES ($id, '$col0', '$col1', '$col2', '$col3', '$col4');") or die(mysql_error());
  229. }
  230. }
  231. fclose($handle);
  232. $files++;
  233. if ($html) echo'<td class="grey" align="left" width="200">';
  234. echo "Yes\n";
  235. $log_incompatible = false;
  236. $actor_version = 'unknown';
  237. $qm_logtype = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Log_Standard'");
  238. if ($qm_logtype['col3'] == 'UTStats') {
  239. $qm_logversion = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Log_Version'");
  240. $actor_version = $qm_logversion['col3'];
  241. }
  242. if (!in_array($actor_version, $compatible_actor_versions)) {
  243. if ($import_incompatible_logs) {
  244. if ($html) echo '</td></tr><tr><td class="smheading" align="left" width="350" style="background-color: red;">';
  245. echo "WARNING: ";
  246. if ($html) echo '</td><td class="grey" align="left" width="200" style="background-color: red;">';
  247. echo "This logfile was created using an incompatible UTStats server actor version ($actor_version). You may experience strange results and/or bugs!\n";
  248. } else {
  249. $log_incompatible = true;
  250. }
  251. }
  252. if ($html) echo '</td></tr><tr><td class="smheading" align="left" width="350">';
  253. echo "Match Data Created: ";
  254. if ($html) echo '</td><td class="grey" align="left" width="200">';
  255. // Get the match table info
  256. $qm_time = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Absolute_Time'");
  257. $qm_servername = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_ServerName'");
  258. $qm_serverip = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'True_Server_IP'");
  259. $qm_serverport = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_Port'");
  260. $qm_gamename = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'GameName'");
  261. #$qm_gamestart = small_query("SELECT col0 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'realstart'");
  262. $qm_gamestart = small_query("SELECT col0 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'Rename'");
  263. $qm_gameend = small_query("SELECT col0 FROM uts_temp_$uid WHERE col1 = 'game_end'");
  264. $qm_insta = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'insta'");
  265. $qm_tournament = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'TournamentMode'");
  266. $qm_teamgame = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'TeamGame'");
  267. $qm_mapname = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'map' AND col2 = 'Title'");
  268. $qm_mapfile = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'map' AND col2 = 'Name'");
  269. $qm_frags = small_query("SELECT SUM(col4) AS frags FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'frags'");
  270. $qm_kills = small_query("SELECT SUM(col4) AS kills FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'kills'");
  271. $qm_suicides = small_query("SELECT SUM(col4) AS suicides FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'suicides'");
  272. $qm_deaths = small_query("SELECT SUM(col4) AS deaths FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'deaths'");
  273. $qm_teamkills = small_query("SELECT SUM(col4) AS teamkills FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'teamkills'");
  274. $qm_ass_obj = small_query("SELECT COUNT(col1) AS ass_obj FROM uts_temp_$uid WHERE col1 = 'assault_obj'");
  275. $qm_playercount = small_count("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'rename' GROUP BY col3");
  276. $s_frags = $qm_frags[frags];
  277. $s_suicides = $qm_suicides[suicides];
  278. $s_deaths = $qm_deaths[deaths];
  279. // Add teamkills only if its a team game, else add them to kills total
  280. IF ($qm_teamgame[col3] == "True") {
  281. $s_kills = $qm_kills[kills];
  282. $s_teamkills = $qm_teamkills[teamkills];
  283. } else {
  284. $s_kills = $qm_kills[kills]+$qm_teamkills[teamkills];
  285. $s_teamkills = 0;
  286. }
  287. // Check if anything happened, if it didnt stop everything now
  288. IF ($qm_kills[kills] == 0 && $qm_deaths[deaths] == 0 && $qm_ass_obj[ass_obj] == 0) {
  289. echo "No (Empty Match)\n";
  290. if ($html) echo '</td></tr>';
  291. } elseIF ($qm_playercount < 2) {
  292. echo "No (Not Enough Players)\n";
  293. if ($html) echo '</td></tr>';
  294. } elseIF ($log_incompatible) {
  295. echo "No (Logfile incompatible [created by UTStats $actor_version])\n";
  296. if ($html) echo '</td></tr>';
  297. } elseIF ($import_ignore_if_gametime_less_than != 0 and ceil(($qm_gameend[col0] - $qm_gamestart[col0]) / 60) < $import_ignore_if_gametime_less_than) {
  298. echo "No (game too short [". ceil(($qm_gameend[col0] - $qm_gamestart[col0]) / 60) ." &lt; $import_ignore_if_gametime_less_than minutes])\n";
  299. if ($html) echo '</td></tr>';
  300. } else {
  301. $sql_mutators = "SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'GoodMutator'";
  302. $q_mutators = mysql_query($sql_mutators);
  303. while ($r_mutators = mysql_fetch_array($q_mutators)) {
  304. $qm_mutators .= "".$r_mutators[col3].", ";
  305. }
  306. $qm_serveran = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_AdminName'");
  307. $qm_serverae = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_AdminEmail'");
  308. $qm_serverm1 = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_MOTDLine1'");
  309. $qm_serverm2 = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_MOTDLine2'");
  310. $qm_serverm3 = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_MOTDLine3'");
  311. $qm_serverm4 = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'info' AND col2 = 'Server_MOTDLine4'");
  312. $qm_gameinfotl = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'TimeLimit'");
  313. $qm_gameinfofl = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'FragLimit'");
  314. $qm_gameinfogt = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'GoalTeamScore'");
  315. $qm_gameinfomp = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'MaxPlayers'");
  316. $qm_gameinfoms = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'MaxSpectators'");
  317. $qm_gameinfogs = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'GameSpeed'");
  318. $qm_gameinfout = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'UseTranslocator'");
  319. $qm_gameinfoff = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'FriendlyFireScale'");
  320. $qm_gameinfows = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'game' AND col2 = 'WeaponsStay'");
  321. $gametime = $qm_time[col3];
  322. $servername = addslashes($qm_servername[col3]);
  323. $serverip = $qm_serverip[col3];
  324. $serverport = $qm_serverport[col3];
  325. $gamename = addslashes($qm_gamename[col3]);
  326. $servergametime = get_dp($qm_gameend[col0] - $qm_gamestart[col0]);
  327. $tournament = $qm_tournament[col3];
  328. $teamgame = $qm_teamgame[col3];
  329. $mapname = addslashes($qm_mapname[col3]);
  330. $mapfile = addslashes($qm_mapfile[col3]);
  331. // Lazy Hack for unknown gametypes
  332. $unknowngt = substr("$mapfile", 0, 3); // Gets first 3 characters
  333. IF ($unknowngt == "JB-") {
  334. $gamename = "JailBreak";
  335. $teamgame = 'True';
  336. }
  337. // Append insta to game if it was an insta game
  338. IF ($qm_insta[col3] == "True") { $gameinsta = 1; $gamename = "$gamename (insta)"; } else { $gameinsta = 0; }
  339. // Get the unique ID of this gametype.
  340. // Create a new one if it has none yet.
  341. $r_gid = small_query("SELECT id FROM uts_games WHERE gamename = '$gamename'");
  342. if ($r_gid) {
  343. $gid = $r_gid['id'];
  344. } else {
  345. mysql_query("INSERT INTO uts_games SET gamename = '$gamename', name = '$gamename'") or die(mysql_error());
  346. $gid = mysql_insert_id();
  347. }
  348. // Check wheter we want to override the gametype for this match
  349. // (Useful if we want a server to have separate stats for one server or if we want to
  350. // combine DM and TDM rankings or ...)
  351. // Read all rules
  352. if (!isset($overriderules)) {
  353. $overriderules = array();
  354. $sql_overriderules = "SELECT id, serverip, gamename, mutator, gid FROM uts_gamestype ORDER BY id ASC;";
  355. $q_overriderules = mysql_query($sql_overriderules);
  356. while ($r_overriderules = mysql_fetch_array($q_overriderules)) {
  357. $overriderules[$r_overriderules['id']]['serverip'] = $r_overriderules['serverip'];
  358. $overriderules[$r_overriderules['id']]['gamename'] = $r_overriderules['gamename'];
  359. $overriderules[$r_overriderules['id']]['mutator'] = $r_overriderules['mutator'];
  360. $overriderules[$r_overriderules['id']]['gid'] = $r_overriderules['gid'];
  361. }
  362. }
  363. // Check if one of our overriderules applies to this match
  364. foreach($overriderules as $rule) {
  365. if ($rule['serverip'] != '*' and $rule['serverip'] != "$serverip:$serverport") continue;
  366. if ($rule['gamename'] != '*' and $rule['gamename'] != $gamename) continue;
  367. if ($rule['mutator'] != '*' and stristr($qm_mutators, $rule['mutator']) === false) continue;
  368. $gid = $rule['gid'];
  369. break;
  370. }
  371. $qm_firstblood = small_query("SELECT col2 FROM uts_temp_$uid WHERE col1 = 'first_blood'");
  372. $firstblood = addslashes($qm_firstblood[col2]);
  373. $serverinfo = addslashes("Admin: $qm_serveran[col3]<br />Email: $qm_serverae[col3] <br /><br />
  374. <u>MOTD</u><br />$qm_serverm1[col3]<br />$qm_serverm2[col3]<br />$qm_serverm3[col3]<br />$qm_serverm4[col3]");
  375. $gameinfo = addslashes( add_info('Time Limit:', $qm_gameinfotl[col3]) .
  376. add_info('Frag Limit:', $qm_gameinfofl[col3]) .
  377. add_info('Goal Team Score:', $qm_gameinfogt[col3]) .
  378. add_info('Max Players:', $qm_gameinfomp[col3]) .
  379. add_info('Max Specs:', $qm_gameinfoms[col3]) .
  380. add_info('Game Speed:', $qm_gameinfogs[col3]) .
  381. add_info('Translocator:', $qm_gameinfout[col3]) .
  382. add_info('Friendly Fire:', $qm_gameinfoff[col3]) .
  383. add_info('Weapon Stay:', $qm_gameinfows[col3]) .
  384. add_info('UTStats Actor Version:', $actor_version));
  385. // Tidy Up The Info
  386. $mutators = substr("$qm_mutators", 0, -2); // remove trailing ,
  387. $mutators = un_ut($mutators); // Remove Class and BotPack. etc
  388. $mutators = addslashes($mutators);
  389. $gametime = utdate($gametime);
  390. // Get Teams Info
  391. $sql_tinfo = "SELECT col4 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'TeamName' GROUP BY col4 ORDER BY col4 ASC";
  392. $q_tinfo = mysql_query($sql_tinfo) or die(mysql_error());
  393. $t0info = 0;
  394. $t1info = 0;
  395. $t2info = 0;
  396. $t3info = 0;
  397. while ($r_tinfo = mysql_fetch_array($q_tinfo)) {
  398. IF ($r_tinfo[col4] == "Red") { $t0info = 1; }
  399. IF ($r_tinfo[col4] == "Blue") { $t1info = 1; }
  400. IF ($r_tinfo[col4] == "Green") { $t2info = 1; }
  401. IF ($r_tinfo[col4] == "Gold") { $t3info = 1; }
  402. }
  403. // Get Teamscores
  404. $sql_tscore = "SELECT col2 AS team, col3 AS score FROM uts_temp_$uid WHERE col1 = 'teamscore'";
  405. $q_tscore = mysql_query($sql_tscore) or die(mysql_error());
  406. $t0score = 0;
  407. $t1score = 0;
  408. $t2score = 0;
  409. $t3score = 0;
  410. while ($r_tscore = mysql_fetch_array($q_tscore)) {
  411. if ($r_tscore['team'] == "0") $t0score = $r_tscore['score'];
  412. if ($r_tscore['team'] == "1") $t1score = $r_tscore['score'];
  413. if ($r_tscore['team'] == "2") $t2score = $r_tscore['score'];
  414. if ($r_tscore['team'] == "3") $t3score = $r_tscore['score'];
  415. }
  416. // Insert Server Info Into Database
  417. $sql_serverinfo = "INSERT INTO uts_match (id, time, servername, serverip, gamename, gid, gametime, mutators, insta, tournament, teamgame, mapname, mapfile, serverinfo, gameinfo, frags, kills, suicides, teamkills, deaths,
  418. t0, t1, t2, t3, t0score, t1score, t2score, t3score)
  419. VALUES ('0', '$gametime', '$servername', '$serverip:$serverport', '$gamename', '$gid', '$servergametime', '$mutators', '$gameinsta', '$tournament',
  420. '$teamgame', '$mapname', '$mapfile', '$serverinfo', '$gameinfo', '$s_frags', '$s_kills', '$s_suicides', '$s_teamkills', '$s_deaths',
  421. $t0info, $t1info, $t2info, $t3info, $t0score, $t1score, $t2score, $t3score);";
  422. $q_serverinfo = mysql_query($sql_serverinfo) or die(mysql_error());
  423. $matchid = mysql_insert_id(); // Get our Match ID
  424. echo "Yes (ID: $matchid)\n";
  425. if ($html) echo '</td></tr>';
  426. // Process Player Stuff
  427. $playerid2pid = array();
  428. $ignored_players = array();
  429. $imported_players = array();
  430. if ($html) echo '<tr><td class="smheading" align="left" width="350">';
  431. echo "Importing Players: ";
  432. if ($html) echo '</td><td class="grey" align="left" width="200">';
  433. // Get List of Player IDs and Process What They Have Done
  434. $sql_player = "SELECT DISTINCT col4 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'rename' AND col4 <> ''";
  435. $q_player = mysql_query($sql_player) or die(mysql_error());
  436. while ($r_player = mysql_fetch_array($q_player)) {
  437. $playerid = $r_player[col4];
  438. // Get players last name used
  439. $r_player2 = small_query("SELECT col3 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'rename' AND col4 = $playerid ORDER BY id DESC LIMIT 0,1");
  440. $playername = addslashes($r_player2[col3]);
  441. // Are they a Bot
  442. $r_player1 = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'IsABot' AND col3 = $playerid ORDER BY id DESC LIMIT 0,1");
  443. $isabot = $r_player1[col4];
  444. // This player is a bot
  445. if ($isabot == 'True' and $import_ignore_bots) {
  446. $ignored_players[] = $playername;
  447. // We do not want to know who killed and who was killed by this bot...
  448. mysql_query("DELETE FROM uts_temp_$uid WHERE (col1 = 'kill' OR col1 = 'teamkill') AND (col2 = '$playerid' OR col4 = '$playerid');") or die(mysql_error());
  449. if ($html) echo "<span style='text-decoration: line-through;'>";
  450. echo "Bot:$playername ";
  451. if ($html) echo "</span>";
  452. continue;
  453. }
  454. // Get players last team
  455. $r_player3 = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'TeamChange' AND col3 = $playerid ORDER BY id DESC LIMIT 0,1");
  456. $playerteam = $r_player3[col4];
  457. //$qc_kills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'kills'AND col3 = $playerid");
  458. //$qc_teamkills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'teamkills' AND col3 = $playerid");
  459. //$qc_deaths = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'deaths' AND col3 = $playerid");
  460. //$qc_suicides = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'suicides' AND col3 = $playerid");
  461. //$qc_score = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'deaths' AND col3 = $playerid");
  462. // Player had no events => ignore
  463. //IF (($qc_kills[col4] + $qc_deaths[col4] + $qc_teamkills[col4] + $qc_suicides[col4]) == 0 && $qc_score[col4] == 0) {
  464. // $ignored_players[] = $playername;
  465. // continue;
  466. //}
  467. // Player was a spectator
  468. $qc_spectate = small_query("SELECT count(col1) as cnt FROM uts_temp_$uid WHERE col1 = 'player' AND col2 = 'Connect' AND col4 = $playerid");
  469. IF ($qc_spectate[cnt] == 0) {
  470. $ignored_players[] = $playername;
  471. continue;
  472. }
  473. // Process all the other player information
  474. include("import/import_playerstuff.php");
  475. if ($playerbanned) {
  476. // Banned players don't have a rank.
  477. mysql_query("DELETE FROM uts_rank WHERE pid = $pid");
  478. if ($import_ban_type == 2) {
  479. // We do not want to know who killed and who was killed by this banned player
  480. $ignored_players[] = $playername;
  481. mysql_query("DELETE FROM uts_temp_$uid WHERE (col1 = 'kill' OR col1 = 'teamkill') AND (col2 = $playerid OR col4 = $playerid);") or die(mysql_error());
  482. if ($html) echo "<span style='text-decoration: line-through;'>";
  483. echo "Banned:$playername ";
  484. if ($html) echo "</span>";
  485. continue;
  486. }
  487. }
  488. // Get Gametype specific stuff done
  489. IF ($gamename == "Assault" || $gamename == "Assault (insta)") { include("import/import_ass.php"); }
  490. IF ($gamename == "Capture the Flag" || $gamename == "Capture the Flag (insta)") { include("import/import_ctf.php"); }
  491. IF ($gamename == "Domination" || $gamename == "Domination (insta)") { include("import/import_dom.php"); }
  492. IF ($gamename == "Tournament Team Game" || $gamename == "Tournament Team Game (insta)") { include("import/import_tdm.php"); }
  493. IF ($gamename == "JailBreak" || $gamename == "JailBreak (insta)") { include("import/import_jailbreak.php"); }
  494. IF ($gamename == "Last Man Standing" || $gamename == "Last Man Standing (insta)") { include("import/import_lms.php"); }
  495. // Do the rankings
  496. include("import/import_ranking.php");
  497. if ($playerbanned) {
  498. if ($html) echo "<span style='font-style: italic;'>";
  499. echo "Banned:";
  500. }
  501. echo $playername.' ';
  502. if ($playerbanned and $html) echo "</span>";
  503. $imported_players[] = $playername;
  504. }
  505. if ($html) echo '</td></tr>';
  506. // Check if theres any players left, if none or one delete the match (its possible ...)
  507. $final_pcount = small_count("SELECT id FROM uts_player WHERE matchid = $matchid");
  508. IF ($final_pcount == NULL || $final_pcount == 1) {
  509. echo'<tr>
  510. <td class="smheading" align="left" width="350">Deleting Match:</td>
  511. <td class="grey" align="left" width="200">0 or 1 Player Entries Left</td>
  512. </tr>';
  513. $sql_radjust = "SELECT pid, gid, rank FROM uts_player WHERE matchid = $matchid";
  514. $q_radjust = mysql_query($sql_radjust) or die(mysql_error());
  515. while ($r_radjust = mysql_fetch_array($q_radjust)) {
  516. $pid = $r_radjust[pid];
  517. $gid = $r_radjust[gid];
  518. $rank = $r_radjust[rank];
  519. $sql_crank = small_query("SELECT id, rank, matches FROM uts_rank WHERE pid = $pid AND gid = $gid");
  520. if (!$sql_crank) continue;
  521. $rid = $sql_crank[id];
  522. $newrank = $sql_crank[rank]-$rank;
  523. $oldrank = $sql_crank[rank];
  524. $matchcount = $sql_crank[matches]-1;
  525. mysql_query("UPDATE uts_rank SET rank = $newrank, prevrank = $oldrank, matches = $matchcount WHERE id = $rid") or die(mysql_error());
  526. }
  527. mysql_query("DELETE FROM uts_rank WHERE matches = 0") or die(mysql_error());
  528. $rem_mrecord = "DELETE FROM uts_match WHERE id = $matchid";
  529. mysql_query($rem_mrecord);
  530. $rem_precord = "DELETE FROM uts_player WHERE matchid = $matchid";
  531. mysql_query($rem_precord);
  532. } else {
  533. // Make our weapons statistics
  534. echo "\n";
  535. if ($html) echo '<tr><td class="smheading" align="left" width="350">';
  536. echo "Importing weapon statistics: ";
  537. if ($html) echo '</td><td class="grey" align="left" width="200">';
  538. include("import/import_weapons.php");
  539. echo "Done\n";
  540. if ($html) echo '</td></tr>';
  541. // Make our kills matrix stuff ...
  542. if ($html) echo '<tr><td class="smheading" align="left" width="350">';
  543. echo "Building kills matrix: ";
  544. if ($html) echo '</td><td class="grey" align="left" width="200">';
  545. include("import/import_killsmatrix.php");
  546. echo "Done\n";
  547. if ($html) echo '</td></tr><tr><td class="smheading" align="left" width="350">';
  548. echo "Combining Duplicate Player Entries: ";
  549. if ($html) echo '</td><td class="grey" align="left" width="200">';
  550. // Combine duplicate player entries ... very intensive :(
  551. include("import/import_pcleanup.php");
  552. echo "Done\n";
  553. if ($html) echo'</td></tr>';
  554. $updategameinfo = false;
  555. if (count($ignored_players) > 0) {
  556. // Maybe we imported the player and ignored another record of him?
  557. $ignored_players = array_unique($ignored_players);
  558. foreach($ignored_players as $t_id => $t_name) {
  559. if (in_array($t_name, $imported_players)) unset($ignored_players[$t_id]);
  560. }
  561. if (count($ignored_players) > 0) {
  562. $gameinfo .= addslashes(add_info('Ignored Players:', implode(', ', $ignored_players)));
  563. $updategameinfo = true;
  564. }
  565. }
  566. if ($updategameinfo) {
  567. mysql_query("UPDATE uts_match SET gameinfo = '$gameinfo' WHERE id = '$matchid'");
  568. $updategameinfo = false;
  569. }
  570. }
  571. }
  572. // Delete Temp MySQL Table
  573. $droptable = "DROP TABLE uts_temp_$uid";
  574. mysql_query($droptable) or die(mysql_error());
  575. if ($html) echo'<tr><td class="smheading" align="left" width="350">';
  576. echo "Deleting Temp MySQL Table: ";
  577. if ($html) echo '</td><td class="grey" align="left" width="200">';
  578. echo "uts_temp_$uid\n";
  579. if ($html) echo '</td></tr></table><br />';
  580. echo "\n\n";
  581. // Clear variables
  582. $asscode = "";
  583. $assteam = "";
  584. $asswin = "";
  585. $avgping = "";
  586. $data = "";
  587. $domplayer = "";
  588. $droptable = "";
  589. $firstblood = "";
  590. $gameinfo = "";
  591. $gameinsta = "";
  592. $gamename = "";
  593. $gametime = "";
  594. $highping = "";
  595. $unknowngt = "";
  596. $lowping = "";
  597. $mapname = "";
  598. $mapfile = "";
  599. $matchid = "";
  600. $mutators = "";
  601. $num = "";
  602. $playerid = "";
  603. $playerfragscnt = "";
  604. $playername = "";
  605. $playerecordid = "";
  606. $playerteam = "";
  607. $qm_mutators = "";
  608. $row = 1;
  609. $servername = "";
  610. $serverinfo = "";
  611. $serverip = "";
  612. $serverport = "";
  613. $suicidecnt = "";
  614. $t0info = "";
  615. $t1info = "";
  616. $t2info = "";
  617. $t3info = "";
  618. $t0score = "";
  619. $t1score = "";
  620. $t2score = "";
  621. $t3score = "";
  622. $teamgame = "";
  623. $tournament = "";
  624. // Delete log file
  625. unlink($filename);
  626. }
  627. closedir($logdir);
  628. if ($html) echo '<br />';
  629. echo "\n";
  630. // Import stats
  631. if ($files != 0) {
  632. $elapsed = $elapsed + time() - $start_time;
  633. if ($html) echo '<p class="pages">';
  634. echo "Processed $files ". ($files == 1 ? 'file' : 'files') ." in $elapsed ". ($elapsed == 1 ? 'second' : 'seconds') ." ";
  635. echo "(". get_dp($elapsed / $files) ." seconds/file)\n";
  636. if ($html) echo '</p><br />';
  637. }
  638. // Optimise database
  639. if (rand(0, 5) == 0) {
  640. if ($html) echo '<p class="pages">';
  641. echo "Optimizing tables... ";
  642. mysql_query("OPTIMIZE TABLE uts_match, uts_player, uts_rank, uts_killsmatrix, uts_weaponstats, uts_pinfo;") or die(mysql_error());
  643. echo "Done\n";
  644. if ($html) echo '</p>';
  645. }
  646. // Analyze Key distribution
  647. if (rand(0, 10) == 0) {
  648. if ($html) echo '<p class="pages">';
  649. echo "Analyzing tables... ";
  650. mysql_query("ANALYZE TABLE uts_match, uts_player, uts_rank, uts_killsmatrix, uts_weaponstats, uts_pinfo;") or die(mysql_error());
  651. echo "Done\n";
  652. if ($html) echo '</p>';
  653. }
  654. // Purge old logs
  655. if ($purged = (purge_backups('logs/backup', $import_log_backups_purge_after))) {
  656. if ($html) echo '<p class="pages">';
  657. echo "Purged $purged old logfiles\n";
  658. if ($html) echo '</p>';
  659. }
  660. // Purge old utdc logs
  661. if ($import_utdc_download_enable) {
  662. if ($purged = (purge_backups('logs/utdc', $import_utdc_log_purge_after))) {
  663. if ($html) echo '<p class="pages">';
  664. echo "Purged $purged old UTDC logfiles\n";
  665. if ($html) echo '</p>';
  666. }
  667. }
  668. // Purge old AnthChecker logs
  669. if ($import_ac_download_enable) {
  670. if ($purged = (purge_backups('logs/ac', $import_ac_log_purge_after))) {
  671. if ($html) echo '<p class="pages">';
  672. echo "Purged $purged old AC logfiles\n";
  673. if ($html) echo '</p>';
  674. }
  675. }
  676. echo "\n\n";
  677. if ($html) echo '<br /><table border="0" cellpadding="1" cellspacing="2" width="720"><tr><td class="heading" align="center" colspan="2">';
  678. echo "Import Script Completed\n";
  679. if ($html) echo '</td></tr></table>';
  680. if ($html) include("includes/footer.php");
  681. ?>