# HG changeset patch # User Teemu Piippo # Date 1452299700 -7200 # Node ID a76af67a3a4ba58e0e992d45910c01d267b67a38 # Parent b78c0ca832a9ace3ee8fbd8461cc3cfce71ec6ab Update the titlebar when sv_hostname changes diff -r b78c0ca832a9 -r a76af67a3a4b sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Sat Jan 09 02:20:28 2016 +0200 +++ b/sources/network/rconsession.cpp Sat Jan 09 02:35:00 2016 +0200 @@ -183,6 +183,9 @@ } m_interface->print ("End of previous messages.\n"); + + // Watch sv_hostname so that we can update the titlebar when it changes. + request_watch("sv_hostname"); break; case SVRC_UPDATE: @@ -236,8 +239,19 @@ break; case SVRC_CVARCHANGED: - m_interface->print ("The value of CVar %s", packet.read_string().chars()); - m_interface->print (" is now %s\n", packet.read_string().chars()); + { + String name = packet.read_string(); + String value = packet.read_string(); + m_interface->print ("The value of CVar %s", name.chars()); + m_interface->print (" is now %s\n", value.chars()); + + // If sv_hostname changes, update the titlebar + if (name == "sv_hostname") + { + m_hostname = value; + m_interface->set_title(m_hostname); + } + } break; case SVRC_YOUREDISCONNECTED: @@ -353,21 +367,7 @@ // Let's hardcode a /watch for CVar watching testing purposes if (message.starts_with ("/watch ")) { - StringList cvars = message.mid(String("/watch ").length(), -1).split(','); - packet.write_byte(CLRC_WATCHCVAR); - - for (int i = 0 ; i < cvars.size(); ++i) - { - String cvar = cvars[i].normalized(); - - if (not cvar.is_empty()) - { - packet.write_string(cvar); - m_interface->print("Requesting watch of %s\n", cvar.chars()); - } - } - - packet.write_string(""); + request_watch(message.mid(String("/watch ").length(), -1).split(',')); } else { @@ -426,3 +426,26 @@ m_interface->print ("This server does not support tab-completion\n", m_serverProtocol); } } + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::request_watch (const String& cvar) +{ + StringList cvars; + cvars.append(cvar); + request_watch(cvars); +} + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::request_watch (const StringList& cvars) +{ + Bytestream packet; + packet.write_byte(CLRC_WATCHCVAR); + + for (int i = 0; i < cvars.size(); ++i) + packet.write_string(cvars[i].normalized()); + + packet.write_string(""); + send(packet); +} diff -r b78c0ca832a9 -r a76af67a3a4b sources/network/rconsession.h --- a/sources/network/rconsession.h Sat Jan 09 02:20:28 2016 +0200 +++ b/sources/network/rconsession.h Sat Jan 09 02:35:00 2016 +0200 @@ -118,6 +118,8 @@ const String& level() const; bool is_active() const; void request_tab_complete (const String& part); + void request_watch (const String& cvar); + void request_watch (const StringList& cvars); private: RCONSession();