From 40dfa7d5c0dc8e4cb2c95e403b6b4b2c4bf70644 Mon Sep 17 00:00:00 2001 From: Matthijs Kuiper Date: Sat, 4 Feb 2017 16:05:45 +0100 Subject: Original UTStats beta 4.2.8 --- html/import/import_ass.php | 34 +++++ html/import/import_bt.php | 46 +++++++ html/import/import_ctf.php | 43 +++++++ html/import/import_dom.php | 19 +++ html/import/import_jailbreak.php | 22 ++++ html/import/import_killsmatrix.php | 22 ++++ html/import/import_lms.php | 46 +++++++ html/import/import_pcleanup.php | 256 +++++++++++++++++++++++++++++++++++++ html/import/import_playerstuff.php | 182 ++++++++++++++++++++++++++ html/import/import_ranking.php | 127 ++++++++++++++++++ html/import/import_tdm.php | 2 + html/import/import_weapons.php | 209 ++++++++++++++++++++++++++++++ html/import/index.htm | 0 13 files changed, 1008 insertions(+) create mode 100755 html/import/import_ass.php create mode 100755 html/import/import_bt.php create mode 100755 html/import/import_ctf.php create mode 100755 html/import/import_dom.php create mode 100755 html/import/import_jailbreak.php create mode 100755 html/import/import_killsmatrix.php create mode 100755 html/import/import_lms.php create mode 100755 html/import/import_pcleanup.php create mode 100755 html/import/import_playerstuff.php create mode 100755 html/import/import_ranking.php create mode 100755 html/import/import_tdm.php create mode 100755 html/import/import_weapons.php create mode 100755 html/import/index.htm (limited to 'html/import') diff --git a/html/import/import_ass.php b/html/import/import_ass.php new file mode 100755 index 0000000..9539bc5 --- /dev/null +++ b/html/import/import_ass.php @@ -0,0 +1,34 @@ + diff --git a/html/import/import_bt.php b/html/import/import_bt.php new file mode 100755 index 0000000..fe6a480 --- /dev/null +++ b/html/import/import_bt.php @@ -0,0 +1,46 @@ + $cap_speed) { + $cap_speed = $r_capbt['col3']; + $col0 = $r_capbt['col0']; // time + $col1 = $r_capbt['col1']; // cap + $col2 = $r_capbt['col2']; // playerid + $col3 = $r_capbt['col3']; // speed in 2000 - seconds (old system) or 600000 - hundreds of seconds (new system) + $col4 = $r_capbt['col4']; // date in seconds since epoch + } + $flag_capture++; + } + + if ($cap_speed != 0) { + # use col2 to store the rank, col3 to store the captime in seconds and col4 to store the date of the record + $col2 = small_count("SELECT DISTINCT col2 FROM uts_temp_$uid WHERE col1 = 'cap' AND col3 > $col3") + 1; + if ($col1 == "btcap") { + $col3 = ceil(600000 - $col3) / 100; + } + else if ($col1 == "cap") { + $col3 = ceil((2000 - $col3-1)*100/1.1) / 100; + $col1 = "btcap"; + } + $col3 = sprintf("%01.2f", $col3); + $sql_eventsbt = "INSERT INTO uts_events + (matchid, playerid, col0, col1, col2, col3, col4) VALUES + ($matchid, $playerid, '$col0', '$col1', '$col2', '$col3', '$col4')"; + mysql_query($sql_eventsbt) or die (mysql_error()); + } + + if ($flag_capture > 0) { + $sql_playerflags = " UPDATE uts_player + SET flag_capture = $flag_capture + WHERE id = $playerecordid"; + mysql_query($sql_playerflags) or die(mysql_error()); + } +?> diff --git a/html/import/import_ctf.php b/html/import/import_ctf.php new file mode 100755 index 0000000..206cbb0 --- /dev/null +++ b/html/import/import_ctf.php @@ -0,0 +1,43 @@ + diff --git a/html/import/import_dom.php b/html/import/import_dom.php new file mode 100755 index 0000000..91106ac --- /dev/null +++ b/html/import/import_dom.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/html/import/import_jailbreak.php b/html/import/import_jailbreak.php new file mode 100755 index 0000000..6d6e0da --- /dev/null +++ b/html/import/import_jailbreak.php @@ -0,0 +1,22 @@ + 'RedeemerDeath' and col4 <> 'JailRelease'"); + $r_suicides = $q_suicides['suicides']; + + $r_frags = $r_kills - $r_suicides; + $r_efficiency = get_dp(($r_kills / ($r_kills + $r_deaths + $r_suicides + $r_teamkills)) * 100); + + + mysql_query(" UPDATE uts_player + SET ass_obj = '$r_releases', + suicides = '$r_suicides', + frags = '$r_frags', + eff = '$r_efficiency' + WHERE id = $playerecordid;") or die(mysql_error()); + +?> \ No newline at end of file diff --git a/html/import/import_killsmatrix.php b/html/import/import_killsmatrix.php new file mode 100755 index 0000000..433a659 --- /dev/null +++ b/html/import/import_killsmatrix.php @@ -0,0 +1,22 @@ + diff --git a/html/import/import_lms.php b/html/import/import_lms.php new file mode 100755 index 0000000..eb3ebd7 --- /dev/null +++ b/html/import/import_lms.php @@ -0,0 +1,46 @@ + diff --git a/html/import/import_pcleanup.php b/html/import/import_pcleanup.php new file mode 100755 index 0000000..3e1be8a --- /dev/null +++ b/html/import/import_pcleanup.php @@ -0,0 +1,256 @@ + 3"; + mysql_query($rem_srecord); +} + +$cleaned = false; +// Get list of players +$sql_pname = "SELECT pid, name FROM uts_player, uts_pinfo AS pi WHERE matchid = $matchid AND pid = pi.id"; +$q_pname = mysql_query($sql_pname); +while ($r_pname = mysql_fetch_array($q_pname)) { + $playername = addslashes($r_pname[name]); + $pid = $r_pname['pid']; + + + // Check if player has more than 1 record + $q_ids = mysql_query("SELECT playerid FROM uts_player WHERE pid = '$pid' AND matchid = $matchid"); + + IF (mysql_num_rows($q_ids) > 1) { + $numrecords = mysql_num_rows($q_ids); + echo $r_pname[name] .' '; + // get all the ids this player had + $playerids = array(); + while ($r_ids = mysql_fetch_array($q_ids)) { + $playerids[] = $r_ids['playerid']; + } + + $r_newplayerid = small_query("SELECT (MAX(playerid) + 1) AS newplayerid FROM uts_player WHERE matchid = $matchid"); + $newplayerid = $r_newplayerid['newplayerid']; + + // Fix the events table + foreach ($playerids as $i => $oldplayerid) { + mysql_query("UPDATE uts_events SET playerid = $newplayerid WHERE playerid = $oldplayerid AND matchid = $matchid"); + } + + // Fix matchcount in ranking table + // mysql_query("UPDATE uts_rank SET matches = matches - ". ($numrecords - 1) ." WHERE pid = '$pid' AND gid = '$gid'") or die(mysql_error()); + + // *********************** + // UPDATE THE KILLS MATRIX + $sql_kmupdate = " SELECT victim, + SUM(kills) AS kills + FROM uts_killsmatrix + WHERE matchid = $matchid + AND killer IN (". implode(",", $playerids) .") + GROUP BY victim;"; + + $q_kmupdate = mysql_query($sql_kmupdate); + while ($r_kmupdate = mysql_fetch_array($q_kmupdate)) { + mysql_query(" INSERT + INTO uts_killsmatrix + SET matchid = $matchid, + killer = $newplayerid, + victim = ${r_kmupdate['victim']}, + kills = ${r_kmupdate['kills']};"); + } + + $sql_kmupdate = " SELECT killer, + SUM(kills) AS kills + FROM uts_killsmatrix + WHERE matchid = $matchid + AND victim IN (". implode(",", $playerids) .") + GROUP BY killer;"; + + $q_kmupdate = mysql_query($sql_kmupdate); + while ($r_kmupdate = mysql_fetch_array($q_kmupdate)) { + mysql_query(" INSERT + INTO uts_killsmatrix + SET matchid = $matchid, + killer = ${r_kmupdate['killer']}, + victim = $newplayerid, + kills = ${r_kmupdate['kills']};"); + } + + mysql_query(" DELETE + FROM uts_killsmatrix + WHERE matchid = $matchid + AND (killer IN (". implode(",", $playerids) .") + OR victim IN (". implode(",", $playerids) ."));"); + + + // FINISHED UPDATING THE KILLS MATRiX + // ********************************** + + + // Get non summed information + + $r_truepinfo1 = small_query("SELECT insta, pid, team, isabot, country, ip, gid FROM uts_player WHERE pid = '$pid' AND matchid = $matchid LIMIT 0,1"); + // fix rejoin as spec + if ($r_treupinfo1['team'] == 255) { + $r_trueteam = small_query("SELECT team FROM uts_player WHERE pid = '$pid' AND matchid = $matchid AND team != 255 LIMIT 0,1"); + if ($r_trueteam['team'] < 255) { + $r_truepinfo1['team'] = $r_trueteam['team']; + } + } + + // Group Player Stuff so we only have 1 player record per match + if ($gamename == "Bunny Track") { + // In bunnytrack the gamescore is 2000 - fastest time in seconds so use MAX gamescore rather then SUM + $r_truepinfo2 = small_query("SELECT + SUM(gametime) AS gametime, + MAX(gamescore) AS gamescore, + AVG(lowping) AS lowping, + AVG(highping) AS highping, + AVG(avgping) AS avgping, + SUM(frags) AS frags, + SUM(deaths) AS deaths, + SUM(kills) AS kills, + SUM(suicides) AS suicides, + SUM(teamkills) AS teamkills, + AVG(eff) AS eff, + AVG(accuracy) AS accuracy, + AVG(ttl) AS ttl, + SUM(flag_taken) AS flag_taken, + SUM(flag_pickedup) AS flag_pickedup, + SUM(flag_dropped) AS flag_dropped, + SUM(flag_return) AS flag_return, + SUM(flag_capture) AS flag_capture, + SUM(flag_cover) AS flag_cover, + SUM(flag_seal) AS flag_seal, + SUM(flag_assist) AS flag_assist, + SUM(flag_kill) AS flag_kill, + SUM(dom_cp) AS dom_cp, + SUM(ass_obj) AS ass_obj, + SUM(spree_double) AS spree_double, + SUM(spree_triple) AS spree_triple, + SUM(spree_multi) AS spree_multi, + SUM(spree_mega) AS spree_mega, + SUM(spree_ultra) AS spree_ultra, + SUM(spree_monster) AS spree_monster, + SUM(spree_kill) AS spree_kill, + SUM(spree_rampage) AS spree_rampage, + SUM(spree_dom) AS spree_dom, + SUM(spree_uns) AS spree_uns, + SUM(spree_god) AS spree_god, + SUM(pu_pads) AS pu_pads, + SUM(pu_armour) AS pu_armour, + SUM(pu_keg) AS pu_keg, + SUM(pu_invis) AS pu_invis, + SUM(pu_belt) AS pu_belt, + SUM(pu_amp) AS pu_amp, + SUM(rank) AS rank + FROM uts_player WHERE matchid = $matchid AND pid = '$pid'"); + } + else { + $r_truepinfo2 = small_query("SELECT + SUM(gametime) AS gametime, + SUM(gamescore) AS gamescore, + AVG(lowping) AS lowping, + AVG(highping) AS highping, + AVG(avgping) AS avgping, + SUM(frags) AS frags, + SUM(deaths) AS deaths, + SUM(kills) AS kills, + SUM(suicides) AS suicides, + SUM(teamkills) AS teamkills, + AVG(eff) AS eff, + AVG(accuracy) AS accuracy, + AVG(ttl) AS ttl, + SUM(flag_taken) AS flag_taken, + SUM(flag_pickedup) AS flag_pickedup, + SUM(flag_dropped) AS flag_dropped, + SUM(flag_return) AS flag_return, + SUM(flag_capture) AS flag_capture, + SUM(flag_cover) AS flag_cover, + SUM(flag_seal) AS flag_seal, + SUM(flag_assist) AS flag_assist, + SUM(flag_kill) AS flag_kill, + SUM(dom_cp) AS dom_cp, + SUM(ass_obj) AS ass_obj, + SUM(spree_double) AS spree_double, + SUM(spree_triple) AS spree_triple, + SUM(spree_multi) AS spree_multi, + SUM(spree_mega) AS spree_mega, + SUM(spree_ultra) AS spree_ultra, + SUM(spree_monster) AS spree_monster, + SUM(spree_kill) AS spree_kill, + SUM(spree_rampage) AS spree_rampage, + SUM(spree_dom) AS spree_dom, + SUM(spree_uns) AS spree_uns, + SUM(spree_god) AS spree_god, + SUM(pu_pads) AS pu_pads, + SUM(pu_armour) AS pu_armour, + SUM(pu_keg) AS pu_keg, + SUM(pu_invis) AS pu_invis, + SUM(pu_belt) AS pu_belt, + SUM(pu_amp) AS pu_amp, + SUM(rank) AS rank + FROM uts_player WHERE matchid = $matchid AND pid = '$pid'"); + } + + // Remove all of this player's records + $rem_precord = "DELETE FROM uts_player WHERE matchid = $matchid AND pid = '$pid'"; + mysql_query($rem_precord); + + // Add this new record to match + $upd_precord = " INSERT + INTO uts_player + SET matchid = $matchid, + insta = '$r_truepinfo1[insta]', + playerid = '$newplayerid', + pid = '$pid', + team = '$r_truepinfo1[team]', + isabot = '$r_truepinfo1[isabot]', + country = '$r_truepinfo1[country]', + ip = '$r_truepinfo1[ip]', + gid = '$r_truepinfo1[gid]', + gametime = '$r_truepinfo2[gametime]', + gamescore = '$r_truepinfo2[gamescore]', + lowping = '".(int)$r_truepinfo2[lowping]."', + highping = '".(int)$r_truepinfo2[highping]."', + avgping = '".(int)$r_truepinfo2[avgping]."', + frags = '$r_truepinfo2[frags]', + deaths = '$r_truepinfo2[deaths]', + kills = '$r_truepinfo2[kills]', + suicides = '$r_truepinfo2[suicides]', + teamkills = '$r_truepinfo2[teamkills]', + eff = '$r_truepinfo2[eff]', + accuracy = '$r_truepinfo2[accuracy]', + ttl = '$r_truepinfo2[ttl]', + flag_taken = '$r_truepinfo2[flag_taken]', + flag_dropped = '$r_truepinfo2[flag_dropped]', + flag_return = '$r_truepinfo2[flag_return]', + flag_capture = '$r_truepinfo2[flag_capture]', + flag_cover = '$r_truepinfo2[flag_cover]', + flag_seal = '$r_truepinfo2[flag_seal]', + flag_assist = '$r_truepinfo2[flag_assist]', + flag_kill = '$r_truepinfo2[flag_kill]', + flag_pickedup = '$r_truepinfo2[flag_pickedup]', + dom_cp = '$r_truepinfo2[dom_cp]', + ass_obj = '$r_truepinfo2[ass_obj]', + spree_double = '$r_truepinfo2[spree_double]', + spree_triple = '$r_truepinfo2[spree_triple]', + spree_multi = '$r_truepinfo2[spree_multi]', + spree_mega = '$r_truepinfo2[spree_mega]', + spree_ultra = '$r_truepinfo2[spree_ultra]', + spree_monster = '$r_truepinfo2[spree_monster]', + spree_kill = '$r_truepinfo2[spree_kill]', + spree_rampage = '$r_truepinfo2[spree_rampage]', + spree_dom = '$r_truepinfo2[spree_dom]', + spree_uns = '$r_truepinfo2[spree_uns]', + spree_god = '$r_truepinfo2[spree_god]', + pu_pads = '$r_truepinfo2[pu_pads]', + pu_armour = '$r_truepinfo2[pu_armour]', + pu_keg = '$r_truepinfo2[pu_keg]', + pu_invis = '$r_truepinfo2[pu_invis]', + pu_belt = '$r_truepinfo2[pu_belt]', + pu_amp = '$r_truepinfo2[pu_amp]', + rank = '$r_truepinfo2[rank]';"; + mysql_query($upd_precord) or die(mysql_error()); + $cleaned = true; + } +} +if ($cleaned and $html) echo "
"; +?> \ No newline at end of file diff --git a/html/import/import_playerstuff.php b/html/import/import_playerstuff.php new file mode 100755 index 0000000..73714e4 --- /dev/null +++ b/html/import/import_playerstuff.php @@ -0,0 +1,182 @@ + 0"); + $lowping = $r_player9[lowping]; + $highping = $r_player9[highping]; + $avgping = (int)$r_player9[avgping]; + + // People who join at the end error the import, this stops it + IF ($lowping == NULL) { $lowping = 0; } + IF ($highping == NULL) { $highping = 0; } + IF ($avgping == NULL) { $avgping = 0; } + + // Get accuracy, ttl etc + $r_acc = 0; + $r_deaths = 0; + $r_efficiency = 0; + $r_frags = 0; + $r_kills = 0; + $r_teamkills = 0; + $r_suicides = 0; + $r_tos = 0; + $r_ttl = 0; + + $q_acc = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'accuracy' AND col3 = $playerid"); + $q_deaths = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'deaths' AND col3 = $playerid"); + $q_kills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'kills' AND col3 = $playerid"); + $q_teamkills = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'teamkills' AND col3 = $playerid"); + $q_efficiency = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'efficiency' AND col3 = $playerid"); + $q_suicides = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'suicides' AND col3 = $playerid"); + $q_tos = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'time_on_server' AND col3 = $playerid"); + $q_ttl = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'ttl' AND col3 = $playerid"); + $q_score = small_query("SELECT col4 FROM uts_temp_$uid WHERE col1 = 'stat_player' AND col2 = 'score' AND col3 = $playerid"); + + IF ($teamgame == "True") { + $r_kills = $q_kills[col4]; + $r_teamkills = $q_teamkills[col4]; + } + IF ($teamgame == "False") { + $r_kills = $q_kills[col4] + $q_teamkills[col4]; + $r_teamkills = 0; + } + + $r_acc = get_dp($q_acc[col4]); + $r_efficiency = get_dp($q_efficiency[col4]); + $r_deaths = $q_deaths[col4]; + $r_suicides = $q_suicides[col4]; + $r_frags = $r_kills-$r_suicides-$r_teamkills; + + $r_tos = get_dp($q_tos[col4]); + // time on server can't be longer then the server game time! + if ($r_tos > $servergametime) { + $r_tos = get_dp($servergametime); + } + $r_ttl = get_dp($q_ttl[col4]); + $r_score = $q_score[col4]; + + // Generate player record + $sql_playerid = " INSERT + INTO uts_player + SET matchid = '$matchid', + playerid = '$playerid', + pid = '$pid', + team = '$playerteam', + gid = '$gid', + insta = '$gameinsta', + country = '$playercountry', + ip = '$playerip', + + + spree_double = '$q_spree_dbl', + spree_multi = '$q_spree_mult', + spree_ultra = '$q_spree_ult', + spree_monster = '$q_spree_mon', + spree_kill = '$q_spree_kill', + spree_rampage = '$q_spree_rampage', + spree_dom = '$q_spree_dom', + spree_uns = '$q_spree_uns', + spree_god = '$q_spree_god', + + pu_pads = '$pu_pads', + pu_armour = '$pu_armour', + pu_keg = '$pu_keg', + pu_belt = '$pu_belt', + pu_amp = '$pu_amp', + pu_invis = '$pu_invis', + + lowping = '$lowping', + highping = '$highping', + avgping = '$avgping', + + accuracy = '$r_acc', + frags = '$r_frags', + deaths = '$r_deaths', + kills = '$r_kills', + suicides = '$r_suicides', + teamkills = '$r_teamkills', + eff = '$r_efficiency', + gametime = '$r_tos', + ttl = '$r_ttl', + gamescore= '$r_score'"; + + $q_playerid = mysql_query($sql_playerid) or die(mysql_error()); + $playerecordid = mysql_insert_id(); + + +?> diff --git a/html/import/import_ranking.php b/html/import/import_ranking.php new file mode 100755 index 0000000..9ad18a2 --- /dev/null +++ b/html/import/import_ranking.php @@ -0,0 +1,127 @@ + 0 AND e.col2 <= 5 GROUP BY e.col2"; + $q_btmaprank = mysql_query($sql_btmaprank) or die ("Can't retrieve \$q_btmaprank: ". mysql_error()); + while($r_btmaprank = mysql_fetch_assoc($q_btmaprank)) { + IF ($r_btmaprank[no] == 1) { + $rank_bt += $r_btmaprank[count] * 10; + } elseIF ($r_btmaprank[no] == 2) { + $rank_bt += $r_btmaprank[count] * 8; + } elseIF ($r_btmaprank[no] == 3) { + $rank_bt += $r_btmaprank[count] * 6; + } elseIF ($r_btmaprank[no] == 4) { + $rank_bt += $r_btmaprank[count] * 4; + } elseIF ($r_btmaprank[no] == 5) { + $rank_bt += $r_btmaprank[count] * 2; + } + // if ($dbg) echo "| pid: $r_btmaprank[no]*$r_btmaprank[count] => $rank_bt
"; + } + + $rank_nrank = $rank_bt; + } else { + $rank_nrank = $rank_fpos-$rank_fneg; + } + + // Average the rank over game minutes + if ($r_gametime == 0) { + // some bug occured, ignore + if ($dbg) echo "Skip ranking. " ; + + return; + } + + $rank_nrank = ($rank_nrank/$r_gametime) * 600; + if ($dbg) echo "Points: $rank_nrank
Time: $r_gametime
"; + + // Add rank gametime to previous amount + $rank_gametime = $r_gametime; + + // Reduce ranking if player hasnt played that much + IF ($rank_gametime < 10) return; + + IF ($rank_gametime < 50) { + $rank_nrank = $rank_nrank*.25; + } + + IF ($rank_gametime >= 50 && $rank_gametime < 100) { + $rank_nrank = $rank_nrank*.50; + } + + IF ($rank_gametime >= 100 && $rank_gametime < 200) { + $rank_nrank = $rank_nrank*.70; + } + + IF ($rank_gametime >= 200 && $rank_gametime < 300) { + $rank_nrank = $rank_nrank*.85; + } + + if ($dbg) echo "Reduced: $rank_nrank
"; + + // Add new rank record if one does not exist + IF($rank_id == NULL) { + mysql_query("INSERT INTO uts_rank SET time = '$r_gametime', pid = '$pid', gid = '$gid', rank = '0', matches = '0';") or die(mysql_error()); + $rank_id = mysql_insert_id(); + $rank_gametime = 0; + $rank_crank = 0; + $rank_matches = 0; + } + + // Add number of matches played + $rank_matches = $rank_matches+1; + + // Work out effective rank given + $eff_rank = $rank_nrank-$rank_crank; + + // if ($dbg) echo "", intval($rank_crank), "-", intval($rank_nrank). "-", $rank_matches, " "; + + // Add effective rank points given to uts_player record + mysql_query("UPDATE uts_player SET rank = $eff_rank WHERE id = $playerecordid") or die(mysql_error()); + + // Update the rank + mysql_query("UPDATE uts_rank SET time = '$rank_gametime', rank = '$rank_nrank', prevrank = '$rank_crank', matches = '$rank_matches' WHERE id = $rank_id;") or die(mysql_error()); +?> diff --git a/html/import/import_tdm.php b/html/import/import_tdm.php new file mode 100755 index 0000000..6595072 --- /dev/null +++ b/html/import/import_tdm.php @@ -0,0 +1,2 @@ + diff --git a/html/import/import_weapons.php b/html/import/import_weapons.php new file mode 100755 index 0000000..5d59a3f --- /dev/null +++ b/html/import/import_weapons.php @@ -0,0 +1,209 @@ + $r_weapons['kills'], + 'weap_shotcount' => 0, + 'weap_hitcount' => 0, + 'weap_damagegiven' => 0, + 'weap_accuracy' => 0 + ); + + +} + + +// Get the weapon statistics +$sql_weapons = " SELECT col1 AS type, + col2 AS weaponname, + col3 AS player, + col4 AS value + FROM uts_temp_$uid + WHERE col1 LIKE 'weap_%'"; + +$q_weapons = mysql_query($sql_weapons) or die(mysql_error()); +while ($r_weapons = mysql_fetch_array($q_weapons)) { + // Get the wepon's id or assign a new one + if (empty($r_weapons['weaponname'])) continue; + if (isset($weaponnames[$r_weapons['weaponname']])) { + $weaponid = $weaponnames[$r_weapons['weaponname']]; + } else { + mysql_query("INSERT INTO uts_weapons SET name = '". addslashes($r_weapons['weaponname']) ."'") or die(mysql_error()); + $weaponid = mysql_insert_id(); + $weaponnames[$r_weapons['weaponname']] = $weaponid; + } + + // Get the unique pid of this player + if (!isset($playerid2pid[$r_weapons['player']])) { +// Happens if we're ignoring bots or banned players + continue; + } else { + $pid = $playerid2pid[$r_weapons['player']]; + } + + if (!isset($weapons[$pid][$weaponid]['weap_kills'])) { + $weapons[$pid][$weaponid] = array( + 'weap_kills' => 0, + 'weap_shotcount' => 0, + 'weap_hitcount' => 0, + 'weap_damagegiven' => 0, + 'weap_accuracy' => 0 + ); + } + + $weapons[$pid][$weaponid][$r_weapons['type']] = $r_weapons['value']; +} + + +// Finally write the weapon statistics for this match +$s_weapons = array(); +foreach($weapons as $playerid => $weapon) { + foreach($weapon as $weaponid => $infos) { + if ($infos['weap_kills'] == 0 and $infos['weap_shotcount'] == 0) continue; + mysql_query(" INSERT + INTO uts_weaponstats + SET matchid = '$matchid', + pid = '$playerid', + weapon = '$weaponid', + kills = '${infos['weap_kills']}', + shots = '${infos['weap_shotcount']}', + hits= '${infos['weap_hitcount']}', + damage = '${infos['weap_damagegiven']}', + acc = '". round($infos['weap_accuracy'], 2) ."';") or die(mysql_error()); + + // Summarize totals for this match + if (!isset($s_weapons[$weaponid]['weap_kills'])) { + $s_weapons[$weaponid]['weap_kills'] = $infos['weap_kills']; + $s_weapons[$weaponid]['weap_shotcount'] = $infos['weap_shotcount']; + $s_weapons[$weaponid]['weap_hitcount'] = $infos['weap_hitcount']; + $s_weapons[$weaponid]['weap_damagegiven'] = $infos['weap_damagegiven']; + $s_weapons[$weaponid]['weap_accuracy'] = $infos['weap_accuracy']; + } else { + $s_weapons[$weaponid]['weap_kills'] += $infos['weap_kills']; + $s_weapons[$weaponid]['weap_shotcount'] += $infos['weap_shotcount']; + $s_weapons[$weaponid]['weap_hitcount'] += $infos['weap_hitcount']; + $s_weapons[$weaponid]['weap_damagegiven'] += $infos['weap_damagegiven']; + $s_weapons[$weaponid]['weap_accuracy'] = ($s_weapons[$weaponid]['weap_accuracy'] + $infos['weap_accuracy']) / 2; + } + } +} + + +// Update the player's weapon statistics (matchid 0); +foreach($weapons as $playerid => $weapon) { + foreach($weapon as $weaponid => $infos) { + if ($infos['weap_kills'] == 0 and $infos['weap_shotcount'] == 0) continue; + // Check whether a record for this player and weapon already + // exists + $r_pstat = small_query(" SELECT pid + FROM uts_weaponstats + WHERE matchid = '0' + AND pid = '$playerid' + AND weapon = '$weaponid'"); + // No -> create + if (!$r_pstat) { + mysql_query(" INSERT + INTO uts_weaponstats + SET matchid = '0', + pid = '$playerid', + weapon = '$weaponid', + kills = '${infos['weap_kills']}', + shots = '${infos['weap_shotcount']}', + hits= '${infos['weap_hitcount']}', + damage = '${infos['weap_damagegiven']}', + acc = '". round($infos['weap_accuracy'], 2) ."';") or die(mysql_error()); + // Yes -> update + } else { + mysql_query(" UPDATE uts_weaponstats + SET weapon = '$weaponid', + kills = kills + '${infos['weap_kills']}', + shots = shots + '${infos['weap_shotcount']}', + hits = hits + '${infos['weap_hitcount']}', + damage = damage + '${infos['weap_damagegiven']}', + acc = (acc + '". round($infos['weap_accuracy'], 2) ."') / 2 + WHERE matchid = '0' + AND pid = '$playerid' + AND weapon = '$weaponid';") or die(mysql_error()); + } + } +} + +// Update the global weapon statistics (matchid 0, playerid 0 ); +foreach($s_weapons as $weaponid => $infos) { + if ($infos['weap_kills'] == 0 and $infos['weap_shotcount'] == 0) continue; + // Check whether the global record for this weapon already exists + $r_pstat = small_query(" SELECT pid + FROM uts_weaponstats + WHERE matchid = '0' + AND pid = '0' + AND weapon = '$weaponid'"); + // No -> create + if (!$r_pstat) { + mysql_query(" INSERT + INTO uts_weaponstats + SET matchid = '0', + pid = '0', + weapon = '$weaponid', + kills = '${infos['weap_kills']}', + shots = '${infos['weap_shotcount']}', + hits= '${infos['weap_hitcount']}', + damage = '${infos['weap_damagegiven']}', + acc = '". round($infos['weap_accuracy'], 2) ."';") or die(mysql_error()); + // Yes -> update + } else { + mysql_query(" UPDATE uts_weaponstats + SET weapon = '$weaponid', + kills = kills + '${infos['weap_kills']}', + shots = shots + '${infos['weap_shotcount']}', + hits = hits + '${infos['weap_hitcount']}', + damage = damage + '${infos['weap_damagegiven']}', + acc = (acc + '". round($infos['weap_accuracy'], 2) ."') / 2 + WHERE matchid = '0' + AND pid = '0' + AND weapon = '$weaponid';") or die(mysql_error()); + } +} + + + + +?> \ No newline at end of file diff --git a/html/import/index.htm b/html/import/index.htm new file mode 100755 index 0000000..e69de29 -- cgit