sources/network/rconsession.cpp

branch
protocol5
changeset 160
cf514fa0f1cc
parent 159
970d58a01e8b
child 165
718a8c4df538
--- a/sources/network/rconsession.cpp	Fri Jul 22 17:59:55 2016 +0300
+++ b/sources/network/rconsession.cpp	Fri Jul 22 18:03:50 2016 +0300
@@ -126,11 +126,11 @@
 
 	try
 	{
-		int32_t header = datagram.message.read_long();
-		int32_t sequenceNumber = (header != 0) ? datagram.message.read_long() : 0;
+		int32_t header = stream.readLong();
+		int32_t sequenceNumber = (header != 0) ? stream.readLong() : 0;
 		m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber);
 
-		while (datagram.message.bytes_left() > 0)
+		while (stream.bytesLeft() > 0)
 		{
 			int header = stream.readByte();
 
@@ -187,7 +187,7 @@
 				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");
+				requestWatch("sv_hostname");
 				m_interface->print ("Watch requested.\n");
 				break;
 
@@ -230,22 +230,22 @@
 				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());
+				m_interface->print ("You are now watching %s\n", stream.readString().chars());
+				m_interface->print ("Its value is: %s\n", stream.readString().chars());
 				break;
 
 			case SVRC_ALREADYWATCHINGCVAR:
-				m_interface->print ("You are already watching %s\n", datagram.message.read_string().chars());
+				m_interface->print ("You are already watching %s\n", stream.readString().chars());
 				break;
 
 			case SVRC_WATCHCVARNOTFOUND:
-				m_interface->print ("CVar %s not found\n", datagram.message.read_string().chars());
+				m_interface->print ("CVar %s not found\n", stream.readString().chars());
 				break;
 
 			case SVRC_CVARCHANGED:
 				{
-					String name = datagram.message.read_string();
-					String value = datagram.message.read_string();
+					String name = stream.readString();
+					String value = stream.readString();
 					m_interface->print ("The value of CVar %s", name.chars());
 					m_interface->print (" is now %s\n", value.chars());
 
@@ -259,7 +259,7 @@
 				break;
 
 			case SVRC_YOUREDISCONNECTED:
-				m_interface->print ("You have been disconnected: %s\n", datagram.message.read_string().chars());
+				m_interface->print ("You have been disconnected: %s\n", stream.readString().chars());
 				m_interface->disconnected();
 				break;
 			}
@@ -430,25 +430,26 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::request_watch (const String& cvar)
+void RCONSession::requestWatch(const String& cvar)
 {
 	StringList cvars;
 	cvars.append(cvar);
-	request_watch(cvars);
+	requestWatch(cvars);
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-void RCONSession::request_watch (const StringList& cvars)
+void RCONSession::requestWatch(const StringList& cvars)
 {
-	Bytestream packet;
-	packet.write_byte(CLRC_WATCHCVAR);
+	Vector<unsigned char> message;
+	Bytestream stream(message);
+	stream.writeByte(CLRC_WATCHCVAR);
 
-	for (int i = 0; i < cvars.size(); ++i)
-		packet.write_string(cvars[i].normalized());
+	for (const String& cvar : cvars)
+		stream.writeString(cvar.normalized());
 
-	packet.write_string("");
-	send(packet);
+	stream.writeString("");
+	send(message);
 }
 
 END_ZFC_NAMESPACE

mercurial