sources/network/rconsession.cpp

branch
protocol5
changeset 106
7b156b764d11
parent 104
a76af67a3a4b
parent 105
b4466472aecd
child 130
9f54db6f9922
equal deleted inserted replaced
104:a76af67a3a4b 106:7b156b764d11
29 */ 29 */
30 30
31 #include <time.h> 31 #include <time.h>
32 #include "rconsession.h" 32 #include "rconsession.h"
33 #include "../interface.h" 33 #include "../interface.h"
34 34 BEGIN_ZFC_NAMESPACE
35 // ------------------------------------------------------------------------------------------------- 35
36 // 36 // -------------------------------------------------------------------------------------------------
37 RCONSession::RCONSession (Interface* iface) : 37 //
38 RCONSession::RCONSession() :
38 m_state (RCON_DISCONNECTED), 39 m_state (RCON_DISCONNECTED),
39 m_lastPing (0), 40 m_lastPing (0),
40 m_numAdmins (0), 41 m_numAdmins (0),
41 m_interface (iface) 42 m_interface (nullptr)
42 { 43 {
43 if (not m_socket.set_blocking (false)) 44 if (not m_socket.set_blocking (false))
44 { 45 {
45 fprintf (stderr, "unable to set socket as non-blocking: %s\n", 46 fprintf (stderr, "unable to set socket as non-blocking: %s\n",
46 m_socket.error_string().chars()); 47 m_socket.error_string().chars());
70 { 71 {
71 // Say goodbye to remote 72 // Say goodbye to remote
72 Bytestream packet; 73 Bytestream packet;
73 packet.write_byte (CLRC_DISCONNECT); 74 packet.write_byte (CLRC_DISCONNECT);
74 this->send (packet); 75 this->send (packet);
75 m_interface->print ("Disconnected from %s\n", m_address.to_string (IP_WITH_PORT).chars()); 76 m_interface->print ("Disconnected from %s\n", m_address.to_string (IPAddress::WITH_PORT).chars());
76 m_interface->update_statusbar(); 77 m_interface->update_statusbar();
77 } 78 }
78 79
79 m_state = RCON_DISCONNECTED; 80 m_state = RCON_DISCONNECTED;
80 } 81 }
309 310
310 // ------------------------------------------------------------------------------------------------- 311 // -------------------------------------------------------------------------------------------------
311 // 312 //
312 void RCONSession::send_hello() 313 void RCONSession::send_hello()
313 { 314 {
314 m_interface->print ("Connecting to %s...\n", m_address.to_string (IP_WITH_PORT).chars()); 315 m_interface->print ("Connecting to %s...\n",
316 m_address.to_string (IPAddress::WITH_PORT).chars());
315 Bytestream packet; 317 Bytestream packet;
316 packet.write_byte (CLRC_BEGINCONNECTION); 318 packet.write_byte (CLRC_BEGINCONNECTION);
317 packet.write_byte (RCON_PROTOCOL_VERSION); 319 packet.write_byte (RCON_PROTOCOL_VERSION);
318 send (packet); 320 send (packet);
319 bump_last_ping(); 321 bump_last_ping();
427 } 429 }
428 } 430 }
429 431
430 // ------------------------------------------------------------------------------------------------- 432 // -------------------------------------------------------------------------------------------------
431 // 433 //
434 void RCONSession::set_interface (Interface* iface)
435 {
436 m_interface = iface;
437 }
438
439 // -------------------------------------------------------------------------------------------------
440 //
432 void RCONSession::request_watch (const String& cvar) 441 void RCONSession::request_watch (const String& cvar)
433 { 442 {
434 StringList cvars; 443 StringList cvars;
435 cvars.append(cvar); 444 cvars.append(cvar);
436 request_watch(cvars); 445 request_watch(cvars);
447 packet.write_string(cvars[i].normalized()); 456 packet.write_string(cvars[i].normalized());
448 457
449 packet.write_string(""); 458 packet.write_string("");
450 send(packet); 459 send(packet);
451 } 460 }
461
462 END_ZFC_NAMESPACE

mercurial