Unsupported PHP app for analysing and displaying stats for Team Fortress 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/database.php');
  3. require_once(dirname(__FILE__) . '/session.php');
  4. class Game {
  5. private static $current = null;
  6. private static $maps = array();
  7. private static $server = null;
  8. private $id;
  9. private function __construct($id = null, $map = null, $starttime = null) {
  10. if ($id != null) {
  11. $this->id = $id;
  12. } else {
  13. assert($map != null && $starttime != null);
  14. $sql = 'INSERT INTO games (map_id, game_starttime, server_id) VALUES (' . self::resolveMap($map) . ', FROM_UNIXTIME(' . $starttime . '), ' . self::$server . ')';
  15. $res = mysql_query($sql);
  16. $this->id = mysql_insert_id();
  17. }
  18. }
  19. public static function setServer($server) {
  20. self::$server = $server;
  21. }
  22. public function getID() {
  23. return $this->id;
  24. }
  25. private function end($timestamp) {
  26. $sql = 'UPDATE games SET game_endtime = FROM_UNIXTIME(' . $timestamp . ') WHERE game_id = ' . $this->id;
  27. $res = mysql_query($sql);
  28. }
  29. public static function init() {
  30. $sql = 'SELECT game_id FROM games WHERE game_endtime = \'0000-00-00\'';
  31. $res = mysql_query($sql);
  32. if (mysql_num_rows($res) > 0) {
  33. self::$current = new Game((int) mysql_result($res, 0));
  34. }
  35. }
  36. public static function changeMap($timestamp, $map) {
  37. if (self::$current != null) {
  38. self::$current->end($timestamp);
  39. }
  40. self::$current = new Game(null, $map, $timestamp);
  41. }
  42. public static function resolveMap($name) {
  43. if (isset(self::$maps[$name])) { return self::$maps[$name]; }
  44. $sql = 'SELECT map_id FROM maps WHERE map_name = \'' . s($name) . '\'';
  45. $res = mysql_query($sql);
  46. if (mysql_num_rows($res) > 0) {
  47. return self::$maps[$name] = (int) mysql_result($res, 0);
  48. } else {
  49. $sql = 'INSERT INTO maps (map_name) VALUES (\'' . s($name) . '\')';
  50. $res = mysql_query($sql);
  51. return self::$maps[$name] = mysql_insert_id();
  52. }
  53. }
  54. public static function getCurrent() {
  55. return self::$current;
  56. }
  57. }
  58. Game::init();
  59. ?>