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 <austin@codebeard.com>
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: protected function processDetails(Buffer $buffer)
57: {
58: // Decode into items
59: $items = $this->decode($buffer);
60:
61: // Set the result to a new result instance
62: $result = new Result();
63:
64: // Server is always dedicated
65: $result->add('dedicated', 1);
66:
67: // These are the same no matter what mode the server is in
68: $result->add('hostname', $items[1]);
69: $result->add('num_players', (int) $items[2]);
70: $result->add('max_players', (int) $items[3]);
71: $result->add('gametype', $items[4]);
72: $result->add('map', $items[5]);
73: $result->add('roundsplayed', (int) $items[6]);
74: $result->add('roundstotal', (int) $items[7]);
75: $result->add('num_teams', (int) $items[8]);
76:
77: // Set the current index
78: $index_current = 9;
79:
80: // Pull the team count
81: $teamCount = $result->get('num_teams');
82:
83: // Loop for the number of teams found, increment along the way
84: for ($id = 1; $id <= $teamCount; $id++, $index_current++) {
85: // Shows the tickets
86: $result->addTeam('tickets', $items[$index_current]);
87: // We add an id so we know which team this is
88: $result->addTeam('id', $id);
89: }
90:
91: // Get and set the rest of the data points.
92: $result->add('targetscore', (int) $items[$index_current]);
93: $result->add('online', 1); // Forced true, it seems $words[$index_current + 1] is always empty
94: $result->add('ranked', (int) $items[$index_current + 2]);
95: $result->add('punkbuster', (int) $items[$index_current + 3]);
96: $result->add('password', (int) $items[$index_current + 4]);
97: $result->add('uptime', (int) $items[$index_current + 5]);
98: $result->add('roundtime', (int) $items[$index_current + 6]);
99: $result->add('ip_port', $items[$index_current + 7]);
100: $result->add('punkbuster_version', $items[$index_current + 8]);
101: $result->add('join_queue', (int) $items[$index_current + 9]);
102: $result->add('region', $items[$index_current + 10]);
103: $result->add('pingsite', $items[$index_current + 11]);
104: $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: $result->add('blaze_player_count', (int) $items[$index_current + 13]);
107: $result->add('blaze_game_state', (int) $items[$index_current + 14]);
108:
109: unset($items, $index_current, $teamCount, $buffer);
110:
111: return $result->fetch();
112: }
113: }
114: