sources/network/rconsession.cpp

changeset 15
33da84af4bba
parent 14
33b8f428bacb
child 17
50341dec533e
equal deleted inserted replaced
14:33b8f428bacb 15:33da84af4bba
1 #include "rconsession.h" 1 #include "rconsession.h"
2 2
3 static Vector<RCONSessionPointer> g_allSessions; 3 RCONSession* g_rconSession = nullptr;
4 4
5 // ------------------------------------------------------------------------------------------------- 5 // -------------------------------------------------------------------------------------------------
6 // 6 //
7 RCONSession::RCONSession() : 7 RCONSession::RCONSession() :
8 m_state (RCON_DISCONNECTED), 8 m_state (RCON_DISCONNECTED),
9 m_lastPing (0) 9 m_lastPing (0)
10 { 10 {
11 if (g_rconSession != NULL)
12 {
13 g_rconSession->disconnect();
14 delete g_rconSession;
15 }
16
17 g_rconSession = this;
18
11 if (not m_socket.set_blocking (false)) 19 if (not m_socket.set_blocking (false))
12 { 20 {
13 // TODO: find a better way to deal with errors 21 // TODO: find a better way to deal with errors
14 print ("unable to set socket as non-blocking: %s\n", 22 print ("unable to set socket as non-blocking: %s\n",
15 m_socket.error_string().chars()); 23 m_socket.error_string().chars());
16 } 24 }
17 } 25 }
18 26
19 // ------------------------------------------------------------------------------------------------- 27 // -------------------------------------------------------------------------------------------------
20 // 28 //
21 RCONSession::~RCONSession() {} 29 RCONSession::~RCONSession()
30 {
31 if (g_rconSession == this)
32 g_rconSession = nullptr;
33 }
22 34
23 // ------------------------------------------------------------------------------------------------- 35 // -------------------------------------------------------------------------------------------------
24 // 36 //
25 METHOD 37 METHOD
26 RCONSession::connect (IPAddress address) -> void 38 RCONSession::connect (IPAddress address) -> void
240 } 252 }
241 253
242 // ------------------------------------------------------------------------------------------------- 254 // -------------------------------------------------------------------------------------------------
243 // 255 //
244 STATIC METHOD 256 STATIC METHOD
245 RCONSession::all_sessions() -> const Vector<RCONSessionPointer>& 257 RCONSession::get_session() -> RCONSession*
246 { 258 {
247 return g_allSessions; 259 return g_rconSession;
248 } 260 }

mercurial