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 |