sources/network/rconsession.cpp

changeset 58
d175243ad169
parent 57
a2f41245e387
child 70
0e947b487b18
--- a/sources/network/rconsession.cpp	Tue Dec 16 02:30:31 2014 +0200
+++ b/sources/network/rconsession.cpp	Tue Dec 16 02:48:18 2014 +0200
@@ -1,48 +1,24 @@
 #include "rconsession.h"
 #include "../interface.h"
 
-RCONSession* g_rconSession = nullptr;
-
 // -------------------------------------------------------------------------------------------------
 //
 RCONSession::RCONSession() :
 	m_state (RCON_DISCONNECTED),
 	m_lastPing (0),
-	m_numAdmins (0) {}
-
-// -------------------------------------------------------------------------------------------------
-//
-STATIC METHOD
-RCONSession::new_session() -> RCONSession*
+	m_numAdmins (0)
 {
-	if (g_rconSession != NULL)
+	if (not m_socket.set_blocking (false))
 	{
-		g_rconSession->disconnect();
-		delete g_rconSession;
+		print_to (stderr, "unable to set socket as non-blocking: %s\n",
+			m_socket.error_string().chars());
+		exit (EXIT_FAILURE);
 	}
-
-	g_rconSession = new RCONSession;
-
-	if (not g_rconSession->socket()->set_blocking (false))
-	{
-		print ("unable to set socket as non-blocking: %s\n",
-			g_rconSession->socket()->error_string().chars());
-		delete g_rconSession;
-		return nullptr;
-	}
-
-	return g_rconSession;
 }
 
 // -------------------------------------------------------------------------------------------------
 //
-RCONSession::~RCONSession()
-{
-	disconnect();
-
-	if (g_rconSession == this)
-		g_rconSession = nullptr;
-}
+RCONSession::~RCONSession() {}
 
 // -------------------------------------------------------------------------------------------------
 //
@@ -279,10 +255,8 @@
 STATIC METHOD
 RCONSession::get_session() -> RCONSession*
 {
-	if (g_rconSession == nullptr)
-		new_session();
-
-	return g_rconSession;
+	static RCONSession session;
+	return &session;
 }
 
 // -------------------------------------------------------------------------------------------------

mercurial