Completed
Push — v3 ( e9ba49...9aaf4b )
by Austin
03:58
created

Justcause2::processPlayersAndTeams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 6
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\Result;
23
24
/**
25
 * Just Cause 2 Multiplayer Protocol Class
26
 *
27
 * Special thanks to Woet for some insight on packing
28
 *
29
 * @package GameQ\Protocols
30
 * @author  Austin Bischoff <[email protected]>
31
 */
32
class Justcause2 extends Gamespy4
33
{
34
    /**
35
     * String name of this protocol class
36
     *
37
     * @type string
38
     */
39
    protected $name = 'justcause2';
40
41
    /**
42
     * Longer string name of this protocol class
43
     *
44
     * @type string
45
     */
46
    protected $name_long = "Just Cause 2 Multiplayer";
47
48
    /**
49
     * The client join link
50
     *
51
     * @type string
52
     */
53
    protected $join_link = "steam://connect/%s:%d/";
54
55
    /**
56
     * Change the packets used
57
     *
58
     * @var array
59
     */
60
    protected $packets = [
61
        self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40",
62
        self::PACKET_ALL       => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x02",
63
    ];
64
65
    /**
66
     * Override the packet split
67
     *
68
     * @var string
69
     */
70
    protected $packetSplit = "/\\x00\\x00\\x00/m";
71
72
    /**
73
     * Normalize settings for this protocol
74
     *
75
     * @type array
76
     */
77
    protected $normalize = [
78
        'general' => [
79
            // target       => source
80
            'dedicated'  => 'dedicated',
81
            'gametype'   => 'gametype',
82
            'hostname'   => 'hostname',
83
            'mapname'    => 'mapname',
84
            'maxplayers' => 'maxplayers',
85
            'numplayers' => 'numplayers',
86
            'password'   => 'password',
87
        ],
88
        // Individual
89
        'player'  => [
90
            'name' => 'name',
91
            'ping' => 'ping',
92
        ],
93
    ];
94
95
    /**
96
     * Overload so we can add in some static data points
97
     *
98
     * @param Buffer $buffer
99
     * @param Result $result
100
     */
101
    protected function processDetails(Buffer &$buffer, Result &$result)
102
    {
103
        parent::processDetails($buffer, $result);
104
105
        // Add in map
106
        $result->add('mapname', 'Panau');
107
        $result->add('dedicated', 'true');
108
    }
109
110
    /**
111
     * Override the parent, this protocol is returned differently
112
     *
113
     * @param Buffer $buffer
114
     * @param Result $result
115
     *
116
     * @see Gamespy3::processPlayersAndTeams()
117
     */
118
    protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
119
    {
120
        // Loop until we run out of data
121
        while ($buffer->getLength()) {
122
            $result->addPlayer('name', $buffer->readString());
123
            $result->addPlayer('steamid', $buffer->readString());
124
            $result->addPlayer('ping', $buffer->readInt16());
125
        }
126
    }
127
}
128