|
ds@579
|
1 |
/** |
|
ds@579
|
2 |
* =============================================================== |
|
ds@579
|
3 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@579
|
4 |
* =============================================================== |
|
ds@579
|
5 |
* |
|
ds@579
|
6 |
* This file is not open source and may not be copied without explicit |
|
ds@579
|
7 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
ds@579
|
8 |
* in whole or significant part. |
|
ds@579
|
9 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
ds@579
|
10 |
* |
|
ds@579
|
11 |
* Version: $Id$ |
|
ds@579
|
12 |
*/ |
|
ds@579
|
13 |
|
|
ds@579
|
14 |
#include "ConCmdManager.h" |
|
ds@579
|
15 |
#include "sm_srvcmds.h" |
|
ds@579
|
16 |
#include "AdminCache.h" |
|
ds@579
|
17 |
#include "sm_stringutil.h" |
|
dvander@591
|
18 |
#include "PlayerManager.h" |
|
dvander@591
|
19 |
#include "Translator.h" |
|
ds@579
|
20 |
|
|
ds@579
|
21 |
ConCmdManager g_ConCmds; |
|
ds@579
|
22 |
|
|
ds@579
|
23 |
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); |
|
ds@579
|
24 |
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int); |
|
ds@579
|
25 |
|
|
ds@579
|
26 |
struct PlCmdInfo |
|
ds@579
|
27 |
{ |
|
ds@579
|
28 |
ConCmdInfo *pInfo; |
|
ds@579
|
29 |
CmdHook *pHook; |
|
ds@579
|
30 |
CmdType type; |
|
ds@579
|
31 |
}; |
|
ds@579
|
32 |
typedef List<PlCmdInfo> CmdList; |
|
ds@579
|
33 |
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info); |
|
ds@579
|
34 |
|
|
ds@579
|
35 |
ConCmdManager::ConCmdManager() : m_Strings(1024) |
|
ds@579
|
36 |
{ |
|
ds@579
|
37 |
m_pCmds = sm_trie_create(); |
|
ds@579
|
38 |
m_pCmdGrps = sm_trie_create(); |
|
ds@579
|
39 |
} |
|
ds@579
|
40 |
|
|
ds@579
|
41 |
ConCmdManager::~ConCmdManager() |
|
ds@579
|
42 |
{ |
|
ds@579
|
43 |
sm_trie_destroy(m_pCmds); |
|
ds@579
|
44 |
sm_trie_destroy(m_pCmdGrps); |
|
ds@579
|
45 |
} |
|
ds@579
|
46 |
|
|
ds@579
|
47 |
void ConCmdManager::OnSourceModAllInitialized() |
|
ds@579
|
48 |
{ |
|
ds@579
|
49 |
g_PluginSys.AddPluginsListener(this); |
|
ds@579
|
50 |
g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this); |
|
ds@579
|
51 |
SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false); |
|
ds@579
|
52 |
} |
|
ds@579
|
53 |
|
|
ds@579
|
54 |
void ConCmdManager::OnSourceModShutdown() |
|
ds@579
|
55 |
{ |
|
ds@579
|
56 |
/* All commands should already be removed by the time we're done */ |
|
ds@579
|
57 |
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false); |
|
ds@579
|
58 |
g_RootMenu.RemoveRootConsoleCommand("cmds", this); |
|
ds@579
|
59 |
g_PluginSys.RemovePluginsListener(this); |
|
ds@579
|
60 |
} |
|
ds@579
|
61 |
|
|
ds@579
|
62 |
void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext) |
|
ds@579
|
63 |
{ |
|
ds@579
|
64 |
List<CmdHook *>::iterator iter = cmdlist.begin(); |
|
ds@579
|
65 |
CmdHook *pHook; |
|
ds@579
|
66 |
|
|
ds@579
|
67 |
while (iter != cmdlist.end()) |
|
ds@579
|
68 |
{ |
|
ds@579
|
69 |
pHook = (*iter); |
|
ds@579
|
70 |
if (pHook->pf->GetParentContext() == pContext) |
|
ds@579
|
71 |
{ |
|
ds@579
|
72 |
delete pHook->pAdmin; |
|
ds@579
|
73 |
delete pHook; |
|
ds@579
|
74 |
iter = cmdlist.erase(iter); |
|
ds@579
|
75 |
} else { |
|
ds@579
|
76 |
iter++; |
|
ds@579
|
77 |
} |
|
ds@579
|
78 |
} |
|
ds@579
|
79 |
} |
|
ds@579
|
80 |
|
|
ds@579
|
81 |
void ConCmdManager::OnPluginDestroyed(IPlugin *plugin) |
|
ds@579
|
82 |
{ |
|
ds@579
|
83 |
CmdList *pList; |
|
ds@579
|
84 |
List<ConCmdInfo *> removed; |
|
ds@579
|
85 |
if (plugin->GetProperty("CommandList", (void **)&pList, true)) |
|
ds@579
|
86 |
{ |
|
ds@579
|
87 |
IPluginContext *pContext = plugin->GetBaseContext(); |
|
ds@579
|
88 |
CmdList::iterator iter; |
|
ds@579
|
89 |
/* First pass! |
|
ds@579
|
90 |
* Only bother if there's an actual command list on this plugin... |
|
ds@579
|
91 |
*/ |
|
ds@579
|
92 |
for (iter=pList->begin(); |
|
ds@579
|
93 |
iter!=pList->end(); |
|
ds@579
|
94 |
iter++) |
|
ds@579
|
95 |
{ |
|
ds@579
|
96 |
PlCmdInfo &cmd = (*iter); |
|
ds@579
|
97 |
ConCmdInfo *pInfo = cmd.pInfo; |
|
ds@579
|
98 |
|
|
ds@579
|
99 |
/* Has this chain already been fully cleaned/removed? */ |
|
ds@579
|
100 |
if (removed.find(pInfo) != removed.end()) |
|
ds@579
|
101 |
{ |
|
ds@579
|
102 |
continue; |
|
ds@579
|
103 |
} |
|
ds@579
|
104 |
|
|
ds@579
|
105 |
/* Remove any hooks from us on this command */ |
|
ds@579
|
106 |
RemoveConCmds(pInfo->conhooks, pContext); |
|
ds@579
|
107 |
RemoveConCmds(pInfo->srvhooks, pContext); |
|
ds@579
|
108 |
|
|
ds@579
|
109 |
/* See if there are still hooks */ |
|
ds@579
|
110 |
if (pInfo->srvhooks.size()) |
|
ds@579
|
111 |
{ |
|
ds@579
|
112 |
continue; |
|
ds@579
|
113 |
} |
|
ds@579
|
114 |
if (pInfo->conhooks.size()) |
|
ds@579
|
115 |
{ |
|
ds@579
|
116 |
continue; |
|
ds@579
|
117 |
} |
|
ds@579
|
118 |
|
|
ds@579
|
119 |
/* Remove the command, it should be safe now */ |
|
ds@579
|
120 |
RemoveConCmd(pInfo); |
|
ds@579
|
121 |
removed.push_back(pInfo); |
|
ds@579
|
122 |
} |
|
ds@579
|
123 |
delete pList; |
|
ds@579
|
124 |
} |
|
ds@579
|
125 |
} |
|
ds@579
|
126 |
|
|
ds@579
|
127 |
void CommandCallback() |
|
ds@579
|
128 |
{ |
|
ds@579
|
129 |
g_ConCmds.InternalDispatch(); |
|
ds@579
|
130 |
} |
|
ds@579
|
131 |
|
|
ds@579
|
132 |
void ConCmdManager::SetCommandClient(int client) |
|
ds@579
|
133 |
{ |
|
ds@579
|
134 |
m_CmdClient = client + 1; |
|
ds@579
|
135 |
} |
|
ds@579
|
136 |
|
|
ds@579
|
137 |
ResultType ConCmdManager::DispatchClientCommand(int client, ResultType type) |
|
ds@579
|
138 |
{ |
|
ds@579
|
139 |
const char *cmd = engine->Cmd_Argv(0); |
|
ds@579
|
140 |
int args = engine->Cmd_Argc() - 1; |
|
ds@579
|
141 |
|
|
ds@579
|
142 |
ConCmdInfo *pInfo; |
|
ds@579
|
143 |
if (sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) |
|
ds@579
|
144 |
{ |
|
ds@579
|
145 |
cell_t result = type; |
|
ds@579
|
146 |
cell_t tempres = result; |
|
ds@579
|
147 |
List<CmdHook *>::iterator iter; |
|
ds@579
|
148 |
CmdHook *pHook; |
|
ds@579
|
149 |
for (iter=pInfo->conhooks.begin(); |
|
ds@579
|
150 |
iter!=pInfo->conhooks.end(); |
|
ds@579
|
151 |
iter++) |
|
ds@579
|
152 |
{ |
|
ds@579
|
153 |
pHook = (*iter); |
|
ds@579
|
154 |
if (!pHook->pf->IsRunnable()) |
|
ds@579
|
155 |
{ |
|
ds@579
|
156 |
continue; |
|
ds@579
|
157 |
} |
|
ds@579
|
158 |
if (pHook->pAdmin && !CheckAccess(client, cmd, pHook->pAdmin)) |
|
ds@579
|
159 |
{ |
|
ds@579
|
160 |
if (result < Pl_Handled) |
|
ds@579
|
161 |
{ |
|
ds@579
|
162 |
result = Pl_Handled; |
|
ds@579
|
163 |
} |
|
ds@579
|
164 |
continue; |
|
ds@579
|
165 |
} |
|
ds@579
|
166 |
pHook->pf->PushCell(client); |
|
ds@579
|
167 |
pHook->pf->PushCell(args); |
|
ds@579
|
168 |
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) |
|
ds@579
|
169 |
{ |
|
ds@579
|
170 |
if (tempres > result) |
|
ds@579
|
171 |
{ |
|
ds@579
|
172 |
result = tempres; |
|
ds@579
|
173 |
} |
|
ds@579
|
174 |
if (result == Pl_Stop) |
|
ds@579
|
175 |
{ |
|
ds@579
|
176 |
break; |
|
ds@579
|
177 |
} |
|
ds@579
|
178 |
} |
|
ds@579
|
179 |
} |
|
ds@579
|
180 |
type = (ResultType)result; |
|
ds@579
|
181 |
} |
|
ds@579
|
182 |
|
|
ds@579
|
183 |
return type; |
|
ds@579
|
184 |
} |
|
ds@579
|
185 |
|
|
ds@579
|
186 |
void ConCmdManager::InternalDispatch() |
|
ds@579
|
187 |
{ |
|
ds@579
|
188 |
/** |
|
ds@579
|
189 |
* Note: Console commands will EITHER go through IServerGameDLL::ClientCommand, |
|
ds@579
|
190 |
* OR this dispatch. They will NEVER go through both. |
|
ds@579
|
191 |
* -- |
|
ds@579
|
192 |
* Whether or not it goes through the callback is determined by FCVAR_GAMEDLL |
|
ds@579
|
193 |
*/ |
|
ds@579
|
194 |
|
|
ds@579
|
195 |
const char *cmd = engine->Cmd_Argv(0); |
|
ds@579
|
196 |
ConCmdInfo *pInfo; |
|
ds@579
|
197 |
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) |
|
ds@579
|
198 |
{ |
|
ds@579
|
199 |
return; |
|
ds@579
|
200 |
} |
|
ds@579
|
201 |
|
|
ds@579
|
202 |
cell_t result = Pl_Continue; |
|
ds@579
|
203 |
int args = engine->Cmd_Argc() - 1; |
|
ds@579
|
204 |
|
|
ds@579
|
205 |
List<CmdHook *>::iterator iter; |
|
ds@579
|
206 |
CmdHook *pHook; |
|
ds@579
|
207 |
|
|
ds@579
|
208 |
/* Execute server-only commands if viable */ |
|
ds@579
|
209 |
if (m_CmdClient == 0 && pInfo->srvhooks.size()) |
|
ds@579
|
210 |
{ |
|
ds@579
|
211 |
cell_t tempres = result; |
|
ds@579
|
212 |
for (iter=pInfo->srvhooks.begin(); |
|
ds@579
|
213 |
iter!=pInfo->srvhooks.end(); |
|
ds@579
|
214 |
iter++) |
|
ds@579
|
215 |
{ |
|
ds@579
|
216 |
pHook = (*iter); |
|
ds@579
|
217 |
if (!pHook->pf->IsRunnable()) |
|
ds@579
|
218 |
{ |
|
ds@579
|
219 |
continue; |
|
ds@579
|
220 |
} |
|
ds@579
|
221 |
pHook->pf->PushCell(args); |
|
ds@579
|
222 |
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) |
|
ds@579
|
223 |
{ |
|
ds@579
|
224 |
if (tempres > result) |
|
ds@579
|
225 |
{ |
|
ds@579
|
226 |
result = tempres; |
|
ds@579
|
227 |
} |
|
ds@579
|
228 |
if (result == Pl_Stop) |
|
ds@579
|
229 |
{ |
|
ds@579
|
230 |
break; |
|
ds@579
|
231 |
} |
|
ds@579
|
232 |
} |
|
ds@579
|
233 |
} |
|
ds@579
|
234 |
|
|
ds@579
|
235 |
/* Check if there's an early stop */ |
|
ds@579
|
236 |
if (result >= Pl_Stop) |
|
ds@579
|
237 |
{ |
|
ds@579
|
238 |
if (!pInfo->sourceMod) |
|
ds@579
|
239 |
{ |
|
ds@579
|
240 |
RETURN_META(MRES_SUPERCEDE); |
|
ds@579
|
241 |
} |
|
ds@579
|
242 |
return; |
|
ds@579
|
243 |
} |
|
ds@579
|
244 |
} |
|
ds@579
|
245 |
|
|
ds@579
|
246 |
/* Execute console commands */ |
|
ds@579
|
247 |
if (pInfo->conhooks.size()) |
|
ds@579
|
248 |
{ |
|
ds@579
|
249 |
cell_t tempres = result; |
|
ds@579
|
250 |
for (iter=pInfo->conhooks.begin(); |
|
ds@579
|
251 |
iter!=pInfo->conhooks.end(); |
|
ds@579
|
252 |
iter++) |
|
ds@579
|
253 |
{ |
|
ds@579
|
254 |
pHook = (*iter); |
|
ds@579
|
255 |
if (!pHook->pf->IsRunnable()) |
|
ds@579
|
256 |
{ |
|
ds@579
|
257 |
continue; |
|
ds@579
|
258 |
} |
|
ds@579
|
259 |
if (m_CmdClient |
|
ds@579
|
260 |
&& pHook->pAdmin |
|
ds@579
|
261 |
&& !CheckAccess(m_CmdClient, cmd, pHook->pAdmin)) |
|
ds@579
|
262 |
{ |
|
ds@579
|
263 |
if (result < Pl_Handled) |
|
ds@579
|
264 |
{ |
|
ds@579
|
265 |
result = Pl_Handled; |
|
ds@579
|
266 |
} |
|
ds@579
|
267 |
continue; |
|
ds@579
|
268 |
} |
|
ds@579
|
269 |
pHook->pf->PushCell(m_CmdClient); |
|
ds@579
|
270 |
pHook->pf->PushCell(args); |
|
ds@579
|
271 |
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) |
|
ds@579
|
272 |
{ |
|
ds@579
|
273 |
if (tempres > result) |
|
ds@579
|
274 |
{ |
|
ds@579
|
275 |
result = tempres; |
|
ds@579
|
276 |
} |
|
ds@579
|
277 |
if (result == Pl_Stop) |
|
ds@579
|
278 |
{ |
|
ds@579
|
279 |
break; |
|
ds@579
|
280 |
} |
|
ds@579
|
281 |
} |
|
ds@579
|
282 |
} |
|
ds@579
|
283 |
} |
|
ds@579
|
284 |
|
|
ds@579
|
285 |
if (result >= Pl_Handled) |
|
ds@579
|
286 |
{ |
|
ds@579
|
287 |
if (!pInfo->sourceMod) |
|
ds@579
|
288 |
{ |
|
ds@579
|
289 |
RETURN_META(MRES_SUPERCEDE); |
|
ds@579
|
290 |
} |
|
ds@579
|
291 |
return; |
|
ds@579
|
292 |
} |
|
ds@579
|
293 |
} |
|
ds@579
|
294 |
|
|
ds@579
|
295 |
bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin) |
|
ds@579
|
296 |
{ |
|
ds@579
|
297 |
FlagBits cmdflags = pAdmin->eflags; |
|
ds@579
|
298 |
if (cmdflags == 0) |
|
ds@579
|
299 |
{ |
|
ds@579
|
300 |
return true; |
|
ds@579
|
301 |
} |
|
ds@579
|
302 |
|
|
ds@579
|
303 |
CPlayer *player = g_Players.GetPlayerByIndex(client); |
|
ds@579
|
304 |
if (!player) |
|
ds@579
|
305 |
{ |
|
ds@579
|
306 |
return false; |
|
ds@579
|
307 |
} |
|
ds@579
|
308 |
|
|
ds@579
|
309 |
AdminId adm = player->GetAdminId(); |
|
ds@579
|
310 |
if (adm != INVALID_ADMIN_ID) |
|
ds@579
|
311 |
{ |
|
ds@579
|
312 |
FlagBits bits = g_Admins.GetAdminFlags(adm, Access_Effective); |
|
ds@579
|
313 |
|
|
ds@579
|
314 |
/* root knows all, WHOA */ |
|
ds@579
|
315 |
if ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT) |
|
ds@579
|
316 |
{ |
|
ds@579
|
317 |
return true; |
|
ds@579
|
318 |
} |
|
ds@579
|
319 |
|
|
ds@579
|
320 |
/* See if our other flags match */ |
|
ds@579
|
321 |
if ((bits & cmdflags) == cmdflags) |
|
ds@579
|
322 |
{ |
|
ds@579
|
323 |
return true; |
|
ds@579
|
324 |
} |
|
ds@579
|
325 |
|
|
ds@579
|
326 |
/* Check for overrides */ |
|
ds@579
|
327 |
unsigned int groups = g_Admins.GetAdminGroupCount(adm); |
|
ds@579
|
328 |
GroupId gid; |
|
ds@579
|
329 |
OverrideRule rule; |
|
ds@579
|
330 |
bool override = false; |
|
ds@579
|
331 |
for (unsigned int i=0; i<groups; i++) |
|
ds@579
|
332 |
{ |
|
ds@579
|
333 |
gid = g_Admins.GetAdminGroup(adm, i, NULL); |
|
ds@579
|
334 |
/* First get group-level override */ |
|
ds@579
|
335 |
override = g_Admins.GetGroupCommandOverride(gid, cmd, Override_CommandGroup, &rule); |
|
ds@579
|
336 |
/* Now get the specific command override */ |
|
ds@579
|
337 |
if (g_Admins.GetGroupCommandOverride(gid, cmd, Override_Command, &rule)) |
|
ds@579
|
338 |
{ |
|
ds@579
|
339 |
override = true; |
|
ds@579
|
340 |
} |
|
ds@579
|
341 |
if (override) |
|
ds@579
|
342 |
{ |
|
ds@579
|
343 |
if (rule == Command_Allow) |
|
ds@579
|
344 |
{ |
|
ds@579
|
345 |
return true; |
|
ds@579
|
346 |
} else if (rule == Command_Deny) { |
|
ds@579
|
347 |
break; |
|
ds@579
|
348 |
} |
|
ds@579
|
349 |
} |
|
ds@579
|
350 |
} |
|
ds@579
|
351 |
} |
|
ds@579
|
352 |
|
|
ds@579
|
353 |
if (player->IsFakeClient() |
|
ds@579
|
354 |
|| player->GetEdict() == NULL) |
|
ds@579
|
355 |
{ |
|
ds@579
|
356 |
return false; |
|
ds@579
|
357 |
} |
|
ds@579
|
358 |
|
|
ds@579
|
359 |
/* If we got here, the command failed... */ |
|
ds@579
|
360 |
char buffer[128]; |
|
ds@579
|
361 |
if (g_Translator.CoreTrans(client, buffer, sizeof(buffer), "No Access", NULL, NULL) |
|
ds@579
|
362 |
!= Trans_Okay) |
|
ds@579
|
363 |
{ |
|
ds@579
|
364 |
snprintf(buffer, sizeof(buffer), "You do not have access to this command"); |
|
ds@579
|
365 |
} |
|
ds@579
|
366 |
|
|
ds@579
|
367 |
char fullbuffer[192]; |
|
ds@579
|
368 |
snprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer); |
|
ds@579
|
369 |
|
|
ds@579
|
370 |
engine->ClientPrintf(player->GetEdict(), fullbuffer); |
|
ds@579
|
371 |
|
|
ds@579
|
372 |
return false; |
|
ds@579
|
373 |
} |
|
ds@579
|
374 |
|
|
ds@579
|
375 |
bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction, |
|
ds@579
|
376 |
const char *name, |
|
ds@579
|
377 |
const char *description, |
|
ds@579
|
378 |
int flags) |
|
ds@579
|
379 |
{ |
|
ds@579
|
380 |
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); |
|
ds@579
|
381 |
|
|
ds@579
|
382 |
if (!pInfo) |
|
ds@579
|
383 |
{ |
|
ds@579
|
384 |
return false; |
|
ds@579
|
385 |
} |
|
ds@579
|
386 |
|
|
ds@579
|
387 |
CmdHook *pHook = new CmdHook(); |
|
ds@579
|
388 |
|
|
ds@579
|
389 |
pHook->pf = pFunction; |
|
ds@579
|
390 |
if (description && description[0]) |
|
ds@579
|
391 |
{ |
|
ds@579
|
392 |
pHook->helptext.assign(description); |
|
ds@579
|
393 |
} |
|
ds@579
|
394 |
pInfo->conhooks.push_back(pHook); |
|
ds@579
|
395 |
|
|
ds@579
|
396 |
/* Add to the plugin */ |
|
ds@579
|
397 |
CmdList *pList; |
|
ds@579
|
398 |
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); |
|
ds@579
|
399 |
if (!pPlugin->GetProperty("CommandList", (void **)&pList)) |
|
ds@579
|
400 |
{ |
|
ds@579
|
401 |
pList = new CmdList(); |
|
ds@579
|
402 |
pPlugin->SetProperty("CommandList", pList); |
|
ds@579
|
403 |
} |
|
ds@579
|
404 |
PlCmdInfo info; |
|
ds@579
|
405 |
info.pInfo = pInfo; |
|
ds@579
|
406 |
info.type = Cmd_Console; |
|
ds@579
|
407 |
info.pHook = pHook; |
|
ds@579
|
408 |
AddToPlCmdList(pList, info); |
|
ds@579
|
409 |
|
|
ds@579
|
410 |
return true; |
|
ds@579
|
411 |
} |
|
ds@579
|
412 |
|
|
ds@579
|
413 |
bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, |
|
ds@579
|
414 |
const char *name, |
|
ds@579
|
415 |
const char *group, |
|
ds@579
|
416 |
int adminflags, |
|
ds@579
|
417 |
const char *description, |
|
ds@579
|
418 |
int flags) |
|
ds@579
|
419 |
{ |
|
ds@579
|
420 |
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); |
|
ds@579
|
421 |
|
|
ds@579
|
422 |
if (!pInfo) |
|
ds@579
|
423 |
{ |
|
ds@579
|
424 |
return false; |
|
ds@579
|
425 |
} |
|
ds@579
|
426 |
|
|
ds@579
|
427 |
CmdHook *pHook = new CmdHook(); |
|
ds@579
|
428 |
AdminCmdInfo *pAdmin = new AdminCmdInfo(); |
|
ds@579
|
429 |
|
|
ds@579
|
430 |
pHook->pf = pFunction; |
|
ds@579
|
431 |
if (description && description[0]) |
|
ds@579
|
432 |
{ |
|
ds@579
|
433 |
pHook->helptext.assign(description); |
|
ds@579
|
434 |
} |
|
ds@579
|
435 |
pHook->pAdmin = pAdmin; |
|
ds@579
|
436 |
|
|
ds@579
|
437 |
void *object; |
|
ds@579
|
438 |
int grpid; |
|
ds@579
|
439 |
if (!sm_trie_retrieve(m_pCmdGrps, group, (void **)&object)) |
|
ds@579
|
440 |
{ |
|
ds@579
|
441 |
grpid = m_Strings.AddString(group); |
|
ds@579
|
442 |
sm_trie_insert(m_pCmdGrps, group, (void *)grpid); |
|
ds@579
|
443 |
} else { |
|
ds@579
|
444 |
grpid = (int)object; |
|
ds@579
|
445 |
} |
|
ds@579
|
446 |
|
|
ds@579
|
447 |
pAdmin->cmdGrpId = grpid; |
|
ds@579
|
448 |
pAdmin->flags = adminflags; |
|
ds@579
|
449 |
|
|
ds@579
|
450 |
/* First get the command group override, if any */ |
|
ds@579
|
451 |
bool override = g_Admins.GetCommandOverride(group, |
|
ds@579
|
452 |
Override_CommandGroup, |
|
ds@579
|
453 |
&(pAdmin->eflags)); |
|
ds@579
|
454 |
|
|
ds@579
|
455 |
/* Next get the command override, if any */ |
|
ds@579
|
456 |
if (g_Admins.GetCommandOverride(name, |
|
ds@579
|
457 |
Override_Command, |
|
ds@579
|
458 |
&(pAdmin->eflags))) |
|
ds@579
|
459 |
{ |
|
ds@579
|
460 |
override = true; |
|
ds@579
|
461 |
} |
|
ds@579
|
462 |
|
|
ds@579
|
463 |
/* Assign normal flags if there were no overrides */ |
|
ds@579
|
464 |
if (!override) |
|
ds@579
|
465 |
{ |
|
ds@579
|
466 |
pAdmin->eflags = pAdmin->flags; |
|
ds@579
|
467 |
} |
|
ds@579
|
468 |
|
|
ds@579
|
469 |
/* Finally, add the hook */ |
|
ds@579
|
470 |
pInfo->conhooks.push_back(pHook); |
|
ds@579
|
471 |
|
|
ds@579
|
472 |
/* Now add to the plugin */ |
|
ds@579
|
473 |
CmdList *pList; |
|
ds@579
|
474 |
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); |
|
ds@579
|
475 |
if (!pPlugin->GetProperty("CommandList", (void **)&pList)) |
|
ds@579
|
476 |
{ |
|
ds@579
|
477 |
pList = new CmdList(); |
|
ds@579
|
478 |
pPlugin->SetProperty("CommandList", pList); |
|
ds@579
|
479 |
} |
|
ds@579
|
480 |
PlCmdInfo info; |
|
ds@579
|
481 |
info.pInfo = pInfo; |
|
ds@579
|
482 |
info.type = Cmd_Admin; |
|
ds@579
|
483 |
info.pHook = pHook; |
|
ds@579
|
484 |
AddToPlCmdList(pList, info); |
|
ds@579
|
485 |
|
|
ds@579
|
486 |
return true; |
|
ds@579
|
487 |
} |
|
ds@579
|
488 |
|
|
ds@579
|
489 |
bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction, |
|
ds@579
|
490 |
const char *name, |
|
ds@579
|
491 |
const char *description, |
|
ds@579
|
492 |
int flags) |
|
ds@579
|
493 |
|
|
ds@579
|
494 |
{ |
|
ds@579
|
495 |
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); |
|
ds@579
|
496 |
|
|
ds@579
|
497 |
if (!pInfo) |
|
ds@579
|
498 |
{ |
|
ds@579
|
499 |
return false; |
|
ds@579
|
500 |
} |
|
ds@579
|
501 |
|
|
ds@579
|
502 |
CmdHook *pHook = new CmdHook(); |
|
ds@579
|
503 |
|
|
ds@579
|
504 |
pHook->pf = pFunction; |
|
ds@579
|
505 |
if (description && description[0]) |
|
ds@579
|
506 |
{ |
|
ds@579
|
507 |
pHook->helptext.assign(description); |
|
ds@579
|
508 |
} |
|
ds@579
|
509 |
|
|
ds@579
|
510 |
pInfo->srvhooks.push_back(pHook); |
|
ds@579
|
511 |
|
|
ds@579
|
512 |
/* Add to the plugin */ |
|
ds@579
|
513 |
CmdList *pList; |
|
ds@579
|
514 |
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); |
|
ds@579
|
515 |
if (!pPlugin->GetProperty("CommandList", (void **)&pList)) |
|
ds@579
|
516 |
{ |
|
ds@579
|
517 |
pList = new CmdList(); |
|
ds@579
|
518 |
pPlugin->SetProperty("CommandList", pList); |
|
ds@579
|
519 |
} |
|
ds@579
|
520 |
PlCmdInfo info; |
|
ds@579
|
521 |
info.pInfo = pInfo; |
|
ds@579
|
522 |
info.type = Cmd_Server; |
|
ds@579
|
523 |
info.pHook = pHook; |
|
ds@579
|
524 |
AddToPlCmdList(pList, info); |
|
ds@579
|
525 |
|
|
ds@579
|
526 |
return true; |
|
ds@579
|
527 |
} |
|
ds@579
|
528 |
|
|
ds@579
|
529 |
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info) |
|
ds@579
|
530 |
{ |
|
ds@579
|
531 |
CmdList::iterator iter = pList->begin(); |
|
ds@579
|
532 |
bool inserted = false; |
|
ds@579
|
533 |
const char *orig = NULL; |
|
ds@579
|
534 |
|
|
ds@579
|
535 |
orig = info.pInfo->pCmd->GetName(); |
|
ds@579
|
536 |
|
|
ds@579
|
537 |
/* Insert this into the help list, SORTED alphabetically. */ |
|
ds@579
|
538 |
while (iter != pList->end()) |
|
ds@579
|
539 |
{ |
|
ds@579
|
540 |
PlCmdInfo &obj = (*iter); |
|
ds@579
|
541 |
const char *cmd = obj.pInfo->pCmd->GetName(); |
|
ds@579
|
542 |
if (strcmp(orig, cmd) < 0) |
|
ds@579
|
543 |
{ |
|
ds@579
|
544 |
pList->insert(iter, info); |
|
ds@579
|
545 |
inserted = true; |
|
ds@579
|
546 |
break; |
|
ds@579
|
547 |
} |
|
ds@579
|
548 |
iter++; |
|
ds@579
|
549 |
} |
|
ds@579
|
550 |
|
|
ds@579
|
551 |
if (!inserted) |
|
ds@579
|
552 |
{ |
|
ds@579
|
553 |
pList->push_back(info); |
|
ds@579
|
554 |
} |
|
ds@579
|
555 |
} |
|
ds@579
|
556 |
|
|
ds@579
|
557 |
void ConCmdManager::AddToCmdList(ConCmdInfo *info) |
|
ds@579
|
558 |
{ |
|
ds@579
|
559 |
List<ConCmdInfo *>::iterator iter = m_CmdList.begin(); |
|
ds@579
|
560 |
ConCmdInfo *pInfo; |
|
ds@579
|
561 |
bool inserted = false; |
|
ds@579
|
562 |
const char *orig = NULL; |
|
ds@579
|
563 |
|
|
ds@579
|
564 |
orig = info->pCmd->GetName(); |
|
ds@579
|
565 |
|
|
ds@579
|
566 |
/* Insert this into the help list, SORTED alphabetically. */ |
|
ds@579
|
567 |
while (iter != m_CmdList.end()) |
|
ds@579
|
568 |
{ |
|
ds@579
|
569 |
const char *cmd = NULL; |
|
ds@579
|
570 |
pInfo = (*iter); |
|
ds@579
|
571 |
cmd = pInfo->pCmd->GetName(); |
|
ds@579
|
572 |
if (strcmp(orig, cmd) < 0) |
|
ds@579
|
573 |
{ |
|
ds@579
|
574 |
m_CmdList.insert(iter, info); |
|
ds@579
|
575 |
inserted = true; |
|
ds@579
|
576 |
break; |
|
ds@579
|
577 |
} |
|
ds@579
|
578 |
iter++; |
|
ds@579
|
579 |
} |
|
ds@579
|
580 |
|
|
ds@579
|
581 |
if (!inserted) |
|
ds@579
|
582 |
{ |
|
ds@579
|
583 |
m_CmdList.push_back(info); |
|
ds@579
|
584 |
} |
|
ds@579
|
585 |
} |
|
ds@579
|
586 |
|
|
ds@579
|
587 |
void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits) |
|
ds@579
|
588 |
{ |
|
ds@579
|
589 |
ConCmdInfo *pInfo; |
|
ds@579
|
590 |
|
|
ds@579
|
591 |
if (type == Override_Command) |
|
ds@579
|
592 |
{ |
|
ds@579
|
593 |
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) |
|
ds@579
|
594 |
{ |
|
ds@579
|
595 |
return; |
|
ds@579
|
596 |
} |
|
ds@579
|
597 |
|
|
ds@579
|
598 |
List<CmdHook *>::iterator iter; |
|
ds@579
|
599 |
CmdHook *pHook; |
|
ds@579
|
600 |
|
|
ds@579
|
601 |
for (iter=pInfo->conhooks.begin(); iter!=pInfo->conhooks.end(); iter++) |
|
ds@579
|
602 |
{ |
|
ds@579
|
603 |
pHook = (*iter); |
|
ds@579
|
604 |
if (pHook->pAdmin) |
|
ds@579
|
605 |
{ |
|
ds@579
|
606 |
if (bits) |
|
ds@579
|
607 |
{ |
|
ds@579
|
608 |
pHook->pAdmin->eflags = bits; |
|
ds@579
|
609 |
} else { |
|
ds@579
|
610 |
pHook->pAdmin->eflags = pHook->pAdmin->flags; |
|
ds@579
|
611 |
} |
|
ds@579
|
612 |
} |
|
ds@579
|
613 |
} |
|
ds@579
|
614 |
} else if (type == Override_CommandGroup) { |
|
ds@579
|
615 |
void *object; |
|
ds@579
|
616 |
if (!sm_trie_retrieve(m_pCmdGrps, cmd, &object)) |
|
ds@579
|
617 |
{ |
|
ds@579
|
618 |
return; |
|
ds@579
|
619 |
} |
|
ds@579
|
620 |
int grpid = (int)object; |
|
ds@579
|
621 |
|
|
ds@579
|
622 |
/* This is bad :( loop through all commands */ |
|
ds@579
|
623 |
List<ConCmdInfo *>::iterator iter; |
|
ds@579
|
624 |
CmdHook *pHook; |
|
ds@579
|
625 |
for (iter=m_CmdList.begin(); iter!=m_CmdList.end(); iter++) |
|
ds@579
|
626 |
{ |
|
ds@579
|
627 |
pInfo = (*iter); |
|
ds@579
|
628 |
for (List<CmdHook *>::iterator citer=pInfo->conhooks.begin(); |
|
ds@579
|
629 |
citer!=pInfo->conhooks.end(); |
|
ds@579
|
630 |
citer++) |
|
ds@579
|
631 |
{ |
|
ds@579
|
632 |
pHook = (*citer); |
|
ds@579
|
633 |
if (pHook->pAdmin && pHook->pAdmin->cmdGrpId == grpid) |
|
ds@579
|
634 |
{ |
|
ds@579
|
635 |
if (bits) |
|
ds@579
|
636 |
{ |
|
ds@579
|
637 |
pHook->pAdmin->eflags = bits; |
|
ds@579
|
638 |
} else { |
|
ds@579
|
639 |
pHook->pAdmin->eflags = pHook->pAdmin->flags; |
|
ds@579
|
640 |
} |
|
ds@579
|
641 |
} |
|
ds@579
|
642 |
} |
|
ds@579
|
643 |
} |
|
ds@579
|
644 |
} |
|
ds@579
|
645 |
} |
|
ds@579
|
646 |
|
|
ds@579
|
647 |
void ConCmdManager::RemoveConCmd(ConCmdInfo *info) |
|
ds@579
|
648 |
{ |
|
ds@579
|
649 |
/* Remove console-specific information |
|
ds@579
|
650 |
* This should always be true as of right now |
|
ds@579
|
651 |
*/ |
|
ds@579
|
652 |
if (info->pCmd) |
|
ds@579
|
653 |
{ |
|
ds@579
|
654 |
/* Remove from the trie */ |
|
ds@579
|
655 |
sm_trie_delete(m_pCmds, info->pCmd->GetName()); |
|
ds@579
|
656 |
|
|
ds@579
|
657 |
if (info->sourceMod) |
|
ds@579
|
658 |
{ |
|
ds@579
|
659 |
/* Unlink from SourceMM */ |
|
ds@579
|
660 |
g_SMAPI->UnregisterConCmdBase(g_PLAPI, info->pCmd); |
|
ds@579
|
661 |
/* Delete the command's memory */ |
|
ds@579
|
662 |
char *new_help = const_cast<char *>(info->pCmd->GetHelpText()); |
|
ds@579
|
663 |
char *new_name = const_cast<char *>(info->pCmd->GetName()); |
|
ds@579
|
664 |
delete [] new_help; |
|
ds@579
|
665 |
delete [] new_name; |
|
ds@579
|
666 |
delete info->pCmd; |
|
ds@579
|
667 |
} else { |
|
ds@579
|
668 |
/* Remove the external hook */ |
|
ds@579
|
669 |
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false); |
|
ds@579
|
670 |
} |
|
ds@579
|
671 |
} |
|
ds@579
|
672 |
|
|
ds@579
|
673 |
/* Remove from list */ |
|
ds@579
|
674 |
m_CmdList.remove(info); |
|
ds@579
|
675 |
|
|
ds@579
|
676 |
delete info; |
|
ds@579
|
677 |
} |
|
ds@579
|
678 |
|
|
ds@579
|
679 |
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags) |
|
ds@579
|
680 |
{ |
|
ds@579
|
681 |
ConCmdInfo *pInfo; |
|
ds@579
|
682 |
if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo)) |
|
ds@579
|
683 |
{ |
|
ds@579
|
684 |
pInfo = new ConCmdInfo(); |
|
ds@579
|
685 |
/* Find the commandopan */ |
|
ds@579
|
686 |
ConCommandBase *pBase = icvar->GetCommands(); |
|
ds@579
|
687 |
ConCommand *pCmd = NULL; |
|
ds@579
|
688 |
while (pBase) |
|
ds@579
|
689 |
{ |
|
ds@579
|
690 |
if (strcmp(pBase->GetName(), name) == 0) |
|
ds@579
|
691 |
{ |
|
ds@579
|
692 |
/* Don't want to return convar with same name */ |
|
ds@579
|
693 |
if (!pBase->IsCommand()) |
|
ds@579
|
694 |
{ |
|
ds@579
|
695 |
return NULL; |
|
ds@579
|
696 |
} |
|
ds@579
|
697 |
|
|
ds@579
|
698 |
pCmd = (ConCommand *)pBase; |
|
ds@579
|
699 |
break; |
|
ds@579
|
700 |
} |
|
ds@579
|
701 |
pBase = const_cast<ConCommandBase *>(pBase->GetNext()); |
|
ds@579
|
702 |
} |
|
ds@579
|
703 |
|
|
ds@579
|
704 |
if (!pCmd) |
|
ds@579
|
705 |
{ |
|
ds@579
|
706 |
/* Note that we have to duplicate because the source might not be |
|
ds@579
|
707 |
* a static string, and these expect static memory. |
|
ds@579
|
708 |
*/ |
|
ds@579
|
709 |
if (!description) |
|
ds@579
|
710 |
{ |
|
ds@579
|
711 |
description = ""; |
|
ds@579
|
712 |
} |
|
ds@579
|
713 |
char *new_name = sm_strdup(name); |
|
ds@579
|
714 |
char *new_help = sm_strdup(description); |
|
ds@579
|
715 |
pCmd = new ConCommand(new_name, CommandCallback, new_help, flags); |
|
ds@579
|
716 |
pInfo->sourceMod = true; |
|
ds@579
|
717 |
} else { |
|
ds@579
|
718 |
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CommandCallback, false); |
|
ds@579
|
719 |
} |
|
ds@579
|
720 |
|
|
ds@579
|
721 |
pInfo->pCmd = pCmd; |
|
ds@579
|
722 |
|
|
ds@579
|
723 |
sm_trie_insert(m_pCmds, name, pInfo); |
|
ds@579
|
724 |
AddToCmdList(pInfo); |
|
ds@579
|
725 |
} |
|
ds@579
|
726 |
|
|
ds@579
|
727 |
return pInfo; |
|
ds@579
|
728 |
} |
|
ds@579
|
729 |
|
|
ds@579
|
730 |
void ConCmdManager::OnRootConsoleCommand(const char *command, unsigned int argcount) |
|
ds@579
|
731 |
{ |
|
ds@579
|
732 |
if (argcount >= 3) |
|
ds@579
|
733 |
{ |
|
ds@579
|
734 |
const char *text = engine->Cmd_Argv(2); |
|
ds@579
|
735 |
int id = atoi(text); |
|
ds@579
|
736 |
CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id); |
|
ds@579
|
737 |
|
|
ds@579
|
738 |
if (!pPlugin) |
|
ds@579
|
739 |
{ |
|
ds@579
|
740 |
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); |
|
ds@579
|
741 |
return; |
|
ds@579
|
742 |
} |
|
ds@579
|
743 |
|
|
ds@582
|
744 |
const sm_plugininfo_t *plinfo = pPlugin->GetPublicInfo(); |
|
ds@582
|
745 |
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : pPlugin->GetFilename(); |
|
ds@582
|
746 |
|
|
ds@579
|
747 |
CmdList *pList; |
|
ds@579
|
748 |
if (!pPlugin->GetProperty("CommandList", (void **)&pList)) |
|
ds@579
|
749 |
{ |
|
ds@582
|
750 |
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); |
|
ds@579
|
751 |
return; |
|
ds@579
|
752 |
} |
|
ds@579
|
753 |
if (!pList->size()) |
|
ds@579
|
754 |
{ |
|
ds@582
|
755 |
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); |
|
ds@579
|
756 |
return; |
|
ds@579
|
757 |
} |
|
ds@579
|
758 |
|
|
ds@579
|
759 |
CmdList::iterator iter; |
|
ds@579
|
760 |
const char *type = NULL; |
|
ds@579
|
761 |
const char *name; |
|
ds@579
|
762 |
const char *help; |
|
ds@582
|
763 |
g_RootMenu.ConsolePrint("[SM] Listing %d commands for: %s", pList->size(), plname); |
|
ds@582
|
764 |
g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); |
|
ds@579
|
765 |
for (iter=pList->begin(); |
|
ds@579
|
766 |
iter!=pList->end(); |
|
ds@582
|
767 |
iter++, id++) |
|
ds@579
|
768 |
{ |
|
ds@579
|
769 |
PlCmdInfo &cmd = (*iter); |
|
ds@579
|
770 |
if (cmd.type == Cmd_Server) |
|
ds@579
|
771 |
{ |
|
ds@579
|
772 |
type = "server"; |
|
ds@579
|
773 |
} else if (cmd.type == Cmd_Console) { |
|
ds@579
|
774 |
type = "console"; |
|
ds@579
|
775 |
} else if (cmd.type == Cmd_Admin) { |
|
ds@579
|
776 |
type = "admin"; |
|
ds@579
|
777 |
} |
|
ds@579
|
778 |
name = cmd.pInfo->pCmd->GetName(); |
|
ds@579
|
779 |
if (cmd.pHook->helptext.size()) |
|
ds@579
|
780 |
{ |
|
ds@579
|
781 |
help = cmd.pHook->helptext.c_str(); |
|
ds@579
|
782 |
} else { |
|
ds@579
|
783 |
help = cmd.pInfo->pCmd->GetHelpText(); |
|
ds@579
|
784 |
} |
|
ds@582
|
785 |
g_RootMenu.ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); |
|
ds@579
|
786 |
} |
|
ds@579
|
787 |
|
|
ds@579
|
788 |
return; |
|
ds@579
|
789 |
} |
|
ds@579
|
790 |
|
|
ds@579
|
791 |
g_RootMenu.ConsolePrint("[SM] Usage: sm cmds <plugin #>"); |
|
ds@579
|
792 |
} |
|
dvander@614
|
793 |
|
|
dvander@614
|
794 |
static int g_yam_state = 0; |
|
dvander@614
|
795 |
void _YamState(int state) |
|
dvander@614
|
796 |
{ |
|
dvander@614
|
797 |
if (state == 0) |
|
dvander@614
|
798 |
{ |
|
dvander@614
|
799 |
g_RootMenu.ConsolePrint("Welcome to the SourceMod Text Adventure."); |
|
dvander@614
|
800 |
g_RootMenu.ConsolePrint("Type sm_text to see the last message."); |
|
dvander@614
|
801 |
g_RootMenu.ConsolePrint("Type sm_text <word> to follow a capital word."); |
|
dvander@614
|
802 |
g_RootMenu.ConsolePrint("-------------------------------"); |
|
dvander@614
|
803 |
g_RootMenu.ConsolePrint("You are at VALVE HEADQUARTERS."); |
|
dvander@614
|
804 |
g_RootMenu.ConsolePrint("To your LEFT is BAILOPAN, rearranging the letters to spell"); |
|
dvander@614
|
805 |
g_RootMenu.ConsolePrint("\"A HARD VEAL QUEST\". FORWARD is the entrance to the building."); |
|
dvander@614
|
806 |
g_RootMenu.ConsolePrint("To your RIGHT is your last chance to flee in terror."); |
|
dvander@614
|
807 |
} else if (state == 1) { |
|
dvander@614
|
808 |
g_RootMenu.ConsolePrint("BAILOPAN tells you that his name his pronounced"); |
|
dvander@614
|
809 |
g_RootMenu.ConsolePrint("\"bye low pahn,\" not \"bay low pan.\" Do you "); |
|
dvander@614
|
810 |
g_RootMenu.ConsolePrint("MOCK him, or NOD quietly?"); |
|
dvander@614
|
811 |
} else if (state == 2) { |
|
dvander@614
|
812 |
g_RootMenu.ConsolePrint("You enter the Valve building. You hear screams coming from within."); |
|
dvander@614
|
813 |
g_RootMenu.ConsolePrint("A grotesque figure lumbers up to greet you; it is Gabe Newell."); |
|
dvander@614
|
814 |
g_RootMenu.ConsolePrint("\"Welcome,\" he belches, \"to my lair.\""); |
|
dvander@614
|
815 |
g_RootMenu.ConsolePrint("Do you SHAKE Gaben's hand, WALK past him, or OFFER a donut?"); |
|
dvander@614
|
816 |
} else if (state == 3) { |
|
dvander@614
|
817 |
g_RootMenu.ConsolePrint("You walk into the break room. Alfred \"Adolf\" Reynolds and"); |
|
dvander@614
|
818 |
g_RootMenu.ConsolePrint("Yahn \"Yeti\" Bernier are discussing something (you overhear "); |
|
dvander@614
|
819 |
g_RootMenu.ConsolePrint("the phrase \"and next Steam update, here's what we should break\")."); |
|
dvander@614
|
820 |
g_RootMenu.ConsolePrint("Should you DIE in a fire, REPORT a bug, REQUEST a feature, or "); |
|
dvander@614
|
821 |
g_RootMenu.ConsolePrint("SPRAY them with butter?"); |
|
dvander@614
|
822 |
} |
|
dvander@614
|
823 |
g_yam_state = state; |
|
dvander@614
|
824 |
} |
|
dvander@614
|
825 |
|
|
dvander@614
|
826 |
void _IntExt_CallYams() |
|
dvander@614
|
827 |
{ |
|
dvander@614
|
828 |
const char *arg = engine->Cmd_Argv(1); |
|
dvander@614
|
829 |
|
|
dvander@614
|
830 |
/* should be impossible */ |
|
dvander@614
|
831 |
if (!arg || arg[0] == '\0') |
|
dvander@614
|
832 |
{ |
|
dvander@614
|
833 |
_YamState(g_yam_state); |
|
dvander@614
|
834 |
} |
|
dvander@614
|
835 |
|
|
dvander@614
|
836 |
if (g_yam_state == 1) |
|
dvander@614
|
837 |
{ |
|
dvander@614
|
838 |
if (strcasecmp(arg, "mock") == 0) |
|
dvander@614
|
839 |
{ |
|
dvander@614
|
840 |
g_RootMenu.ConsolePrint("You mock BAILOPAN's pronounciation. In a fit of range, "); |
|
dvander@614
|
841 |
g_RootMenu.ConsolePrint("he sticks an INT 3 call into your chest, rendering you broken."); |
|
dvander@614
|
842 |
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); |
|
dvander@614
|
843 |
g_yam_state = 0; |
|
dvander@614
|
844 |
} else if (strcasecmp(arg, "nod") == 0) { |
|
dvander@614
|
845 |
g_RootMenu.ConsolePrint("You nod quietly, and then slowly back away into the Valve headquarters."); |
|
dvander@614
|
846 |
_YamState(2); |
|
dvander@614
|
847 |
} else { |
|
dvander@614
|
848 |
g_RootMenu.ConsolePrint("Commands are MOCK and NOD."); |
|
dvander@614
|
849 |
} |
|
dvander@614
|
850 |
} else if (g_yam_state == 3) { |
|
dvander@614
|
851 |
if (strcasecmp(arg, "report") == 0) |
|
dvander@614
|
852 |
{ |
|
dvander@614
|
853 |
g_RootMenu.ConsolePrint("You report a bug to Alfred and Yeti. Immediately, both fall asleep."); |
|
dvander@614
|
854 |
g_RootMenu.ConsolePrint("You decay in the break room for two years while they sleep."); |
|
dvander@614
|
855 |
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); |
|
dvander@614
|
856 |
g_yam_state = 0; |
|
dvander@614
|
857 |
} else if (strcasecmp(arg, "request") == 0) { |
|
dvander@614
|
858 |
g_RootMenu.ConsolePrint("You request a feature to Alfred and Yeti. They both mutter something"); |
|
dvander@614
|
859 |
g_RootMenu.ConsolePrint("about it being implemented \"soon.\" Then, by accident, someone sends"); |
|
dvander@614
|
860 |
g_RootMenu.ConsolePrint("a message over \"Friends.\" The entire building catches fire."); |
|
dvander@614
|
861 |
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); |
|
dvander@614
|
862 |
g_yam_state = 0; |
|
dvander@614
|
863 |
} else if (strcasecmp(arg, "die") == 0) { |
|
dvander@614
|
864 |
g_RootMenu.ConsolePrint("For no reason, you suddenly catch fire. Alfred and Yeti find this"); |
|
dvander@614
|
865 |
g_RootMenu.ConsolePrint("deeply disturbing, and cover your flaming corpse with Episode 2"); |
|
dvander@614
|
866 |
g_RootMenu.ConsolePrint("advertisments. Coming soon, with Team Fortress 2, and Portal!"); |
|
dvander@614
|
867 |
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); |
|
dvander@614
|
868 |
g_yam_state = 0; |
|
dvander@614
|
869 |
} else if (strcasecmp(arg, "spray") == 0) { |
|
dvander@614
|
870 |
g_RootMenu.ConsolePrint("You spray Alfred and Yeti with butter. Like Jack Thompson to an"); |
|
dvander@614
|
871 |
g_RootMenu.ConsolePrint("ambulance, Gabe Newell instantly appears and devours them both."); |
|
dvander@614
|
872 |
g_RootMenu.ConsolePrint("You run away, just in time, as Gabe Newell explodes, registering "); |
|
dvander@614
|
873 |
g_RootMenu.ConsolePrint("a 5.6 earthquake. Outside, world peace is achieved."); |
|
dvander@614
|
874 |
g_RootMenu.ConsolePrint("YOU HAVE WON."); |
|
dvander@614
|
875 |
g_yam_state = 0; |
|
dvander@614
|
876 |
} |
|
dvander@614
|
877 |
} else if (g_yam_state == 2) { |
|
dvander@614
|
878 |
if (strcasecmp(arg, "shake") == 0) |
|
dvander@614
|
879 |
{ |
|
dvander@614
|
880 |
g_RootMenu.ConsolePrint("You shake Gaben's hand. It is a terrifying and disgusting experience."); |
|
dvander@614
|
881 |
g_RootMenu.ConsolePrint("However, you survive, and continue on."); |
|
dvander@614
|
882 |
_YamState(3); |
|
dvander@614
|
883 |
} else if (strcasecmp(arg, "offer") == 0) { |
|
dvander@614
|
884 |
g_RootMenu.ConsolePrint("You offer Gabe Newell one (1) donut. With a gleam in his eyes, "); |
|
dvander@614
|
885 |
g_RootMenu.ConsolePrint("he picks you up and devours you whole."); |
|
dvander@614
|
886 |
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); |
|
dvander@614
|
887 |
g_yam_state = 0; |
|
dvander@614
|
888 |
} else if (strcasecmp(arg, "walk") == 0) { |
|
dvander@614
|
889 |
g_RootMenu.ConsolePrint("You walk past Gabe Newell. He can't keep up with your pace!"); |
|
dvander@614
|
890 |
_YamState(3); |
|
dvander@614
|
891 |
} else { |
|
dvander@614
|
892 |
g_RootMenu.ConsolePrint("Commands are SHAKE, OFFER, and WALK."); |
|
dvander@614
|
893 |
} |
|
dvander@614
|
894 |
} else if (g_yam_state == 0) { |
|
dvander@614
|
895 |
if (strcasecmp(arg, "left") == 0) |
|
dvander@614
|
896 |
{ |
|
dvander@614
|
897 |
_YamState(1); |
|
dvander@614
|
898 |
} else if (strcasecmp(arg, "right") == 0) { |
|
dvander@614
|
899 |
g_RootMenu.ConsolePrint("You run away from the Valve headquarters in sheer terror."); |
|
dvander@614
|
900 |
g_RootMenu.ConsolePrint("While running, you smash into an unknown person, who turns out to be your soul mate."); |
|
dvander@614
|
901 |
g_RootMenu.ConsolePrint("You marry and raise a family of 3 kids."); |
|
dvander@614
|
902 |
g_RootMenu.ConsolePrint("Many years later, you look back, and realize this was your best choice."); |
|
dvander@614
|
903 |
g_RootMenu.ConsolePrint("YOU HAVE WON."); |
|
dvander@614
|
904 |
g_yam_state = 0; |
|
dvander@614
|
905 |
} else if (strcasecmp(arg, "forward") == 0) { |
|
dvander@614
|
906 |
_YamState(2); |
|
dvander@614
|
907 |
} else if (arg[0] != '\0') { |
|
dvander@614
|
908 |
g_RootMenu.ConsolePrint("Commands are FORWARD, LEFT, and RIGHT."); |
|
dvander@614
|
909 |
} |
|
dvander@614
|
910 |
} |
|
dvander@614
|
911 |
} |
|
dvander@614
|
912 |
|
|
dvander@614
|
913 |
void _IntExt_EnableYams() |
|
dvander@614
|
914 |
{ |
|
dvander@614
|
915 |
static ConCommand *pCmd = NULL; |
|
dvander@614
|
916 |
if (!pCmd) |
|
dvander@614
|
917 |
{ |
|
dvander@614
|
918 |
pCmd = new ConCommand("sm_text", _IntExt_CallYams, "Fountain of Yams Adventure Game", FCVAR_GAMEDLL); |
|
dvander@614
|
919 |
g_RootMenu.ConsolePrint("Something is now enabled..."); |
|
dvander@614
|
920 |
} else { |
|
dvander@614
|
921 |
g_RootMenu.ConsolePrint("Something is already enabled..."); |
|
dvander@614
|
922 |
} |
|
dvander@614
|
923 |
} |