sources/network/rconsession.cpp

changeset 138
c909c38ca886
parent 137
485cb6d6b98c
child 141
d9073c13dc98
child 145
d0aedc9be448
equal deleted inserted replaced
137:485cb6d6b98c 138:c909c38ca886
57 // 57 //
58 void RCONSession::connect (IPAddress address) 58 void RCONSession::connect (IPAddress address)
59 { 59 {
60 m_address = address; 60 m_address = address;
61 m_state = RCON_CONNECTING; 61 m_state = RCON_CONNECTING;
62 m_interface->update_statusbar(); 62 m_interface->updateStatusBar();
63 send_hello(); 63 send_hello();
64 } 64 }
65 65
66 // ------------------------------------------------------------------------------------------------- 66 // -------------------------------------------------------------------------------------------------
67 // 67 //
133 int header = packet.read_byte(); 133 int header = packet.read_byte();
134 134
135 switch (ServerResponse (header)) 135 switch (ServerResponse (header))
136 { 136 {
137 case SVRC_OLDPROTOCOL: 137 case SVRC_OLDPROTOCOL:
138 m_interface->print_error ("Your RCON client is using outdated protocol.\n"); 138 m_interface->printError ("Your RCON client is using outdated protocol.\n");
139 m_state = RCON_DISCONNECTED; 139 m_state = RCON_DISCONNECTED;
140 break; 140 break;
141 141
142 case SVRC_BANNED: 142 case SVRC_BANNED:
143 m_interface->print_error ("You have been banned from the server.\n"); 143 m_interface->printError ("You have been banned from the server.\n");
144 m_state = RCON_DISCONNECTED; 144 m_state = RCON_DISCONNECTED;
145 break; 145 break;
146 146
147 case SVRC_SALT: 147 case SVRC_SALT:
148 m_salt = packet.read_string(); 148 m_salt = packet.read_string();
149 m_state = RCON_AUTHENTICATING; 149 m_state = RCON_AUTHENTICATING;
150 send_password(); 150 send_password();
151 break; 151 break;
152 152
153 case SVRC_INVALIDPASSWORD: 153 case SVRC_INVALIDPASSWORD:
154 m_interface->print_error ("Login failed.\n"); 154 m_interface->printError ("Login failed.\n");
155 m_state = RCON_DISCONNECTED; 155 m_state = RCON_DISCONNECTED;
156 break; 156 break;
157 157
158 case SVRC_MESSAGE: 158 case SVRC_MESSAGE:
159 { 159 {
160 String message = packet.read_string(); 160 String message = packet.read_string();
161 message.normalize(); 161 message.normalize();
162 m_interface->print_text ("%s\n", message.chars()); 162 m_interface->printText ("%s\n", message.chars());
163 } 163 }
164 break; 164 break;
165 165
166 case SVRC_LOGGEDIN: 166 case SVRC_LOGGEDIN:
167 m_interface->print ("Login successful!\n"); 167 m_interface->print ("Login successful!\n");
168 m_serverProtocol = packet.read_byte(); 168 m_serverProtocol = packet.read_byte();
169 m_hostname = packet.read_string(); 169 m_hostname = packet.read_string();
170 m_interface->set_title (m_hostname); 170 m_interface->setTitle (m_hostname);
171 m_state = RCON_CONNECTED; 171 m_state = RCON_CONNECTED;
172 172
173 for (int i = packet.read_byte(); i > 0; --i) 173 for (int i = packet.read_byte(); i > 0; --i)
174 process_server_updates (packet); 174 process_server_updates (packet);
175 175
177 177
178 for (int i = packet.read_byte(); i > 0; --i) 178 for (int i = packet.read_byte(); i > 0; --i)
179 { 179 {
180 String message = packet.read_string(); 180 String message = packet.read_string();
181 message.normalize(); 181 message.normalize();
182 m_interface->print_text ("--- %s\n", message.chars()); 182 m_interface->printText ("--- %s\n", message.chars());
183 } 183 }
184 184
185 m_interface->print ("End of previous messages.\n"); 185 m_interface->print ("End of previous messages.\n");
186 break; 186 break;
187 187
205 for (String& completion : completes) 205 for (String& completion : completes)
206 completion = packet.read_string(); 206 completion = packet.read_string();
207 207
208 if (completes.size() == 1) 208 if (completes.size() == 1)
209 { 209 {
210 m_interface->tab_complete (m_lastTabComplete, completes[0]); 210 m_interface->tabComplete (m_lastTabComplete, completes[0]);
211 } 211 }
212 else if (not completes.is_empty()) 212 else if (not completes.is_empty())
213 { 213 {
214 m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars()); 214 m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars());
215 215
225 } 225 }
226 } 226 }
227 } 227 }
228 catch (std::exception& e) 228 catch (std::exception& e)
229 { 229 {
230 m_interface->print_warning ("Couldn't process packet: %s\n", e.what()); 230 m_interface->printWarning ("Couldn't process packet: %s\n", e.what());
231 } 231 }
232 } 232 }
233 233
234 void RCONSession::process_server_updates (Bytestream& packet) 234 void RCONSession::process_server_updates (Bytestream& packet)
235 { 235 {
242 StringList players; 242 StringList players;
243 243
244 for (int i = packet.read_byte(); i > 0; --i) 244 for (int i = packet.read_byte(); i > 0; --i)
245 players.append (packet.read_string()); 245 players.append (packet.read_string());
246 246
247 m_interface->set_player_names (players); 247 m_interface->setPlayerNames (players);
248 } 248 }
249 break; 249 break;
250 250
251 case SVRCU_ADMINCOUNT: 251 case SVRCU_ADMINCOUNT:
252 m_numAdmins = packet.read_byte(); 252 m_numAdmins = packet.read_byte();
253 m_interface->update_statusbar(); 253 m_interface->updateStatusBar();
254 break; 254 break;
255 255
256 case SVRCU_MAP: 256 case SVRCU_MAP:
257 m_level = packet.read_string(); 257 m_level = packet.read_string();
258 m_interface->update_statusbar(); 258 m_interface->updateStatusBar();
259 break; 259 break;
260 260
261 default: 261 default:
262 m_interface->print_warning ("Unknown server update type: %d\n", header); 262 m_interface->printWarning ("Unknown server update type: %d\n", header);
263 break; 263 break;
264 } 264 }
265 } 265 }
266 266
267 // ------------------------------------------------------------------------------------------------- 267 // -------------------------------------------------------------------------------------------------

mercurial