[Dedicated] Add sv_motd dvar, so serverowners can set motds

The motd will be displayed instead of the didyouknow messages in the
loadscreen
This commit is contained in:
momo5502 2016-11-27 14:30:21 +01:00
parent 159f172a07
commit 2969ae64e0
4 changed files with 27 additions and 2 deletions

View File

@ -330,6 +330,7 @@ namespace Components
Dvar::OnInit([] ()
{
Dvar::Register<const char*>("sv_sayName", "^7Console", Game::dvar_flag::DVAR_FLAG_NONE, "The name to pose as for 'say' commands");
Dvar::Register<const char*>("sv_motd", "", Game::dvar_flag::DVAR_FLAG_NONE, "A custom message of the day for servers");
// Say command
Command::AddSV("say", [] (Command::Params params)

View File

@ -623,7 +623,16 @@ namespace Components
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_MENUFILE, Menus::MenuFileLoad);
// Don't open connect menu
Utils::Hook::Nop(0x428E48, 5);
//Utils::Hook::Nop(0x428E48, 5);
// Use the connect menu open call to update server motds
Utils::Hook(0x428E48, []()
{
if (!Party::GetMotd().empty())
{
Dvar::Var("didyouknow").set(Party::GetMotd());
}
}, HOOK_CALL).install()->quick();
// Intercept menu painting
Utils::Hook(0x4FFBDF, Menus::IsMenuVisible, HOOK_CALL).install()->quick();

View File

@ -72,6 +72,11 @@ namespace Components
Command::Execute("openmenu menu_xboxlive_partyended");
}
std::string Party::GetMotd()
{
return Party::Container.motd;
}
Game::dvar_t* Party::RegisterMinPlayers(const char* name, int /*value*/, int /*min*/, int max, Game::dvar_flag flag, const char* description)
{
return Dvar::Register<int>(name, 1, 1, max, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED | flag, description).get<Game::dvar_t*>();
@ -319,6 +324,11 @@ namespace Components
info.set("securityLevel", fmt::sprintf("%i", Dvar::Var("sv_securityLevel").get<int>()));
info.set("sv_running", (Dvar::Var("sv_running").get<bool>() ? "1" : "0"));
if (Dedicated::IsEnabled())
{
info.set("sv_motd", Dvar::Var("sv_motd").get<std::string>());
}
// Ensure mapname is set
if (info.get("mapname").empty() || (Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>() && !Dvar::Var("sv_running").get<bool>()))
{
@ -398,6 +408,8 @@ namespace Components
}
else
{
Party::Container.motd = info.get("sv_motd");
if (Party::Container.matchType == 1) // Party
{
// Send playlist request

View File

@ -21,12 +21,15 @@ namespace Components
static void ConnectError(std::string message);
static std::string GetMotd();
private:
class JoinContainer
{
public:
Network::Address target;
std::string challenge;
std::string motd;
DWORD joinTime;
bool valid;
int matchType;
@ -35,7 +38,7 @@ namespace Components
// Party-specific stuff
DWORD requestTime;
bool awaitingPlaylist;
bool awaitingPlaylist;
};
static JoinContainer Container;