CVar watching stuff works now, fixed compilation protocol5

Sat, 09 Jan 2016 02:20:28 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 09 Jan 2016 02:20:28 +0200
branch
protocol5
changeset 103
b78c0ca832a9
parent 84
3bd32eec3d57
child 104
a76af67a3a4b

CVar watching stuff works now, fixed compilation

sources/interface.cpp file | annotate | diff | comparison | revisions
sources/interface.h 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
--- a/sources/interface.cpp	Wed May 27 21:15:52 2015 +0300
+++ b/sources/interface.cpp	Sat Jan 09 02:20:28 2016 +0200
@@ -640,10 +640,7 @@
 	if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION)
 	{
 		if (ch == 'y' or ch == 'Y')
-		{
-			Session.disconnect();
-			DisconnectConfirmFunction();
-		}
+			disconnected();
 		else if (ch == 'n' or ch == 'N')
 			set_input_state (INPUTSTATE_NORMAL);
 
@@ -1028,3 +1025,11 @@
 		NeedInputRender = true;
 	}
 }
+
+// -------------------------------------------------------------------------------------------------
+//
+void Interface::disconnected()
+{
+	Session.disconnect();
+	set_input_state (INPUTSTATE_NORMAL);
+}
--- a/sources/interface.h	Wed May 27 21:15:52 2015 +0300
+++ b/sources/interface.h	Sat Jan 09 02:20:28 2016 +0200
@@ -81,7 +81,7 @@
 	Function<void (void)> DisconnectConfirmFunction = nullptr;
 	IPAddress CurrentAddress;
 	String StatusBarText;
-	List<ColoredLine> PlayerNames;
+	StringList PlayerNames;
 	String PasteBuffer;
 	RCONSession Session;
 
@@ -105,4 +105,4 @@
 	void yank (int a, int b);
 	int find_previous_word();
 	int find_next_word();
-};
\ No newline at end of file
+};
--- a/sources/mystring.cpp	Wed May 27 21:15:52 2015 +0300
+++ b/sources/mystring.cpp	Sat Jan 09 02:20:28 2016 +0200
@@ -495,3 +495,12 @@
 	else if (a != 0 or b != length() - 1)
 		m_string = m_string.substr (a, b - a + 1);
 }
+
+// -------------------------------------------------------------------------------------------------
+//
+String String::normalized (int (*filter)(int)) const
+{
+	String result = *this;
+	result.normalize(filter);
+	return result;
+}
--- a/sources/mystring.h	Wed May 27 21:15:52 2015 +0300
+++ b/sources/mystring.h	Sat Jan 09 02:20:28 2016 +0200
@@ -95,6 +95,7 @@
 	void insert (int pos, const char*c) { m_string.insert (pos, c); }
 	void modify_index (int &a) { if (a < 0) { a = length() - a; } }
 	void normalize (int (*filter)(int) = &std::isspace);
+	String normalized (int (*filter)(int) = &std::isspace) const;
 	void prepend (String a) { m_string = (a + m_string).std_string(); }
 	void remove (int pos, int len) { m_string.replace (pos, len, ""); }
 	void remove_at (int pos) { m_string.erase (m_string.begin() + pos); }
@@ -104,7 +105,6 @@
 	void replace (int pos, int n, const String &a) { m_string.replace (pos, n, a.chars()); }
 	void shrink_to_fit() { m_string.shrink_to_fit(); }
 	void __cdecl sprintf (const char* fmtstr, ...);
-	void sprintf (const char* fmtstr, ...);
 	void vsprintf (const char* fmtstr, va_list args);
 	bool starts_with (const String &other) const;
 	String strip (char unwanted) { return strip ({unwanted}); }
--- a/sources/network/rconsession.cpp	Wed May 27 21:15:52 2015 +0300
+++ b/sources/network/rconsession.cpp	Sat Jan 09 02:20:28 2016 +0200
@@ -221,6 +221,29 @@
 					}
 				}
 				break;
+
+			case SVRC_WATCHINGCVAR:
+				m_interface->print ("You are now watching %s\n", packet.read_string().chars());
+				m_interface->print ("Its value is: %s\n", packet.read_string().chars());
+				break;
+
+			case SVRC_ALREADYWATCHINGCVAR:
+				m_interface->print ("You are already watching %s\n", packet.read_string().chars());
+				break;
+
+			case SVRC_WATCHCVARNOTFOUND:
+				m_interface->print ("CVar %s not found\n", packet.read_string().chars());
+				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());
+				break;
+
+			case SVRC_YOUREDISCONNECTED:
+				m_interface->print ("You have been disconnected: %s", packet.read_string().chars());
+				m_interface->disconnected();
+				break;
 			}
 		}
 	}
@@ -326,8 +349,32 @@
 		return false;
 
 	Bytestream packet;
-	packet.write_byte (CLRC_COMMAND);
-	packet.write_string (message);
+
+	// 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("");
+	}
+	else
+	{
+		packet.write_byte (CLRC_COMMAND);
+		packet.write_string (message);
+	}
+
 	send (packet);
 	bump_last_ping();
 	return true;
@@ -378,4 +425,4 @@
 	{
 		m_interface->print ("This server does not support tab-completion\n", m_serverProtocol);
 	}
-}
\ No newline at end of file
+}

mercurial