Untitled diff

Created Diff never expires
91 removals
292 lines
98 additions
301 lines
/*
// Donor Menu (C) 2014 Sarabveer Singh <sarabveer@sarabveer.me>
* In-game Help Menu
//
* Written by chundo (chundo@mefightclub.com)
// Donor Menu is free software: you can redistribute it and/or modify
*
// it under the terms of the GNU General Public License as published by
* Licensed under the GPL version 2 or above
// the Free Software Foundation, per version 3 of the License.
*/
//
// Donor Menu is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Donor Menu. If not, see <http://www.gnu.org/licenses/>.
//
// This file incorporates work covered by the following copyright(s):
//
// Help Menu 0.3
// Copyright (C) 2008 chundo <chundo@mefightclub.com>
// Licensed under GNU GPL version 3
// Page: <https://forums.alliedmods.net/showthread.php?p=637467>
//


#pragma semicolon 1
#pragma semicolon 1


#include <sourcemod>
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <updater>


#define PLUGIN_VERSION "0.3"
#define PLUGIN_VERSION "1.4"
#define UPDATE_URL "https://raw.githubusercontent.com/Sarabveer/SM-Plugins/master/donormenu/updater.txt"


enum ChatCommand {
enum ChatCommand {
String:command[32],
String:command[32],
String:description[255]
String:description[255]
}
}


enum HelpMenuType {
enum DonorMenuType {
HelpMenuType_List,
DonorMenuType_List,
HelpMenuType_Text
DonorMenuType_Text
}
}


enum HelpMenu {
enum DonorMenu {
String:name[32],
String:dname[32],
String:title[128],
String:title[128],
HelpMenuType:type,
DonorMenuType:type,
Handle:items,
Handle:items,
itemct
itemct
}
}


// CVars
// CVars
new Handle:g_cvarWelcome = INVALID_HANDLE;
new Handle:g_cvarWelcome = INVALID_HANDLE;
new Handle:g_cvarAdmins = INVALID_HANDLE;
new Handle:g_cvarAdmins = INVALID_HANDLE;


// Help menus
// Help menus
new Handle:g_helpMenus = INVALID_HANDLE;
new Handle:g_DonorMenus = INVALID_HANDLE;

// Map cache
new Handle:g_mapArray = INVALID_HANDLE;
new g_mapSerial = -1;


// Config parsing
// Config parsing
new g_configLevel = -1;
new g_configLevel = -1;


public Plugin:myinfo =
public Plugin:myinfo =
{
{
name = "In-game Help Menu",
name = "[ANY] Donor Menu",
author = "chundo",
author = "Sarabveer(VEER™)",
description = "Display a help menu to users",
description = "Display a Donor menu to users",
version = PLUGIN_VERSION,
version = PLUGIN_VERSION,
url = "http://www.mefightclub.com"
url = "https://www.sarabveer.me"
};
}


public OnPluginStart() {
public OnPluginStart() {
CreateConVar("sm_helpmenu_version", PLUGIN_VERSION, "Help menu version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
CreateConVar("sm_donormenu_version", PLUGIN_VERSION, "Donor menu version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_cvarWelcome = CreateConVar("sm_helpmenu_welcome", "1", "Show welcome message to newly connected users.", FCVAR_PLUGIN);
g_cvarWelcome = CreateConVar("sm_donormenu_welcome", "0", "Show welcome message to newly connected users.", FCVAR_PLUGIN);
g_cvarAdmins = CreateConVar("sm_helpmenu_admins", "1", "Show a list of online admins in the menu.", FCVAR_PLUGIN);
g_cvarAdmins = CreateConVar("sm_donormenu_admins", "0", "Show a list of online admins in the menu.", FCVAR_PLUGIN);
RegConsoleCmd("sm_helpmenu", Command_HelpMenu, "Display the help menu.", FCVAR_PLUGIN);
RegAdminCmd("sm_donor", Command_DonorMenu, ADMFLAG_KICK, "Display the Donor menu.");

new String:hc[PLATFORM_MAX_PATH];
new String:hc[PLATFORM_MAX_PATH];
BuildPath(Path_SM, hc, sizeof(hc), "configs/helpmenu.cfg");
BuildPath(Path_SM, hc, sizeof(hc), "configs/donors.cfg");
g_mapArray = CreateArray(32);
ParseConfigFile(hc);
ParseConfigFile(hc);


AutoExecConfig(false);
AutoExecConfig(false);
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}

public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
}


public OnMapStart() {
public OnMapStart() {
new String:hc[PLATFORM_MAX_PATH];
new String:hc[PLATFORM_MAX_PATH];
BuildPath(Path_SM, hc, sizeof(hc), "configs/helpmenu.cfg");
BuildPath(Path_SM, hc, sizeof(hc), "configs/donors.cfg");
ParseConfigFile(hc);
ParseConfigFile(hc);
}
}


public OnClientPutInServer(client) {
public OnClientPutInServer(client) {
if (GetConVarBool(g_cvarWelcome))
if (GetConVarBool(g_cvarWelcome))
CreateTimer(30.0, Timer_WelcomeMessage, client);
CreateTimer(30.0, Timer_WelcomeMessage, client);
}
}


public Action:Timer_WelcomeMessage(Handle:timer, any:client) {
public Action:Timer_WelcomeMessage(Handle:timer, any:client) {
if (GetConVarBool(g_cvarWelcome) && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
if (GetConVarBool(g_cvarWelcome) && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
PrintToChat(client, "\x01[SM] For help, type \x04!helpmenu\x01 in chat");
PrintToChat(client, "\x04[SM] \x01For the Donor Menu, type \x04!donor\x01 in chat! \x04[Donor's Only]");
}
}


bool:ParseConfigFile(const String:file[]) {
bool:ParseConfigFile(const String:file[]) {
if (g_helpMenus != INVALID_HANDLE) {
if (g_DonorMenus != INVALID_HANDLE) {
ClearArray(g_helpMenus);
ClearArray(g_DonorMenus);
CloseHandle(g_helpMenus);
CloseHandle(g_DonorMenus);
g_helpMenus = INVALID_HANDLE;
g_DonorMenus = INVALID_HANDLE;
}
}


new Handle:parser = SMC_CreateParser();
new Handle:parser = SMC_CreateParser();
SMC_SetReaders(parser, Config_NewSection, Config_KeyValue, Config_EndSection);
SMC_SetReaders(parser, Config_NewSection, Config_KeyValue, Config_EndSection);
SMC_SetParseEnd(parser, Config_End);
SMC_SetParseEnd(parser, Config_End);


new line = 0;
new line = 0;
new col = 0;
new col = 0;
new String:error[128];
new String:error[128];
new SMCError:result = SMC_ParseFile(parser, file, line, col);
new SMCError:result = SMC_ParseFile(parser, file, line, col);
CloseHandle(parser);
CloseHandle(parser);


if (result != SMCError_Okay) {
if (result != SMCError_Okay) {
SMC_GetErrorString(result, error, sizeof(error));
SMC_GetErrorString(result, error, sizeof(error));
LogError("%s on line %d, col %d of %s", error, line, col, file);
LogError("%s on line %d, col %d of %s", error, line, col, file);
}
}


return (result == SMCError_Okay);
return (result == SMCError_Okay);
}
}


public SMCResult:Config_NewSection(Handle:parser, const String:section[], bool:quotes) {
public SMCResult:Config_NewSection(Handle:parser, const String:section[], bool:quotes) {
g_configLevel++;
g_configLevel++;
if (g_configLevel == 1) {
if (g_configLevel == 1) {
new hmenu[HelpMenu];
new hmenu[DonorMenu];
strcopy(hmenu[name], sizeof(hmenu[name]), section);
strcopy(hmenu[dname], sizeof(hmenu[dname]), section);
hmenu[items] = CreateDataPack();
hmenu[items] = CreateDataPack();
hmenu[itemct] = 0;
hmenu[itemct] = 0;
if (g_helpMenus == INVALID_HANDLE)
if (g_DonorMenus == INVALID_HANDLE)
g_helpMenus = CreateArray(sizeof(hmenu));
g_DonorMenus = CreateArray(sizeof(hmenu));
PushArrayArray(g_helpMenus, hmenu[0]);
PushArrayArray(g_DonorMenus, hmenu[0]);
}
}
return SMCParse_Continue;
return SMCParse_Continue;
}
}


public SMCResult:Config_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) {
public SMCResult:Config_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) {
new msize = GetArraySize(g_helpMenus);
new msize = GetArraySize(g_DonorMenus);
new hmenu[HelpMenu];
new hmenu[DonorMenu];
GetArrayArray(g_helpMenus, msize-1, hmenu[0]);
GetArrayArray(g_DonorMenus, msize-1, hmenu[0]);
switch (g_configLevel) {
switch (g_configLevel) {
case 1: {
case 1: {
if(strcmp(key, "title", false) == 0)
if(strcmp(key, "title", false) == 0)
strcopy(hmenu[title], sizeof(hmenu[title]), value);
strcopy(hmenu[title], sizeof(hmenu[title]), value);
if(strcmp(key, "type", false) == 0) {
if(strcmp(key, "type", false) == 0) {
if(strcmp(value, "text", false) == 0)
if(strcmp(value, "text", false) == 0)
hmenu[type] = HelpMenuType_Text;
hmenu[type] = DonorMenuType_Text;
else
else
hmenu[type] = HelpMenuType_List;
hmenu[type] = DonorMenuType_List;
}
}
}
}
case 2: {
case 2: {
WritePackString(hmenu[items], key);
WritePackString(hmenu[items], key);
WritePackString(hmenu[items], value);
WritePackString(hmenu[items], value);
hmenu[itemct]++;
hmenu[itemct]++;
}
}
}
}
SetArrayArray(g_helpMenus, msize-1, hmenu[0]);
SetArrayArray(g_DonorMenus, msize-1, hmenu[0]);
return SMCParse_Continue;
return SMCParse_Continue;
}
}
public SMCResult:Config_EndSection(Handle:parser) {
public SMCResult:Config_EndSection(Handle:parser) {
g_configLevel--;
g_configLevel--;
if (g_configLevel == 1) {
if (g_configLevel == 1) {
new hmenu[HelpMenu];
new hmenu[DonorMenu];
new msize = GetArraySize(g_helpMenus);
new msize = GetArraySize(g_DonorMenus);
GetArrayArray(g_helpMenus, msize-1, hmenu[0]);
GetArrayArray(g_DonorMenus, msize-1, hmenu[0]);
ResetPack(hmenu[items]);
ResetPack(hmenu[items]);
}
}
return SMCParse_Continue;
return SMCParse_Continue;
}
}


public Config_End(Handle:parser, bool:halted, bool:failed) {
public Config_End(Handle:parser, bool:halted, bool:failed) {
if (failed)
if (failed)
SetFailState("Plugin configuration error");
SetFailState("DonorMenu: Plugin Configuration Error");
}
}


public Action:Command_HelpMenu(client, args) {
public Action:Command_DonorMenu(client, args) {
Help_ShowMainMenu(client);
Help_ShowMainMenu(client);
return Plugin_Handled;
return Plugin_Handled;
}
}


Help_ShowMainMenu(client) {
Help_ShowMainMenu(client) {
new Handle:menu = CreateMenu(Help_MainMenuHandler);
new Handle:menu = CreateMenu(Help_MainMenuHandler);
SetMenuExitBackButton(menu, false);
SetMenuExitBackButton(menu, false);
SetMenuTitle(menu, "Help Menu\n ");
SetMenuTitle(menu, "Donor Menu\n ");
new msize = GetArraySize(g_helpMenus);
new msize = GetArraySize(g_DonorMenus);
new hmenu[HelpMenu];
new hmenu[DonorMenu];
new String:menuid[10];
new String:menuid[10];
for (new i = 0; i < msize; ++i) {
for (new i = 0; i < msize; ++i) {
Format(menuid, sizeof(menuid), "helpmenu_%d", i);
Format(menuid, sizeof(menuid), "DonorMenu_%d", i);
GetArrayArray(g_helpMenus, i, hmenu[0]);
GetArrayArray(g_DonorMenus, i, hmenu[0]);
AddMenuItem(menu, menuid, hmenu[name]);
AddMenuItem(menu, menuid, hmenu[dname]);
}
}
AddMenuItem(menu, "maplist", "Map Rotation");
if (GetConVarBool(g_cvarAdmins))
if (GetConVarBool(g_cvarAdmins))
AddMenuItem(menu, "admins", "List Online Admins");
AddMenuItem(menu, "admins", "List Online Admins");
DisplayMenu(menu, client, 30);
DisplayMenu(menu, client, 30);
}
}


public Help_MainMenuHandler(Handle:menu, MenuAction:action, param1, param2) {
public Help_MainMenuHandler(Handle:menu, MenuAction:action, param1, param2) {
if (action == MenuAction_End) {
if (action == MenuAction_End) {
CloseHandle(menu);
CloseHandle(menu);
} else if (action == MenuAction_Select) {
} else if (action == MenuAction_Select) {
new String:buf[64];
new msize = GetArraySize(g_DonorMenus);
new msize = GetArraySize(g_helpMenus);
if (param2 == msize) { // Admins
if (param2 == msize) { // Maps
new Handle:mapMenu = CreateMenu(Help_MenuHandler);
SetMenuExitBackButton(mapMenu, true);
ReadMapList(g_mapArray, g_mapSerial, "default");
Format(buf, sizeof(buf), "Current Rotation (%d maps)\n ", GetArraySize(g_mapArray));
SetMenuTitle(mapMenu, buf);
if (g_mapArray != INVALID_HANDLE) {
new mapct = GetArraySize(g_mapArray);
new String:mapname[64];
for (new i = 0; i < mapct; ++i) {
GetArrayString(g_mapArray, i, mapname, sizeof(mapname));
AddMenuItem(mapMenu, mapname, mapname, ITEMDRAW_DISABLED);
}
}
DisplayMenu(mapMenu, param1, 30);
} else if (param2 == msize+1) { // Admins
new Handle:adminMenu = CreateMenu(Help_MenuHandler);
new Handle:adminMenu = CreateMenu(Help_MenuHandler);
SetMenuExitBackButton(adminMenu, true);
SetMenuExitBackButton(adminMenu, true);
SetMenuTitle(adminMenu, "Online Admins\n ");
SetMenuTitle(adminMenu, "Online Admins\n ");
new maxc = GetMaxClients();
new maxc = GetMaxClients();
new String:aname[64];
new String:aname[64];
for (new i = 1; i < maxc; ++i) {
for (new i = 1; i < maxc; ++i) {
if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && (GetUserFlagBits(i) & ADMFLAG_GENERIC) == ADMFLAG_GENERIC) {
if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && (GetUserFlagBits(i) & ADMFLAG_GENERIC) == ADMFLAG_GENERIC) {
GetClientName(i, aname, sizeof(aname));
GetClientName(i, aname, sizeof(aname));
AddMenuItem(adminMenu, aname, aname, ITEMDRAW_DISABLED);
AddMenuItem(adminMenu, aname, aname, ITEMDRAW_DISABLED);
}
}
}
}
DisplayMenu(adminMenu, param1, 30);
DisplayMenu(adminMenu, param1, 30);
} else { // Menu from config file
} else { // Menu from config file
if (param2 <= msize) {
if (param2 <= msize) {
new hmenu[HelpMenu];
new hmenu[DonorMenu];
GetArrayArray(g_helpMenus, param2, hmenu[0]);
GetArrayArray(g_DonorMenus, param2, hmenu[0]);
new String:mtitle[512];
new String:mtitle[512];
Format(mtitle, sizeof(mtitle), "%s\n ", hmenu[title]);
Format(mtitle, sizeof(mtitle), "%s\n ", hmenu[title]);
if (hmenu[type] == HelpMenuType_Text) {
if (hmenu[type] == DonorMenuType_Text) {
new Handle:cpanel = CreatePanel();
new Handle:cpanel = CreatePanel();
SetPanelTitle(cpanel, mtitle);
SetPanelTitle(cpanel, mtitle);
new String:text[128];
new String:text[128];
new String:junk[128];
new String:junk[128];
for (new i = 0; i < hmenu[itemct]; ++i) {
for (new i = 0; i < hmenu[itemct]; ++i) {
ReadPackString(hmenu[items], junk, sizeof(junk));
ReadPackString(hmenu[items], junk, sizeof(junk));
ReadPackString(hmenu[items], text, sizeof(text));
ReadPackString(hmenu[items], text, sizeof(text));
DrawPanelText(cpanel, text);
DrawPanelText(cpanel, text);
}
}
for (new j = 0; j < 7; ++j)
for (new j = 0; j < 7; ++j)
DrawPanelItem(cpanel, " ", ITEMDRAW_NOTEXT);
DrawPanelItem(cpanel, " ", ITEMDRAW_NOTEXT);
DrawPanelText(cpanel, " ");
DrawPanelText(cpanel, " ");
DrawPanelItem(cpanel, "Back", ITEMDRAW_CONTROL);
DrawPanelItem(cpanel, "Back", ITEMDRAW_CONTROL);
DrawPanelItem(cpanel, " ", ITEMDRAW_NOTEXT);
DrawPanelItem(cpanel, " ", ITEMDRAW_NOTEXT);
DrawPanelText(cpanel, " ");
DrawPanelText(cpanel, " ");
DrawPanelItem(cpanel, "Exit", ITEMDRAW_CONTROL);
DrawPanelItem(cpanel, "Exit", ITEMDRAW_CONTROL);
ResetPack(hmenu[items]);
ResetPack(hmenu[items]);
SendPanelToClient(cpanel, param1, Help_MenuHandler, 30);
SendPanelToClient(cpanel, param1, Help_MenuHandler, 30);
CloseHandle(cpanel);
CloseHandle(cpanel);
} else {
} else {
new Handle:cmenu = CreateMenu(Help_CustomMenuHandler);
new Handle:cmenu = CreateMenu(Help_CustomMenuHandler);
SetMenuExitBackButton(cmenu, true);
SetMenuExitBackButton(cmenu, true);
SetMenuTitle(cmenu, mtitle);
SetMenuTitle(cmenu, mtitle);
new String:cmd[128];
new String:cmd[128];
new String:desc[128];
new String:desc[128];
for (new i = 0; i < hmenu[itemct]; ++i) {
for (new i = 0; i < hmenu[itemct]; ++i) {
ReadPackString(hmenu[items], cmd, sizeof(cmd));
ReadPackString(hmenu[items], cmd, sizeof(cmd));
ReadPackString(hmenu[items], desc, sizeof(desc));
ReadPackString(hmenu[items], desc, sizeof(desc));
new drawstyle = ITEMDRAW_DEFAULT;
new drawstyle = ITEMDRAW_DEFAULT;
if (strlen(cmd) == 0)
if (strlen(cmd) == 0)
drawstyle = ITEMDRAW_DISABLED;
drawstyle = ITEMDRAW_DISABLED;
AddMenuItem(cmenu, cmd, desc, drawstyle);
AddMenuItem(cmenu, cmd, desc, drawstyle);
}
}
ResetPack(hmenu[items]);
ResetPack(hmenu[items]);
DisplayMenu(cmenu, param1, 30);
DisplayMenu(cmenu, param1, 30);
}
}
}
}
}
}
}
}
}
}


public Help_MenuHandler(Handle:menu, MenuAction:action, param1, param2) {
public Help_MenuHandler(Handle:menu, MenuAction:action, param1, param2) {
if (action == MenuAction_End) {
if (action == MenuAction_End) {
CloseHandle(menu);
CloseHandle(menu);
} else if (menu == INVALID_HANDLE && action == MenuAction_Select && param2 == 8) {
} else if (menu == INVALID_HANDLE && action == MenuAction_Select && param2 == 8) {
Help_ShowMainMenu(param1);
Help_ShowMainMenu(param1);
} else if (action == MenuAction_Cancel) {
} else if (action == MenuAction_Cancel) {
if (param2 == MenuCancel_ExitBack)
if (param2 == MenuCancel_ExitBack)
Help_ShowMainMenu(param1);
Help_ShowMainMenu(param1);
}
}
}
}


public Help_CustomMenuHandler(Handle:menu, MenuAction:action, param1, param2) {
public Help_CustomMenuHandler(Handle:menu, MenuAction:action, param1, param2) {
if (action == MenuAction_End) {
if (action == MenuAction_End) {
CloseHandle(menu);
CloseHandle(menu);
} else if (action == MenuAction_Select) {
} else if (action == MenuAction_Select) {
new String:itemval[32];
new String:itemval[32];
GetMenuItem(menu, param2, itemval, sizeof(itemval));
GetMenuItem(menu, param2, itemval, sizeof(itemval));
if (strlen(itemval) > 0)
if (strlen(itemval) > 0)
FakeClientCommand(param1, itemval);
FakeClientCommand(param1, itemval);
} else if (action == MenuAction_Cancel) {
} else if (action == MenuAction_Cancel) {
if (param2 == MenuCancel_ExitBack)
if (param2 == MenuCancel_ExitBack)
Help_ShowMainMenu(param1);
Help_ShowMainMenu(param1);
}
}
}
}