# HG changeset patch # User Teemu Piippo # Date 1469266023 -10800 # Node ID 718a8c4df538739b9657d95a7c3fcfc72094e10e # Parent cf514fa0f1cca7f3261b7bf7127c0fe953e04a50# Parent e3794f48a58983a9df4420499cd13d22d01ed627 Merged with default diff -r e3794f48a589 -r 718a8c4df538 sources/coloredline.cpp diff -r e3794f48a589 -r 718a8c4df538 sources/coloredline.h diff -r e3794f48a589 -r 718a8c4df538 sources/interface.cpp --- a/sources/interface.cpp Sat Jul 23 12:23:07 2016 +0300 +++ b/sources/interface.cpp Sat Jul 23 12:27:03 2016 +0300 @@ -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 e3794f48a589 -r 718a8c4df538 sources/interface.h diff -r e3794f48a589 -r 718a8c4df538 sources/mystring.cpp diff -r e3794f48a589 -r 718a8c4df538 sources/mystring.h diff -r e3794f48a589 -r 718a8c4df538 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Sat Jul 23 12:23:07 2016 +0300 +++ b/sources/network/rconsession.cpp Sat Jul 23 12:27:03 2016 +0300 @@ -126,6 +126,10 @@ try { + int32_t header = stream.readLong(); + int32_t sequenceNumber = (header != 0) ? stream.readLong() : 0; + m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); + while (stream.bytesLeft() > 0) { int header = stream.readByte(); @@ -181,6 +185,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: @@ -220,6 +228,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; } } } @@ -388,4 +430,28 @@ m_interface = interface; } +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const String& cvar) +{ + StringList cvars; + cvars.append(cvar); + requestWatch(cvars); +} + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::requestWatch(const StringList& cvars) +{ + Vector 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 e3794f48a589 -r 718a8c4df538 sources/network/rconsession.h --- a/sources/network/rconsession.h Sat Jul 23 12:23:07 2016 +0300 +++ b/sources/network/rconsession.h Sat Jul 23 12:27:03 2016 +0300 @@ -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 e3794f48a589 -r 718a8c4df538 sources/network/udpsocket.cpp --- a/sources/network/udpsocket.cpp Sat Jul 23 12:23:07 2016 +0300 +++ b/sources/network/udpsocket.cpp Sat Jul 23 12:27:03 2016 +0300 @@ -129,6 +129,12 @@ return false; } + if (length < 4) + { + m_error = "The server sent a too short packet"; + return false; + } + unsigned char decodedPacket[MAX_DATAGRAM_LENGTH]; int decodedLength = sizeof decodedPacket; HUFFMAN_Decode (reinterpret_cast (HuffmanBuffer),