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

Method LoadMap

src/engine/server/server.cpp:2909–2999  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2907}
2908
2909int CServer::LoadMap(const char *pMapName)
2910{
2911 m_MapReload = false;
2912 m_SameMapReload = false;
2913
2914 char aBuf[IO_MAX_PATH_LENGTH];
2915 str_format(aBuf, sizeof(aBuf), "maps/%s.map", pMapName);
2916 if(!str_valid_filename(fs_filename(aBuf)))
2917 {
2918 log_error("server", "The name '%s' cannot be used for maps because not all platforms support it", aBuf);
2919 return 0;
2920 }
2921 if(!GameServer()->OnMapChange(aBuf, sizeof(aBuf)))
2922 {
2923 return 0;
2924 }
2925 if(!GameServer()->Map()->Load(pMapName, Storage(), aBuf, IStorage::TYPE_ALL))
2926 {
2927 return 0;
2928 }
2929
2930 // reinit snapshot ids
2931 m_IdPool.TimeoutIds();
2932
2933 // get the crc of the map
2934 m_aCurrentMapSha256[MAP_TYPE_SIX] = GameServer()->Map()->Sha256();
2935 m_aCurrentMapCrc[MAP_TYPE_SIX] = GameServer()->Map()->Crc();
2936 char aBufMsg[256];
2937 char aSha256[SHA256_MAXSTRSIZE];
2938 sha256_str(m_aCurrentMapSha256[MAP_TYPE_SIX], aSha256, sizeof(aSha256));
2939 str_format(aBufMsg, sizeof(aBufMsg), "%s sha256 is %s", aBuf, aSha256);
2940 Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg);
2941
2942 // load complete map into memory for download
2943 {
2944 free(m_apCurrentMapData[MAP_TYPE_SIX]);
2945 void *pData;
2946 Storage()->ReadFile(aBuf, IStorage::TYPE_ALL, &pData, &m_aCurrentMapSize[MAP_TYPE_SIX]);
2947 m_apCurrentMapData[MAP_TYPE_SIX] = (unsigned char *)pData;
2948 }
2949
2950 if(Config()->m_SvMapsBaseUrl[0])
2951 {
2952 char aEscaped[256];
2953 str_format(aBuf, sizeof(aBuf), "%s_%s.map", pMapName, aSha256);
2954 EscapeUrl(aEscaped, aBuf);
2955 str_format(m_aMapDownloadUrl, sizeof(m_aMapDownloadUrl), "%s%s", Config()->m_SvMapsBaseUrl, aEscaped);
2956 }
2957 else
2958 {
2959 m_aMapDownloadUrl[0] = '\0';
2960 }
2961
2962 // load sixup version of the map
2963 if(Config()->m_SvSixup)
2964 {
2965 str_format(aBuf, sizeof(aBuf), "maps7/%s.map", pMapName);
2966 void *pData;

Callers

nothing calls this directly

Calls 15

str_formatFunction · 0.85
str_valid_filenameFunction · 0.85
fs_filenameFunction · 0.85
StorageFunction · 0.85
sha256_strFunction · 0.85
sha256Function · 0.85
crc32Function · 0.85
OnMapChangeMethod · 0.80
TimeoutIdsMethod · 0.80
ReadFileMethod · 0.80
OnConfigChangeMethod · 0.80
ConfigFunction · 0.50

Tested by

no test coverage detected