mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed problems with map downloading if the map changes during download. Closes #236
This commit is contained in:
parent
927954a53b
commit
b63dbfede5
|
@ -1137,6 +1137,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket)
|
|||
{
|
||||
const char *pMap = Unpacker.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES);
|
||||
int MapCrc = Unpacker.GetInt();
|
||||
int MapSize = Unpacker.GetInt();
|
||||
const char *pError = 0;
|
||||
|
||||
if(Unpacker.Error())
|
||||
|
@ -1148,6 +1149,9 @@ void CClient::ProcessPacket(CNetChunk *pPacket)
|
|||
pError = "strange character in map name";
|
||||
}
|
||||
|
||||
if(MapSize < 0)
|
||||
pError = "invalid map size";
|
||||
|
||||
if(pError)
|
||||
DisconnectWithReason(pError);
|
||||
else
|
||||
|
@ -1174,7 +1178,7 @@ void CClient::ProcessPacket(CNetChunk *pPacket)
|
|||
io_close(m_MapdownloadFile);
|
||||
m_MapdownloadFile = Storage()->OpenFile(m_aMapdownloadFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
m_MapdownloadCrc = MapCrc;
|
||||
m_MapdownloadTotalsize = -1;
|
||||
m_MapdownloadTotalsize = MapSize;
|
||||
m_MapdownloadAmount = 0;
|
||||
|
||||
CMsgPacker Msg(NETMSG_REQUEST_MAP_DATA);
|
||||
|
@ -1192,17 +1196,17 @@ void CClient::ProcessPacket(CNetChunk *pPacket)
|
|||
else if(Msg == NETMSG_MAP_DATA)
|
||||
{
|
||||
int Last = Unpacker.GetInt();
|
||||
int TotalSize = Unpacker.GetInt();
|
||||
int MapCRC = Unpacker.GetInt();
|
||||
int Chunk = Unpacker.GetInt();
|
||||
int Size = Unpacker.GetInt();
|
||||
const unsigned char *pData = Unpacker.GetRaw(Size);
|
||||
|
||||
// check fior errors
|
||||
if(Unpacker.Error() || Size <= 0 || TotalSize <= 0 || !m_MapdownloadFile)
|
||||
if(Unpacker.Error() || Size <= 0 || MapCRC != m_MapdownloadCrc || Chunk != m_MapdownloadChunk || !m_MapdownloadFile)
|
||||
return;
|
||||
|
||||
io_write(m_MapdownloadFile, pData, Size);
|
||||
|
||||
m_MapdownloadTotalsize = TotalSize;
|
||||
m_MapdownloadAmount += Size;
|
||||
|
||||
if(Last)
|
||||
|
|
|
@ -585,6 +585,7 @@ void CServer::SendMap(int ClientID)
|
|||
CMsgPacker Msg(NETMSG_MAP_CHANGE);
|
||||
Msg.AddString(GetMapName(), 0);
|
||||
Msg.AddInt(m_CurrentMapCrc);
|
||||
Msg.AddInt(m_CurrentMapSize);
|
||||
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID, true);
|
||||
}
|
||||
|
||||
|
@ -685,7 +686,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
|
||||
CMsgPacker Msg(NETMSG_MAP_DATA);
|
||||
Msg.AddInt(Last);
|
||||
Msg.AddInt(m_CurrentMapSize);
|
||||
Msg.AddInt(m_CurrentMapCrc);
|
||||
Msg.AddInt(Chunk);
|
||||
Msg.AddInt(ChunkSize);
|
||||
Msg.AddRaw(&m_pCurrentMapData[Offset], ChunkSize);
|
||||
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID, true);
|
||||
|
|
Loading…
Reference in a new issue