Skip to content

Commit

Permalink
Less errors in console
Browse files Browse the repository at this point in the history
* Fixed error when clicking "Continue" in Motd UI
* Fixed timeout error in CloseAllMenus
* Prevent map info from showing up when clicking "Continue" in Motd UI
  • Loading branch information
DosMike committed Jul 29, 2021
1 parent bcf07a7 commit 10af3da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions addons/sourcemod/scripting/include/motdmenu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#define MOTD_MENU

#define MOTDMENU_VERSION_YEAR 21
#define MOTDMENU_VERSION_WEEK 26
#define MOTDMENU_VERSION_BUILD 'c'
#define MOTDMENU_VERSION "21w26c"
#define MOTDMENU_VERSION_WEEK 30
#define MOTDMENU_VERSION_BUILD 'a'
#define MOTDMENU_VERSION "21w30a"

/**
* A mapper that provides an image path for the motd browser for the specified menu item
Expand Down
37 changes: 29 additions & 8 deletions addons/sourcemod/scripting/motdmenu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Database g_database;
bool g_bDBconnected;
bool g_bEngineIsTF2;
ConVar g_cvarVersion;

// enum taken from dynamic_motd
enum /* Ep2vMOTDCmd */ {
Expand Down Expand Up @@ -101,6 +102,11 @@ public void OnPluginStart() {
if (!strlen(g_motdmenuwwwbase))
ThrowError("baseurl in config must be set!");

// for server admins i guess
g_cvarVersion = CreateConVar("motdmenu_version", MOTDMENU_VERSION, "Version of MotdMenus running on the server (Read Only)", FCVAR_DONTRECORD|FCVAR_CHEAT);
g_cvarVersion.AddChangeHook(versionCvarChangeHook);
versionCvarChangeHook(g_cvarVersion,"","");

// hookeroo

g_bEngineIsTF2 = GetEngineVersion() == Engine_TF2;
Expand All @@ -122,6 +128,12 @@ public void OnPluginStart() {
PrintToChatAll("[MotdMenu] Version %s was loaded", MOTDMENU_VERSION);
}

public void versionCvarChangeHook(ConVar convar, const char[] oldValue, const char[] newValue) {
if (!StrEqual(newValue, MOTDMENU_VERSION)) {
g_cvarVersion.SetString(MOTDMENU_VERSION);
}
}

public void OnPluginEnd() {
NukeEntries();
}
Expand Down Expand Up @@ -264,7 +276,7 @@ public Action UserMsg_VGUIMenu(UserMsg msg_id, BfRead msg, const int[] players,
}

public Action Event_ClosedHtmlpage(int client, const char[] command, int argc) {
Impl_CancelMotdMenu(client, _, MenuCancel_Exit);
Impl_CancelMotdMenu(client, true, MenuCancel_Exit);
return Plugin_Continue;
}

Expand All @@ -273,18 +285,20 @@ public Action Event_ClosedHtmlpage(int client, const char[] command, int argc) {
*/
void MenuActionIndirect(SMenuExtra mex, MenuAction action, int param1, int param2) {
if (!(mex.filter & action)) return; //action was not subscribed to
//if a menu is cancelled/interacted with, it usually ends afterwards
bool menuEnded, playSound;
int endReason, endP2;
//determin the proper menu end action and context to play for this action (if any)
// using isvalidhanle is ok since the callback can delete the menu
playSound = (!(mex.handle.OptionFlags & MENUFLAG_NO_SOUND)); //this has to be done first in case the menu is immediately exited

//perform primary action
Call_StartFunction(mex.owner, mex.callback);
Call_PushCell(mex.handle);
Call_PushCell(action);
Call_PushCell(param1);
Call_PushCell(param2);
Call_Finish();
//if a menu is cancelled/interacted with, it usually ends afterwards
bool menuEnded, playSound;
int endReason, endP2;
//determin the proper menu end action and context to play for this action (if any)
playSound = (!(mex.handle.OptionFlags & MENUFLAG_NO_SOUND));
switch (action) {
case MenuAction_Cancel: {
if (param2 == MenuCancel_Exit) {
Expand Down Expand Up @@ -346,14 +360,21 @@ static void Impl_CancelMotdMenu(int client, bool closePanel=false, int exitcance
}
}
clientActiveMotdMenu[client] = null;
if (closePanel) CloseMOTDPanel(client);
if (closePanel) {
CloseMOTDPanel(client);
RequestFrame(CloseMapInfoPanel, client);
}
NukeEntries(client);
}
}
static void CloseMOTDPanel(int client) {
if (!Client_IsValid(client)) return;
ShowVGUIPanel(client, "info", _, false);
}
static void CloseMapInfoPanel(int client) {
if (!Client_IsValid(client)) return;
ShowVGUIPanel(client, "mapinfo", _, false);
}
static void ShowMOTDPanelEx(int client, const char[] title, const char[] msg, int motdpanel_type, int cmd = Cmd_None, bool big=false) {
KeyValues kv = new KeyValues("data");
kv.SetString("title", title);
Expand Down Expand Up @@ -736,7 +757,7 @@ public any Native_CloseAllMenus(Handle plugin, int args) {
for (int i = MenuExtra.Length-1; i >= 0; i--) {
MenuExtra.GetArray(i, mex, sizeof(SMenuExtra));
if (mex.owner != plugin) continue;
for (int c=1;c<MaxClients;i++)
for (int c=1;c<MaxClients;c++)
if (clientActiveMotdMenu[c]==mex.handle) {
clientActiveMotdMenu[c]=null;
CloseMOTDPanel(c);
Expand Down
2 changes: 1 addition & 1 deletion web/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'rcon_code.php';

$menuTitle = 'MOTD Menu';
$supprtedPluginVersions = [ '21w26b','21w26c' ];
$supprtedPluginVersions = [ '21w26b','21w26c','21w30a' ];

//static data - taken from source mod 'menus.inc'

Expand Down

0 comments on commit 10af3da

Please sign in to comment.