Skip to content

Commit

Permalink
Merge pull request ddnet#9395 from infclass/kaffeine/map-url
Browse files Browse the repository at this point in the history
Add 'sv_maps_base_url' to support map download https urls
  • Loading branch information
heinrich5991 authored Dec 17, 2024
2 parents d0e2d8c + d9573fb commit 257e634
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
{
char aUrl[256];
char aEscaped[256];
EscapeUrl(aEscaped, sizeof(aEscaped), m_aMapdownloadFilename + 15); // cut off downloadedmaps/
EscapeUrl(aEscaped, m_aMapdownloadFilename + 15); // cut off downloadedmaps/
bool UseConfigUrl = str_comp(g_Config.m_ClMapDownloadUrl, "https://maps.ddnet.org") != 0 || m_aMapDownloadUrl[0] == '\0';
str_format(aUrl, sizeof(aUrl), "%s/%s", UseConfigUrl ? g_Config.m_ClMapDownloadUrl : m_aMapDownloadUrl, aEscaped);

Expand Down
20 changes: 19 additions & 1 deletion src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ CServer::CServer()
m_ReloadedWhenEmpty = false;
m_aCurrentMap[0] = '\0';
m_pCurrentMapName = m_aCurrentMap;
m_aMapDownloadUrl[0] = '\0';

m_RconClientId = IServer::RCON_CID_SERV;
m_RconAuthLevel = AUTHED_ADMIN;
Expand Down Expand Up @@ -1214,7 +1215,14 @@ void CServer::SendMap(int ClientId)
Msg.AddRaw(&m_aCurrentMapSha256[MapType].data, sizeof(m_aCurrentMapSha256[MapType].data));
Msg.AddInt(m_aCurrentMapCrc[MapType]);
Msg.AddInt(m_aCurrentMapSize[MapType]);
Msg.AddString("", 0); // HTTPS map download URL
if(m_aMapDownloadUrl[0])
{
Msg.AddString(m_aMapDownloadUrl, 0);
}
else
{
Msg.AddString("", 0);
}
SendMsg(&Msg, MSGFLAG_VITAL, ClientId);
}
{
Expand Down Expand Up @@ -2591,6 +2599,16 @@ int CServer::LoadMap(const char *pMapName)
m_apCurrentMapData[MAP_TYPE_SIX] = (unsigned char *)pData;
}

if(Config()->m_SvMapsBaseUrl[0])
{
str_format(aBuf, sizeof(aBuf), "%s%s_%s.map", Config()->m_SvMapsBaseUrl, pMapName, aSha256);
EscapeUrl(m_aMapDownloadUrl, aBuf);
}
else
{
m_aMapDownloadUrl[0] = '\0';
}

// load sixup version of the map
if(Config()->m_SvSixup)
{
Expand Down
1 change: 1 addition & 0 deletions src/engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class CServer : public IServer
unsigned m_aCurrentMapCrc[NUM_MAP_TYPES];
unsigned char *m_apCurrentMapData[NUM_MAP_TYPES];
unsigned int m_aCurrentMapSize[NUM_MAP_TYPES];
char m_aMapDownloadUrl[256];

CDemoRecorder m_aDemoRecorder[NUM_RECORDERS];
CAuthManager m_AuthManager;
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ MACRO_CONFIG_INT(SvHighBandwidth, sv_high_bandwidth, 0, 0, 1, CFGFLAG_SERVER, "U
MACRO_CONFIG_STR(SvRegister, sv_register, 16, "1", CFGFLAG_SERVER, "Register server with master server for public listing, can also accept a comma-separated list of protocols to register on, like 'ipv4,ipv6'")
MACRO_CONFIG_STR(SvRegisterExtra, sv_register_extra, 256, "", CFGFLAG_SERVER, "Extra headers to send to the register endpoint, comma separated 'Header: Value' pairs")
MACRO_CONFIG_STR(SvRegisterUrl, sv_register_url, 128, "https://master1.ddnet.org/ddnet/15/register", CFGFLAG_SERVER, "Masterserver URL to register to")
MACRO_CONFIG_STR(SvMapsBaseUrl, sv_maps_base_url, 128, "", CFGFLAG_SERVER, "Base path used to provide HTTPS map download URL to the clients")
MACRO_CONFIG_STR(SvRconPassword, sv_rcon_password, 128, "", CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, "Remote console password (full access)")
MACRO_CONFIG_STR(SvRconModPassword, sv_rcon_mod_password, 128, "", CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, "Remote console password for moderators (limited access)")
MACRO_CONFIG_STR(SvRconHelperPassword, sv_rcon_helper_password, 128, "", CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, "Remote console password for helpers (limited access)")
Expand Down
7 changes: 7 additions & 0 deletions src/engine/shared/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ inline std::unique_ptr<CHttpRequest> HttpPostJson(const char *pUrl, const char *
}

void EscapeUrl(char *pBuf, int Size, const char *pStr);

template<int N>
void EscapeUrl(char (&aBuf)[N], const char *pStr)
{
EscapeUrl(aBuf, N, pStr);
}

bool HttpHasIpresolveBug();

// In an ideal world this would be a kernel interface
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/components/skins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void CSkins::CSkinDownloadJob::Run()
const char *pBaseUrl = g_Config.m_ClDownloadCommunitySkins != 0 ? g_Config.m_ClSkinCommunityDownloadUrl : g_Config.m_ClSkinDownloadUrl;

char aEscapedName[256];
EscapeUrl(aEscapedName, sizeof(aEscapedName), m_aName);
EscapeUrl(aEscapedName, m_aName);

char aUrl[IO_MAX_PATH_LENGTH];
str_format(aUrl, sizeof(aUrl), "%s%s.png", pBaseUrl, aEscapedName);
Expand Down

0 comments on commit 257e634

Please sign in to comment.