Update the titlebar when sv_hostname changes protocol5

Sat, 09 Jan 2016 02:35:00 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 09 Jan 2016 02:35:00 +0200
branch
protocol5
changeset 104
a76af67a3a4b
parent 103
b78c0ca832a9
child 106
7b156b764d11

Update the titlebar when sv_hostname changes

sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.h file | annotate | diff | comparison | revisions
--- a/sources/network/rconsession.cpp	Sat Jan 09 02:20:28 2016 +0200
+++ b/sources/network/rconsession.cpp	Sat Jan 09 02:35:00 2016 +0200
@@ -183,6 +183,9 @@
 				}
 
 				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");
 				break;
 
 			case SVRC_UPDATE:
@@ -236,8 +239,19 @@
 				break;
 
 			case SVRC_CVARCHANGED:
-				m_interface->print ("The value of CVar %s", packet.read_string().chars());
-				m_interface->print (" is now %s\n", packet.read_string().chars());
+				{
+					String name = packet.read_string();
+					String value = packet.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->set_title(m_hostname);
+					}
+				}
 				break;
 
 			case SVRC_YOUREDISCONNECTED:
@@ -353,21 +367,7 @@
 	// Let's hardcode a /watch for CVar watching testing purposes
 	if (message.starts_with ("/watch "))
 	{
-		StringList cvars = message.mid(String("/watch ").length(), -1).split(',');
-		packet.write_byte(CLRC_WATCHCVAR);
-
-		for (int i = 0 ; i < cvars.size(); ++i)
-		{
-			String cvar = cvars[i].normalized();
-
-			if (not cvar.is_empty())
-			{
-				packet.write_string(cvar);
-				m_interface->print("Requesting watch of %s\n", cvar.chars());
-			}
-		}
-
-		packet.write_string("");
+		request_watch(message.mid(String("/watch ").length(), -1).split(','));
 	}
 	else
 	{
@@ -426,3 +426,26 @@
 		m_interface->print ("This server does not support tab-completion\n", m_serverProtocol);
 	}
 }
+
+// -------------------------------------------------------------------------------------------------
+//
+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);
+}
--- a/sources/network/rconsession.h	Sat Jan 09 02:20:28 2016 +0200
+++ b/sources/network/rconsession.h	Sat Jan 09 02:35:00 2016 +0200
@@ -118,6 +118,8 @@
 	const String& level() const;
 	bool is_active() const;
 	void request_tab_complete (const String& part);
+	void request_watch (const String& cvar);
+	void request_watch (const StringList& cvars);
 
 private:
 	RCONSession();

mercurial