# HG changeset patch # User Teemu Piippo # Date 1431872540 -10800 # Node ID 62cfb7b97fc097e080c1436dfd290562212e8104 # Parent c1d43ade656e301a9eb295f8a002feb109de2bf4 Added rudimentary support for CVar watch (only as a debug command for now) diff -r c1d43ade656e -r 62cfb7b97fc0 sources/mystring.cpp --- 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; diff -r c1d43ade656e -r 62cfb7b97fc0 sources/mystring.h --- 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 &unwanted); void trim (int n); diff -r c1d43ade656e -r 62cfb7b97fc0 sources/network/rconsession.cpp --- 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); diff -r c1d43ade656e -r 62cfb7b97fc0 sources/network/rconsession.h --- 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, }; // -------------------------------------------------------------------------------------------------