sources/network/rconsession.cpp

branch
protocol5
changeset 104
a76af67a3a4b
parent 103
b78c0ca832a9
child 106
7b156b764d11
equal deleted inserted replaced
103:b78c0ca832a9 104:a76af67a3a4b
181 message.normalize(); 181 message.normalize();
182 m_interface->print ("--- %s\n", message.chars()); 182 m_interface->print ("--- %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
187 // Watch sv_hostname so that we can update the titlebar when it changes.
188 request_watch("sv_hostname");
186 break; 189 break;
187 190
188 case SVRC_UPDATE: 191 case SVRC_UPDATE:
189 process_server_updates (packet); 192 process_server_updates (packet);
190 break; 193 break;
234 case SVRC_WATCHCVARNOTFOUND: 237 case SVRC_WATCHCVARNOTFOUND:
235 m_interface->print ("CVar %s not found\n", packet.read_string().chars()); 238 m_interface->print ("CVar %s not found\n", packet.read_string().chars());
236 break; 239 break;
237 240
238 case SVRC_CVARCHANGED: 241 case SVRC_CVARCHANGED:
239 m_interface->print ("The value of CVar %s", packet.read_string().chars()); 242 {
240 m_interface->print (" is now %s\n", packet.read_string().chars()); 243 String name = packet.read_string();
244 String value = packet.read_string();
245 m_interface->print ("The value of CVar %s", name.chars());
246 m_interface->print (" is now %s\n", value.chars());
247
248 // If sv_hostname changes, update the titlebar
249 if (name == "sv_hostname")
250 {
251 m_hostname = value;
252 m_interface->set_title(m_hostname);
253 }
254 }
241 break; 255 break;
242 256
243 case SVRC_YOUREDISCONNECTED: 257 case SVRC_YOUREDISCONNECTED:
244 m_interface->print ("You have been disconnected: %s", packet.read_string().chars()); 258 m_interface->print ("You have been disconnected: %s", packet.read_string().chars());
245 m_interface->disconnected(); 259 m_interface->disconnected();
351 Bytestream packet; 365 Bytestream packet;
352 366
353 // Let's hardcode a /watch for CVar watching testing purposes 367 // Let's hardcode a /watch for CVar watching testing purposes
354 if (message.starts_with ("/watch ")) 368 if (message.starts_with ("/watch "))
355 { 369 {
356 StringList cvars = message.mid(String("/watch ").length(), -1).split(','); 370 request_watch(message.mid(String("/watch ").length(), -1).split(','));
357 packet.write_byte(CLRC_WATCHCVAR);
358
359 for (int i = 0 ; i < cvars.size(); ++i)
360 {
361 String cvar = cvars[i].normalized();
362
363 if (not cvar.is_empty())
364 {
365 packet.write_string(cvar);
366 m_interface->print("Requesting watch of %s\n", cvar.chars());
367 }
368 }
369
370 packet.write_string("");
371 } 371 }
372 else 372 else
373 { 373 {
374 packet.write_byte (CLRC_COMMAND); 374 packet.write_byte (CLRC_COMMAND);
375 packet.write_string (message); 375 packet.write_string (message);
424 else 424 else
425 { 425 {
426 m_interface->print ("This server does not support tab-completion\n", m_serverProtocol); 426 m_interface->print ("This server does not support tab-completion\n", m_serverProtocol);
427 } 427 }
428 } 428 }
429
430 // -------------------------------------------------------------------------------------------------
431 //
432 void RCONSession::request_watch (const String& cvar)
433 {
434 StringList cvars;
435 cvars.append(cvar);
436 request_watch(cvars);
437 }
438
439 // -------------------------------------------------------------------------------------------------
440 //
441 void RCONSession::request_watch (const StringList& cvars)
442 {
443 Bytestream packet;
444 packet.write_byte(CLRC_WATCHCVAR);
445
446 for (int i = 0; i < cvars.size(); ++i)
447 packet.write_string(cvars[i].normalized());
448
449 packet.write_string("");
450 send(packet);
451 }

mercurial