ConnectAnnounce: clean up + add to sm_settings

This commit is contained in:
Dogan 2019-01-16 14:25:57 +01:00
parent c89e6f8235
commit 9196f8fcb6

View File

@ -17,7 +17,6 @@ Handle g_hCustomMessageFile;
Handle g_hCustomMessageFile2; Handle g_hCustomMessageFile2;
bool g_bHideCsays[MAXPLAYERS + 1] = { false, ... }; bool g_bHideCsays[MAXPLAYERS + 1] = { false, ... };
bool g_bHideCsaysHooked = false;
Handle g_hCookieHideCsays = null; Handle g_hCookieHideCsays = null;
#define MSGLENGTH 100 #define MSGLENGTH 100
@ -56,32 +55,27 @@ public void OnPluginStart()
RegAdminCmd("sm_joinmsg", Command_JoinMsg, ADMFLAG_CUSTOM1, "Sets a custom message which will be shown upon connecting to the server"); RegAdminCmd("sm_joinmsg", Command_JoinMsg, ADMFLAG_CUSTOM1, "Sets a custom message which will be shown upon connecting to the server");
RegAdminCmd("sm_resetjoinmsg", Command_ResetJoinMsg, ADMFLAG_CUSTOM1, "Resets your custom connect message"); RegAdminCmd("sm_resetjoinmsg", Command_ResetJoinMsg, ADMFLAG_CUSTOM1, "Resets your custom connect message");
RegConsoleCmd("sm_hide_connect_csay", HideCsays, "Toggle blocking connect csay messages"); RegConsoleCmd("sm_hide_connect_csay", OnToggleHideCsays, "Toggle blocking connect csay messages");
g_hCookieHideCsays = RegClientCookie("csays_blocked", "are csays blocked", CookieAccess_Protected); g_hCookieHideCsays = RegClientCookie("csays_blocked", "are csays blocked", CookieAccess_Protected);
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide Connect Csays");
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action HideCsays(int client, int args) public void ToggleHideCsays(int client)
{ {
g_bHideCsays[client] = !g_bHideCsays[client]; g_bHideCsays[client] = !g_bHideCsays[client];
CheckHooks();
if(g_bHideCsays[client]) SetClientCookie(client, g_hCookieHideCsays, g_bHideCsays[client] ? "1" : "");
{ CPrintToChat(client, "{cyan}[AntiLenny] {white}%s", g_bHideCsays[client] ? "You hid Connect Csay Messages." : "You unhid Connect Csay Messages.");
ReplyToCommand(client, "You blocked Connect Csays");
SetClientCookie(client, g_hCookieHideCsays, "1");
}
else
{
ReplyToCommand(client, "You unblocked Connect Csays");
SetClientCookie(client, g_hCookieHideCsays, "");
}
return Plugin_Handled;
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientCookiesCached(int client) public void OnClientCookiesCached(int client)
{ {
char sBuffer[2]; char sBuffer[2];
@ -91,7 +85,6 @@ public void OnClientCookiesCached(int client)
if(sBuffer[0] != '\0') if(sBuffer[0] != '\0')
{ {
g_bHideCsays[client] = true; g_bHideCsays[client] = true;
g_bHideCsaysHooked = true;
} }
else else
{ {
@ -99,26 +92,85 @@ public void OnClientCookiesCached(int client)
} }
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
g_bHideCsays[client] = false; g_bHideCsays[client] = false;
CheckHooks();
} }
public void CheckHooks() //----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleHideCsays(int client, int args)
{ {
bool bShouldHook = false; ToggleHideCsays(client);
return Plugin_Handled;
}
for(int i = 1; i <= MaxClients; i++) //----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client)
{
Menu menu = new Menu(MenuHandler_MainMenu);
menu.SetTitle("ConnectCsay Settings", client);
char sBuffer[128];
Format(sBuffer, sizeof(sBuffer), "Hiding Connect Csays: %s", g_bHideCsays[client] ? "Enabled" : "Disabled");
menu.AddItem("0", sBuffer);
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{
switch(action)
{ {
if(g_bHideCsays[i]) case(CookieMenuAction_DisplayOption):
{ {
bShouldHook = true; Format(buffer, maxlen, "ConnectAnnounce", client);
break; }
case(CookieMenuAction_SelectOption):
{
ShowSettingsMenu(client);
} }
} }
}
g_bHideCsaysHooked = bShouldHook; //----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case(MenuAction_Select):
{
switch(selection)
{
case(0): ToggleHideCsays(client);
}
ShowSettingsMenu(client);
}
case(MenuAction_Cancel):
{
ShowCookieMenu(client);
}
case(MenuAction_End):
{
delete menu;
}
}
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------