diff options
Diffstat (limited to 'src/engine/server')
| -rw-r--r-- | src/engine/server/server.cpp | 101 | ||||
| -rw-r--r-- | src/engine/server/server.h | 6 |
2 files changed, 52 insertions, 55 deletions
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 577c040f..4fa872eb 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -36,45 +36,23 @@ #include <windows.h> #endif -static const char *StrUTF8Ltrim(const char *pStr) +static const char *StrLtrim(const char *pStr) { - while(*pStr) - { - const char *pStrOld = pStr; - int Code = str_utf8_decode(&pStr); - - // check if unicode is not empty - if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && - (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && - Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) - { - return pStrOld; - } - } + while(*pStr && *pStr >= 0 && *pStr <= 32) + pStr++; return pStr; } -static void StrUTF8Rtrim(char *pStr) +static void StrRtrim(char *pStr) { - const char *p = pStr; - const char *pEnd = 0; - while(*p) + int i = str_length(pStr); + while(i >= 0) { - const char *pStrOld = p; - int Code = str_utf8_decode(&p); - - // check if unicode is not empty - if(Code > 0x20 && Code != 0xA0 && Code != 0x034F && (Code < 0x2000 || Code > 0x200F) && (Code < 0x2028 || Code > 0x202F) && - (Code < 0x205F || Code > 0x2064) && (Code < 0x206A || Code > 0x206F) && (Code < 0xFE00 || Code > 0xFE0F) && - Code != 0xFEFF && (Code < 0xFFF9 || Code > 0xFFFC)) - { - pEnd = 0; - } - else if(pEnd == 0) - pEnd = pStrOld; + if(pStr[i] < 0 || pStr[i] > 32) + break; + pStr[i] = 0; + i--; } - if(pEnd != 0) - *(const_cast<char *>(pEnd)) = 0; } @@ -167,7 +145,7 @@ void CSnapIDPool::FreeID(int ID) } -void CServerBan::Init(IConsole *pConsole, IStorage *pStorage, CServer* pServer) +void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer* pServer) { CNetBan::Init(pConsole, pStorage); @@ -331,8 +309,12 @@ int CServer::TrySetClientName(int ClientID, const char *pName) char aTrimmedName[64]; // trim the name - str_copy(aTrimmedName, StrUTF8Ltrim(pName), sizeof(aTrimmedName)); - StrUTF8Rtrim(aTrimmedName); + str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName)); + StrRtrim(aTrimmedName); + + // check for empty names + if(!aTrimmedName[0]) + return -1; // check if new and old name are the same if(m_aClients[ClientID].m_aName[0] && str_comp(m_aClients[ClientID].m_aName, aTrimmedName) == 0) @@ -343,11 +325,6 @@ int CServer::TrySetClientName(int ClientID, const char *pName) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); pName = aTrimmedName; - - // check for empty names - if(!pName[0]) - return -1; - // make sure that two clients doesn't have the same name for(int i = 0; i < MAX_CLIENTS; i++) if(i != ClientID && m_aClients[i].m_State >= CClient::STATE_READY) @@ -371,14 +348,23 @@ void CServer::SetClientName(int ClientID, const char *pName) if(!pName) return; - char aNameTry[MAX_NAME_LENGTH]; - str_copy(aNameTry, pName, MAX_NAME_LENGTH); - if(TrySetClientName(ClientID, aNameTry)) + char aCleanName[MAX_NAME_LENGTH]; + str_copy(aCleanName, pName, sizeof(aCleanName)); + + // clear name + for(char *p = aCleanName; *p; ++p) + { + if(*p < 32) + *p = ' '; + } + + if(TrySetClientName(ClientID, aCleanName)) { // auto rename for(int i = 1;; i++) { - str_format(aNameTry, MAX_NAME_LENGTH, "(%d)%s", i, pName); + char aNameTry[MAX_NAME_LENGTH]; + str_format(aNameTry, sizeof(aCleanName), "(%d)%s", i, aCleanName); if(TrySetClientName(ClientID, aNameTry) == 0) break; } @@ -870,6 +856,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) } else if(Msg == NETMSG_REQUEST_MAP_DATA) { + if(m_aClients[ClientID].m_State < CClient::STATE_CONNECTING) + return; + int Chunk = Unpacker.GetInt(); int ChunkSize = 1024-128; int Offset = Chunk * ChunkSize; @@ -1270,10 +1259,6 @@ void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterS int CServer::Run() { - m_pGameServer = Kernel()->RequestInterface<IGameServer>(); - m_pMap = Kernel()->RequestInterface<IEngineMap>(); - m_pStorage = Kernel()->RequestInterface<IStorage>(); - // m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_ConsoleOutputLevel, SendRconLineAuthed, this); @@ -1289,6 +1274,7 @@ int CServer::Run() if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NETTYPE_ALL) == 0) { // sweet! + BindAddr.type = NETTYPE_ALL; BindAddr.port = g_Config.m_SvPort; } else @@ -1306,7 +1292,6 @@ int CServer::Run() m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this); - m_ServerBan.Init(Console(), Storage(), this); m_Econ.Init(Console(), &m_ServerBan); char aBuf[256]; @@ -1482,8 +1467,12 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser) { net_addr_str(pThis->m_NetServer.ClientAddr(i), aAddrStr, sizeof(aAddrStr), true); if(pThis->m_aClients[i].m_State == CClient::STATE_INGAME) - str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d", i, aAddrStr, - pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score); + { + const char *pAuthStr = pThis->m_aClients[i].m_Authed == CServer::AUTHED_ADMIN ? "(Admin)" : + pThis->m_aClients[i].m_Authed == CServer::AUTHED_MOD ? "(Mod)" : ""; + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' score=%d %s", i, aAddrStr, + pThis->m_aClients[i].m_aName, pThis->m_aClients[i].m_Score, pAuthStr); + } else str_format(aBuf, sizeof(aBuf), "id=%d addr=%s connecting", i, aAddrStr); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); @@ -1564,6 +1553,7 @@ void CServer::ConLogout(IConsole::IResult *pResult, void *pUser) pServer->SendMsgEx(&Msg, MSGFLAG_VITAL, pServer->m_RconClientID, true); pServer->m_aClients[pServer->m_RconClientID].m_Authed = AUTHED_NO; + pServer->m_aClients[pServer->m_RconClientID].m_AuthTries = 0; pServer->m_aClients[pServer->m_RconClientID].m_pRconCmdToSend = 0; pServer->SendRconLine(pServer->m_RconClientID, "Logout successful."); char aBuf[32]; @@ -1628,7 +1618,11 @@ void CServer::ConchainConsoleOutputLevelUpdate(IConsole::IResult *pResult, void void CServer::RegisterCommands() { m_pConsole = Kernel()->RequestInterface<IConsole>(); + m_pGameServer = Kernel()->RequestInterface<IGameServer>(); + m_pMap = Kernel()->RequestInterface<IEngineMap>(); + m_pStorage = Kernel()->RequestInterface<IStorage>(); + // register console commands Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason"); Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "List players"); Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "Shut down"); @@ -1645,6 +1639,10 @@ 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); + + // register console commands in sub parts + m_ServerBan.InitServerBan(Console(), Storage(), this); + m_pGameServer->OnConsoleInit(); } @@ -1725,7 +1723,6 @@ int main(int argc, const char **argv) // ignore_convention // register all console commands pServer->RegisterCommands(); - pGameServer->OnConsoleInit(); /* This banmaster is added into the source of the server that i'm able to ban players even if no banmaster.cfg is used. * Often serverhoster doesn't add this file because they don't know what it is for and remove it, not diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 27991746..4a1f7344 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -50,10 +50,10 @@ class CServerBan : public CNetBan public: class CServer *Server() const { return m_pServer; } - void Init(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); + void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer* pServer); - int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); - int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); + virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); + virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); static void ConBanExt(class IConsole::IResult *pResult, void *pUser); }; |