ds@579: /**
ds@579: * vim: set ts=4 :
ds@1330: * =============================================================================
dvander@1231: * SourceMod
dvander@1231: * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ds@579: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
dvander@1231: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
dvander@1231: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
dvander@1231: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
ds@579: *
ds@579: * Version: $Id$
ds@579: */
ds@579:
ds@579: #ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
ds@579: #define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
ds@579:
ds@579: #include "sm_globals.h"
ds@579: #include "sourcemm_api.h"
ds@579: #include "ForwardSys.h"
ds@579: #include "sm_trie.h"
ds@579: #include "sm_memtable.h"
ds@579: #include
ds@579: #include
ds@579: #include
ds@579: #include
ds@579:
ds@579: using namespace SourceHook;
ds@579:
ds@579: enum CmdType
ds@579: {
ds@579: Cmd_Server,
ds@579: Cmd_Console,
ds@579: Cmd_Admin,
ds@579: };
ds@579:
ds@579: struct AdminCmdInfo
ds@579: {
ds@579: AdminCmdInfo()
ds@579: {
ds@579: cmdGrpId = -1;
ds@579: flags = 0;
ds@579: eflags = 0;
ds@579: }
ds@579: int cmdGrpId; /* index into cmdgroup string table */
ds@579: FlagBits flags; /* default flags */
ds@579: FlagBits eflags; /* effective flags */
ds@579: };
ds@579:
ds@579: struct CmdHook
ds@579: {
ds@579: CmdHook()
ds@579: {
ds@579: pf = NULL;
ds@579: pAdmin = NULL;
ds@579: }
ds@579: IPluginFunction *pf; /* function hook */
ds@579: String helptext; /* help text */
ds@579: AdminCmdInfo *pAdmin; /* admin requirements, if any */
ds@579: };
ds@579:
ds@579: struct ConCmdInfo
ds@579: {
ds@579: ConCmdInfo()
ds@579: {
ds@579: sourceMod = false;
ds@579: pCmd = NULL;
ds@579: }
ds@579: bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
ds@579: ConCommand *pCmd; /**< Pointer to the command itself */
ds@579: List srvhooks; /**< Hooks as a server command */
ds@579: List conhooks; /**< Hooks as a console command */
dvander@1119: AdminCmdInfo admin; /**< Admin info, if any */
dvander@1349: bool is_admin_set; /**< Whether or not admin info is set */
ds@579: };
ds@579:
ds@579: class ConCmdManager :
ds@579: public SMGlobalClass,
ds@579: public IRootConsoleCommand,
ds@579: public IPluginsListener
ds@579: {
ds@579: friend void CommandCallback();
ds@579: public:
ds@579: ConCmdManager();
ds@579: ~ConCmdManager();
ds@579: public: //SMGlobalClass
ds@579: void OnSourceModAllInitialized();
ds@579: void OnSourceModShutdown();
ds@579: public: //IPluginsListener
ds@579: void OnPluginDestroyed(IPlugin *plugin);
ds@579: public: //IRootConsoleCommand
ds@579: void OnRootConsoleCommand(const char *command, unsigned int argcount);
ds@579: public:
ds@579: bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
ds@579: bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
ds@579: bool AddAdminCommand(IPluginFunction *pFunction,
ds@579: const char *name,
ds@579: const char *group,
ds@579: int adminflags,
ds@579: const char *description,
ds@579: int flags);
dvander@1335: ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
ds@579: void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
dvander@893: bool LookForSourceModCommand(const char *cmd);
dvander@1349: bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
dvander@1119: bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
ds@579: private:
ds@579: void InternalDispatch();
ds@579: ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
ds@579: ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
ds@579: void SetCommandClient(int client);
ds@579: void AddToCmdList(ConCmdInfo *info);
ds@579: void RemoveConCmd(ConCmdInfo *info);
ds@579: void RemoveConCmds(List &cmdlist, IPluginContext *pContext);
ds@579: bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
dvander@769: public:
dvander@769: inline int GetCommandClient()
dvander@769: {
dvander@769: return m_CmdClient;
dvander@769: }
dvander@1119: inline const List & GetCommandList()
dvander@1119: {
dvander@1119: return m_CmdList;
dvander@1119: }
ds@579: private:
ds@579: Trie *m_pCmds; /* command lookup */
ds@579: Trie *m_pCmdGrps; /* command group lookup */
ds@579: List m_CmdList; /* command list */
ds@579: int m_CmdClient; /* current client */
ds@579: BaseStringTable m_Strings; /* string table */
ds@579: };
ds@579:
ds@579: extern ConCmdManager g_ConCmds;
ds@579:
ds@579: #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_