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