Justcause2::processDetails()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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
     * @var string
38
     */
39
    protected $name = 'justcause2';
40
41
    /**
42
     * Longer string name of this protocol class
43
     *
44
     * @var string
45
     */
46
    protected $name_long = "Just Cause 2 Multiplayer";
47
48
    /**
49
     * The client join link
50
     *
51
     * @var 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
     * @var 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
     * @return void
101
     * @throws \GameQ\Exception\Protocol
102
     */
103 18
    protected function processDetails(Buffer &$buffer, Result &$result)
104
    {
105 18
        parent::processDetails($buffer, $result);
106
107
        // Add in map
108 18
        $result->add('mapname', 'Panau');
109 18
        $result->add('dedicated', 'true');
110
    }
111
112
    /**
113
     * Override the parent, this protocol is returned differently
114
     *
115
     * @param Buffer $buffer
116
     * @param Result $result
117
     * @return void
118
     * @throws \GameQ\Exception\Protocol
119
     *
120
     * @see Gamespy3::processPlayersAndTeams()
121
     */
122 18
    protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
123
    {
124
        // Loop until we run out of data
125 18
        while ($buffer->getLength()) {
126 18
            $result->addPlayer('name', $buffer->readString());
127 18
            $result->addPlayer('steamid', $buffer->readString());
128 18
            $result->addPlayer('ping', $buffer->readInt16());
129
        }
130
    }
131
}
132