1.1 --- a/core/ConCmdManager.h Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,161 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id$
1.33 - */
1.34 -
1.35 -#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
1.36 -#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
1.37 -
1.38 -#include "sm_globals.h"
1.39 -#include "sourcemm_api.h"
1.40 -#include "ForwardSys.h"
1.41 -#include "sm_trie.h"
1.42 -#include "sm_memtable.h"
1.43 -#include <sh_list.h>
1.44 -#include <sh_string.h>
1.45 -#include <IRootConsoleMenu.h>
1.46 -#include <IAdminSystem.h>
1.47 -#include "concmd_cleaner.h"
1.48 -
1.49 -using namespace SourceHook;
1.50 -
1.51 -enum CmdType
1.52 -{
1.53 - Cmd_Server,
1.54 - Cmd_Console,
1.55 - Cmd_Admin,
1.56 -};
1.57 -
1.58 -struct AdminCmdInfo
1.59 -{
1.60 - AdminCmdInfo()
1.61 - {
1.62 - cmdGrpId = -1;
1.63 - flags = 0;
1.64 - eflags = 0;
1.65 - }
1.66 - int cmdGrpId; /* index into cmdgroup string table */
1.67 - FlagBits flags; /* default flags */
1.68 - FlagBits eflags; /* effective flags */
1.69 -};
1.70 -
1.71 -struct CmdHook
1.72 -{
1.73 - CmdHook()
1.74 - {
1.75 - pf = NULL;
1.76 - pAdmin = NULL;
1.77 - }
1.78 - IPluginFunction *pf; /* function hook */
1.79 - String helptext; /* help text */
1.80 - AdminCmdInfo *pAdmin; /* admin requirements, if any */
1.81 -};
1.82 -
1.83 -struct ConCmdInfo
1.84 -{
1.85 - ConCmdInfo()
1.86 - {
1.87 - sourceMod = false;
1.88 - pCmd = NULL;
1.89 - }
1.90 - bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
1.91 - ConCommand *pCmd; /**< Pointer to the command itself */
1.92 - List<CmdHook *> srvhooks; /**< Hooks as a server command */
1.93 - List<CmdHook *> conhooks; /**< Hooks as a console command */
1.94 - AdminCmdInfo admin; /**< Admin info, if any */
1.95 - bool is_admin_set; /**< Whether or not admin info is set */
1.96 -};
1.97 -
1.98 -class ConCmdManager :
1.99 - public SMGlobalClass,
1.100 - public IRootConsoleCommand,
1.101 - public IPluginsListener,
1.102 - public IConCommandTracker
1.103 -{
1.104 -#if defined ORANGEBOX_BUILD
1.105 - friend void CommandCallback(const CCommand &command);
1.106 -#else
1.107 - friend void CommandCallback();
1.108 -#endif
1.109 -public:
1.110 - ConCmdManager();
1.111 - ~ConCmdManager();
1.112 -public: //SMGlobalClass
1.113 - void OnSourceModAllInitialized();
1.114 - void OnSourceModShutdown();
1.115 -public: //IPluginsListener
1.116 - void OnPluginDestroyed(IPlugin *plugin);
1.117 -public: //IRootConsoleCommand
1.118 - void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
1.119 -public: //IConCommandTracker
1.120 - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
1.121 -public:
1.122 - bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
1.123 - bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
1.124 - bool AddAdminCommand(IPluginFunction *pFunction,
1.125 - const char *name,
1.126 - const char *group,
1.127 - int adminflags,
1.128 - const char *description,
1.129 - int flags);
1.130 - ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
1.131 - void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
1.132 - bool LookForSourceModCommand(const char *cmd);
1.133 - bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
1.134 - bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
1.135 -private:
1.136 - void InternalDispatch(const CCommand &command);
1.137 - ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
1.138 - ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
1.139 - void SetCommandClient(int client);
1.140 - void AddToCmdList(ConCmdInfo *info);
1.141 - void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack);
1.142 - void RemoveConCmds(List<CmdHook *> &cmdlist);
1.143 - void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
1.144 - bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
1.145 -public:
1.146 - inline int GetCommandClient()
1.147 - {
1.148 - return m_CmdClient;
1.149 - }
1.150 - inline const List<ConCmdInfo *> & GetCommandList()
1.151 - {
1.152 - return m_CmdList;
1.153 - }
1.154 -private:
1.155 - Trie *m_pCmds; /* command lookup */
1.156 - Trie *m_pCmdGrps; /* command group lookup */
1.157 - List<ConCmdInfo *> m_CmdList; /* command list */
1.158 - int m_CmdClient; /* current client */
1.159 - BaseStringTable m_Strings; /* string table */
1.160 -};
1.161 -
1.162 -extern ConCmdManager g_ConCmds;
1.163 -
1.164 -#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_