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(); |