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.

roleperiod.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/class.php');
  3. class RolePeriod {
  4. private static $teams = array('Red' => 1, 'Blue' => 2, 'Spectator' => 3, '' => 0, 'Unassigned' => 0);
  5. private $id;
  6. private $class;
  7. public function __construct(Player &$player, Session &$session, $id = null, $timestamp = null, $team = null, $class = null) {
  8. if ($id == null) {
  9. assert($timestamp != null && $team != null && $class != null);
  10. $team = self::$teams[$team];
  11. $class = $this->class = PlayerClass::getID($class);
  12. $sql = 'INSERT INTO roleperiods (session_id, player_id, roleperiod_team, class_id, roleperiod_starttime)';
  13. $sql .= ' VALUES(' . $session->getID() . ', ' . $player->getID() . ', ' . $team . ', ' . $class . ', FROM_UNIXTIME(' . $timestamp . '))';
  14. $res = mysql_query($sql);
  15. $this->id = mysql_insert_id();
  16. } else {
  17. $this->id = $id;
  18. $sql = 'SELECT class_id FROM roleperiods WHERE roleperiod_id = ' . $id;
  19. $res = mysql_query($sql);
  20. $this->class = mysql_result($res, 0);
  21. }
  22. }
  23. public function getID() {
  24. return $this->id;
  25. }
  26. public function getClass() {
  27. return $this->class;
  28. }
  29. public function close($timestamp) {
  30. $sql = 'UPDATE roleperiods SET roleperiod_endtime = FROM_UNIXTIME(' . $timestamp . '),';
  31. $sql .= ' roleperiod_kills = (SELECT COUNT(*) FROM kills WHERE kill_killer = roleperiod_id),';
  32. $sql .= ' roleperiod_deaths = (SELECT COUNT(*) FROM kills WHERE kill_victim = roleperiod_id),';
  33. $sql .= ' roleperiod_assists = (SELECT COUNT(*) FROM kills WHERE kill_assist = roleperiod_id)';
  34. $sql .= ' WHERE roleperiod_id = ' . $this->id;
  35. $res = mysql_query($sql);
  36. }
  37. }
  38. ?>