Quake4   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A processPlayers() 0 29 2
1
<?php
2
/**
3
 * This file is part of GameQ.
4
 *
5
 * GameQ is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * GameQ is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace GameQ\Protocols;
20
21
use GameQ\Buffer;
22
use GameQ\Helpers\Str;
23
use GameQ\Result;
24
25
/**
26
 * Quake 4 Protocol Class
27
 *
28
 * @package GameQ\Protocols
29
 *
30
 * @author  Wilson Jesus <>
31
 */
32
class Quake4 extends Doom3
33
{
34
    /**
35
     * String name of this protocol class
36
     *
37
     * @var string
38
     */
39
    protected $name = 'quake4';
40
41
    /**
42
     * Longer string name of this protocol class
43
     *
44
     * @var string
45
     */
46
    protected $name_long = "Quake 4";
47
48
    /**
49
     * Handle processing of player data
50
     *
51
     * @param \GameQ\Buffer $buffer
52
     * @return array
53
     * @throws \GameQ\Exception\Protocol
54
     */
55 12
    protected function processPlayers(Buffer $buffer)
56
    {
57
        // Some games do not have a number of current players
58 12
        $playerCount = 0;
59
60
        // Set the result to a new result instance
61 12
        $result = new Result();
62
63
        // Parse players
64
        // Loop thru the buffer until we run out of data
65 12
        while (($id = $buffer->readInt8()) != 32) {
66
            // Add player info results
67 6
            $result->addPlayer('id', $id);
68 6
            $result->addPlayer('ping', $buffer->readInt16());
69 6
            $result->addPlayer('rate', $buffer->readInt32());
70
            // Add player name, encoded
71 6
            $result->addPlayer('name', Str::isoToUtf8(trim($buffer->readString())));
72 6
            $result->addPlayer('clantag', $buffer->readString());
73
            // Increment
74 6
            $playerCount++;
75
        }
76
77
        // Add the number of players to the result
78 12
        $result->add('numplayers', $playerCount);
79
80
        // Clear
81 12
        unset($buffer, $playerCount);
82
83 12
        return $result->fetch();
84
    }
85
}
86