sources/network/rconsession.cpp

changeset 27
089e37c0887e
parent 25
88b41eea08e0
child 29
e534f2f78196
equal deleted inserted replaced
26:24c7b804c99f 27:089e37c0887e
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 // -------------------------------------------------------------------------------------------------
293 METHOD 300 METHOD
294 RCONSession::state() const -> RCONSessionState 301 RCONSession::state() const -> RCONSessionState
295 { 302 {
296 return m_state; 303 return m_state;
297 } 304 }
305
306 // -------------------------------------------------------------------------------------------------
307 //
308 METHOD
309 RCONSession::address() const -> const IPAddress&
310 {
311 return m_address;
312 }
313
314 // -------------------------------------------------------------------------------------------------
315 //
316 METHOD
317 RCONSession::num_admins() const -> int
318 {
319 return m_numAdmins;
320 }
321
322 // -------------------------------------------------------------------------------------------------
323 //
324 METHOD
325 RCONSession::level() const -> const String&
326 {
327 return m_level;
328 }

mercurial