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

Method ValidateHeader

src/engine/client/ghost.cpp:257–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257bool CGhostLoader::ValidateHeader(const CGhostHeader &Header, const char *pFilename) const
258{
259 if(mem_comp(Header.m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) != 0)
260 {
261 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': invalid header marker", pFilename);
262 return false;
263 }
264
265 if(Header.m_Version < 4 || Header.m_Version > gs_CurVersion)
266 {
267 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': ghost version '%d' is not supported", pFilename, Header.m_Version);
268 return false;
269 }
270
271 if(!mem_has_null(Header.m_aOwner, sizeof(Header.m_aOwner)) || !str_utf8_check(Header.m_aOwner))
272 {
273 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': owner name is invalid", pFilename);
274 return false;
275 }
276
277 if(!mem_has_null(Header.m_aMap, sizeof(Header.m_aMap)) || !str_utf8_check(Header.m_aMap))
278 {
279 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': map name is invalid", pFilename);
280 return false;
281 }
282
283 const int NumTicks = Header.GetTicks();
284 if(NumTicks <= 0)
285 {
286 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': number of ticks '%d' is invalid", pFilename, NumTicks);
287 return false;
288 }
289
290 const int Time = Header.GetTime();
291 if(Time <= 0)
292 {
293 log_error_color(LOG_COLOR_GHOST, "ghost_loader", "Failed to read ghost file '%s': time '%d' is invalid", pFilename, Time);
294 return false;
295 }
296
297 return true;
298}
299
300bool CGhostLoader::CheckHeaderMap(const CGhostHeader &Header, const char *pFilename, const char *pMap, const SHA256_DIGEST &MapSha256, unsigned MapCrc, bool LogMapMismatch) const
301{

Callers

nothing calls this directly

Calls 5

mem_compFunction · 0.85
mem_has_nullFunction · 0.85
str_utf8_checkFunction · 0.85
GetTicksMethod · 0.80
GetTimeMethod · 0.80

Tested by

no test coverage detected