# HG changeset patch # User Teemu Piippo # Date 1469199595 -10800 # Node ID 970d58a01e8bd7b18e701dff42390c9f3234eedf # Parent 9f71f854474a04762014eda9493dc98dd94dc19d# Parent de7574d292ad616ccb013e70819cb1fec3387d55 Merged with default diff -r de7574d292ad -r 970d58a01e8b sources/coloredline.cpp diff -r de7574d292ad -r 970d58a01e8b sources/coloredline.h diff -r de7574d292ad -r 970d58a01e8b sources/interface.cpp --- a/sources/interface.cpp Fri Jul 22 17:52:23 2016 +0300 +++ b/sources/interface.cpp Fri Jul 22 17:59:55 2016 +0300 @@ -1094,6 +1094,13 @@ endwin(); throw Exitception(); } + else if (command == "watch") + { + if (not args.is_empty()) + m_session.request_watch(args); + else + printError("No CVars to watch.\n"); + } else printError("Unknown command: %s\n", command.chars()); } diff -r de7574d292ad -r 970d58a01e8b sources/interface.h diff -r de7574d292ad -r 970d58a01e8b sources/mystring.cpp diff -r de7574d292ad -r 970d58a01e8b sources/mystring.h diff -r de7574d292ad -r 970d58a01e8b sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Fri Jul 22 17:52:23 2016 +0300 +++ b/sources/network/rconsession.cpp Fri Jul 22 17:59:55 2016 +0300 @@ -126,7 +126,11 @@ try { - while (stream.bytesLeft() > 0) + int32_t header = datagram.message.read_long(); + int32_t sequenceNumber = (header != 0) ? datagram.message.read_long() : 0; + m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); + + while (datagram.message.bytes_left() > 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. + request_watch("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", datagram.message.read_string().chars()); + m_interface->print ("Its value is: %s\n", datagram.message.read_string().chars()); + break; + + case SVRC_ALREADYWATCHINGCVAR: + m_interface->print ("You are already watching %s\n", datagram.message.read_string().chars()); + break; + + case SVRC_WATCHCVARNOTFOUND: + m_interface->print ("CVar %s not found\n", datagram.message.read_string().chars()); + break; + + case SVRC_CVARCHANGED: + { + String name = datagram.message.read_string(); + String value = datagram.message.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->setTitle(m_hostname); + } + } + break; + + case SVRC_YOUREDISCONNECTED: + m_interface->print ("You have been disconnected: %s\n", datagram.message.read_string().chars()); + m_interface->disconnected(); + break; } } } @@ -386,4 +428,27 @@ m_interface = interface; } +// ------------------------------------------------------------------------------------------------- +// +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); +} + END_ZFC_NAMESPACE diff -r de7574d292ad -r 970d58a01e8b sources/network/rconsession.h --- a/sources/network/rconsession.h Fri Jul 22 17:52:23 2016 +0300 +++ b/sources/network/rconsession.h Fri Jul 22 17:59:55 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, }; // ------------------------------------------------------------------------------------------------- @@ -114,6 +120,8 @@ void setInterface(class Interface* interface); void setPassword(const String& password); void tick(); + void request_watch (const String& cvar); + void request_watch (const StringList& cvars); private: RCONSessionState m_state; diff -r de7574d292ad -r 970d58a01e8b sources/network/udpsocket.cpp --- a/sources/network/udpsocket.cpp Fri Jul 22 17:52:23 2016 +0300 +++ b/sources/network/udpsocket.cpp Fri Jul 22 17:59:55 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),