Skip to content

Commit 38f3190

Browse files
committed
Fixed player death webhook not displaying player name.
1 parent 4d9df51 commit 38f3190

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//---------------------------------------------------------------------------------
1515
// Core P2:MM ConVars | These shouldn't be modified manually. Hidden to prevent accidentally breaking something.
1616
//---------------------------------------------------------------------------------
17-
ConVar p2mm_loop("p2mm_loop", "0", FCVAR_HIDDEN, "Flag if P2MMLoop should be looping.");
17+
ConVar p2mm_loop("p2mm_loop", "0", FCVAR_HIDDEN, "Flag if P2MMLoop should be looping."); //! REMOVE THIS AT SOME POINT!!!
1818
ConVar p2mm_lastmap("p2mm_lastmap", "", FCVAR_HIDDEN, "Last map recorded for the Last Map system.");
1919
ConVar p2mm_splitscreen("p2mm_splitscreen", "0", FCVAR_HIDDEN, "Flag for the main menu buttons and launcher to start in splitscreen or not.");
2020

discordrpc.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ static void WebhookCheck(IConVar* var, const char* pOldValue, float flOldValue)
103103
}
104104
}
105105
}
106-
ConVar p2mm_discord_webhooks("p2mm_discord_webhooks", "0", FCVAR_NOTIFY, "Enable or disable webhooks been the P2:MM Server and Discord.", true, 0, true, 1, WebhookCheck);
107-
ConVar p2mm_discord_webhooks_url("p2mm_discord_webhooks_url", "", FCVAR_HIDDEN, "Channel webhook URL to send messages to. Should be set in launcher, not here.");
106+
ConVar p2mm_discord_webhooks("p2mm_discord_webhooks", "0", FCVAR_NOTIFY, "Enable or disable webhooks between the P2:MM Server and Discord.", true, 0, true, 1, WebhookCheck);
107+
ConVar p2mm_discord_webhooks_url("p2mm_discord_webhooks_url", "", FCVAR_HIDDEN, "Channel webhook URL. Recommended to be set in launcher, not here.");
108108
ConVar p2mm_discord_webhooks_defaultfooter("p2mm_discord_webhooks_defaultfooter", "1", FCVAR_NONE, "Enable or disable the default embed footer for webhooks.", true, 0, true, 1);
109109
ConVar p2mm_discord_webhooks_customfooter("p2mm_discord_webhooks_customfooter", "", FCVAR_NONE, "Set a custom embed footer for webhook messages.");
110110

111-
// Parameters that are sent through to the Discord webhook
111+
// Parameters that are sent through to the Discord webhook.
112112
struct WebHookParams
113113
{
114114
std::string title = "Unknown";
@@ -117,11 +117,12 @@ struct WebHookParams
117117
std::string footer;
118118
};
119119

120-
// Generates a footer with the player count with max allowed client count and also the current map name
120+
// Generates a footer with the player count with max allowed client count and also the current map name.
121121
static std::string DefaultFooter()
122122
{
123123
// g_pGlobals doesn't exist yet at certain situations, so return a blank string.
124-
if (!g_pGlobals) return "";
124+
if (!g_pGlobals)
125+
return "";
125126

126127
const std::string curPlayerCount = std::to_string(CURPLAYERCOUNT());
127128
const std::string maxPlayerCount = std::to_string(MAX_PLAYERS);

p2mm.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ void CP2MMServerPlugin::LevelInit(char const* pMapName)
566566

567567
if (!g_P2MMServerPlugin.m_bSeenFirstRunPrompt) return;
568568

569-
std::string changeMapStr = std::string("The server has changed the map to: `" + std::string(CURMAPFILENAME) + "`");
570-
g_pDiscordIntegration->SendWebHookEmbed("Server", changeMapStr, EMBED_COLOR_SERVER, false);
569+
const auto changeMapStr = std::string("The server has changed the map to: `" + std::string(CURMAPFILENAME) + "`");
570+
CDiscordIntegration::SendWebHookEmbed("Server", changeMapStr, EMBED_COLOR_SERVER, false);
571571

572572
// Update Discord RPC to update current map information.
573573
CDiscordIntegration::UpdateDiscordRPC();
@@ -780,12 +780,12 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
780780
// Event called when a player dies, "player_death" returns:
781781
/*
782782
"userid" "int" // user ID who died
783-
"attacker" "short" // user ID who killed
783+
"attacker" "int" // user ID who killed
784784
*/
785785
if (FStrEq(event->GetName(), "player_death"))
786786
{
787787
int userid = event->GetInt("userid");
788-
short attacker = event->GetInt("attacker");
788+
int attacker = event->GetInt("attacker");
789789
int entindex = UserIDToPlayerIndex(userid);
790790

791791
if (g_pScriptVM)
@@ -796,13 +796,14 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
796796
if (HSCRIPT playerHandle = INDEXHANDLE(entindex))
797797
{
798798
g_pScriptVM->Call<HSCRIPT>(od_func, nullptr, false, nullptr, playerHandle);
799-
g_pDiscordIntegration->SendWebHookEmbed(std::string(GetPlayerName(entindex) + std::string(" Died!")), "", EMBED_COLOR_PLAYERDEATH);
799+
std::string playerName = GetPlayerName(entindex);
800+
CDiscordIntegration::SendWebHookEmbed(playerName + std::string(" Died!"), "", EMBED_COLOR_PLAYERDEATH);
800801
}
801802
}
802803

803804
// Handle VScript game event function
804805
if (HSCRIPT geFunc = g_pScriptVM->LookupFunction("GEPlayerDeath"))
805-
g_pScriptVM->Call<int, short, int>(geFunc, nullptr, false, nullptr, userid, attacker, entindex);
806+
g_pScriptVM->Call<int, int, int>(geFunc, nullptr, false, nullptr, userid, attacker, entindex);
806807
}
807808

808809
if (spewInfo)
@@ -869,7 +870,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
869870
if (HSCRIPT geFunc = g_pScriptVM->LookupFunction("GEPlayerConnect"))
870871
{
871872
g_pScriptVM->Call<const char*, int, int, const char*, const char*, const char*, bool, int>(geFunc, nullptr, false, nullptr, name, index, userid, xuid, networkid, address, bot, entindex);
872-
g_pDiscordIntegration->SendWebHookEmbed(std::string(name + std::string(" Joined!")), std::string(name + std::string(" joined the server!")));
873+
CDiscordIntegration::SendWebHookEmbed(std::string(name + std::string(" Joined!")), std::string(name + std::string(" joined the server!")));
873874
}
874875
}
875876

@@ -964,7 +965,7 @@ void CP2MMServerPlugin::FireGameEvent(IGameEvent* event)
964965
pos += std::string("\\\\").length();
965966
}
966967
if (!chatMsg.starts_with("!"))
967-
g_pDiscordIntegration->SendWebHookEmbed(playerName, chatMsg);
968+
CDiscordIntegration::SendWebHookEmbed(playerName, chatMsg);
968969
}
969970
}
970971

@@ -1048,7 +1049,7 @@ extern void UpdateMapsList();
10481049
void CP2MMServerPlugin::LevelShutdown(void)
10491050
{
10501051
P2MMLog(INFO, true, "Level Shutdown! Map: %s", CURMAPFILENAME);
1051-
p2mm_loop.SetValue("0"); // REMOVE THIS at some point...
1052+
p2mm_loop.SetValue("0"); //! REMOVE THIS at some point...
10521053
UpdateMapsList(); // Update the maps list for p2mm_map.
10531054
// Update Discord RPC to update the level information or to say the host is on the main menu.
10541055
CDiscordIntegration::UpdateDiscordRPC();

vscript.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Purpose: Portal 2: Multiplayer Mod server plugin
55
//
66
//===========================================================================//
7-
#pragma once
87

98
#include "sdk.hpp"
109
#include "commands.hpp"
@@ -16,7 +15,7 @@
1615
//---------------------------------------------------------------------------------
1716
// Purpose: Logging for the P2MM VScript. The log message must be passed as a string or it will error.
1817
//---------------------------------------------------------------------------------
19-
static void printlP2MM(int level, bool dev, const char* pMsgFormat)
18+
static void printlP2MM(const int level, const bool dev, const char* pMsgFormat)
2019
{
2120
if (dev && !p2mm_developer.GetBool()) return;
2221

@@ -77,8 +76,7 @@ static void InitializeEntity(HSCRIPT ent)
7776
{
7877
static uintptr_t func = (uintptr_t)Memory::Scanner::Scan<void*>(SERVERDLL, "E8 ?? ?? ?? ?? 8B 4D 18 8B 57 5C", 1);
7978
static auto GetCBaseEntityScriptDesc = reinterpret_cast<ScriptClassDesc_t* (__cdecl*)()>(*reinterpret_cast<uintptr_t*>(func) + func + sizeof(func));
80-
void* pEntity = reinterpret_cast<void*>(g_pScriptVM->GetInstanceValue(ent, GetCBaseEntityScriptDesc()));;
81-
if (pEntity)
79+
if (void* pEntity = reinterpret_cast<void*>(g_pScriptVM->GetInstanceValue(ent, GetCBaseEntityScriptDesc())))
8280
{
8381
g_pServerTools->DispatchSpawn(pEntity);
8482

@@ -102,8 +100,7 @@ static void SendToChat(int playerIndex, const char* msg)
102100
player_info_t playerInfo;
103101
if (engineServer->GetPlayerInfo(i, &playerInfo))
104102
{
105-
CBasePlayer* pPlayer = UTIL_PlayerByIndex(i);
106-
if (pPlayer)
103+
if (CBasePlayer* pPlayer = UTIL_PlayerByIndex(i))
107104
{
108105
UTIL_ClientPrint(pPlayer, HUD_PRINTTALK, msg);
109106
}
@@ -175,7 +172,7 @@ static void CallFirstRunPrompt()
175172
// Specifying no playerIndex or 0 sends to all players.
176173
// Supports printing localization strings but those that require formatting can't be formatted.
177174
//---------------------------------------------------------------------------------
178-
void ConsolePrint(int playerIndex, const char* msg)
175+
static void ConsolePrint(int playerIndex, const char* msg)
179176
{
180177
if (!msg) return;
181178

@@ -186,8 +183,7 @@ void ConsolePrint(int playerIndex, const char* msg)
186183
player_info_t playerInfo;
187184
if (engineServer->GetPlayerInfo(i, &playerInfo))
188185
{
189-
CBasePlayer* pPlayer = UTIL_PlayerByIndex(i);
190-
if (pPlayer)
186+
if (CBasePlayer* pPlayer = UTIL_PlayerByIndex(i))
191187
{
192188
UTIL_ClientPrint(pPlayer, HUD_PRINTCONSOLE, msg);
193189
}
@@ -212,7 +208,7 @@ void ConsolePrint(int playerIndex, const char* msg)
212208
// Specifying no playerIndex or 0 sends to all players.
213209
// Supports printing localization strings but those that require formatting can't be formatted.
214210
//---------------------------------------------------------------------------------
215-
void ClientPrint(int playerIndex, const char* msg)
211+
static void ClientPrint(int playerIndex, const char* msg)
216212
{
217213
if (!msg) return;
218214

@@ -223,8 +219,7 @@ void ClientPrint(int playerIndex, const char* msg)
223219
player_info_t playerInfo;
224220
if (engineServer->GetPlayerInfo(i, &playerInfo))
225221
{
226-
CBasePlayer* pPlayer = UTIL_PlayerByIndex(i);
227-
if (pPlayer)
222+
if (CBasePlayer* pPlayer = UTIL_PlayerByIndex(i))
228223
{
229224
UTIL_ClientPrint(pPlayer, HUD_PRINTTALK, msg);
230225
}
@@ -252,7 +247,7 @@ void ClientPrint(int playerIndex, const char* msg)
252247
// Vector is used to consolidate x, y, and channel parameters together.
253248
// Vector is used to consolidate fadeinTime, fadeoutTime, and holdTime.
254249
//---------------------------------------------------------------------------------
255-
void HudPrint
250+
static void HudPrint
256251
(
257252
int playerIndex, const char* msg,
258253
Vector posChannel, int effect, float fxTime,
@@ -282,7 +277,7 @@ void HudPrint
282277

283278
if (!playerIndex)
284279
{
285-
UTIL_HudMessage(NULL, hudTextParams, msg);
280+
UTIL_HudMessage(nullptr, hudTextParams, msg);
286281
return;
287282
}
288283

@@ -299,15 +294,15 @@ void HudPrint
299294
//---------------------------------------------------------------------------------
300295
// Purpose: Self-explanatory.
301296
//---------------------------------------------------------------------------------
302-
int GetMaxPlayers()
297+
static int GetMaxPlayers()
303298
{
304299
return MAX_PLAYERS;
305300
}
306301

307302
//---------------------------------------------------------------------------------
308303
// Purpose: Enable or disable displaying the score board for a player.
309304
//---------------------------------------------------------------------------------
310-
void ShowScoreboard(int playerIndex, bool bEnable)
305+
static void ShowScoreboard(int playerIndex, bool bEnable)
311306
{
312307
CBasePlayer__ShowViewPortPanel(playerIndex, "scores", bEnable);
313308
}

0 commit comments

Comments
 (0)