2007-02-16 08:48:38 +01:00
|
|
|
/**
|
2007-03-22 22:50:20 +01:00
|
|
|
* vim: set ts=4 :
|
2007-03-01 02:02:47 +01:00
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
2007-02-16 08:48:38 +01:00
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
#include "ConCmdManager.h"
|
2007-02-15 23:17:01 +01:00
|
|
|
#include "sm_srvcmds.h"
|
2007-02-17 08:54:20 +01:00
|
|
|
#include "AdminCache.h"
|
2007-02-16 08:48:38 +01:00
|
|
|
#include "sm_stringutil.h"
|
2007-03-10 22:18:07 +01:00
|
|
|
#include "PlayerManager.h"
|
|
|
|
#include "Translator.h"
|
2007-02-15 23:17:01 +01:00
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
ConCmdManager g_ConCmds;
|
2007-02-15 23:17:01 +01:00
|
|
|
|
|
|
|
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
|
|
|
|
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
|
|
|
|
|
|
|
|
struct PlCmdInfo
|
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo;
|
2007-02-17 08:54:20 +01:00
|
|
|
CmdHook *pHook;
|
2007-02-15 23:17:01 +01:00
|
|
|
CmdType type;
|
|
|
|
};
|
|
|
|
typedef List<PlCmdInfo> CmdList;
|
2007-05-02 22:44:35 +02:00
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info);
|
2007-02-15 23:17:01 +01:00
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
ConCmdManager::ConCmdManager() : m_Strings(1024)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
m_pCmds = sm_trie_create();
|
2007-02-17 08:54:20 +01:00
|
|
|
m_pCmdGrps = sm_trie_create();
|
2007-05-02 22:44:35 +02:00
|
|
|
m_bServerCfgDone = true;
|
|
|
|
m_pExecCmd = NULL;
|
|
|
|
m_pServerCfgFile = NULL;
|
|
|
|
m_pServerCfgFwd = NULL;
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
ConCmdManager::~ConCmdManager()
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
sm_trie_destroy(m_pCmds);
|
2007-02-17 08:54:20 +01:00
|
|
|
sm_trie_destroy(m_pCmdGrps);
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::OnSourceModAllInitialized()
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
g_PluginSys.AddPluginsListener(this);
|
|
|
|
g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this);
|
2007-03-06 07:15:19 +01:00
|
|
|
SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
|
2007-05-02 22:44:35 +02:00
|
|
|
|
|
|
|
ConCommandBase *pCmd = icvar->GetCommands();
|
|
|
|
while (pCmd)
|
|
|
|
{
|
|
|
|
if (pCmd->IsCommand()
|
|
|
|
&& strcmp(pCmd->GetName(), "exec") == 0)
|
|
|
|
{
|
|
|
|
m_pExecCmd = (ConCommand *)pCmd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pCmd = const_cast<ConCommandBase *>(pCmd->GetNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_pExecCmd)
|
|
|
|
{
|
|
|
|
m_pServerCfgFile = (ConVar *)icvar->FindVar("servercfgfile");
|
|
|
|
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pExecCmd, this, &ConCmdManager::OnExecCmd, true);
|
|
|
|
m_pServerCfgFwd = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
|
|
|
|
}
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::OnSourceModShutdown()
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-05-02 22:44:35 +02:00
|
|
|
if (m_pExecCmd)
|
|
|
|
{
|
|
|
|
SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pExecCmd, this, &ConCmdManager::OnExecCmd, true);
|
|
|
|
g_Forwards.ReleaseForward(m_pServerCfgFwd);
|
|
|
|
m_pServerCfgFwd = NULL;
|
|
|
|
m_pExecCmd = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-16 03:17:41 +01:00
|
|
|
/* All commands should already be removed by the time we're done */
|
2007-03-06 07:15:19 +01:00
|
|
|
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
|
2007-02-15 23:17:01 +01:00
|
|
|
g_RootMenu.RemoveRootConsoleCommand("cmds", this);
|
|
|
|
}
|
|
|
|
|
2007-05-02 22:44:35 +02:00
|
|
|
void ConCmdManager::OnSourceModPluginsLoaded()
|
|
|
|
{
|
|
|
|
m_bServerCfgDone = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConCmdManager::OnExecCmd()
|
|
|
|
{
|
|
|
|
const char *arg = engine->Cmd_Argv(1);
|
|
|
|
const char *cfgfile = "server.cfg";
|
|
|
|
|
|
|
|
if (m_pServerCfgFile)
|
|
|
|
{
|
|
|
|
cfgfile = m_pServerCfgFile->GetString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(arg, cfgfile) == 0)
|
|
|
|
{
|
|
|
|
engine->ServerCommand("sm cmds internal 1\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConCmdManager::NotifyExecDone(const char *file)
|
|
|
|
{
|
|
|
|
if (file == NULL && !m_bServerCfgDone)
|
|
|
|
{
|
|
|
|
/* Server-cfg file */
|
|
|
|
m_bServerCfgDone = true;
|
|
|
|
m_pServerCfgFwd->Execute(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
List<CmdHook *>::iterator iter = cmdlist.begin();
|
|
|
|
CmdHook *pHook;
|
|
|
|
|
|
|
|
while (iter != cmdlist.end())
|
|
|
|
{
|
|
|
|
pHook = (*iter);
|
|
|
|
if (pHook->pf->GetParentContext() == pContext)
|
|
|
|
{
|
|
|
|
delete pHook->pAdmin;
|
|
|
|
delete pHook;
|
|
|
|
iter = cmdlist.erase(iter);
|
|
|
|
} else {
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
CmdList *pList;
|
2007-02-16 03:17:41 +01:00
|
|
|
List<ConCmdInfo *> removed;
|
2007-02-15 23:17:01 +01:00
|
|
|
if (plugin->GetProperty("CommandList", (void **)&pList, true))
|
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
IPluginContext *pContext = plugin->GetBaseContext();
|
2007-02-15 23:17:01 +01:00
|
|
|
CmdList::iterator iter;
|
2007-02-17 08:54:20 +01:00
|
|
|
/* First pass!
|
|
|
|
* Only bother if there's an actual command list on this plugin...
|
|
|
|
*/
|
2007-02-15 23:17:01 +01:00
|
|
|
for (iter=pList->begin();
|
2007-02-17 08:54:20 +01:00
|
|
|
iter!=pList->end();
|
|
|
|
iter++)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
PlCmdInfo &cmd = (*iter);
|
2007-02-17 08:54:20 +01:00
|
|
|
ConCmdInfo *pInfo = cmd.pInfo;
|
|
|
|
|
|
|
|
/* Has this chain already been fully cleaned/removed? */
|
|
|
|
if (removed.find(pInfo) != removed.end())
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove any hooks from us on this command */
|
|
|
|
RemoveConCmds(pInfo->conhooks, pContext);
|
|
|
|
RemoveConCmds(pInfo->srvhooks, pContext);
|
|
|
|
|
|
|
|
/* See if there are still hooks */
|
|
|
|
if (pInfo->srvhooks.size())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pInfo->conhooks.size())
|
|
|
|
{
|
|
|
|
continue;
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
2007-02-17 08:54:20 +01:00
|
|
|
|
|
|
|
/* Remove the command, it should be safe now */
|
|
|
|
RemoveConCmd(pInfo);
|
|
|
|
removed.push_back(pInfo);
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
delete pList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandCallback()
|
|
|
|
{
|
|
|
|
g_ConCmds.InternalDispatch();
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::SetCommandClient(int client)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
m_CmdClient = client + 1;
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
ResultType ConCmdManager::DispatchClientCommand(int client, ResultType type)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-16 03:17:41 +01:00
|
|
|
const char *cmd = engine->Cmd_Argv(0);
|
|
|
|
int args = engine->Cmd_Argc() - 1;
|
|
|
|
|
|
|
|
ConCmdInfo *pInfo;
|
|
|
|
if (sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-16 03:17:41 +01:00
|
|
|
cell_t result = type;
|
2007-02-17 08:54:20 +01:00
|
|
|
cell_t tempres = result;
|
|
|
|
List<CmdHook *>::iterator iter;
|
|
|
|
CmdHook *pHook;
|
|
|
|
for (iter=pInfo->conhooks.begin();
|
|
|
|
iter!=pInfo->conhooks.end();
|
|
|
|
iter++)
|
2007-02-16 03:17:41 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook = (*iter);
|
2007-02-22 03:05:50 +01:00
|
|
|
if (!pHook->pf->IsRunnable())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-17 09:59:52 +01:00
|
|
|
if (pHook->pAdmin && !CheckAccess(client, cmd, pHook->pAdmin))
|
2007-02-17 08:54:20 +01:00
|
|
|
{
|
2007-02-17 09:59:52 +01:00
|
|
|
if (result < Pl_Handled)
|
|
|
|
{
|
|
|
|
result = Pl_Handled;
|
|
|
|
}
|
|
|
|
continue;
|
2007-02-17 08:54:20 +01:00
|
|
|
}
|
|
|
|
pHook->pf->PushCell(client);
|
|
|
|
pHook->pf->PushCell(args);
|
|
|
|
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
|
|
|
|
{
|
|
|
|
if (tempres > result)
|
|
|
|
{
|
|
|
|
result = tempres;
|
|
|
|
}
|
|
|
|
if (result == Pl_Stop)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 03:17:41 +01:00
|
|
|
}
|
|
|
|
type = (ResultType)result;
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-02-16 03:17:41 +01:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::InternalDispatch()
|
2007-02-16 03:17:41 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Note: Console commands will EITHER go through IServerGameDLL::ClientCommand,
|
|
|
|
* OR this dispatch. They will NEVER go through both.
|
|
|
|
* --
|
|
|
|
* Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
|
|
|
|
*/
|
|
|
|
|
2007-02-15 23:17:01 +01:00
|
|
|
const char *cmd = engine->Cmd_Argv(0);
|
|
|
|
ConCmdInfo *pInfo;
|
|
|
|
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t result = Pl_Continue;
|
2007-02-16 03:17:41 +01:00
|
|
|
int args = engine->Cmd_Argc() - 1;
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
List<CmdHook *>::iterator iter;
|
|
|
|
CmdHook *pHook;
|
|
|
|
|
|
|
|
/* Execute server-only commands if viable */
|
|
|
|
if (m_CmdClient == 0 && pInfo->srvhooks.size())
|
2007-02-16 03:17:41 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
cell_t tempres = result;
|
|
|
|
for (iter=pInfo->srvhooks.begin();
|
|
|
|
iter!=pInfo->srvhooks.end();
|
|
|
|
iter++)
|
2007-02-16 03:17:41 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook = (*iter);
|
2007-02-22 03:05:50 +01:00
|
|
|
if (!pHook->pf->IsRunnable())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook->pf->PushCell(args);
|
|
|
|
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
|
|
|
|
{
|
|
|
|
if (tempres > result)
|
|
|
|
{
|
|
|
|
result = tempres;
|
|
|
|
}
|
|
|
|
if (result == Pl_Stop)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 03:17:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if there's an early stop */
|
|
|
|
if (result >= Pl_Stop)
|
|
|
|
{
|
|
|
|
if (!pInfo->sourceMod)
|
|
|
|
{
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
/* Execute console commands */
|
|
|
|
if (pInfo->conhooks.size())
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
cell_t tempres = result;
|
|
|
|
for (iter=pInfo->conhooks.begin();
|
|
|
|
iter!=pInfo->conhooks.end();
|
|
|
|
iter++)
|
|
|
|
{
|
|
|
|
pHook = (*iter);
|
2007-02-22 03:05:50 +01:00
|
|
|
if (!pHook->pf->IsRunnable())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-17 08:54:20 +01:00
|
|
|
if (m_CmdClient
|
|
|
|
&& pHook->pAdmin
|
2007-02-17 09:59:52 +01:00
|
|
|
&& !CheckAccess(m_CmdClient, cmd, pHook->pAdmin))
|
2007-02-17 08:54:20 +01:00
|
|
|
{
|
2007-02-17 09:59:52 +01:00
|
|
|
if (result < Pl_Handled)
|
|
|
|
{
|
|
|
|
result = Pl_Handled;
|
|
|
|
}
|
|
|
|
continue;
|
2007-02-17 08:54:20 +01:00
|
|
|
}
|
|
|
|
pHook->pf->PushCell(m_CmdClient);
|
|
|
|
pHook->pf->PushCell(args);
|
2007-02-28 00:51:38 +01:00
|
|
|
if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE)
|
2007-02-17 08:54:20 +01:00
|
|
|
{
|
|
|
|
if (tempres > result)
|
|
|
|
{
|
|
|
|
result = tempres;
|
|
|
|
}
|
|
|
|
if (result == Pl_Stop)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result >= Pl_Handled)
|
|
|
|
{
|
|
|
|
if (!pInfo->sourceMod)
|
|
|
|
{
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin)
|
2007-02-17 08:54:20 +01:00
|
|
|
{
|
2007-02-17 09:59:52 +01:00
|
|
|
FlagBits cmdflags = pAdmin->eflags;
|
|
|
|
if (cmdflags == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPlayer *player = g_Players.GetPlayerByIndex(client);
|
|
|
|
if (!player)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AdminId adm = player->GetAdminId();
|
|
|
|
if (adm != INVALID_ADMIN_ID)
|
|
|
|
{
|
|
|
|
FlagBits bits = g_Admins.GetAdminFlags(adm, Access_Effective);
|
|
|
|
|
|
|
|
/* root knows all, WHOA */
|
|
|
|
if ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if our other flags match */
|
2007-02-17 20:03:18 +01:00
|
|
|
if ((bits & cmdflags) == cmdflags)
|
2007-02-17 09:59:52 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for overrides */
|
|
|
|
unsigned int groups = g_Admins.GetAdminGroupCount(adm);
|
|
|
|
GroupId gid;
|
|
|
|
OverrideRule rule;
|
|
|
|
bool override = false;
|
|
|
|
for (unsigned int i=0; i<groups; i++)
|
|
|
|
{
|
|
|
|
gid = g_Admins.GetAdminGroup(adm, i, NULL);
|
|
|
|
/* First get group-level override */
|
|
|
|
override = g_Admins.GetGroupCommandOverride(gid, cmd, Override_CommandGroup, &rule);
|
|
|
|
/* Now get the specific command override */
|
|
|
|
if (g_Admins.GetGroupCommandOverride(gid, cmd, Override_Command, &rule))
|
|
|
|
{
|
|
|
|
override = true;
|
|
|
|
}
|
|
|
|
if (override)
|
|
|
|
{
|
|
|
|
if (rule == Command_Allow)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
} else if (rule == Command_Deny) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-17 20:03:18 +01:00
|
|
|
if (player->IsFakeClient()
|
|
|
|
|| player->GetEdict() == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-17 09:59:52 +01:00
|
|
|
/* If we got here, the command failed... */
|
2007-02-17 20:03:18 +01:00
|
|
|
char buffer[128];
|
|
|
|
if (g_Translator.CoreTrans(client, buffer, sizeof(buffer), "No Access", NULL, NULL)
|
|
|
|
!= Trans_Okay)
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeof(buffer), "You do not have access to this command");
|
|
|
|
}
|
|
|
|
|
|
|
|
char fullbuffer[192];
|
|
|
|
snprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer);
|
|
|
|
|
|
|
|
engine->ClientPrintf(player->GetEdict(), fullbuffer);
|
|
|
|
|
2007-02-17 09:59:52 +01:00
|
|
|
return false;
|
2007-02-17 08:54:20 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction,
|
2007-02-16 03:17:41 +01:00
|
|
|
const char *name,
|
|
|
|
const char *description,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
|
2007-03-06 07:15:19 +01:00
|
|
|
|
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
CmdHook *pHook = new CmdHook();
|
2007-02-16 03:17:41 +01:00
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook->pf = pFunction;
|
|
|
|
if (description && description[0])
|
2007-02-16 03:17:41 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook->helptext.assign(description);
|
2007-02-16 03:17:41 +01:00
|
|
|
}
|
2007-02-17 08:54:20 +01:00
|
|
|
pInfo->conhooks.push_back(pHook);
|
2007-02-16 03:17:41 +01:00
|
|
|
|
|
|
|
/* Add to the plugin */
|
|
|
|
CmdList *pList;
|
|
|
|
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
|
|
|
|
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
|
|
|
|
{
|
|
|
|
pList = new CmdList();
|
|
|
|
pPlugin->SetProperty("CommandList", pList);
|
|
|
|
}
|
|
|
|
PlCmdInfo info;
|
|
|
|
info.pInfo = pInfo;
|
|
|
|
info.type = Cmd_Console;
|
2007-02-17 08:54:20 +01:00
|
|
|
info.pHook = pHook;
|
|
|
|
AddToPlCmdList(pList, info);
|
2007-03-06 07:15:19 +01:00
|
|
|
|
|
|
|
return true;
|
2007-02-17 08:54:20 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
|
2007-02-17 08:54:20 +01:00
|
|
|
const char *name,
|
|
|
|
const char *group,
|
|
|
|
int adminflags,
|
|
|
|
const char *description,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
CmdHook *pHook = new CmdHook();
|
|
|
|
AdminCmdInfo *pAdmin = new AdminCmdInfo();
|
|
|
|
|
|
|
|
pHook->pf = pFunction;
|
|
|
|
if (description && description[0])
|
|
|
|
{
|
|
|
|
pHook->helptext.assign(description);
|
|
|
|
}
|
|
|
|
pHook->pAdmin = pAdmin;
|
|
|
|
|
|
|
|
void *object;
|
|
|
|
int grpid;
|
|
|
|
if (!sm_trie_retrieve(m_pCmdGrps, group, (void **)&object))
|
|
|
|
{
|
|
|
|
grpid = m_Strings.AddString(group);
|
|
|
|
sm_trie_insert(m_pCmdGrps, group, (void *)grpid);
|
|
|
|
} else {
|
|
|
|
grpid = (int)object;
|
|
|
|
}
|
|
|
|
|
|
|
|
pAdmin->cmdGrpId = grpid;
|
2007-02-17 20:03:18 +01:00
|
|
|
pAdmin->flags = adminflags;
|
2007-02-17 08:54:20 +01:00
|
|
|
|
|
|
|
/* First get the command group override, if any */
|
|
|
|
bool override = g_Admins.GetCommandOverride(group,
|
|
|
|
Override_CommandGroup,
|
|
|
|
&(pAdmin->eflags));
|
|
|
|
|
|
|
|
/* Next get the command override, if any */
|
|
|
|
if (g_Admins.GetCommandOverride(name,
|
|
|
|
Override_Command,
|
|
|
|
&(pAdmin->eflags)))
|
|
|
|
{
|
|
|
|
override = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assign normal flags if there were no overrides */
|
|
|
|
if (!override)
|
|
|
|
{
|
|
|
|
pAdmin->eflags = pAdmin->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, add the hook */
|
|
|
|
pInfo->conhooks.push_back(pHook);
|
|
|
|
|
|
|
|
/* Now add to the plugin */
|
|
|
|
CmdList *pList;
|
|
|
|
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
|
|
|
|
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
|
|
|
|
{
|
|
|
|
pList = new CmdList();
|
|
|
|
pPlugin->SetProperty("CommandList", pList);
|
|
|
|
}
|
|
|
|
PlCmdInfo info;
|
|
|
|
info.pInfo = pInfo;
|
|
|
|
info.type = Cmd_Admin;
|
|
|
|
info.pHook = pHook;
|
|
|
|
AddToPlCmdList(pList, info);
|
|
|
|
|
|
|
|
return true;
|
2007-02-16 03:17:41 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction,
|
2007-02-15 23:17:01 +01:00
|
|
|
const char *name,
|
|
|
|
const char *description,
|
|
|
|
int flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
|
2007-03-06 07:15:19 +01:00
|
|
|
|
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
CmdHook *pHook = new CmdHook();
|
2007-02-15 23:17:01 +01:00
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook->pf = pFunction;
|
|
|
|
if (description && description[0])
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-17 08:54:20 +01:00
|
|
|
pHook->helptext.assign(description);
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-02-17 08:54:20 +01:00
|
|
|
pInfo->srvhooks.push_back(pHook);
|
2007-02-15 23:17:01 +01:00
|
|
|
|
|
|
|
/* Add to the plugin */
|
|
|
|
CmdList *pList;
|
|
|
|
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
|
|
|
|
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
|
|
|
|
{
|
|
|
|
pList = new CmdList();
|
|
|
|
pPlugin->SetProperty("CommandList", pList);
|
|
|
|
}
|
|
|
|
PlCmdInfo info;
|
|
|
|
info.pInfo = pInfo;
|
2007-02-16 03:17:41 +01:00
|
|
|
info.type = Cmd_Server;
|
2007-02-17 08:54:20 +01:00
|
|
|
info.pHook = pHook;
|
|
|
|
AddToPlCmdList(pList, info);
|
2007-03-06 07:15:19 +01:00
|
|
|
|
|
|
|
return true;
|
2007-02-17 08:54:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info)
|
|
|
|
{
|
|
|
|
CmdList::iterator iter = pList->begin();
|
|
|
|
bool inserted = false;
|
|
|
|
const char *orig = NULL;
|
|
|
|
|
|
|
|
orig = info.pInfo->pCmd->GetName();
|
|
|
|
|
|
|
|
/* Insert this into the help list, SORTED alphabetically. */
|
|
|
|
while (iter != pList->end())
|
|
|
|
{
|
|
|
|
PlCmdInfo &obj = (*iter);
|
|
|
|
const char *cmd = obj.pInfo->pCmd->GetName();
|
|
|
|
if (strcmp(orig, cmd) < 0)
|
|
|
|
{
|
|
|
|
pList->insert(iter, info);
|
|
|
|
inserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inserted)
|
|
|
|
{
|
|
|
|
pList->push_back(info);
|
|
|
|
}
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::AddToCmdList(ConCmdInfo *info)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
List<ConCmdInfo *>::iterator iter = m_CmdList.begin();
|
|
|
|
ConCmdInfo *pInfo;
|
|
|
|
bool inserted = false;
|
2007-02-16 05:43:48 +01:00
|
|
|
const char *orig = NULL;
|
2007-02-15 23:17:01 +01:00
|
|
|
|
2007-02-16 05:43:48 +01:00
|
|
|
orig = info->pCmd->GetName();
|
2007-02-15 23:17:01 +01:00
|
|
|
|
|
|
|
/* Insert this into the help list, SORTED alphabetically. */
|
|
|
|
while (iter != m_CmdList.end())
|
|
|
|
{
|
|
|
|
const char *cmd = NULL;
|
|
|
|
pInfo = (*iter);
|
2007-02-16 05:43:48 +01:00
|
|
|
cmd = pInfo->pCmd->GetName();
|
2007-02-15 23:17:01 +01:00
|
|
|
if (strcmp(orig, cmd) < 0)
|
|
|
|
{
|
|
|
|
m_CmdList.insert(iter, info);
|
|
|
|
inserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inserted)
|
|
|
|
{
|
|
|
|
m_CmdList.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits)
|
2007-02-17 09:59:52 +01:00
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo;
|
|
|
|
|
|
|
|
if (type == Override_Command)
|
|
|
|
{
|
|
|
|
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<CmdHook *>::iterator iter;
|
|
|
|
CmdHook *pHook;
|
|
|
|
|
|
|
|
for (iter=pInfo->conhooks.begin(); iter!=pInfo->conhooks.end(); iter++)
|
|
|
|
{
|
|
|
|
pHook = (*iter);
|
|
|
|
if (pHook->pAdmin)
|
|
|
|
{
|
|
|
|
if (bits)
|
|
|
|
{
|
|
|
|
pHook->pAdmin->eflags = bits;
|
|
|
|
} else {
|
|
|
|
pHook->pAdmin->eflags = pHook->pAdmin->flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type == Override_CommandGroup) {
|
|
|
|
void *object;
|
|
|
|
if (!sm_trie_retrieve(m_pCmdGrps, cmd, &object))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int grpid = (int)object;
|
|
|
|
|
|
|
|
/* This is bad :( loop through all commands */
|
|
|
|
List<ConCmdInfo *>::iterator iter;
|
|
|
|
CmdHook *pHook;
|
|
|
|
for (iter=m_CmdList.begin(); iter!=m_CmdList.end(); iter++)
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
|
|
|
for (List<CmdHook *>::iterator citer=pInfo->conhooks.begin();
|
|
|
|
citer!=pInfo->conhooks.end();
|
|
|
|
citer++)
|
|
|
|
{
|
|
|
|
pHook = (*citer);
|
|
|
|
if (pHook->pAdmin && pHook->pAdmin->cmdGrpId == grpid)
|
|
|
|
{
|
|
|
|
if (bits)
|
|
|
|
{
|
|
|
|
pHook->pAdmin->eflags = bits;
|
|
|
|
} else {
|
|
|
|
pHook->pAdmin->eflags = pHook->pAdmin->flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::RemoveConCmd(ConCmdInfo *info)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-16 05:43:48 +01:00
|
|
|
/* Remove console-specific information
|
|
|
|
* This should always be true as of right now
|
|
|
|
*/
|
2007-02-15 23:17:01 +01:00
|
|
|
if (info->pCmd)
|
|
|
|
{
|
|
|
|
/* Remove from the trie */
|
|
|
|
sm_trie_delete(m_pCmds, info->pCmd->GetName());
|
|
|
|
|
|
|
|
if (info->sourceMod)
|
|
|
|
{
|
|
|
|
/* Unlink from SourceMM */
|
|
|
|
g_SMAPI->UnregisterConCmdBase(g_PLAPI, info->pCmd);
|
|
|
|
/* Delete the command's memory */
|
|
|
|
char *new_help = const_cast<char *>(info->pCmd->GetHelpText());
|
|
|
|
char *new_name = const_cast<char *>(info->pCmd->GetName());
|
|
|
|
delete [] new_help;
|
|
|
|
delete [] new_name;
|
|
|
|
delete info->pCmd;
|
|
|
|
} else {
|
|
|
|
/* Remove the external hook */
|
|
|
|
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove from list */
|
|
|
|
m_CmdList.remove(info);
|
2007-02-17 08:54:20 +01:00
|
|
|
|
|
|
|
delete info;
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
|
|
|
ConCmdInfo *pInfo;
|
|
|
|
if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo))
|
|
|
|
{
|
|
|
|
pInfo = new ConCmdInfo();
|
|
|
|
/* Find the commandopan */
|
|
|
|
ConCommandBase *pBase = icvar->GetCommands();
|
|
|
|
ConCommand *pCmd = NULL;
|
|
|
|
while (pBase)
|
|
|
|
{
|
2007-03-06 07:15:19 +01:00
|
|
|
if (strcmp(pBase->GetName(), name) == 0)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-03-06 07:15:19 +01:00
|
|
|
/* Don't want to return convar with same name */
|
|
|
|
if (!pBase->IsCommand())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-15 23:17:01 +01:00
|
|
|
pCmd = (ConCommand *)pBase;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pBase = const_cast<ConCommandBase *>(pBase->GetNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pCmd)
|
|
|
|
{
|
|
|
|
/* Note that we have to duplicate because the source might not be
|
|
|
|
* a static string, and these expect static memory.
|
|
|
|
*/
|
|
|
|
if (!description)
|
|
|
|
{
|
|
|
|
description = "";
|
|
|
|
}
|
|
|
|
char *new_name = sm_strdup(name);
|
|
|
|
char *new_help = sm_strdup(description);
|
|
|
|
pCmd = new ConCommand(new_name, CommandCallback, new_help, flags);
|
|
|
|
pInfo->sourceMod = true;
|
|
|
|
} else {
|
|
|
|
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CommandCallback, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->pCmd = pCmd;
|
|
|
|
|
|
|
|
sm_trie_insert(m_pCmds, name, pInfo);
|
|
|
|
AddToCmdList(pInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pInfo;
|
|
|
|
}
|
|
|
|
|
2007-03-06 07:15:19 +01:00
|
|
|
void ConCmdManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
|
2007-02-15 23:17:01 +01:00
|
|
|
{
|
2007-02-16 01:04:14 +01:00
|
|
|
if (argcount >= 3)
|
|
|
|
{
|
|
|
|
const char *text = engine->Cmd_Argv(2);
|
2007-05-02 22:44:35 +02:00
|
|
|
|
|
|
|
if (strcmp(text, "internal") == 0)
|
|
|
|
{
|
|
|
|
const char *num = engine->Cmd_Argv(3);
|
|
|
|
if (atoi(num) == 1)
|
|
|
|
{
|
2007-05-02 22:46:21 +02:00
|
|
|
NotifyExecDone(NULL);
|
2007-05-02 22:44:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-16 01:04:14 +01:00
|
|
|
int id = atoi(text);
|
|
|
|
CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id);
|
|
|
|
|
|
|
|
if (!pPlugin)
|
|
|
|
{
|
|
|
|
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-07 00:59:25 +01:00
|
|
|
const sm_plugininfo_t *plinfo = pPlugin->GetPublicInfo();
|
|
|
|
const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : pPlugin->GetFilename();
|
|
|
|
|
2007-02-16 01:04:14 +01:00
|
|
|
CmdList *pList;
|
|
|
|
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
|
|
|
|
{
|
2007-03-07 00:59:25 +01:00
|
|
|
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname);
|
2007-02-16 01:04:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pList->size())
|
|
|
|
{
|
2007-03-07 00:59:25 +01:00
|
|
|
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname);
|
2007-02-16 01:04:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CmdList::iterator iter;
|
|
|
|
const char *type = NULL;
|
|
|
|
const char *name;
|
|
|
|
const char *help;
|
2007-03-07 00:59:25 +01:00
|
|
|
g_RootMenu.ConsolePrint("[SM] Listing %d commands for: %s", pList->size(), plname);
|
|
|
|
g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]");
|
2007-02-16 01:04:14 +01:00
|
|
|
for (iter=pList->begin();
|
|
|
|
iter!=pList->end();
|
2007-03-07 00:59:25 +01:00
|
|
|
iter++, id++)
|
2007-02-16 01:04:14 +01:00
|
|
|
{
|
|
|
|
PlCmdInfo &cmd = (*iter);
|
|
|
|
if (cmd.type == Cmd_Server)
|
|
|
|
{
|
|
|
|
type = "server";
|
|
|
|
} else if (cmd.type == Cmd_Console) {
|
|
|
|
type = "console";
|
2007-02-17 08:54:20 +01:00
|
|
|
} else if (cmd.type == Cmd_Admin) {
|
|
|
|
type = "admin";
|
2007-02-16 01:04:14 +01:00
|
|
|
}
|
|
|
|
name = cmd.pInfo->pCmd->GetName();
|
2007-02-17 08:54:20 +01:00
|
|
|
if (cmd.pHook->helptext.size())
|
|
|
|
{
|
|
|
|
help = cmd.pHook->helptext.c_str();
|
|
|
|
} else {
|
|
|
|
help = cmd.pInfo->pCmd->GetHelpText();
|
|
|
|
}
|
2007-03-07 00:59:25 +01:00
|
|
|
g_RootMenu.ConsolePrint(" %-17.16s %-12.11s %s", name, type, help);
|
2007-02-16 01:04:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_RootMenu.ConsolePrint("[SM] Usage: sm cmds <plugin #>");
|
2007-02-15 23:17:01 +01:00
|
|
|
}
|
2007-03-15 05:23:46 +01:00
|
|
|
|
|
|
|
static int g_yam_state = 0;
|
|
|
|
void _YamState(int state)
|
|
|
|
{
|
|
|
|
if (state == 0)
|
|
|
|
{
|
|
|
|
g_RootMenu.ConsolePrint("Welcome to the SourceMod Text Adventure.");
|
|
|
|
g_RootMenu.ConsolePrint("Type sm_text to see the last message.");
|
|
|
|
g_RootMenu.ConsolePrint("Type sm_text <word> to follow a capital word.");
|
|
|
|
g_RootMenu.ConsolePrint("-------------------------------");
|
|
|
|
g_RootMenu.ConsolePrint("You are at VALVE HEADQUARTERS.");
|
|
|
|
g_RootMenu.ConsolePrint("To your LEFT is BAILOPAN, rearranging the letters to spell");
|
|
|
|
g_RootMenu.ConsolePrint("\"A HARD VEAL QUEST\". FORWARD is the entrance to the building.");
|
|
|
|
g_RootMenu.ConsolePrint("To your RIGHT is your last chance to flee in terror.");
|
|
|
|
} else if (state == 1) {
|
|
|
|
g_RootMenu.ConsolePrint("BAILOPAN tells you that his name his pronounced");
|
|
|
|
g_RootMenu.ConsolePrint("\"bye low pahn,\" not \"bay low pan.\" Do you ");
|
|
|
|
g_RootMenu.ConsolePrint("MOCK him, or NOD quietly?");
|
|
|
|
} else if (state == 2) {
|
|
|
|
g_RootMenu.ConsolePrint("You enter the Valve building. You hear screams coming from within.");
|
|
|
|
g_RootMenu.ConsolePrint("A grotesque figure lumbers up to greet you; it is Gabe Newell.");
|
|
|
|
g_RootMenu.ConsolePrint("\"Welcome,\" he belches, \"to my lair.\"");
|
|
|
|
g_RootMenu.ConsolePrint("Do you SHAKE Gaben's hand, WALK past him, or OFFER a donut?");
|
|
|
|
} else if (state == 3) {
|
|
|
|
g_RootMenu.ConsolePrint("You walk into the break room. Alfred \"Adolf\" Reynolds and");
|
|
|
|
g_RootMenu.ConsolePrint("Yahn \"Yeti\" Bernier are discussing something (you overhear ");
|
|
|
|
g_RootMenu.ConsolePrint("the phrase \"and next Steam update, here's what we should break\").");
|
|
|
|
g_RootMenu.ConsolePrint("Should you DIE in a fire, REPORT a bug, REQUEST a feature, or ");
|
|
|
|
g_RootMenu.ConsolePrint("SPRAY them with butter?");
|
|
|
|
}
|
|
|
|
g_yam_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _IntExt_CallYams()
|
|
|
|
{
|
|
|
|
const char *arg = engine->Cmd_Argv(1);
|
|
|
|
|
|
|
|
/* should be impossible */
|
|
|
|
if (!arg || arg[0] == '\0')
|
|
|
|
{
|
|
|
|
_YamState(g_yam_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_yam_state == 1)
|
|
|
|
{
|
|
|
|
if (strcasecmp(arg, "mock") == 0)
|
|
|
|
{
|
2007-05-03 05:45:53 +02:00
|
|
|
g_RootMenu.ConsolePrint("You mock BAILOPAN's pronunciation. In a fit of rage, ");
|
2007-03-15 05:23:46 +01:00
|
|
|
g_RootMenu.ConsolePrint("he sticks an INT 3 call into your chest, rendering you broken.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "nod") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You nod quietly, and then slowly back away into the Valve headquarters.");
|
|
|
|
_YamState(2);
|
|
|
|
} else {
|
|
|
|
g_RootMenu.ConsolePrint("Commands are MOCK and NOD.");
|
|
|
|
}
|
|
|
|
} else if (g_yam_state == 3) {
|
|
|
|
if (strcasecmp(arg, "report") == 0)
|
|
|
|
{
|
|
|
|
g_RootMenu.ConsolePrint("You report a bug to Alfred and Yeti. Immediately, both fall asleep.");
|
|
|
|
g_RootMenu.ConsolePrint("You decay in the break room for two years while they sleep.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "request") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You request a feature to Alfred and Yeti. They both mutter something");
|
|
|
|
g_RootMenu.ConsolePrint("about it being implemented \"soon.\" Then, by accident, someone sends");
|
|
|
|
g_RootMenu.ConsolePrint("a message over \"Friends.\" The entire building catches fire.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "die") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("For no reason, you suddenly catch fire. Alfred and Yeti find this");
|
|
|
|
g_RootMenu.ConsolePrint("deeply disturbing, and cover your flaming corpse with Episode 2");
|
2007-03-15 05:45:33 +01:00
|
|
|
g_RootMenu.ConsolePrint("advertisements. Coming soon, with Team Fortress 2, and Portal!");
|
2007-03-15 05:23:46 +01:00
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "spray") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You spray Alfred and Yeti with butter. Like Jack Thompson to an");
|
|
|
|
g_RootMenu.ConsolePrint("ambulance, Gabe Newell instantly appears and devours them both.");
|
|
|
|
g_RootMenu.ConsolePrint("You run away, just in time, as Gabe Newell explodes, registering ");
|
|
|
|
g_RootMenu.ConsolePrint("a 5.6 earthquake. Outside, world peace is achieved.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE WON.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
}
|
|
|
|
} else if (g_yam_state == 2) {
|
|
|
|
if (strcasecmp(arg, "shake") == 0)
|
|
|
|
{
|
|
|
|
g_RootMenu.ConsolePrint("You shake Gaben's hand. It is a terrifying and disgusting experience.");
|
|
|
|
g_RootMenu.ConsolePrint("However, you survive, and continue on.");
|
|
|
|
_YamState(3);
|
|
|
|
} else if (strcasecmp(arg, "offer") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You offer Gabe Newell one (1) donut. With a gleam in his eyes, ");
|
|
|
|
g_RootMenu.ConsolePrint("he picks you up and devours you whole.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "walk") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You walk past Gabe Newell. He can't keep up with your pace!");
|
|
|
|
_YamState(3);
|
|
|
|
} else {
|
|
|
|
g_RootMenu.ConsolePrint("Commands are SHAKE, OFFER, and WALK.");
|
|
|
|
}
|
|
|
|
} else if (g_yam_state == 0) {
|
|
|
|
if (strcasecmp(arg, "left") == 0)
|
|
|
|
{
|
|
|
|
_YamState(1);
|
|
|
|
} else if (strcasecmp(arg, "right") == 0) {
|
|
|
|
g_RootMenu.ConsolePrint("You run away from the Valve headquarters in sheer terror.");
|
|
|
|
g_RootMenu.ConsolePrint("While running, you smash into an unknown person, who turns out to be your soul mate.");
|
|
|
|
g_RootMenu.ConsolePrint("You marry and raise a family of 3 kids.");
|
|
|
|
g_RootMenu.ConsolePrint("Many years later, you look back, and realize this was your best choice.");
|
|
|
|
g_RootMenu.ConsolePrint("YOU HAVE WON.");
|
|
|
|
g_yam_state = 0;
|
|
|
|
} else if (strcasecmp(arg, "forward") == 0) {
|
|
|
|
_YamState(2);
|
|
|
|
} else if (arg[0] != '\0') {
|
|
|
|
g_RootMenu.ConsolePrint("Commands are FORWARD, LEFT, and RIGHT.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _IntExt_EnableYams()
|
|
|
|
{
|
|
|
|
static ConCommand *pCmd = NULL;
|
|
|
|
if (!pCmd)
|
|
|
|
{
|
|
|
|
pCmd = new ConCommand("sm_text", _IntExt_CallYams, "Fountain of Yams Adventure Game", FCVAR_GAMEDLL);
|
|
|
|
g_RootMenu.ConsolePrint("Something is now enabled...");
|
|
|
|
} else {
|
|
|
|
g_RootMenu.ConsolePrint("Something is already enabled...");
|
|
|
|
}
|
|
|
|
}
|