[Merge] feature/www-download -> develop

This commit is contained in:
TheApadayo 2017-06-19 16:23:01 -04:00
commit 1799379e42
2 changed files with 61 additions and 13 deletions

View File

@ -192,7 +192,32 @@ namespace Components
}
}
std::string url = "http://" + download->target.getString() + "/file/" + (download->isMap ? "map/" : "") + file.name;
std::string host = "http://" + download->target.getString();
std::string fastHost = "http://" + Dvar::Var("sv_wwwBaseUrl").get<std::string>();
std::string url;
// file directory for fasthost looks like this
// /-usermaps
// /-mp_test
// -mp_test.ff
// -mp_test.iwd
// /-mp_whatever
// /-mp_whatever.ff
// /-mods
// /-mod1
// -mod1.iwd
// -mod.ff
// /-mod2
// ...
if (Dvar::Var("sv_wwwDownload").get<bool>())
{
url = fastHost + path;
}
else
{
url = host + "/file/" + (download->isMap ? "map/" : "") + file.name;
}
Download::FileDownload fDownload;
fDownload.file = file;
@ -738,6 +763,12 @@ namespace Components
mg_mgr_poll(&Download::Mgr, 100);
}
});
Dvar::OnInit([]()
{
Dvar::Register<bool>("sv_wwwDownload", false, Game::dvar_flag::DVAR_FLAG_DEDISAVED, "Set to true to enable downloading maps/mods from an external server.");
Dvar::Register<const char*>("sv_wwwBaseUrl", "", Game::dvar_flag::DVAR_FLAG_DEDISAVED, "Set to the base url for the external map download.");
});
}
else
{
@ -746,6 +777,8 @@ namespace Components
Dvar::Register<const char*>("ui_dl_timeLeft", "", Game::dvar_flag::DVAR_FLAG_NONE, "");
Dvar::Register<const char*>("ui_dl_progress", "", Game::dvar_flag::DVAR_FLAG_NONE, "");
Dvar::Register<const char*>("ui_dl_transRate", "", Game::dvar_flag::DVAR_FLAG_NONE, "");
Dvar::Register<bool>("sv_wwwDownload", false, Game::dvar_flag::DVAR_FLAG_DEDISAVED, "Set to true to enable downloading maps/mods from an external server.");
Dvar::Register<const char*>("sv_wwwBaseUrl", "", Game::dvar_flag::DVAR_FLAG_DEDISAVED, "Set to the base url for the external map download.");
});
UIScript::Add("mod_download_cancel", [] (UIScript::Token)

View File

@ -47,7 +47,7 @@ namespace Components
{
return Utils::String::VA("%d", address.getIP().full);
}
else if (key =="port")
else if (key == "port")
{
return Utils::String::VA("%d", address.getPort());
}
@ -154,7 +154,7 @@ namespace Components
Utils::Hook::Set<BYTE>(0x5AC2CF, 0xEB); // CL_ParseGamestate
Utils::Hook::Set<BYTE>(0x5AC2C3, 0xEB); // CL_ParseGamestate
// AnonymousAddRequest
// AnonymousAddRequest
Utils::Hook::Set<BYTE>(0x5B5E18, 0xEB);
Utils::Hook::Set<BYTE>(0x5B5E64, 0xEB);
Utils::Hook::Nop(0x5B5E5C, 2);
@ -217,7 +217,7 @@ namespace Components
Utils::Hook::Set<BYTE>(0x4D6171, 0);
Utils::Hook::Nop(0x4077A1, 5); // PartyMigrate_Frame
// Patch playlist stuff for non-party behavior
// Patch playlist stuff for non-party behavior
Utils::Hook::Set<Game::dvar_t**>(0x4A4093, &partyEnable);
Utils::Hook::Set<Game::dvar_t**>(0x4573F1, &partyEnable);
Utils::Hook::Set<Game::dvar_t**>(0x5B1A0C, &partyEnable);
@ -249,14 +249,14 @@ namespace Components
// Patch Live_PlayerHasLoopbackAddr
//Utils::Hook::Set<DWORD>(0x418F30, 0x90C3C033);
Command::Add("connect", [] (Command::Params* params)
Command::Add("connect", [](Command::Params* params)
{
if (params->length() < 2)
{
return;
}
if(Game::CL_IsCgameInitialized())
if (Game::CL_IsCgameInitialized())
{
Command::Execute("disconnect", false);
Command::Execute(Utils::String::VA("%s", params->join(0).data()), false);
@ -266,12 +266,12 @@ namespace Components
Party::Connect(Network::Address(params->get(1)));
}
});
Command::Add("reconnect", [] (Command::Params*)
Command::Add("reconnect", [](Command::Params*)
{
Party::Connect(Party::Container.target);
});
Scheduler::OnFrame([] ()
Scheduler::OnFrame([]()
{
if (Party::Container.valid)
{
@ -293,7 +293,7 @@ namespace Components
}, true);
// Basic info handler
Network::Handle("getInfo", [] (Network::Address address, std::string data)
Network::Handle("getInfo", [](Network::Address address, std::string data)
{
int botCount = 0;
int clientCount = 0;
@ -370,10 +370,13 @@ namespace Components
info.set("matchtype", "0");
}
info.set("wwwDownload", (Dvar::Var("sv_wwwDownload").get<bool>() ? "1" : "0"));
info.set("wwwUrl", Dvar::Var("sv_wwwBaseUrl").get<std::string>());
Network::SendCommand(address, "infoResponse", "\\" + info.build());
});
Network::Handle("infoResponse", [] (Network::Address address, std::string data)
Network::Handle("infoResponse", [](Network::Address address, std::string data)
{
Utils::InfoString info(data);
@ -393,6 +396,18 @@ namespace Components
std::string mod = Dvar::Var("fs_game").get<std::string>();
// set fast server stuff here so its updated when we go to download stuff
if (info.get("wwwDownload") == "1"s)
{
Dvar::Var("sv_wwwDownload").set(true);
Dvar::Var("sv_wwwBaseUrl").set(info.get("wwwUrl"));
}
else
{
Dvar::Var("sv_wwwDownload").set(false);
Dvar::Var("sv_wwwBaseUrl").set("");
}
if (info.get("challenge") != Party::Container.challenge)
{
Party::ConnectError("Invalid join response: Challenge mismatch.");
@ -407,7 +422,7 @@ namespace Components
{
Party::ConnectError("Server is not hosting a match.");
}
else if(Party::Container.matchType > 2 || Party::Container.matchType < 0)
else if (Party::Container.matchType > 2 || Party::Container.matchType < 0)
{
Party::ConnectError("Invalid join response: Unknown matchtype");
}
@ -415,12 +430,12 @@ namespace Components
{
Party::ConnectError("Invalid map or gametype.");
}
else if(isUsermap && usermapHash != Maps::GetUsermapHash(info.get("mapname")))
else if (isUsermap && usermapHash != Maps::GetUsermapHash(info.get("mapname")))
{
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateMapDownload(info.get("mapname"));
}
else if(!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
else if (!info.get("fs_game").empty() && Utils::String::ToLower(mod) != Utils::String::ToLower(info.get("fs_game")))
{
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateClientDownload(info.get("fs_game"));