|
ferret99gt@1789
|
1 |
/** |
|
ferret99gt@1789
|
2 |
* vim: set ts=4 : |
|
ferret99gt@1789
|
3 |
* ============================================================================= |
|
ferret99gt@1789
|
4 |
* SourceMod Basecommands Plugin |
|
ferret99gt@1789
|
5 |
* Provides exec cfg functionality |
|
ferret99gt@1789
|
6 |
* |
|
ds@1947
|
7 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
ferret99gt@1789
|
8 |
* ============================================================================= |
|
ferret99gt@1789
|
9 |
* |
|
ferret99gt@1789
|
10 |
* This program is free software; you can redistribute it and/or modify it under |
|
ferret99gt@1789
|
11 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ferret99gt@1789
|
12 |
* Free Software Foundation. |
|
ferret99gt@1789
|
13 |
* |
|
ferret99gt@1789
|
14 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ferret99gt@1789
|
15 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ferret99gt@1789
|
16 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ferret99gt@1789
|
17 |
* details. |
|
ferret99gt@1789
|
18 |
* |
|
ferret99gt@1789
|
19 |
* You should have received a copy of the GNU General Public License along with |
|
ferret99gt@1789
|
20 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ferret99gt@1789
|
21 |
* |
|
ferret99gt@1789
|
22 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ferret99gt@1789
|
23 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ferret99gt@1789
|
24 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ferret99gt@1789
|
25 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ferret99gt@1789
|
26 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ferret99gt@1789
|
27 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ferret99gt@1789
|
28 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ferret99gt@1789
|
29 |
* or <http://www.sourcemod.net/license.php>. |
|
ferret99gt@1789
|
30 |
* |
|
ds@1990
|
31 |
* Version: $Id$ |
|
ferret99gt@1789
|
32 |
*/ |
|
ferret99gt@1789
|
33 |
|
|
dvander@1592
|
34 |
new Handle:g_ConfigMenu = INVALID_HANDLE; |
|
dvander@1592
|
35 |
|
|
pred@1536
|
36 |
PerformExec(client, String:path[]) |
|
pred@1536
|
37 |
{ |
|
pred@1536
|
38 |
if (!FileExists(path)) |
|
pred@1536
|
39 |
{ |
|
pred@1536
|
40 |
ReplyToCommand(client, "[SM] %t", "Config not found", path[4]); |
|
pred@1536
|
41 |
return; |
|
pred@1536
|
42 |
} |
|
pred@1536
|
43 |
|
|
dvander@1623
|
44 |
ShowActivity2(client, "[SM] ", "%t", "Executed config", path[4]); |
|
pred@1536
|
45 |
|
|
pred@1536
|
46 |
LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]); |
|
pred@1536
|
47 |
|
|
pred@1536
|
48 |
ServerCommand("exec \"%s\"", path[4]); |
|
pred@1536
|
49 |
} |
|
pred@1536
|
50 |
|
|
pred@1536
|
51 |
public AdminMenu_ExecCFG(Handle:topmenu, |
|
pred@1536
|
52 |
TopMenuAction:action, |
|
pred@1536
|
53 |
TopMenuObject:object_id, |
|
pred@1536
|
54 |
param, |
|
pred@1536
|
55 |
String:buffer[], |
|
pred@1536
|
56 |
maxlength) |
|
pred@1536
|
57 |
{ |
|
pred@1536
|
58 |
if (action == TopMenuAction_DisplayOption) |
|
pred@1536
|
59 |
{ |
|
pred@1536
|
60 |
Format(buffer, maxlength, "%T", "Exec CFG", param); |
|
pred@1536
|
61 |
} |
|
pred@1536
|
62 |
else if (action == TopMenuAction_SelectOption) |
|
pred@1536
|
63 |
{ |
|
dvander@1592
|
64 |
DisplayMenu(g_ConfigMenu, param, MENU_TIME_FOREVER); |
|
pred@1536
|
65 |
} |
|
pred@1536
|
66 |
} |
|
pred@1536
|
67 |
|
|
pred@1536
|
68 |
public MenuHandler_ExecCFG(Handle:menu, MenuAction:action, param1, param2) |
|
pred@1536
|
69 |
{ |
|
pred@1536
|
70 |
if (action == MenuAction_Cancel) |
|
pred@1536
|
71 |
{ |
|
pred@1536
|
72 |
if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE) |
|
pred@1536
|
73 |
{ |
|
pred@1536
|
74 |
DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory); |
|
pred@1536
|
75 |
} |
|
pred@1536
|
76 |
} |
|
pred@1536
|
77 |
else if (action == MenuAction_Select) |
|
pred@1536
|
78 |
{ |
|
pred@1536
|
79 |
decl String:path[256]; |
|
pred@1536
|
80 |
|
|
pred@1536
|
81 |
GetMenuItem(menu, param2, path, sizeof(path)); |
|
pred@1536
|
82 |
|
|
pred@1536
|
83 |
PerformExec(param1, path); |
|
pred@1536
|
84 |
} |
|
skamonkey@3887
|
85 |
else if (action == MenuAction_Display) |
|
skamonkey@3887
|
86 |
{ |
|
skamonkey@3887
|
87 |
decl String:title[128]; |
|
skamonkey@3887
|
88 |
Format(title, sizeof(title), "%T", "Choose Config", param1); |
|
skamonkey@3887
|
89 |
SetPanelTitle(Handle:param2, title); |
|
skamonkey@3887
|
90 |
} |
|
pred@1536
|
91 |
} |
|
pred@1536
|
92 |
|
|
pred@1536
|
93 |
public Action:Command_ExecCfg(client, args) |
|
pred@1536
|
94 |
{ |
|
pred@1536
|
95 |
if (args < 1) |
|
pred@1536
|
96 |
{ |
|
pred@1536
|
97 |
ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>"); |
|
pred@1536
|
98 |
return Plugin_Handled; |
|
pred@1536
|
99 |
} |
|
pred@1536
|
100 |
|
|
pred@1536
|
101 |
new String:path[64] = "cfg/"; |
|
pred@1536
|
102 |
GetCmdArg(1, path[4], sizeof(path)-4); |
|
pred@1536
|
103 |
|
|
pred@1536
|
104 |
PerformExec(client, path); |
|
pred@1536
|
105 |
|
|
pred@1536
|
106 |
return Plugin_Handled; |
|
pred@1536
|
107 |
} |
|
pred@1536
|
108 |
|
|
dvander@1592
|
109 |
new Handle:config_parser = INVALID_HANDLE; |
|
pred@1536
|
110 |
ParseConfigs() |
|
pred@1536
|
111 |
{ |
|
dvander@1592
|
112 |
if (config_parser == INVALID_HANDLE) |
|
dvander@1592
|
113 |
{ |
|
dvander@1592
|
114 |
config_parser = SMC_CreateParser(); |
|
dvander@1592
|
115 |
} |
|
dvander@1592
|
116 |
|
|
dvander@1592
|
117 |
SMC_SetReaders(config_parser, NewSection, KeyValue, EndSection); |
|
pred@1536
|
118 |
|
|
dvander@1592
|
119 |
if (g_ConfigMenu != INVALID_HANDLE) |
|
dvander@1592
|
120 |
{ |
|
dvander@1592
|
121 |
CloseHandle(g_ConfigMenu); |
|
dvander@1592
|
122 |
} |
|
dvander@1592
|
123 |
|
|
skamonkey@3887
|
124 |
g_ConfigMenu = CreateMenu(MenuHandler_ExecCFG, MenuAction_Display); |
|
skamonkey@3887
|
125 |
SetMenuTitle(g_ConfigMenu, "%T", "Choose Config", LANG_SERVER); |
|
dvander@1592
|
126 |
SetMenuExitBackButton(g_ConfigMenu, true); |
|
pred@1536
|
127 |
|
|
pred@1536
|
128 |
decl String:configPath[256]; |
|
dvander@1592
|
129 |
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_cfgs.txt"); |
|
pred@1536
|
130 |
|
|
pred@1536
|
131 |
if (!FileExists(configPath)) |
|
pred@1536
|
132 |
{ |
|
pred@1536
|
133 |
LogError("Unable to locate exec config file, no maps loaded."); |
|
pred@1536
|
134 |
|
|
pred@1536
|
135 |
return; |
|
pred@1536
|
136 |
} |
|
pred@1536
|
137 |
|
|
dvander@1592
|
138 |
new line; |
|
dvander@1592
|
139 |
new SMCError:err = SMC_ParseFile(config_parser, configPath, line); |
|
dvander@1592
|
140 |
if (err != SMCError_Okay) |
|
dvander@1592
|
141 |
{ |
|
dvander@1592
|
142 |
decl String:error[256]; |
|
dvander@1592
|
143 |
SMC_GetErrorString(err, error, sizeof(error)); |
|
dvander@1592
|
144 |
LogError("Could not parse file (line %d, file \"%s\"):", line, configPath); |
|
dvander@1592
|
145 |
LogError("Parser encountered error: %s", error); |
|
dvander@1592
|
146 |
} |
|
pred@1536
|
147 |
|
|
pred@1536
|
148 |
return; |
|
pred@1536
|
149 |
} |
|
pred@1536
|
150 |
|
|
pred@1536
|
151 |
public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes) |
|
pred@1536
|
152 |
{ |
|
pred@1536
|
153 |
|
|
pred@1536
|
154 |
} |
|
pred@1536
|
155 |
|
|
pred@1536
|
156 |
public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) |
|
pred@1536
|
157 |
{ |
|
dvander@1592
|
158 |
AddMenuItem(g_ConfigMenu, key, value); |
|
pred@1536
|
159 |
} |
|
pred@1536
|
160 |
|
|
pred@1536
|
161 |
public SMCResult:EndSection(Handle:smc) |
|
pred@1536
|
162 |
{ |
|
pred@1536
|
163 |
|
|
pred@1536
|
164 |
} |