sources/network/rconsession.cpp

changeset 183
9b6a0daedfc0
parent 182
20ca0a6be175
child 185
e83ec58cc458
equal deleted inserted replaced
182:20ca0a6be175 183:9b6a0daedfc0
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 = stream.readString(); 160 std::string message = stream.readString();
161 normalize(message); 161 normalize(message);
162 m_interface->printText("%s\n", message.data()); 162 m_interface->printText("%s\n", message.data());
163 } 163 }
164 break; 164 break;
165 165
175 175
176 m_interface->print("Previous messages:\n"); 176 m_interface->print("Previous messages:\n");
177 177
178 for (int i = stream.readByte(); i > 0; --i) 178 for (int i = stream.readByte(); i > 0; --i)
179 { 179 {
180 String message = stream.readString(); 180 std::string message = stream.readString();
181 normalize(message); 181 normalize(message);
182 m_interface->printText("--- %s\n", message.data()); 182 m_interface->printText("--- %s\n", message.data());
183 } 183 }
184 184
185 m_interface->print("End of previous messages.\n"); 185 m_interface->print("End of previous messages.\n");
197 } 197 }
198 break; 198 break;
199 199
200 case SVRC_TABCOMPLETE: 200 case SVRC_TABCOMPLETE:
201 { 201 {
202 StringList completes; 202 std::vector<std::string> completes;
203 completes.resize(stream.readByte()); 203 completes.resize(stream.readByte());
204 204
205 for (String& completion : completes) 205 for (std::string& completion : completes)
206 completion = stream.readString(); 206 completion = stream.readString();
207 207
208 if (completes.size() == 1) 208 if (completes.size() == 1)
209 { 209 {
210 m_interface->tabComplete(m_lastTabComplete, completes[0]); 210 m_interface->tabComplete(m_lastTabComplete, completes[0]);
214 m_interface->print("Completions for '%s':\n", m_lastTabComplete.data()); 214 m_interface->print("Completions for '%s':\n", m_lastTabComplete.data());
215 215
216 for (int i : range(0, static_cast<int>(completes.size()), 8)) 216 for (int i : range(0, static_cast<int>(completes.size()), 8))
217 { 217 {
218 const int end = min(i + 8, static_cast<int>(completes.size())); 218 const int end = min(i + 8, static_cast<int>(completes.size()));
219 StringList splices = splice(completes, i, end); 219 std::vector<std::string> splices = splice(completes, i, end);
220 m_interface->print("- %s\n", join_string_list(splices, ", ").data()); 220 m_interface->print("- %s\n", join_string_list(splices, ", ").data());
221 } 221 }
222 } 222 }
223 } 223 }
224 break; 224 break;
239 239
240 switch (RCONUpdateType(header)) 240 switch (RCONUpdateType(header))
241 { 241 {
242 case SVRCU_PLAYERDATA: 242 case SVRCU_PLAYERDATA:
243 { 243 {
244 StringList players; 244 std::vector<std::string> players;
245 245
246 for (int i = packet.readByte(); i > 0; --i) 246 for (int i = packet.readByte(); i > 0; --i)
247 players.push_back(packet.readString()); 247 players.push_back(packet.readString());
248 248
249 m_interface->setPlayerNames(players); 249 m_interface->setPlayerNames(players);
295 bumpLastPing(); 295 bumpLastPing();
296 } 296 }
297 297
298 // ------------------------------------------------------------------------------------------------- 298 // -------------------------------------------------------------------------------------------------
299 // 299 //
300 void RCONSession::setPassword(const String& password) 300 void RCONSession::setPassword(const std::string& password)
301 { 301 {
302 m_password = password; 302 m_password = password;
303 } 303 }
304 304
305 // ------------------------------------------------------------------------------------------------- 305 // -------------------------------------------------------------------------------------------------
319 } 319 }
320 320
321 // ------------------------------------------------------------------------------------------------- 321 // -------------------------------------------------------------------------------------------------
322 // Returns true if the message was successfully sent. 322 // Returns true if the message was successfully sent.
323 // 323 //
324 bool RCONSession::sendCommand(const String& commandString) 324 bool RCONSession::sendCommand(const std::string& commandString)
325 { 325 {
326 if (m_state != RCON_CONNECTED or commandString.empty()) 326 if (m_state != RCON_CONNECTED or commandString.empty())
327 return false; 327 return false;
328 328
329 ByteArray message; 329 ByteArray message;
356 return m_adminCount; 356 return m_adminCount;
357 } 357 }
358 358
359 // ------------------------------------------------------------------------------------------------- 359 // -------------------------------------------------------------------------------------------------
360 // 360 //
361 const String& RCONSession::getLevel() const 361 const std::string& RCONSession::getLevel() const
362 { 362 {
363 return m_level; 363 return m_level;
364 } 364 }
365 365
366 // ------------------------------------------------------------------------------------------------- 366 // -------------------------------------------------------------------------------------------------
367 // 367 //
368 void RCONSession::requestTabCompletion(const String& part) 368 void RCONSession::requestTabCompletion(const std::string& part)
369 { 369 {
370 if (m_serverProtocol >= 4) 370 if (m_serverProtocol >= 4)
371 { 371 {
372 ByteArray message; 372 ByteArray message;
373 Bytestream stream(message); 373 Bytestream stream(message);

mercurial