sourcemod /Athena/parser.php

Language PHP Lines 101
MD5 Hash 010dc7ebc18cbde64de38688d83bd98b
Repository https://github.com/kirkelifson/sourcemod.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
<?

class Parser {
    // team scores
    public $ct_score;
    public $t_score;

    // ct flag
    private $is_ct;

    // player arrays per team
    private $counter_terrorists;
    private $terrorists;

    public function __construct()
    {
        $this->ct_score   = 0;
        $this->t_score    = 0;

        $this->is_ct      = 0;

        $this->counter_terrorists = array();
        $this->terrorists         = array();
    }

    public function read_file($file)
    {
        $ct_counter = 0;
        $t_counter  = 0;

        $log = fopen($file, "r") or die("FILE READ ERROR");

        while (!feof($log))
        {
            $line = fgets($log);

            // Filter Counter-Terrorist team score
            if (preg_match("/COUNTERTERRORIST (.*)/", $line, $matches))
            {
                $this->is_ct    = 1;
                $this->ct_score = $matches[1];
            }

            // Filter Terrorist team score
            elseif (preg_match("/TERRORIST (.*)/", $line, $matches))
            {
                $this->is_ct    = 0;
                $this->t_score  = $matches[1];
            }

            else
            {
                // Fill array containing each player's score
                if (empty($line))
                    break;

                $split  = explode(",", $line);

                $nick   = $split[0];
                $kills  = $split[1];
                $deaths = $split[2];

                if ($this->is_ct)
                    $this->counter_terrorists[$ct_counter++] = array($nick, $kills, $deaths);
                else
                    $this->terrorists[$t_counter++] = array($nick, $kills, $deaths);
            }
        }

        fclose($log);
    }

    public function print_tscore()
    {
        // Print Terrorist team score + player scores
        foreach ($this->terrorists as $t)
        {
            printf("\t<tr>\n");
            printf("\t\t<td>%s</td>\n", $t[0]);
            printf("\t\t<td>%d</td>\n", $t[1]);
            printf("\t\t<td>%d</td>\n", $t[2]);
            printf("\t</tr>\n");
        }
    }

    public function print_ctscore()
    {
        // Print Counter-Terrorist team score + player scores
        foreach ($this->counter_terrorists as $ct)
        {
            printf("\t<tr>\n");
            printf("\t\t<td>%s</td>\n", $ct[0]);
            printf("\t\t<td>%d</td>\n", $ct[1]);
            printf("\t\t<td>%d</td>\n", $ct[2]);
            printf("\t</tr>\n");
        }
    }
}

?>
Back to Top