MCPcopy Create free account
hub / github.com/ddnet/ddnet / HandleChecksum

Method HandleChecksum

src/engine/client/client.cpp:4218–4314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4216#endif
4217
4218int CClient::HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker)
4219{
4220 int Start = pUnpacker->GetInt();
4221 int Length = pUnpacker->GetInt();
4222 if(pUnpacker->Error())
4223 {
4224 return 1;
4225 }
4226 if(Start < 0 || Length < 0 || Start > std::numeric_limits<int>::max() - Length)
4227 {
4228 return 2;
4229 }
4230 int End = Start + Length;
4231 int ChecksumBytesEnd = minimum(End, (int)sizeof(m_Checksum.m_aBytes));
4232 int FileStart = maximum(Start, (int)sizeof(m_Checksum.m_aBytes));
4233 unsigned char aStartBytes[sizeof(int32_t)];
4234 unsigned char aEndBytes[sizeof(int32_t)];
4235 uint_to_bytes_be(aStartBytes, Start);
4236 uint_to_bytes_be(aEndBytes, End);
4237
4238 if(Start <= (int)sizeof(m_Checksum.m_aBytes))
4239 {
4240 mem_zero(&m_Checksum.m_Data.m_Config, sizeof(m_Checksum.m_Data.m_Config));
4241#define CHECKSUM_RECORD(Flags) (((Flags) & CFGFLAG_CLIENT) == 0 || ((Flags) & CFGFLAG_INSENSITIVE) != 0)
4242#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \
4243 if(CHECKSUM_RECORD(Flags)) \
4244 { \
4245 m_Checksum.m_Data.m_Config.m_##Name = g_Config.m_##Name; \
4246 }
4247#define MACRO_CONFIG_COL(Name, ScriptName, Def, Flags, Desc) \
4248 if(CHECKSUM_RECORD(Flags)) \
4249 { \
4250 m_Checksum.m_Data.m_Config.m_##Name = g_Config.m_##Name; \
4251 }
4252#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Flags, Desc) \
4253 if(CHECKSUM_RECORD(Flags)) \
4254 { \
4255 str_copy(m_Checksum.m_Data.m_Config.m_##Name, g_Config.m_##Name, sizeof(m_Checksum.m_Data.m_Config.m_##Name)); \
4256 }
4257#include <engine/shared/config_variables.h>
4258#undef CHECKSUM_RECORD
4259#undef MACRO_CONFIG_INT
4260#undef MACRO_CONFIG_COL
4261#undef MACRO_CONFIG_STR
4262 }
4263 if(End > (int)sizeof(m_Checksum.m_aBytes))
4264 {
4265 if(m_OwnExecutableSize == 0)
4266 {
4267 m_OwnExecutable = io_current_exe();
4268 // io_length returns -1 on error.
4269 m_OwnExecutableSize = m_OwnExecutable ? io_length(m_OwnExecutable) : -1;
4270 }
4271 // Own executable not available.
4272 if(m_OwnExecutableSize < 0)
4273 {
4274 return 3;
4275 }

Callers

nothing calls this directly

Calls 14

maximumFunction · 0.85
uint_to_bytes_beFunction · 0.85
mem_zeroFunction · 0.85
io_current_exeFunction · 0.85
io_lengthFunction · 0.85
io_seekFunction · 0.85
io_readFunction · 0.85
AddRawMethod · 0.80
minimumFunction · 0.50
sha256_initFunction · 0.50
sha256_updateFunction · 0.50
sha256_finishFunction · 0.50

Tested by

no test coverage detected