PageRenderTime 36ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Athena/parser.php

https://github.com/kirkelifson/sourcemod
PHP | 100 lines | 73 code | 19 blank | 8 comment | 4 complexity | 010dc7ebc18cbde64de38688d83bd98b MD5 | raw file
  1. <?
  2. class Parser {
  3. // team scores
  4. public $ct_score;
  5. public $t_score;
  6. // ct flag
  7. private $is_ct;
  8. // player arrays per team
  9. private $counter_terrorists;
  10. private $terrorists;
  11. public function __construct()
  12. {
  13. $this->ct_score = 0;
  14. $this->t_score = 0;
  15. $this->is_ct = 0;
  16. $this->counter_terrorists = array();
  17. $this->terrorists = array();
  18. }
  19. public function read_file($file)
  20. {
  21. $ct_counter = 0;
  22. $t_counter = 0;
  23. $log = fopen($file, "r") or die("FILE READ ERROR");
  24. while (!feof($log))
  25. {
  26. $line = fgets($log);
  27. // Filter Counter-Terrorist team score
  28. if (preg_match("/COUNTERTERRORIST (.*)/", $line, $matches))
  29. {
  30. $this->is_ct = 1;
  31. $this->ct_score = $matches[1];
  32. }
  33. // Filter Terrorist team score
  34. elseif (preg_match("/TERRORIST (.*)/", $line, $matches))
  35. {
  36. $this->is_ct = 0;
  37. $this->t_score = $matches[1];
  38. }
  39. else
  40. {
  41. // Fill array containing each player's score
  42. if (empty($line))
  43. break;
  44. $split = explode(",", $line);
  45. $nick = $split[0];
  46. $kills = $split[1];
  47. $deaths = $split[2];
  48. if ($this->is_ct)
  49. $this->counter_terrorists[$ct_counter++] = array($nick, $kills, $deaths);
  50. else
  51. $this->terrorists[$t_counter++] = array($nick, $kills, $deaths);
  52. }
  53. }
  54. fclose($log);
  55. }
  56. public function print_tscore()
  57. {
  58. // Print Terrorist team score + player scores
  59. foreach ($this->terrorists as $t)
  60. {
  61. printf("\t<tr>\n");
  62. printf("\t\t<td>%s</td>\n", $t[0]);
  63. printf("\t\t<td>%d</td>\n", $t[1]);
  64. printf("\t\t<td>%d</td>\n", $t[2]);
  65. printf("\t</tr>\n");
  66. }
  67. }
  68. public function print_ctscore()
  69. {
  70. // Print Counter-Terrorist team score + player scores
  71. foreach ($this->counter_terrorists as $ct)
  72. {
  73. printf("\t<tr>\n");
  74. printf("\t\t<td>%s</td>\n", $ct[0]);
  75. printf("\t\t<td>%d</td>\n", $ct[1]);
  76. printf("\t\t<td>%d</td>\n", $ct[2]);
  77. printf("\t</tr>\n");
  78. }
  79. }
  80. }
  81. ?>