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: /**
22: * Unreal Tournament 3 Protocol Class
23: *
24: * Note: The response from UT3 appears to not be consistent. Many times packets are incomplete or there are extra
25: * "echoes" in the responses. This may cause issues like odd characters showing up in the keys for the player and team
26: * array responses. Not sure much can be done about it.
27: *
28: * @author Austin Bischoff <austin@codebeard.com>
29: */
30: class Ut3 extends Gamespy3
31: {
32: /**
33: * String name of this protocol class
34: *
35: * @var string
36: */
37: protected $name = 'ut3';
38:
39: /**
40: * Longer string name of this protocol class
41: *
42: * @var string
43: */
44: protected $name_long = "Unreal Tournament 3";
45:
46: /**
47: * Normalize settings for this protocol
48: *
49: * @var array
50: */
51: protected $normalize = [
52: // General
53: 'general' => [
54: 'dedicated' => 'bIsDedicated',
55: 'hostname' => 'hostname',
56: 'numplayers' => 'numplayers',
57: ],
58: ];
59:
60: /**
61: * Overload the response process so we can make some changes
62: *
63: * @return array
64: * @throws \GameQ\Exception\Protocol
65: */
66: public function processResponse()
67: {
68: // Grab the result from the parent
69: /** @var array $result */
70: $result = parent::processResponse();
71:
72: // Move some stuff around
73: $this->renameResult($result, 'OwningPlayerName', 'hostname');
74: $this->renameResult($result, 'p1073741825', 'mapname');
75: $this->renameResult($result, 'p1073741826', 'gametype');
76: $this->renameResult($result, 'p1073741827', 'servername');
77: $this->renameResult($result, 'p1073741828', 'custom_mutators');
78: $this->renameResult($result, 'gamemode', 'open');
79: $this->renameResult($result, 's32779', 'gamemode');
80: $this->renameResult($result, 's0', 'bot_skill');
81: $this->renameResult($result, 's6', 'pure_server');
82: $this->renameResult($result, 's7', 'password');
83: $this->renameResult($result, 's8', 'vs_bots');
84: $this->renameResult($result, 's10', 'force_respawn');
85: $this->renameResult($result, 'p268435704', 'frag_limit');
86: $this->renameResult($result, 'p268435705', 'time_limit');
87: $this->renameResult($result, 'p268435703', 'numbots');
88: $this->renameResult($result, 'p268435717', 'stock_mutators');
89:
90: // Put custom mutators into an array
91: if (isset($result['custom_mutators'])) {
92: $result['custom_mutators'] = explode("\x1c", $result['custom_mutators']);
93: }
94:
95: // Delete some unknown stuff
96: $this->deleteResult($result, ['s1', 's9', 's11', 's12', 's13', 's14']);
97:
98: // Return the result
99: return $result;
100: }
101:
102: /**
103: * Dirty hack to rename result entries into something more useful
104: *
105: * @param array $result
106: * @param string $old
107: * @param string $new
108: */
109: protected function renameResult(array &$result, $old, $new)
110: {
111: // Check to see if the old item is there
112: if (isset($result[$old])) {
113: $result[$new] = $result[$old];
114: unset($result[$old]);
115: }
116: }
117:
118: /**
119: * Dirty hack to delete result items
120: *
121: * @param array $result
122: * @param array $array
123: */
124: protected function deleteResult(array &$result, array $array)
125: {
126: foreach ($array as $key) {
127: unset($result[$key]);
128: }
129: }
130: }
131: