Coded menus for most base plugins
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401542
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
PerformExec(client, String:path[])
|
||||
{
|
||||
if (!FileExists(path))
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
|
||||
return;
|
||||
}
|
||||
|
||||
ShowActivity(client, "%t", "Executed config", path[4]);
|
||||
|
||||
LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]);
|
||||
|
||||
ServerCommand("exec \"%s\"", path[4]);
|
||||
}
|
||||
|
||||
public AdminMenu_ExecCFG(Handle:topmenu,
|
||||
TopMenuAction:action,
|
||||
TopMenuObject:object_id,
|
||||
param,
|
||||
String:buffer[],
|
||||
maxlength)
|
||||
{
|
||||
if (action == TopMenuAction_DisplayOption)
|
||||
{
|
||||
Format(buffer, maxlength, "%T", "Exec CFG", param);
|
||||
}
|
||||
else if (action == TopMenuAction_SelectOption)
|
||||
{
|
||||
DisplayMenu(g_ConfigList, param, MENU_TIME_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
public MenuHandler_ExecCFG(Handle:menu, MenuAction:action, param1, param2)
|
||||
{
|
||||
if (action == MenuAction_Cancel)
|
||||
{
|
||||
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
|
||||
{
|
||||
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
|
||||
}
|
||||
}
|
||||
else if (action == MenuAction_Select)
|
||||
{
|
||||
decl String:path[256];
|
||||
|
||||
GetMenuItem(menu, param2, path, sizeof(path));
|
||||
|
||||
PerformExec(param1, path);
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_ExecCfg(client, args)
|
||||
{
|
||||
if (args < 1)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new String:path[64] = "cfg/";
|
||||
GetCmdArg(1, path[4], sizeof(path)-4);
|
||||
|
||||
PerformExec(client, path);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
ParseConfigs()
|
||||
{
|
||||
new Handle:list = SMC_CreateParser();
|
||||
SMC_SetReaders(list, NewSection, KeyValue, EndSection);
|
||||
SMC_SetParseEnd(list, ParseEnd);
|
||||
|
||||
new Handle:menu = CreateMenu(MenuHandler_ExecCFG);
|
||||
SetMenuTitle(menu, "Choose Config");
|
||||
SetMenuExitBackButton(menu, true);
|
||||
|
||||
decl String:configPath[256];
|
||||
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/menu_configs.cfg");
|
||||
|
||||
if (!FileExists(configPath))
|
||||
{
|
||||
LogError("Unable to locate exec config file, no maps loaded.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
g_ConfigList = menu;
|
||||
|
||||
SMC_ParseFile(list, configPath);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
|
||||
{
|
||||
AddMenuItem(g_ConfigList, key, value);
|
||||
}
|
||||
|
||||
public SMCResult:EndSection(Handle:smc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ParseEnd(Handle:smc, bool:halted, bool:failed)
|
||||
{
|
||||
if (halted || failed)
|
||||
LogError("Reading of configs file failed");
|
||||
|
||||
CloseHandle(smc);
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
|
||||
{
|
||||
if (action == MenuAction_Cancel)
|
||||
{
|
||||
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
|
||||
{
|
||||
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
|
||||
}
|
||||
}
|
||||
else if (action == MenuAction_Select)
|
||||
{
|
||||
decl String:map[64];
|
||||
|
||||
GetMenuItem(menu, param2, map, sizeof(map));
|
||||
|
||||
ShowActivity(param1, "%t", "Changing map", map);
|
||||
|
||||
LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);
|
||||
|
||||
new Handle:dp;
|
||||
CreateDataTimer(3.0, Timer_ChangeMap, dp);
|
||||
WritePackString(dp, map);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public AdminMenu_Map(Handle:topmenu,
|
||||
TopMenuAction:action,
|
||||
TopMenuObject:object_id,
|
||||
param,
|
||||
String:buffer[],
|
||||
maxlength)
|
||||
{
|
||||
if (action == TopMenuAction_DisplayOption)
|
||||
{
|
||||
Format(buffer, maxlength, "%T", "Choose Map", param);
|
||||
}
|
||||
else if (action == TopMenuAction_SelectOption)
|
||||
{
|
||||
DisplayMenu(g_MapList, param, MENU_TIME_FOREVER);
|
||||
}
|
||||
}
|
||||
|
||||
public Action:Command_Map(client, args)
|
||||
{
|
||||
if (args < 1)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Usage: sm_map <map>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:map[64];
|
||||
GetCmdArg(1, map, sizeof(map));
|
||||
|
||||
if (!IsMapValid(map))
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %t", "Map was not found", map);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
ShowActivity(client, "%t", "Changing map", map);
|
||||
|
||||
LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);
|
||||
|
||||
new Handle:dp;
|
||||
CreateDataTimer(3.0, Timer_ChangeMap, dp);
|
||||
WritePackString(dp, map);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
|
||||
{
|
||||
decl String:map[65];
|
||||
|
||||
ResetPack(dp);
|
||||
ReadPackString(dp, map, sizeof(map));
|
||||
|
||||
ServerCommand("changelevel \"%s\"", map);
|
||||
|
||||
return Plugin_Stop;
|
||||
}
|
||||
|
||||
LoadMaps(Handle:menu)
|
||||
{
|
||||
decl String:mapPath[256];
|
||||
BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/menu_maplist.ini");
|
||||
|
||||
if (!FileExists(mapPath))
|
||||
{
|
||||
LogError("Unable to locate menu_maplist, no maps loaded.");
|
||||
|
||||
if (g_MapList != INVALID_HANDLE)
|
||||
{
|
||||
RemoveAllMenuItems(menu);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the file hasn't changed, there's no reason to reload
|
||||
// all of the maps.
|
||||
new fileTime = GetFileTime(mapPath, FileTime_LastChange);
|
||||
if (g_mapFileTime == fileTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_mapFileTime = fileTime;
|
||||
|
||||
// Reset the array
|
||||
if (g_MapList != INVALID_HANDLE)
|
||||
{
|
||||
RemoveAllMenuItems(menu);
|
||||
}
|
||||
|
||||
LogMessage("[SM] Loading menu map list file [%s]", mapPath);
|
||||
|
||||
new Handle:file = OpenFile(mapPath, "rt");
|
||||
if (file == INVALID_HANDLE)
|
||||
{
|
||||
LogError("[SM] Could not open file: %s", mapPath);
|
||||
return;
|
||||
}
|
||||
|
||||
decl String:buffer[64], len;
|
||||
while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
|
||||
{
|
||||
TrimString(buffer);
|
||||
|
||||
if ((len = StrContains(buffer, ".bsp", false)) != -1)
|
||||
{
|
||||
buffer[len] = '\0';
|
||||
}
|
||||
|
||||
if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AddMenuItem(menu, buffer, buffer);
|
||||
}
|
||||
|
||||
CloseHandle(file);
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
|
||||
PerformWho(client, target, ReplySource:reply)
|
||||
{
|
||||
new flags = GetUserFlagBits(target);
|
||||
decl String:flagstring[255];
|
||||
if (flags == 0)
|
||||
{
|
||||
strcopy(flagstring, sizeof(flagstring), "none");
|
||||
} else if (flags & ADMFLAG_ROOT) {
|
||||
strcopy(flagstring, sizeof(flagstring), "root");
|
||||
} else {
|
||||
FlagsToString(flagstring, sizeof(flagstring), flags);
|
||||
}
|
||||
|
||||
if (reply == SM_REPLY_TO_CHAT)
|
||||
PrintToChat(client, "[SM] %t: %s", "Access", flagstring);
|
||||
else
|
||||
PrintToConsole(client, "[SM] %t: %s", "Access", flagstring);
|
||||
}
|
||||
|
||||
DisplayWhoMenu(client)
|
||||
{
|
||||
new Handle:menu = CreateMenu(MenuHandler_Who);
|
||||
|
||||
decl String:title[100];
|
||||
Format(title, sizeof(title), "%T:", "Check player access", client);
|
||||
SetMenuTitle(menu, title);
|
||||
SetMenuExitBackButton(menu, true);
|
||||
|
||||
AddTargetsToMenu(menu, client, false);
|
||||
|
||||
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
||||
}
|
||||
|
||||
public AdminMenu_Who(Handle:topmenu,
|
||||
TopMenuAction:action,
|
||||
TopMenuObject:object_id,
|
||||
param,
|
||||
String:buffer[],
|
||||
maxlength)
|
||||
{
|
||||
if (action == TopMenuAction_DisplayOption)
|
||||
{
|
||||
Format(buffer, maxlength, "%T", "Check player access", param);
|
||||
}
|
||||
else if (action == TopMenuAction_SelectOption)
|
||||
{
|
||||
DisplayWhoMenu(param);
|
||||
}
|
||||
}
|
||||
|
||||
public MenuHandler_Who(Handle:menu, MenuAction:action, param1, param2)
|
||||
{
|
||||
if (action == MenuAction_End)
|
||||
{
|
||||
CloseHandle(menu);
|
||||
}
|
||||
else if (action == MenuAction_Cancel)
|
||||
{
|
||||
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
|
||||
{
|
||||
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
|
||||
}
|
||||
}
|
||||
else if (action == MenuAction_Select)
|
||||
{
|
||||
decl String:info[32];
|
||||
new userid, target;
|
||||
|
||||
GetMenuItem(menu, param2, info, sizeof(info));
|
||||
userid = StringToInt(info);
|
||||
|
||||
if ((target = GetClientOfUserId(userid)) == 0)
|
||||
{
|
||||
PrintToChat(param1, "[SM] %t", "Player no longer available");
|
||||
}
|
||||
else if (!CanUserTarget(param1, target))
|
||||
{
|
||||
PrintToChat(param1, "[SM] %t", "Unable to target");
|
||||
}
|
||||
else
|
||||
{
|
||||
PerformWho(param1, target, SM_REPLY_TO_CHAT);
|
||||
}
|
||||
|
||||
/* Re-draw the menu if they're still valid */
|
||||
|
||||
/* - Close the menu? redisplay? jump back up to the category?
|
||||
if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
|
||||
{
|
||||
DisplayWhoMenu(param1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
public Action:Command_Who(client, args)
|
||||
{
|
||||
if (args < 1)
|
||||
{
|
||||
/* Display header */
|
||||
decl String:t_access[16], String:t_name[16];
|
||||
Format(t_access, sizeof(t_access), "%t", "Access", client);
|
||||
Format(t_name, sizeof(t_name), "%t", "Name", client);
|
||||
|
||||
PrintToConsole(client, "%-24.23s %s", t_name, t_access);
|
||||
|
||||
/* List all players */
|
||||
new maxClients = GetMaxClients();
|
||||
decl String:flagstring[255];
|
||||
|
||||
for (new i=1; i<=maxClients; i++)
|
||||
{
|
||||
if (!IsClientInGame(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
new flags = GetUserFlagBits(i);
|
||||
if (flags == 0)
|
||||
{
|
||||
strcopy(flagstring, sizeof(flagstring), "none");
|
||||
} else if (flags & ADMFLAG_ROOT) {
|
||||
strcopy(flagstring, sizeof(flagstring), "root");
|
||||
} else {
|
||||
FlagsToString(flagstring, sizeof(flagstring), flags);
|
||||
}
|
||||
decl String:name[65];
|
||||
GetClientName(i, name, sizeof(name));
|
||||
PrintToConsole(client, "%d. %-24.23s %s", i, name, flagstring);
|
||||
}
|
||||
|
||||
if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %t", "See console for output");
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg[65];
|
||||
GetCmdArg(1, arg, sizeof(arg));
|
||||
|
||||
new clients[2];
|
||||
new numClients = SearchForClients(arg, clients, 2);
|
||||
|
||||
if (numClients == 0)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] %t", "No matching client");
|
||||
return Plugin_Handled;
|
||||
} else if (numClients > 1) {
|
||||
ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
PerformWho(client, clients[0], GetCmdReplySource());
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
Reference in New Issue
Block a user