core/CConCmdManager.h
author David Anderson <dvander@alliedmods.net>
Mon Feb 26 09:21:08 2007 +0000 (2007-02-26)
changeset 539 fa7e8a232a18
parent 514 4c02b38c26ed
permissions -rw-r--r--
fixed stupid export
     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_CCONCMDMANAGER_H_
    16 #define _INCLUDE_SOURCEMOD_CCONCMDMANAGER_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 CConCmdManager :
    76 	public SMGlobalClass,
    77 	public IRootConsoleCommand,
    78 	public IPluginsListener
    79 {
    80 	friend void CommandCallback();
    81 public:
    82 	CConCmdManager();
    83 	~CConCmdManager();
    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 	void AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    93 	void 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 private:
   103 	void InternalDispatch();
   104 	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
   105 	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
   106 	void SetCommandClient(int client);
   107 	void AddToCmdList(ConCmdInfo *info);
   108 	void RemoveConCmd(ConCmdInfo *info);
   109 	void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
   110 	bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
   111 private:
   112 	Trie *m_pCmds;					/* command lookup */
   113 	Trie *m_pCmdGrps;				/* command group lookup */
   114 	List<ConCmdInfo *> m_CmdList;	/* command list */
   115 	int m_CmdClient;				/* current client */
   116 	BaseStringTable m_Strings;		/* string table */
   117 };
   118 
   119 extern CConCmdManager g_ConCmds;
   120 
   121 #endif // _INCLUDE_SOURCEMOD_CCONCMDMANAGER_H_
   122