sources/network/rconsession.cpp

branch
protocol5
changeset 160
cf514fa0f1cc
parent 159
970d58a01e8b
child 165
718a8c4df538
equal deleted inserted replaced
159:970d58a01e8b 160:cf514fa0f1cc
124 124
125 Bytestream stream(datagram.message); 125 Bytestream stream(datagram.message);
126 126
127 try 127 try
128 { 128 {
129 int32_t header = datagram.message.read_long(); 129 int32_t header = stream.readLong();
130 int32_t sequenceNumber = (header != 0) ? datagram.message.read_long() : 0; 130 int32_t sequenceNumber = (header != 0) ? stream.readLong() : 0;
131 m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); 131 m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber);
132 132
133 while (datagram.message.bytes_left() > 0) 133 while (stream.bytesLeft() > 0)
134 { 134 {
135 int header = stream.readByte(); 135 int header = stream.readByte();
136 136
137 switch (ServerResponse(header)) 137 switch (ServerResponse(header))
138 { 138 {
185 } 185 }
186 186
187 m_interface->print("End of previous messages.\n"); 187 m_interface->print("End of previous messages.\n");
188 188
189 // Watch sv_hostname so that we can update the titlebar when it changes. 189 // Watch sv_hostname so that we can update the titlebar when it changes.
190 request_watch("sv_hostname"); 190 requestWatch("sv_hostname");
191 m_interface->print ("Watch requested.\n"); 191 m_interface->print ("Watch requested.\n");
192 break; 192 break;
193 193
194 case SVRC_UPDATE: 194 case SVRC_UPDATE:
195 processServerUpdates(stream); 195 processServerUpdates(stream);
228 } 228 }
229 } 229 }
230 break; 230 break;
231 231
232 case SVRC_WATCHINGCVAR: 232 case SVRC_WATCHINGCVAR:
233 m_interface->print ("You are now watching %s\n", datagram.message.read_string().chars()); 233 m_interface->print ("You are now watching %s\n", stream.readString().chars());
234 m_interface->print ("Its value is: %s\n", datagram.message.read_string().chars()); 234 m_interface->print ("Its value is: %s\n", stream.readString().chars());
235 break; 235 break;
236 236
237 case SVRC_ALREADYWATCHINGCVAR: 237 case SVRC_ALREADYWATCHINGCVAR:
238 m_interface->print ("You are already watching %s\n", datagram.message.read_string().chars()); 238 m_interface->print ("You are already watching %s\n", stream.readString().chars());
239 break; 239 break;
240 240
241 case SVRC_WATCHCVARNOTFOUND: 241 case SVRC_WATCHCVARNOTFOUND:
242 m_interface->print ("CVar %s not found\n", datagram.message.read_string().chars()); 242 m_interface->print ("CVar %s not found\n", stream.readString().chars());
243 break; 243 break;
244 244
245 case SVRC_CVARCHANGED: 245 case SVRC_CVARCHANGED:
246 { 246 {
247 String name = datagram.message.read_string(); 247 String name = stream.readString();
248 String value = datagram.message.read_string(); 248 String value = stream.readString();
249 m_interface->print ("The value of CVar %s", name.chars()); 249 m_interface->print ("The value of CVar %s", name.chars());
250 m_interface->print (" is now %s\n", value.chars()); 250 m_interface->print (" is now %s\n", value.chars());
251 251
252 // If sv_hostname changes, update the titlebar 252 // If sv_hostname changes, update the titlebar
253 if (name == "sv_hostname") 253 if (name == "sv_hostname")
257 } 257 }
258 } 258 }
259 break; 259 break;
260 260
261 case SVRC_YOUREDISCONNECTED: 261 case SVRC_YOUREDISCONNECTED:
262 m_interface->print ("You have been disconnected: %s\n", datagram.message.read_string().chars()); 262 m_interface->print ("You have been disconnected: %s\n", stream.readString().chars());
263 m_interface->disconnected(); 263 m_interface->disconnected();
264 break; 264 break;
265 } 265 }
266 } 266 }
267 } 267 }
428 m_interface = interface; 428 m_interface = interface;
429 } 429 }
430 430
431 // ------------------------------------------------------------------------------------------------- 431 // -------------------------------------------------------------------------------------------------
432 // 432 //
433 void RCONSession::request_watch (const String& cvar) 433 void RCONSession::requestWatch(const String& cvar)
434 { 434 {
435 StringList cvars; 435 StringList cvars;
436 cvars.append(cvar); 436 cvars.append(cvar);
437 request_watch(cvars); 437 requestWatch(cvars);
438 } 438 }
439 439
440 // ------------------------------------------------------------------------------------------------- 440 // -------------------------------------------------------------------------------------------------
441 // 441 //
442 void RCONSession::request_watch (const StringList& cvars) 442 void RCONSession::requestWatch(const StringList& cvars)
443 { 443 {
444 Bytestream packet; 444 Vector<unsigned char> message;
445 packet.write_byte(CLRC_WATCHCVAR); 445 Bytestream stream(message);
446 446 stream.writeByte(CLRC_WATCHCVAR);
447 for (int i = 0; i < cvars.size(); ++i) 447
448 packet.write_string(cvars[i].normalized()); 448 for (const String& cvar : cvars)
449 449 stream.writeString(cvar.normalized());
450 packet.write_string(""); 450
451 send(packet); 451 stream.writeString("");
452 send(message);
452 } 453 }
453 454
454 END_ZFC_NAMESPACE 455 END_ZFC_NAMESPACE

mercurial