|
pred@1536
|
1 |
PerformExec(client, String:path[]) |
|
pred@1536
|
2 |
{ |
|
pred@1536
|
3 |
if (!FileExists(path)) |
|
pred@1536
|
4 |
{ |
|
pred@1536
|
5 |
ReplyToCommand(client, "[SM] %t", "Config not found", path[4]); |
|
pred@1536
|
6 |
return; |
|
pred@1536
|
7 |
} |
|
pred@1536
|
8 |
|
|
pred@1536
|
9 |
ShowActivity(client, "%t", "Executed config", path[4]); |
|
pred@1536
|
10 |
|
|
pred@1536
|
11 |
LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]); |
|
pred@1536
|
12 |
|
|
pred@1536
|
13 |
ServerCommand("exec \"%s\"", path[4]); |
|
pred@1536
|
14 |
} |
|
pred@1536
|
15 |
|
|
pred@1536
|
16 |
public AdminMenu_ExecCFG(Handle:topmenu, |
|
pred@1536
|
17 |
TopMenuAction:action, |
|
pred@1536
|
18 |
TopMenuObject:object_id, |
|
pred@1536
|
19 |
param, |
|
pred@1536
|
20 |
String:buffer[], |
|
pred@1536
|
21 |
maxlength) |
|
pred@1536
|
22 |
{ |
|
pred@1536
|
23 |
if (action == TopMenuAction_DisplayOption) |
|
pred@1536
|
24 |
{ |
|
pred@1536
|
25 |
Format(buffer, maxlength, "%T", "Exec CFG", param); |
|
pred@1536
|
26 |
} |
|
pred@1536
|
27 |
else if (action == TopMenuAction_SelectOption) |
|
pred@1536
|
28 |
{ |
|
pred@1536
|
29 |
DisplayMenu(g_ConfigList, param, MENU_TIME_FOREVER); |
|
pred@1536
|
30 |
} |
|
pred@1536
|
31 |
} |
|
pred@1536
|
32 |
|
|
pred@1536
|
33 |
public MenuHandler_ExecCFG(Handle:menu, MenuAction:action, param1, param2) |
|
pred@1536
|
34 |
{ |
|
pred@1536
|
35 |
if (action == MenuAction_Cancel) |
|
pred@1536
|
36 |
{ |
|
pred@1536
|
37 |
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE) |
|
pred@1536
|
38 |
{ |
|
pred@1536
|
39 |
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory); |
|
pred@1536
|
40 |
} |
|
pred@1536
|
41 |
} |
|
pred@1536
|
42 |
else if (action == MenuAction_Select) |
|
pred@1536
|
43 |
{ |
|
pred@1536
|
44 |
decl String:path[256]; |
|
pred@1536
|
45 |
|
|
pred@1536
|
46 |
GetMenuItem(menu, param2, path, sizeof(path)); |
|
pred@1536
|
47 |
|
|
pred@1536
|
48 |
PerformExec(param1, path); |
|
pred@1536
|
49 |
} |
|
pred@1536
|
50 |
} |
|
pred@1536
|
51 |
|
|
pred@1536
|
52 |
public Action:Command_ExecCfg(client, args) |
|
pred@1536
|
53 |
{ |
|
pred@1536
|
54 |
if (args < 1) |
|
pred@1536
|
55 |
{ |
|
pred@1536
|
56 |
ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>"); |
|
pred@1536
|
57 |
return Plugin_Handled; |
|
pred@1536
|
58 |
} |
|
pred@1536
|
59 |
|
|
pred@1536
|
60 |
new String:path[64] = "cfg/"; |
|
pred@1536
|
61 |
GetCmdArg(1, path[4], sizeof(path)-4); |
|
pred@1536
|
62 |
|
|
pred@1536
|
63 |
PerformExec(client, path); |
|
pred@1536
|
64 |
|
|
pred@1536
|
65 |
return Plugin_Handled; |
|
pred@1536
|
66 |
} |
|
pred@1536
|
67 |
|
|
pred@1536
|
68 |
ParseConfigs() |
|
pred@1536
|
69 |
{ |
|
pred@1536
|
70 |
new Handle:list = SMC_CreateParser(); |
|
pred@1536
|
71 |
SMC_SetReaders(list, NewSection, KeyValue, EndSection); |
|
pred@1536
|
72 |
SMC_SetParseEnd(list, ParseEnd); |
|
pred@1536
|
73 |
|
|
pred@1536
|
74 |
new Handle:menu = CreateMenu(MenuHandler_ExecCFG); |
|
pred@1536
|
75 |
SetMenuTitle(menu, "Choose Config"); |
|
pred@1536
|
76 |
SetMenuExitBackButton(menu, true); |
|
pred@1536
|
77 |
|
|
pred@1536
|
78 |
decl String:configPath[256]; |
|
pred@1536
|
79 |
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/menu_configs.cfg"); |
|
pred@1536
|
80 |
|
|
pred@1536
|
81 |
if (!FileExists(configPath)) |
|
pred@1536
|
82 |
{ |
|
pred@1536
|
83 |
LogError("Unable to locate exec config file, no maps loaded."); |
|
pred@1536
|
84 |
|
|
pred@1536
|
85 |
return; |
|
pred@1536
|
86 |
} |
|
pred@1536
|
87 |
|
|
pred@1536
|
88 |
g_ConfigList = menu; |
|
pred@1536
|
89 |
|
|
pred@1536
|
90 |
SMC_ParseFile(list, configPath); |
|
pred@1536
|
91 |
|
|
pred@1536
|
92 |
return; |
|
pred@1536
|
93 |
} |
|
pred@1536
|
94 |
|
|
pred@1536
|
95 |
public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes) |
|
pred@1536
|
96 |
{ |
|
pred@1536
|
97 |
|
|
pred@1536
|
98 |
} |
|
pred@1536
|
99 |
|
|
pred@1536
|
100 |
public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) |
|
pred@1536
|
101 |
{ |
|
pred@1536
|
102 |
AddMenuItem(g_ConfigList, key, value); |
|
pred@1536
|
103 |
} |
|
pred@1536
|
104 |
|
|
pred@1536
|
105 |
public SMCResult:EndSection(Handle:smc) |
|
pred@1536
|
106 |
{ |
|
pred@1536
|
107 |
|
|
pred@1536
|
108 |
} |
|
pred@1536
|
109 |
|
|
pred@1536
|
110 |
public ParseEnd(Handle:smc, bool:halted, bool:failed) |
|
pred@1536
|
111 |
{ |
|
pred@1536
|
112 |
if (halted || failed) |
|
pred@1536
|
113 |
LogError("Reading of configs file failed"); |
|
pred@1536
|
114 |
|
|
pred@1536
|
115 |
CloseHandle(smc); |
|
pred@1536
|
116 |
} |