about summary refs log tree commit diff
path: root/src/engine/server/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/server/server.cpp')
-rw-r--r--src/engine/server/server.cpp127
1 files changed, 16 insertions, 111 deletions
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 8e151035..ee7de31b 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -16,6 +16,7 @@
 #include <engine/shared/config.h>
 #include <engine/shared/datafile.h>
 #include <engine/shared/demo.h>
+#include <engine/shared/econ.h>
 #include <engine/shared/mapchecker.h>
 #include <engine/shared/network.h>
 #include <engine/shared/packer.h>
@@ -317,15 +318,8 @@ int CServer::Init()
 		m_aClients[i].m_Snapshots.Init();
 	}
 
-	for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++)
-	{
-		m_aEconClients[i].m_State = CEconClient::STATE_EMPTY;
-	}
-
 	m_CurrentGameTick = 0;
 
-	m_UseEcon = 0;
-
 	return 0;
 }
 
@@ -618,30 +612,6 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser)
 	return 0;
 }
 
-int CServer::NewConsoleClientCallback(int EconID, void *pUser)
-{
-	CServer *pThis = (CServer *)pUser;
-	pThis->m_aEconClients[EconID].m_State = CEconClient::STATE_CONNECTED;
-	pThis->m_NetConsole.SetTimeout(EconID, g_Config.m_SvEconAuthTimeout);
-	return 0;
-}
-
-int CServer::DelConsoleClientCallback(int EconID, const char *pReason, void *pUser)
-{
-	CServer *pThis = (CServer *)pUser;
-
-	NETADDR Addr = pThis->m_NetConsole.ClientAddr(EconID);
-	char aAddrStr[NETADDR_MAXSTRSIZE];
-	net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
-	char aBuf[256];
-	str_format(aBuf, sizeof(aBuf), "econ client dropped. eid=%d addr=%s reason='%s'", EconID, aAddrStr, pReason);
-	pThis->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
-
-	pThis->m_aEconClients[EconID].m_State = CEconClient::STATE_EMPTY;
-	return 0;
-}
-
-
 void CServer::SendMap(int ClientID)
 {
 	CMsgPacker Msg(NETMSG_MAP_CHANGE);
@@ -664,12 +634,7 @@ void CServer::SendRconLine(int ClientID, const char *pLine)
 	SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
 }
 
-void CServer::SendEconLine(int EconID, const char *pLine)
-{
-	m_NetConsole.Send(EconID, pLine);
-}
-
-void CServer::SendConsoleLineAuthed(const char *pLine, void *pUser)
+void CServer::SendRconLineAuthed(const char *pLine, void *pUser)
 {
 	CServer *pThis = (CServer *)pUser;
 	static volatile int ReentryGuard = 0;
@@ -684,15 +649,6 @@ void CServer::SendConsoleLineAuthed(const char *pLine, void *pUser)
 			pThis->SendRconLine(i, pLine);
 	}
 
-	if(pThis->m_UseEcon)
-	{
-		for(i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++)
-		{
-			if(pThis->m_aEconClients[i].m_State == CEconClient::STATE_AUTHED)
-				pThis->SendEconLine(i, pLine);
-		}
-	}
-
 	ReentryGuard--;
 }
 
@@ -1130,46 +1086,7 @@ void CServer::PumpNetwork()
 			ProcessClientPacket(&Packet);
 	}
 
-	if(m_UseEcon)
-		EconPumpNetwork();
-}
-
-void CServer::EconPumpNetwork()
-{
-	m_NetConsole.Update();
-
-	char aBuf[NET_MAX_PACKETSIZE];
-	int EconID;
-
-	while(m_NetConsole.Recv(aBuf, sizeof(aBuf) - 1, &EconID))
-	{
-		dbg_assert(m_aEconClients[EconID].m_State != CEconClient::STATE_EMPTY, "got message from empty slot");
-		if(m_aEconClients[EconID].m_State == CEconClient::STATE_CONNECTED)
-		{
-			if(str_comp(aBuf, g_Config.m_SvRconPassword) == 0)
-			{
-				m_aEconClients[EconID].m_State = CEconClient::STATE_AUTHED;
-				m_NetConsole.Send(EconID, "Authentication successful. Remote console access granted.");
-				m_NetConsole.SetTimeout(EconID, g_Config.m_SvEconTimeout);
-
-				str_format(aBuf, sizeof(aBuf), "EconID=%d authed", EconID);
-				Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
-			}
-			else
-			{
-				m_NetConsole.Send(EconID, "Wrong password");
-			}
-		}
-		else if(m_aEconClients[EconID].m_State == CEconClient::STATE_AUTHED)
-		{
-			char aFormatted[256];
-			str_format(aFormatted, sizeof(aBuf), "eid=%d cmd='%s'", EconID, aBuf);
-			Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aFormatted);
-			m_RconClientID = EconID;
-			Console()->ExecuteLine(aBuf);
-			m_RconClientID = -1;
-		}
-	}
+	m_Econ.Update();
 }
 
 char *CServer::GetMapName()
@@ -1244,7 +1161,7 @@ int CServer::Run()
 	m_pStorage = Kernel()->RequestInterface<IStorage>();
 
 	//
-	Console()->RegisterPrintCallback(SendConsoleLineAuthed, this);
+	m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_ConsoleOutputLevel, SendRconLineAuthed, this);
 
 	// load map
 	if(!LoadMap(g_Config.m_SvMap))
@@ -1275,30 +1192,7 @@ int CServer::Run()
 
 	m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this);
 
-	if(g_Config.m_SvEconPort && g_Config.m_SvRconPassword[0])
-	{
-		dbg_msg("econ", "binding econ to %s:%d", g_Config.m_SvEconBindaddr, g_Config.m_SvEconPort);
-		if(g_Config.m_SvEconBindaddr[0] && net_host_lookup(g_Config.m_SvEconBindaddr, &BindAddr, NETTYPE_ALL) == 0)
-		{
-			BindAddr.port = g_Config.m_SvEconPort;
-		}
-		else
-		{
-			mem_zero(&BindAddr, sizeof(BindAddr));
-			BindAddr.type = NETTYPE_ALL;
-			BindAddr.port = g_Config.m_SvEconPort;
-		}
-
-		if(m_NetConsole.Open(BindAddr, 0))
-		{
-			m_NetConsole.SetCallbacks(NewConsoleClientCallback, DelConsoleClientCallback, this);
-			m_UseEcon = 1;
-		}
-		else
-		{
-			dbg_msg("econ", "couldn't open econ socket. port might already be in use");
-		}
-	}
+	m_Econ.Init(Console());
 
 	char aBuf[256];
 	str_format(aBuf, sizeof(aBuf), "server name is '%s'", g_Config.m_SvName);
@@ -1694,6 +1588,16 @@ void CServer::ConchainModCommandUpdate(IConsole::IResult *pResult, void *pUserDa
 		pfnCallback(pResult, pCallbackUserData);
 }
 
+void CServer::ConchainConsoleOutputLevelUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
+{
+	pfnCallback(pResult, pCallbackUserData);
+	if(pResult->NumArguments() == 1)
+	{
+		CServer *pThis = static_cast<CServer *>(pUserData);
+		pThis->Console()->SetPrintOutputLevel(pThis->m_PrintCBIndex, pResult->GetInteger(0));
+	}
+}
+
 void CServer::RegisterCommands()
 {
 	m_pConsole = Kernel()->RequestInterface<IConsole>();
@@ -1715,6 +1619,7 @@ void CServer::RegisterCommands()
 
 	Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this);
 	Console()->Chain("mod_command", ConchainModCommandUpdate, this);
+	Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this);
 }