# HG changeset patch # User Teemu Piippo # Date 1611769721 -7200 # Node ID be953e1621d9cbea4b3b54d4ef97c55f89a530e1 # Parent 060a13878ca0c7c5e5721543baadd33faa3aa707# Parent 0c7e44e1078ad572a8eadb409f253076b50d224a merged with default diff -r 0c7e44e1078a -r be953e1621d9 CMakeLists.txt diff -r 0c7e44e1078a -r be953e1621d9 sources/coloredline.cpp diff -r 0c7e44e1078a -r be953e1621d9 sources/coloredline.h diff -r 0c7e44e1078a -r be953e1621d9 sources/interface.cpp --- a/sources/interface.cpp Wed Jan 27 19:44:36 2021 +0200 +++ b/sources/interface.cpp Wed Jan 27 19:48:41 2021 +0200 @@ -1086,6 +1086,13 @@ this->m_session.disconnect(); *shouldquit = true; } + else if (command == "watch") + { + if (not args.empty()) + m_session.requestWatch(args); + else + printError("No CVars to watch.\n"); + } else printError("Unknown command: %s\n", command.data()); } diff -r 0c7e44e1078a -r be953e1621d9 sources/interface.h diff -r 0c7e44e1078a -r be953e1621d9 sources/mystring.cpp diff -r 0c7e44e1078a -r be953e1621d9 sources/mystring.h diff -r 0c7e44e1078a -r be953e1621d9 sources/network/bytestream.cpp diff -r 0c7e44e1078a -r be953e1621d9 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Wed Jan 27 19:44:36 2021 +0200 +++ b/sources/network/rconsession.cpp Wed Jan 27 19:48:41 2021 +0200 @@ -118,6 +118,7 @@ } } + // Check for new packets in our socket std::stringstream errors; for (net::Datagram datagram; m_socket.read(datagram, errors);) { @@ -195,6 +196,10 @@ } m_interface->print("End of previous messages.\n"); + + // Watch sv_hostname so that we can update the titlebar when it changes. + requestWatch("sv_hostname"); + m_interface->print ("Watch requested.\n"); break; case SVRC_UPDATE: @@ -234,6 +239,40 @@ } } break; + + case SVRC_WATCHINGCVAR: + m_interface->print ("You are now watching %s\n", stream.readString().data()); + m_interface->print ("Its value is: %s\n", stream.readString().data()); + break; + + case SVRC_ALREADYWATCHINGCVAR: + m_interface->print ("You are already watching %s\n", stream.readString().data()); + break; + + case SVRC_WATCHCVARNOTFOUND: + m_interface->print ("CVar %s not found\n", stream.readString().data()); + break; + + case SVRC_CVARCHANGED: + { + String name = stream.readString(); + String value = stream.readString(); + m_interface->print ("The value of CVar %s", name.data()); + m_interface->print (" is now %s\n", value.data()); + + // If sv_hostname changes, update the titlebar + if (name == "sv_hostname") + { + m_hostname = value; + m_interface->setTitle(m_hostname); + } + } + break; + + case SVRC_YOUREDISCONNECTED: + m_interface->print ("You have been disconnected: %s\n", stream.readString().data()); + m_interface->disconnected(); + break; } } } @@ -402,4 +441,28 @@ m_interface = interface; } +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const String& cvar) +{ + const std::vector cvars{{cvar}}; + requestWatch(cvars); +} + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const std::vector& cvars) +{ + std::vector message; + Bytestream stream(message); + stream.writeByte(CLRC_WATCHCVAR); + for (String cvar : cvars) + { + normalize(cvar); + stream.writeString(cvar); + } + stream.writeString(""); + send(message); +} + END_ZFC_NAMESPACE diff -r 0c7e44e1078a -r be953e1621d9 sources/network/rconsession.h --- a/sources/network/rconsession.h Wed Jan 27 19:44:36 2021 +0200 +++ b/sources/network/rconsession.h Wed Jan 27 19:48:41 2021 +0200 @@ -54,6 +54,11 @@ SVRC_UPDATE, SVRC_TABCOMPLETE, SVRC_TOOMANYTABCOMPLETES, + SVRC_WATCHINGCVAR, + SVRC_ALREADYWATCHINGCVAR, + SVRC_WATCHCVARNOTFOUND, + SVRC_CVARCHANGED, + SVRC_YOUREDISCONNECTED, }; // ------------------------------------------------------------------------------------------------- @@ -66,6 +71,7 @@ CLRC_PONG, CLRC_DISCONNECT, CLRC_TABCOMPLETE, + CLRC_WATCHCVAR, }; // ------------------------------------------------------------------------------------------------- @@ -107,6 +113,8 @@ bool isActive() const; void processServerUpdates(Bytestream& packet); void requestTabCompletion(const std::string& part); + void requestWatch (const String& cvar); + void requestWatch (const StringList& cvars); bool send(const std::vector& packet); bool sendCommand(const std::string& commandString); void sendHello(); diff -r 0c7e44e1078a -r be953e1621d9 sources/network/udpsocket.cpp