138 int header = packet.read_byte(); |
138 int header = packet.read_byte(); |
139 |
139 |
140 switch (ServerResponse (header)) |
140 switch (ServerResponse (header)) |
141 { |
141 { |
142 case SVRC_OLDPROTOCOL: |
142 case SVRC_OLDPROTOCOL: |
143 m_interface->print_error ("Your RCON client is using outdated protocol.\n"); |
143 m_interface->printError ("Your RCON client is using outdated protocol.\n"); |
144 m_state = RCON_DISCONNECTED; |
144 m_state = RCON_DISCONNECTED; |
145 break; |
145 break; |
146 |
146 |
147 case SVRC_BANNED: |
147 case SVRC_BANNED: |
148 m_interface->print_error ("You have been banned from the server.\n"); |
148 m_interface->printError ("You have been banned from the server.\n"); |
149 m_state = RCON_DISCONNECTED; |
149 m_state = RCON_DISCONNECTED; |
150 break; |
150 break; |
151 |
151 |
152 case SVRC_SALT: |
152 case SVRC_SALT: |
153 m_salt = packet.read_string(); |
153 m_salt = packet.read_string(); |
154 m_state = RCON_AUTHENTICATING; |
154 m_state = RCON_AUTHENTICATING; |
155 send_password(); |
155 send_password(); |
156 break; |
156 break; |
157 |
157 |
158 case SVRC_INVALIDPASSWORD: |
158 case SVRC_INVALIDPASSWORD: |
159 m_interface->print_error ("Login failed.\n"); |
159 m_interface->printError ("Login failed.\n"); |
160 m_state = RCON_DISCONNECTED; |
160 m_state = RCON_DISCONNECTED; |
161 break; |
161 break; |
162 |
162 |
163 case SVRC_MESSAGE: |
163 case SVRC_MESSAGE: |
164 { |
164 { |
165 String message = packet.read_string(); |
165 String message = packet.read_string(); |
166 message.normalize(); |
166 message.normalize(); |
167 m_interface->print_text ("%s\n", message.chars()); |
167 m_interface->printText ("%s\n", message.chars()); |
168 } |
168 } |
169 break; |
169 break; |
170 |
170 |
171 case SVRC_LOGGEDIN: |
171 case SVRC_LOGGEDIN: |
172 m_interface->print ("Login successful!\n"); |
172 m_interface->print ("Login successful!\n"); |
173 m_serverProtocol = packet.read_byte(); |
173 m_serverProtocol = packet.read_byte(); |
174 m_hostname = packet.read_string(); |
174 m_hostname = packet.read_string(); |
175 m_interface->set_title (m_hostname); |
175 m_interface->setTitle (m_hostname); |
176 m_state = RCON_CONNECTED; |
176 m_state = RCON_CONNECTED; |
177 |
177 |
178 for (int i = packet.read_byte(); i > 0; --i) |
178 for (int i = packet.read_byte(); i > 0; --i) |
179 process_server_updates (packet); |
179 process_server_updates (packet); |
180 |
180 |
182 |
182 |
183 for (int i = packet.read_byte(); i > 0; --i) |
183 for (int i = packet.read_byte(); i > 0; --i) |
184 { |
184 { |
185 String message = packet.read_string(); |
185 String message = packet.read_string(); |
186 message.normalize(); |
186 message.normalize(); |
187 m_interface->print_text ("--- %s\n", message.chars()); |
187 m_interface->printText ("--- %s\n", message.chars()); |
188 } |
188 } |
189 |
189 |
190 m_interface->print ("End of previous messages.\n"); |
190 m_interface->print ("End of previous messages.\n"); |
191 |
191 |
192 // Watch sv_hostname so that we can update the titlebar when it changes. |
192 // Watch sv_hostname so that we can update the titlebar when it changes. |
207 break; |
207 break; |
208 |
208 |
209 case SVRC_TABCOMPLETE: |
209 case SVRC_TABCOMPLETE: |
210 { |
210 { |
211 StringList completes; |
211 StringList completes; |
212 |
212 completes.resize(packet.read_byte()); |
213 for (signed int i = packet.read_byte(); i > 0; --i) |
213 |
214 completes << packet.read_string(); |
214 for (String& completion : completes) |
|
215 completion = packet.read_string(); |
215 |
216 |
216 if (completes.size() == 1) |
217 if (completes.size() == 1) |
217 { |
218 { |
218 m_interface->tab_complete (m_lastTabComplete, completes[0]); |
219 m_interface->tabComplete (m_lastTabComplete, completes[0]); |
219 } |
220 } |
220 else if (not completes.is_empty()) |
221 else if (not completes.is_empty()) |
221 { |
222 { |
222 m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars()); |
223 m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars()); |
223 |
224 |
224 for (int i = 0; i < completes.size(); i += 8) |
225 for (int i : range(0, completes.size(), 8)) |
225 { |
226 { |
226 Range<int> spliceRange (i, min (i + 8, completes.size() - 1)); |
227 Range<int> spliceRange (i, min (i + 8, completes.size())); |
227 StringList splice (completes.splice (spliceRange)); |
228 StringList splice (completes.splice (spliceRange)); |
228 m_interface->print ("- %s\n", splice.join (", ").chars()); |
229 m_interface->print ("- %s\n", splice.join (", ").chars()); |
229 } |
230 } |
230 } |
231 } |
231 } |
232 } |
284 StringList players; |
285 StringList players; |
285 |
286 |
286 for (int i = packet.read_byte(); i > 0; --i) |
287 for (int i = packet.read_byte(); i > 0; --i) |
287 players.append (packet.read_string()); |
288 players.append (packet.read_string()); |
288 |
289 |
289 m_interface->set_player_names (players); |
290 m_interface->setPlayerNames (players); |
290 } |
291 } |
291 break; |
292 break; |
292 |
293 |
293 case SVRCU_ADMINCOUNT: |
294 case SVRCU_ADMINCOUNT: |
294 m_numAdmins = packet.read_byte(); |
295 m_numAdmins = packet.read_byte(); |
295 m_interface->update_statusbar(); |
296 m_interface->updateStatusBar(); |
296 break; |
297 break; |
297 |
298 |
298 case SVRCU_MAP: |
299 case SVRCU_MAP: |
299 m_level = packet.read_string(); |
300 m_level = packet.read_string(); |
300 m_interface->update_statusbar(); |
301 m_interface->updateStatusBar(); |
301 break; |
302 break; |
302 |
303 |
303 default: |
304 default: |
304 m_interface->print_warning ("Unknown server update type: %d\n", header); |
305 m_interface->printWarning ("Unknown server update type: %d\n", header); |
305 break; |
306 break; |
306 } |
307 } |
307 } |
308 } |
308 |
309 |
309 // ------------------------------------------------------------------------------------------------- |
310 // ------------------------------------------------------------------------------------------------- |