Sun, 17 May 2015 17:22:20 +0300
Added rudimentary support for CVar watch (only as a debug command for now)
--- a/sources/mystring.cpp Fri May 15 22:46:53 2015 +0300 +++ b/sources/mystring.cpp Sun May 17 17:22:20 2015 +0300 @@ -303,7 +303,7 @@ // ------------------------------------------------------------------------------------------------- // -bool String::starts_with (const String& other) +bool String::starts_with (const String& other) const { if (length() < other.length()) return false;
--- a/sources/mystring.h Fri May 15 22:46:53 2015 +0300 +++ b/sources/mystring.h Sun May 17 17:22:20 2015 +0300 @@ -104,7 +104,7 @@ void replace (int pos, int n, const String &a) { m_string.replace (pos, n, a.chars()); } void shrink_to_fit() { m_string.shrink_to_fit(); } void sprintf (const char* fmtstr, ...); - bool starts_with (const String &other); + bool starts_with (const String &other) const; String strip (char unwanted) { return strip ({unwanted}); } String strip (const List<char> &unwanted); void trim (int n);
--- a/sources/network/rconsession.cpp Fri May 15 22:46:53 2015 +0300 +++ b/sources/network/rconsession.cpp Sun May 17 17:22:20 2015 +0300 @@ -220,6 +220,27 @@ } } break; + + case SVRC_WATCHINGCVAR: + m_interface->print ("Server acknowledges watch on %1\n", packet.read_string()); + m_interface->print ("Its current value is %1\n", packet.read_string()); + break; + + case SVRC_ALREADYWATCHINGCVAR: + m_interface->print ("Server says you are already watching %1\n", packet.read_string()); + break; + + case SVRC_WATCHCVARNOTFOUND: + m_interface->print ("No such cvar %1\n", packet.read_string()); + break; + + case SVRC_CVARCHANGED: + { + String name = packet.read_string(); + String value = packet.read_string(); + m_interface->print ("New value of %1: %2\n", name, value); + } + break; } } } @@ -324,6 +345,24 @@ if (m_state != RCON_CONNECTED or message.is_empty()) return false; + if (message.starts_with ("/watch ")) + { + String cvarnamelist = message.mid (String ("/watch ").length(), -1); + cvarnamelist.normalize(); + + Bytestream packet; + packet.write_byte (CLRC_WATCHCVAR); + + for (String cvarname : cvarnamelist.split (' ')) + { + m_interface->print (TEXTCOLOR_Green "Requesting watch on %1...\n", cvarname); + packet.write_string (cvarname); + } + send (packet); + bump_last_ping(); + return true; + } + Bytestream packet; packet.write_byte (CLRC_COMMAND); packet.write_string (message);
--- a/sources/network/rconsession.h Fri May 15 22:46:53 2015 +0300 +++ b/sources/network/rconsession.h Sun May 17 17:22:20 2015 +0300 @@ -53,6 +53,10 @@ SVRC_UPDATE, SVRC_TABCOMPLETE, SVRC_TOOMANYTABCOMPLETES, + SVRC_WATCHINGCVAR, + SVRC_ALREADYWATCHINGCVAR, + SVRC_WATCHCVARNOTFOUND, + SVRC_CVARCHANGED, }; // ------------------------------------------------------------------------------------------------- @@ -65,6 +69,7 @@ CLRC_PONG, CLRC_DISCONNECT, CLRC_TABCOMPLETE, + CLRC_WATCHCVAR, }; // -------------------------------------------------------------------------------------------------