Bf4   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 36
c 1
b 0
f 0
dl 0
loc 80
ccs 34
cts 34
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A processDetails() 0 56 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\Result;
23
24
/**
25
 * Battlefield 4 Protocol class
26
 *
27
 * Good place for doc status and info is http://battlelog.battlefield.com/bf4/forum/view/2955064768683911198/
28
 *
29
 * @package GameQ\Protocols
30
 * @author  Austin Bischoff <[email protected]>
31
 */
32
class Bf4 extends Bf3
33
{
34
    /**
35
     * String name of this protocol class
36
     *
37
     * @var string
38
     */
39
    protected $name = 'bf4';
40
41
    /**
42
     * Longer string name of this protocol class
43
     *
44
     * @var string
45
     */
46
    protected $name_long = "Battlefield 4";
47
48
    /**
49
     * Handle processing details since they are different than BF3
50
     *
51
     * @param \GameQ\Buffer $buffer
52
     *
53
     * @return array
54
     * @throws \GameQ\Exception\Protocol
55
     */
56 24
    protected function processDetails(Buffer $buffer)
57
    {
58
        // Decode into items
59 24
        $items = $this->decode($buffer);
60
61
        // Set the result to a new result instance
62 24
        $result = new Result();
63
64
        // Server is always dedicated
65 24
        $result->add('dedicated', 1);
66
67
        // These are the same no matter what mode the server is in
68 24
        $result->add('hostname', $items[1]);
69 24
        $result->add('num_players', (int) $items[2]);
70 24
        $result->add('max_players', (int) $items[3]);
71 24
        $result->add('gametype', $items[4]);
72 24
        $result->add('map', $items[5]);
73 24
        $result->add('roundsplayed', (int) $items[6]);
74 24
        $result->add('roundstotal', (int) $items[7]);
75 24
        $result->add('num_teams', (int) $items[8]);
76
77
        // Set the current index
78 24
        $index_current = 9;
79
80
        // Pull the team count
81 24
        $teamCount = $result->get('num_teams');
82
83
        // Loop for the number of teams found, increment along the way
84 24
        for ($id = 1; $id <= $teamCount; $id++, $index_current++) {
85
            // Shows the tickets
86 24
            $result->addTeam('tickets', $items[$index_current]);
87
            // We add an id so we know which team this is
88 24
            $result->addTeam('id', $id);
89
        }
90
91
        // Get and set the rest of the data points.
92 24
        $result->add('targetscore', (int) $items[$index_current]);
93 24
        $result->add('online', 1); // Forced true, it seems $words[$index_current + 1] is always empty
94 24
        $result->add('ranked', (int) $items[$index_current + 2]);
95 24
        $result->add('punkbuster', (int) $items[$index_current + 3]);
96 24
        $result->add('password', (int) $items[$index_current + 4]);
97 24
        $result->add('uptime', (int) $items[$index_current + 5]);
98 24
        $result->add('roundtime', (int) $items[$index_current + 6]);
99 24
        $result->add('ip_port', $items[$index_current + 7]);
100 24
        $result->add('punkbuster_version', $items[$index_current + 8]);
101 24
        $result->add('join_queue', (int) $items[$index_current + 9]);
102 24
        $result->add('region', $items[$index_current + 10]);
103 24
        $result->add('pingsite', $items[$index_current + 11]);
104 24
        $result->add('country', $items[$index_current + 12]);
105
        //$result->add('quickmatch', (int) $items[$index_current + 13]); Supposed to be here according to R42 but is not
106 24
        $result->add('blaze_player_count', (int) $items[$index_current + 13]);
107 24
        $result->add('blaze_game_state', (int) $items[$index_current + 14]);
108
109 24
        unset($items, $index_current, $teamCount, $buffer);
110
111 24
        return $result->fetch();
112
    }
113
}
114