cleanup + add server rpc info
This commit is contained in:
parent
2db853c4c1
commit
f2fb484b57
@ -42,6 +42,8 @@ namespace discord
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.startTimestamp = 0;
|
||||
discord_presence.largeImageKey = SELECT_VALUE("menu_singleplayer", "menu_multiplayer");
|
||||
discord_presence.largeImageText = "";
|
||||
discord_presence.smallImageKey = "";
|
||||
|
||||
discord_presence.matchSecret = "";
|
||||
discord_presence.joinSecret = "";
|
||||
@ -57,27 +59,25 @@ namespace discord
|
||||
else
|
||||
{
|
||||
static char details[0x80] = {0};
|
||||
const auto map = game::Dvar_FindVar("mapname")->current.string;
|
||||
const auto key = utils::string::va("PRESENCE_%s%s", SELECT_VALUE("SP_", ""), map);
|
||||
const char* mapname = map;
|
||||
const auto mapname = game::Dvar_FindVar("mapname")->current.string;
|
||||
const auto presence_key = utils::string::va("PRESENCE_%s%s", SELECT_VALUE("SP_", ""), mapname);
|
||||
const char* clean_mapname = mapname;
|
||||
|
||||
if (game::DB_XAssetExists(game::ASSET_TYPE_LOCALIZE, key) && !game::DB_IsXAssetDefault(game::ASSET_TYPE_LOCALIZE, key))
|
||||
if (game::DB_XAssetExists(game::ASSET_TYPE_LOCALIZE, presence_key) && !game::DB_IsXAssetDefault(game::ASSET_TYPE_LOCALIZE, presence_key))
|
||||
{
|
||||
mapname = game::UI_SafeTranslateString(key);
|
||||
clean_mapname = game::UI_SafeTranslateString(presence_key);
|
||||
}
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
static char clean_gametype[0x80] = {0};
|
||||
const auto gametype = game::UI_GetGameTypeDisplayName(
|
||||
game::Dvar_FindVar("g_gametype")->current.string);
|
||||
utils::string::strip(gametype,
|
||||
clean_gametype, sizeof(clean_gametype));
|
||||
strcpy_s(details, 0x80, utils::string::va("%s on %s", clean_gametype, mapname));
|
||||
const auto gametype = game::UI_GetGameTypeDisplayName(game::Dvar_FindVar("g_gametype")->current.string);
|
||||
utils::string::strip(gametype, clean_gametype, sizeof(clean_gametype));
|
||||
strcpy_s(details, 0x80, utils::string::va("%s on %s", clean_gametype, clean_mapname));
|
||||
|
||||
static char clean_hostname[0x80] = {0};
|
||||
utils::string::strip(game::Dvar_FindVar("sv_hostname")->current.string,
|
||||
clean_hostname, sizeof(clean_hostname));
|
||||
utils::string::strip(game::Dvar_FindVar("sv_hostname")->current.string, clean_hostname, sizeof(clean_hostname));
|
||||
|
||||
auto max_clients = party::server_client_count();
|
||||
|
||||
if (game::SV_Loaded())
|
||||
@ -121,18 +121,38 @@ namespace discord
|
||||
|
||||
discord_presence.partyMax = max_clients;
|
||||
discord_presence.state = clean_hostname;
|
||||
discord_presence.largeImageKey = map;
|
||||
|
||||
if (!fastfiles::is_stock_map(map))
|
||||
auto discord_map_image_asset = mapname;
|
||||
if (!fastfiles::is_stock_map(mapname))
|
||||
{
|
||||
discord_presence.largeImageKey = "menu_multiplayer";
|
||||
discord_map_image_asset = "menu_multiplayer";
|
||||
}
|
||||
|
||||
auto discord_server_info = party::get_discord_server_image();
|
||||
if (!discord_server_info.empty())
|
||||
{
|
||||
// prioritize server image as large image instead
|
||||
discord_presence.smallImageKey = discord_map_image_asset;
|
||||
discord_presence.largeImageKey = discord_server_info.data();
|
||||
discord_server_info = party::get_discord_server_text();
|
||||
if (!discord_server_info.empty())
|
||||
{
|
||||
discord_presence.largeImageText = discord_server_info.data();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
discord_presence.smallImageKey = "";
|
||||
discord_presence.largeImageKey = discord_map_image_asset;
|
||||
discord_presence.largeImageText = "";
|
||||
}
|
||||
}
|
||||
else if (game::environment::is_sp())
|
||||
{
|
||||
discord_presence.state = "";
|
||||
discord_presence.largeImageKey = map;
|
||||
strcpy_s(details, 0x80, mapname);
|
||||
discord_presence.largeImageKey = mapname;
|
||||
discord_presence.smallImageKey = "";
|
||||
strcpy_s(details, 0x80, clean_mapname);
|
||||
}
|
||||
|
||||
discord_presence.details = details;
|
||||
|
@ -767,6 +767,16 @@ namespace party
|
||||
return party::sv_maxclients;
|
||||
}
|
||||
|
||||
std::string get_discord_server_image()
|
||||
{
|
||||
return saved_info_response.info_string.get("sv_discordImageUrl");
|
||||
}
|
||||
|
||||
std::string get_discord_server_text()
|
||||
{
|
||||
return saved_info_response.info_string.get("sv_discordImageText");
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -777,7 +787,7 @@ namespace party
|
||||
return;
|
||||
}
|
||||
|
||||
// detour CL_Disconnect to clear motd
|
||||
// clear motd & usermap
|
||||
cl_disconnect_hook.create(0x12F080_b, cl_disconnect_stub);
|
||||
|
||||
if (game::environment::is_mp())
|
||||
@ -965,7 +975,7 @@ namespace party
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
sv_say_name = dvars::register_string("sv_sayName", "console", game::DvarFlags::DVAR_FLAG_NONE, "");
|
||||
sv_say_name = dvars::register_string("sv_sayName", "console", game::DvarFlags::DVAR_FLAG_NONE, "Custom name for RCON console");
|
||||
}, scheduler::pipeline::main);
|
||||
|
||||
command::add("tell", [](const command::params& params)
|
||||
@ -1060,6 +1070,8 @@ namespace party
|
||||
info.set("sv_running", utils::string::va("%i", get_dvar_bool("sv_running") && !game::VirtualLobby_Loaded()));
|
||||
info.set("dedicated", utils::string::va("%i", get_dvar_bool("dedicated")));
|
||||
info.set("sv_wwwBaseUrl", get_dvar_string("sv_wwwBaseUrl"));
|
||||
info.set("sv_discordImageUrl", get_dvar_string("sv_discordImageUrl"));
|
||||
info.set("sv_discordImageText", get_dvar_string("sv_discordImageText"));
|
||||
|
||||
if (!fastfiles::is_stock_map(mapname))
|
||||
{
|
||||
|
@ -16,6 +16,8 @@ namespace party
|
||||
void clear_sv_motd();
|
||||
game::netadr_s get_state_host();
|
||||
int server_client_count();
|
||||
std::string get_discord_server_image();
|
||||
std::string get_discord_server_text();
|
||||
|
||||
int get_client_num_by_name(const std::string& name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user