Unsupported PHP app for analysing and displaying stats for Team Fortress 2
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

session.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/database.php');
  3. require_once(dirname(__FILE__) . '/group.php');
  4. require_once(dirname(__FILE__) . '/roleperiod.php');
  5. require_once(dirname(__FILE__) . '/player.php');
  6. class Session {
  7. private $id;
  8. private $player;
  9. private $alias;
  10. private $roleperiod;
  11. public function __construct(Player &$player, $id = null, $timestamp = null, $uid = null, $alias = null) {
  12. $this->player =& $player;
  13. if ($id == null) {
  14. assert($timestamp != null && $uid != null && $alias != null);
  15. $sql = 'INSERT INTO sessions (session_starttime, player_id, session_uid, session_alias, game_id) VALUES (';
  16. $sql .= 'FROM_UNIXTIME(' . $timestamp . '), ' . $player->getID() . ', ' . $uid . ', ';
  17. $sql .= '\'' . s($alias) . '\', ' . Game::getCurrent()->getID() . ')';
  18. $res = mysql_query($sql);
  19. $this->id = mysql_insert_id();
  20. $this->alias = $alias;
  21. $this->checkGroups();
  22. } else {
  23. $this->id = $id;
  24. $sql = 'SELECT roleperiod_id FROM roleperiods WHERE session_id = ' . $id . ' AND roleperiod_endtime = \'0000-00-00\'';
  25. $res = mysql_query($sql);
  26. if (mysql_num_rows($res) > 0) {
  27. $this->roleperiod = new RolePeriod($this->player, $this, (int) mysql_result($res, 0));
  28. }
  29. $sql = 'SELECT session_alias FROM sessions WHERE session_id = ' . $id;
  30. $res = mysql_query($sql);
  31. $this->alias = mysql_result($res, 0);
  32. }
  33. }
  34. public function getAlias() {
  35. return $this->alias;
  36. }
  37. protected function checkGroups() {
  38. foreach ($this->getGroups() as $group) {
  39. Group::getGroup($group)->ensureMember($this->player);
  40. }
  41. }
  42. protected function getGroups() {
  43. $results = array();
  44. if (preg_match_all('/^\[.*?\]|\[.*?\]$/', $this->alias, $m)) {
  45. $results = array_merge($results, $m[0]);
  46. }
  47. if (preg_match_all('/^\|.*?\||\|.*?\|$/', $this->alias, $m)) {
  48. $results = array_merge($results, $m[0]);
  49. }
  50. if (preg_match('/@.*?$/', $this->alias, $m)) {
  51. $results[] = $m[0];
  52. }
  53. return $results;
  54. }
  55. public function getID() {
  56. return $this->id;
  57. }
  58. public function close($timestamp) {
  59. $sql = 'UPDATE sessions SET session_endtime = FROM_UNIXTIME(' . $timestamp . ') WHERE session_id = ' . $this->id;
  60. $res = mysql_query($sql);
  61. if ($this->roleperiod != null) {
  62. $this->roleperiod->close($timestamp);
  63. }
  64. }
  65. public function getRolePeriod() {
  66. return $this->roleperiod;
  67. }
  68. public function changeRole($timestamp, $team, $class) {
  69. if ($this->roleperiod != null) {
  70. $this->roleperiod->close($timestamp);
  71. }
  72. $this->roleperiod = new RolePeriod($this->player, $this, null, $timestamp, $team, $class);
  73. }
  74. public function changeTeam($timestamp, $team) {
  75. if ($this->roleperiod != null) {
  76. $this->roleperiod->close($timestamp);
  77. $this->roleperiod = new RolePeriod($this->player, $this, null, $timestamp, $team, $this->roleperiod->getClass());
  78. }
  79. }
  80. }
  81. ?>