Unsupported PHP app for analysing and displaying stats for Team Fortress 2
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/database.php');
  3. require_once(dirname(__FILE__) . '/class.php');
  4. class Player {
  5. private static $players = array();
  6. private $id;
  7. private $steamid;
  8. private $score;
  9. private $session = null;
  10. private function __construct($id, $steamid, $score, $session = null) {
  11. $this->id = $id;
  12. $this->steamid = $steamid;
  13. $this->score = $score;
  14. if ($session != null) {
  15. $this->session = new Session($this, $session);
  16. }
  17. }
  18. public function getKPD() {
  19. $sql = 'SELECT SUM(roleperiod_kills)/SUM(roleperiod_deaths) AS kpd FROM ';
  20. $sql .= 'sessions NATURAL JOIN roleperiods WHERE player_id = ' . $this->id;
  21. $res = mysql_query($sql);
  22. $row = mysql_fetch_assoc($res);
  23. return $row['kpd'];
  24. }
  25. public function getScore() {
  26. return $this->score;
  27. }
  28. public function addScore($score) {
  29. $this->score += $score;
  30. $sql = 'UPDATE players SET player_score = ' . $this->score . ' WHERE player_id = ' . $this->id;
  31. $res = mysql_query($sql);
  32. }
  33. public function getID() {
  34. return $this->id;
  35. }
  36. public function getSteamID() {
  37. return $this->steamid;
  38. }
  39. public function getOpenSession() {
  40. return $this->session;
  41. }
  42. public function closeSession($timestamp) {
  43. if ($this->session == null) {
  44. // Do nothing - broken?
  45. } else {
  46. $this->session->close($timestamp);
  47. $this->session = null;
  48. }
  49. }
  50. public function openSession($timestamp, $uid, $alias) {
  51. if ($this->session != null) { $this->closeSession($timestamp); }
  52. $this->session = new Session($this, null, $timestamp + 1, $uid, $alias);
  53. }
  54. public static function getBySteamID($steamid) {
  55. if (isset(self::$players[$steamid])) {
  56. // We already have one cached.
  57. return self::$players[$steamid];
  58. }
  59. $sql = 'SELECT player_id, player_score FROM players WHERE player_steamid = \'' . s($steamid) . '\'';
  60. $res = mysql_query($sql);
  61. if (mysql_num_rows($res) > 0) {
  62. // Player already known, grab ID from db.
  63. $row = mysql_fetch_assoc($res);
  64. $id = $row['player_id'];
  65. $score = $row['player_score'];
  66. $session = null;
  67. // Check for open sessions
  68. $sql = 'SELECT session_id FROM sessions WHERE player_id = ' . $id . ' AND session_endtime = \'0000-00-00\'';
  69. $res = mysql_query($sql);
  70. if (mysql_num_rows($res) > 0) {
  71. $session = (int) mysql_result($res, 0);
  72. }
  73. return self::$players[$steamid] = new Player($id, $steamid, $score, $session);
  74. } else {
  75. // New player, insert them into the db.
  76. $sql = 'INSERT INTO players (player_steamid) VALUES (\'' . s($steamid) . '\')';
  77. $res = mysql_query($sql);
  78. return self::$players[$steamid] = new Player(mysql_insert_id(), $steamid, 1000);
  79. }
  80. }
  81. }
  82. ?>