Merged with default protocol5

Fri, 22 Jul 2016 17:59:55 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Fri, 22 Jul 2016 17:59:55 +0300
branch
protocol5
changeset 159
970d58a01e8b
parent 155
9f71f854474a (diff)
parent 158
de7574d292ad (current diff)
child 160
cf514fa0f1cc

Merged with default

sources/interface.cpp file | annotate | diff | comparison | revisions
sources/mystring.cpp file | annotate | diff | comparison | revisions
sources/mystring.h file | annotate | diff | comparison | revisions
sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.h file | annotate | diff | comparison | revisions
sources/network/udpsocket.cpp file | annotate | diff | comparison | revisions
--- 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());
 }
--- 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
--- 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;
--- 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<unsigned char*> (HuffmanBuffer),

mercurial