5 |
5 |
6 // ------------------------------------------------------------------------------------------------- |
6 // ------------------------------------------------------------------------------------------------- |
7 // |
7 // |
8 RCONSession::RCONSession() : |
8 RCONSession::RCONSession() : |
9 m_state (RCON_DISCONNECTED), |
9 m_state (RCON_DISCONNECTED), |
10 m_lastPing (0) |
10 m_lastPing (0), |
|
11 m_numAdmins (0) |
11 { |
12 { |
12 if (g_rconSession != NULL) |
13 if (g_rconSession != NULL) |
13 { |
14 { |
14 g_rconSession->disconnect(); |
15 g_rconSession->disconnect(); |
15 delete g_rconSession; |
16 delete g_rconSession; |
38 |
39 |
39 // ------------------------------------------------------------------------------------------------- |
40 // ------------------------------------------------------------------------------------------------- |
40 // |
41 // |
41 RCONSession::~RCONSession() |
42 RCONSession::~RCONSession() |
42 { |
43 { |
|
44 disconnect(); |
|
45 |
43 if (g_rconSession == this) |
46 if (g_rconSession == this) |
44 g_rconSession = nullptr; |
47 g_rconSession = nullptr; |
45 } |
48 } |
46 |
49 |
47 // ------------------------------------------------------------------------------------------------- |
50 // ------------------------------------------------------------------------------------------------- |
49 METHOD |
52 METHOD |
50 RCONSession::connect (IPAddress address) -> void |
53 RCONSession::connect (IPAddress address) -> void |
51 { |
54 { |
52 m_address = address; |
55 m_address = address; |
53 m_state = RCON_CONNECTING; |
56 m_state = RCON_CONNECTING; |
|
57 Interface::update_statusbar(); |
54 } |
58 } |
55 |
59 |
56 // ------------------------------------------------------------------------------------------------- |
60 // ------------------------------------------------------------------------------------------------- |
57 // |
61 // |
58 METHOD |
62 METHOD |
59 RCONSession::disconnect() -> void |
63 RCONSession::disconnect() -> void |
60 { |
64 { |
61 if (m_state == RCON_CONNECTED) |
65 if (m_state > RCON_CONNECTING) |
62 { |
66 { |
63 // Say goodbye to remote |
67 // Say goodbye to remote |
64 Bytestream packet; |
68 Bytestream packet; |
65 packet.write_byte (CLRC_DISCONNECT); |
69 packet.write_byte (CLRC_DISCONNECT); |
66 this->send (packet); |
70 this->send (packet); |
67 print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT)); |
71 print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT)); |
|
72 Interface::update_statusbar(); |
68 } |
73 } |
69 |
74 |
70 m_state = RCON_DISCONNECTED; |
75 m_state = RCON_DISCONNECTED; |
71 } |
76 } |
72 |
77 |
200 print ("Players: %1\n", players); |
205 print ("Players: %1\n", players); |
201 } |
206 } |
202 break; |
207 break; |
203 |
208 |
204 case SVRCU_ADMINCOUNT: |
209 case SVRCU_ADMINCOUNT: |
205 print ("Admin count: %d1\n", packet.read_byte()); |
210 m_numAdmins = packet.read_byte(); |
|
211 Interface::update_statusbar(); |
206 break; |
212 break; |
207 |
213 |
208 case SVRCU_MAP: |
214 case SVRCU_MAP: |
209 print ("New level: %1\n", packet.read_string()); |
215 m_level = packet.read_string(); |
|
216 Interface::update_statusbar(); |
210 break; |
217 break; |
211 } |
218 } |
212 } |
219 } |
213 |
220 |
214 // ------------------------------------------------------------------------------------------------- |
221 // ------------------------------------------------------------------------------------------------- |