sources/network/rconsession.cpp

branch
protocol5
changeset 104
a76af67a3a4b
parent 103
b78c0ca832a9
child 106
7b156b764d11
--- 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);
+}

mercurial