1 | <?php |
||
21 | class Ffow extends Protocol |
||
22 | { |
||
23 | /** |
||
24 | * Array of packets we want to look up. |
||
25 | * Each key should correspond to a defined method in this or a parent class |
||
26 | * |
||
27 | * @type array |
||
28 | */ |
||
29 | protected $packets = [ |
||
30 | self::PACKET_CHALLENGE => "\xFF\xFF\xFF\xFF\x57", |
||
31 | self::PACKET_RULES => "\xFF\xFF\xFF\xFF\x56%s", |
||
32 | self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFF\x55%s", |
||
33 | self::PACKET_INFO => "\xFF\xFF\xFF\xFF\x46\x4C\x53\x51", |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Use the response flag to figure out what method to run |
||
38 | * |
||
39 | * @type array |
||
40 | */ |
||
41 | protected $responses = [ |
||
42 | "\xFF\xFF\xFF\xFF\x49\x02" => 'processInfo', // I |
||
43 | "\xFF\xFF\xFF\xFF\x45\x00" => 'processRules', // E |
||
44 | "\xFF\xFF\xFF\xFF\x44\x00" => 'processPlayers', // D |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * The query protocol used to make the call |
||
49 | * |
||
50 | * @type string |
||
51 | */ |
||
52 | protected $protocol = 'ffow'; |
||
53 | |||
54 | /** |
||
55 | * String name of this protocol class |
||
56 | * |
||
57 | * @type string |
||
58 | */ |
||
59 | protected $name = 'ffow'; |
||
60 | |||
61 | /** |
||
62 | * Longer string name of this protocol class |
||
63 | * |
||
64 | * @type string |
||
65 | */ |
||
66 | protected $name_long = "Frontlines Fuel of War"; |
||
67 | |||
68 | /** |
||
69 | * The client join link |
||
70 | * |
||
71 | * @type string |
||
72 | */ |
||
73 | protected $join_link = null; |
||
74 | |||
75 | /** |
||
76 | * query_port = client_port + 2 |
||
77 | * |
||
78 | * @type int |
||
79 | */ |
||
80 | protected $port_diff = 2; |
||
81 | |||
82 | /** |
||
83 | * Normalize settings for this protocol |
||
84 | * |
||
85 | * @type array |
||
86 | */ |
||
87 | protected $normalize = [ |
||
88 | // General |
||
89 | 'general' => [ |
||
90 | // target => source |
||
91 | 'gametype' => 'gamemode', |
||
92 | 'hostname' => 'servername', |
||
93 | 'mapname' => 'mapname', |
||
94 | 'maxplayers' => 'max_players', |
||
95 | 'mod' => 'modname', |
||
96 | 'numplayers' => 'num_players', |
||
97 | 'password' => 'password', |
||
98 | ], |
||
99 | // Individual |
||
100 | 'player' => [ |
||
101 | 'name' => 'name', |
||
102 | 'ping' => 'ping', |
||
103 | 'score' => 'frags', |
||
104 | ], |
||
105 | ]; |
||
106 | |||
107 | /** |
||
108 | * Parse the challenge response and apply it to all the packet types |
||
109 | * |
||
110 | * @param \GameQ\Buffer $challenge_buffer |
||
111 | * |
||
112 | * @return bool |
||
113 | * @throws \GameQ\Exception\Protocol |
||
114 | */ |
||
115 | 1 | public function challengeParseAndApply(Buffer $challenge_buffer) |
|
123 | |||
124 | /** |
||
125 | * Handle response from the server |
||
126 | * |
||
127 | * @return mixed |
||
128 | * @throws Exception |
||
129 | */ |
||
130 | 4 | public function processResponse() |
|
157 | |||
158 | /** |
||
159 | * Handle processing the server information |
||
160 | * |
||
161 | * @param Buffer $buffer |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 2 | protected function processInfo(Buffer $buffer) |
|
192 | |||
193 | /** |
||
194 | * Handle processing the server rules |
||
195 | * |
||
196 | * @param Buffer $buffer |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | 4 | protected function processRules(Buffer $buffer) |
|
224 | |||
225 | /** |
||
226 | * Handle processing of player data |
||
227 | * |
||
228 | * @todo: Build this out when there is a server with players to test against |
||
229 | * |
||
230 | * @param Buffer $buffer |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | 4 | protected function processPlayers(Buffer $buffer) |
|
243 | } |
||
244 |