From cae8c68d8782dfd31017c12915065a68c72729cc Mon Sep 17 00:00:00 2001 From: eeeee Date: Sat, 14 Apr 2012 01:30:18 +0200 Subject: [PATCH] send ahead window for maps downloading. works with vanilla client. --- src/engine/server/server.cpp | 53 ++++++++++++++++++++++++++++ src/engine/shared/config_variables.h | 2 ++ src/engine/shared/network_server.cpp | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 904141595..941fdc9d3 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -748,8 +748,13 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser) return 0; } +static int lastsent[MAX_CLIENTS]; +static int lastask[MAX_CLIENTS]; + void CServer::SendMap(int ClientID) { + lastsent[ClientID] = 0; + lastask[ClientID] = 0; CMsgPacker Msg(NETMSG_MAP_CHANGE); Msg.AddString(GetMapName(), 0); Msg.AddInt(m_CurrentMapCrc); @@ -876,6 +881,12 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) int Offset = Chunk * ChunkSize; int Last = 0; + lastask[ClientID] = Chunk; + if (Chunk == 0) + { + lastsent[ClientID] = 0; + } + // drop faulty map data requests if(Chunk < 0 || Offset > m_CurrentMapSize) return; @@ -888,6 +899,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) Last = 1; } + if (lastsent[ClientID]+ChunkSize < m_CurrentMapSize && lastsent[ClientID] < Chunk+g_Config.m_SvMapWindow) + return; + CMsgPacker Msg(NETMSG_MAP_DATA); Msg.AddInt(Last); Msg.AddInt(m_CurrentMapCrc); @@ -1208,6 +1222,45 @@ void CServer::PumpNetwork() ProcessClientPacket(&Packet); } + for (int i=0;i m_CurrentMapSize) + continue; + if(Offset+ChunkSize >= m_CurrentMapSize) + { + ChunkSize = m_CurrentMapSize-Offset; + if(ChunkSize < 0) + ChunkSize = 0; + Last = 1; + } + + CMsgPacker Msg(NETMSG_MAP_DATA); + Msg.AddInt(Last); + Msg.AddInt(m_CurrentMapCrc); + Msg.AddInt(Chunk); + Msg.AddInt(ChunkSize); + Msg.AddRaw(&m_pCurrentMapData[Offset], ChunkSize); + SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, i, true); + + if(g_Config.m_Debug) + { + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "sending chunk %d with size %d", Chunk, ChunkSize); + Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); + } + } + m_ServerBan.Update(); m_Econ.Update(); } diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 3e5182aea..87da1a445 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -93,6 +93,8 @@ MACRO_CONFIG_INT(SvRconBantime, sv_rcon_bantime, 5, 0, 1440, CFGFLAG_SERVER, "Th MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos") MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)") +MACRO_CONFIG_INT(SvMapWindow, sv_map_window, 15, 0, 100, CFGFLAG_SERVER, "Map downloading send-ahead window") + MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous") MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console") MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_ECON, "External console password") diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 1264a4a5a..e506fb885 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -232,7 +232,7 @@ int CNetServer::Send(CNetChunk *pChunk) } else { - Drop(pChunk->m_ClientID, "Error sending data"); +// Drop(pChunk->m_ClientID, "Error sending data"); } } return 0;