# HG changeset patch # User Teemu Piippo # Date 1611743958 -7200 # Node ID 18f2d2de19298296ac202e1d705c44bed055cce6 # Parent 78ee24fd332140b0ae3497d9aceffd28b3b87274# Parent 248fba6d1e7640882d4fc1a7f0f0409f1ae8367e merged with default diff -r 248fba6d1e76 -r 18f2d2de1929 CMakeLists.txt diff -r 248fba6d1e76 -r 18f2d2de1929 sources/coloredline.cpp diff -r 248fba6d1e76 -r 18f2d2de1929 sources/coloredline.h diff -r 248fba6d1e76 -r 18f2d2de1929 sources/interface.cpp --- a/sources/interface.cpp Wed Jan 27 12:38:00 2021 +0200 +++ b/sources/interface.cpp Wed Jan 27 12:39:18 2021 +0200 @@ -1094,6 +1094,13 @@ endwin(); throw Exitception(); } + else if (command == "watch") + { + if (not args.is_empty()) + m_session.requestWatch(args); + else + printError("No CVars to watch.\n"); + } else printError("Unknown command: %s\n", command.chars()); } diff -r 248fba6d1e76 -r 18f2d2de1929 sources/interface.h diff -r 248fba6d1e76 -r 18f2d2de1929 sources/mystring.cpp diff -r 248fba6d1e76 -r 18f2d2de1929 sources/mystring.h diff -r 248fba6d1e76 -r 18f2d2de1929 sources/network/bytestream.cpp diff -r 248fba6d1e76 -r 18f2d2de1929 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Wed Jan 27 12:38:00 2021 +0200 +++ b/sources/network/rconsession.cpp Wed Jan 27 12:39:18 2021 +0200 @@ -33,6 +33,12 @@ #include "../interface.h" BEGIN_ZFC_NAMESPACE +struct PacketHeader +{ + int32_t header; + int sequenceNumber; +}; + // ------------------------------------------------------------------------------------------------- // RCONSession::RCONSession() : @@ -111,6 +117,7 @@ } } + // Check for new packets in our socket for (Datagram datagram; m_socket.read(datagram);) { // Only process packets that originate from the game server. @@ -182,6 +189,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: @@ -221,6 +232,40 @@ } } break; + + case SVRC_WATCHINGCVAR: + m_interface->print ("You are now watching %s\n", stream.readString().chars()); + m_interface->print ("Its value is: %s\n", stream.readString().chars()); + break; + + case SVRC_ALREADYWATCHINGCVAR: + m_interface->print ("You are already watching %s\n", stream.readString().chars()); + break; + + case SVRC_WATCHCVARNOTFOUND: + m_interface->print ("CVar %s not found\n", stream.readString().chars()); + break; + + case SVRC_CVARCHANGED: + { + String name = stream.readString(); + String value = stream.readString(); + 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->setTitle(m_hostname); + } + } + break; + + case SVRC_YOUREDISCONNECTED: + m_interface->print ("You have been disconnected: %s\n", stream.readString().chars()); + m_interface->disconnected(); + break; } } } @@ -389,4 +434,28 @@ m_interface = interface; } +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const String& cvar) +{ + StringList cvars; + cvars.append(cvar); + requestWatch(cvars); +} + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const StringList& cvars) +{ + ByteArray message; + Bytestream stream(message); + stream.writeByte(CLRC_WATCHCVAR); + + for (const String& cvar : cvars) + stream.writeString(cvar.normalized()); + + stream.writeString(""); + send(message); +} + END_ZFC_NAMESPACE diff -r 248fba6d1e76 -r 18f2d2de1929 sources/network/rconsession.h --- a/sources/network/rconsession.h Wed Jan 27 12:38:00 2021 +0200 +++ b/sources/network/rconsession.h Wed Jan 27 12:39:18 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 String& part); + void requestWatch (const String& cvar); + void requestWatch (const StringList& cvars); void send(const ByteArray& packet); bool sendCommand(const String& commandString); void sendHello(); diff -r 248fba6d1e76 -r 18f2d2de1929 sources/network/udpsocket.cpp