core/ConCmdManager.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 978 54782a83a1ef
child 1119 9e3486386c04
permissions -rw-r--r--
Removed strange debugging code
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
    16 #define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
    17 
    18 #include "sm_globals.h"
    19 #include "sourcemm_api.h"
    20 #include "ForwardSys.h"
    21 #include "sm_trie.h"
    22 #include "sm_memtable.h"
    23 #include <sh_list.h>
    24 #include <sh_string.h>
    25 #include <IRootConsoleMenu.h>
    26 #include <IAdminSystem.h>
    27 
    28 using namespace SourceHook;
    29 
    30 enum CmdType
    31 {
    32 	Cmd_Server,
    33 	Cmd_Console,
    34 	Cmd_Admin,
    35 };
    36 
    37 struct AdminCmdInfo
    38 {
    39 	AdminCmdInfo()
    40 	{
    41 		cmdGrpId = -1;
    42 		flags = 0;
    43 		eflags = 0;
    44 	}
    45 	int cmdGrpId;			/* index into cmdgroup string table */
    46 	FlagBits flags;			/* default flags */
    47 	FlagBits eflags;		/* effective flags */
    48 };
    49 
    50 struct CmdHook
    51 {
    52 	CmdHook()
    53 	{
    54 		pf = NULL;
    55 		pAdmin = NULL;
    56 	}
    57 	IPluginFunction *pf;	/* function hook */
    58 	String helptext;		/* help text */
    59 	AdminCmdInfo *pAdmin;	/* admin requirements, if any */
    60 };
    61 
    62 struct ConCmdInfo
    63 {
    64 	ConCmdInfo()
    65 	{
    66 		sourceMod = false;
    67 		pCmd = NULL;
    68 	}
    69 	bool sourceMod;					/**< Determines whether or not concmd was created by a SourceMod plugin */
    70 	ConCommand *pCmd;				/**< Pointer to the command itself */
    71 	List<CmdHook *> srvhooks;		/**< Hooks as a server command */
    72 	List<CmdHook *> conhooks;		/**< Hooks as a console command */
    73 };
    74 
    75 class ConCmdManager :
    76 	public SMGlobalClass,
    77 	public IRootConsoleCommand,
    78 	public IPluginsListener
    79 {
    80 	friend void CommandCallback();
    81 public:
    82 	ConCmdManager();
    83 	~ConCmdManager();
    84 public: //SMGlobalClass
    85 	void OnSourceModAllInitialized();
    86 	void OnSourceModShutdown();
    87 public: //IPluginsListener
    88 	void OnPluginDestroyed(IPlugin *plugin);
    89 public: //IRootConsoleCommand
    90 	void OnRootConsoleCommand(const char *command, unsigned int argcount);
    91 public:
    92 	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    93 	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    94 	bool AddAdminCommand(IPluginFunction *pFunction, 
    95 						 const char *name, 
    96 						 const char *group,
    97 						 int adminflags,
    98 						 const char *description, 
    99 						 int flags);
   100 	ResultType DispatchClientCommand(int client, ResultType type);
   101 	void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
   102 	bool LookForSourceModCommand(const char *cmd);
   103 private:
   104 	void InternalDispatch();
   105 	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
   106 	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
   107 	void SetCommandClient(int client);
   108 	void AddToCmdList(ConCmdInfo *info);
   109 	void RemoveConCmd(ConCmdInfo *info);
   110 	void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
   111 	bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
   112 public:
   113 	inline int GetCommandClient()
   114 	{
   115 		return m_CmdClient;
   116 	}
   117 private:
   118 	Trie *m_pCmds;					/* command lookup */
   119 	Trie *m_pCmdGrps;				/* command group lookup */
   120 	List<ConCmdInfo *> m_CmdList;	/* command list */
   121 	int m_CmdClient;				/* current client */
   122 	BaseStringTable m_Strings;		/* string table */
   123 };
   124 
   125 extern ConCmdManager g_ConCmds;
   126 
   127 #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_