core/ConCmdManager.h
author David Anderson <dvander@alliedmods.net>
Tue May 22 20:50:48 2007 +0000 (2007-05-22)
changeset 833 732bedfcbe3e
parent 769 d7dc79f1f93e
child 848 32c29dd9c7ec
permissions -rw-r--r--
added ReplaceString and ReplaceStringEx (phew!)
     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 	void OnSourceModPluginsLoaded();
    88 public: //IPluginsListener
    89 	void OnPluginDestroyed(IPlugin *plugin);
    90 public: //IRootConsoleCommand
    91 	void OnRootConsoleCommand(const char *command, unsigned int argcount);
    92 public:
    93 	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    94 	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    95 	bool AddAdminCommand(IPluginFunction *pFunction, 
    96 						 const char *name, 
    97 						 const char *group,
    98 						 int adminflags,
    99 						 const char *description, 
   100 						 int flags);
   101 	ResultType DispatchClientCommand(int client, ResultType type);
   102 	void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
   103 	void NotifyExecDone(const char *file);
   104 private:
   105 	void InternalDispatch();
   106 	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
   107 	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
   108 	void SetCommandClient(int client);
   109 	void AddToCmdList(ConCmdInfo *info);
   110 	void RemoveConCmd(ConCmdInfo *info);
   111 	void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
   112 	bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
   113 	void OnExecCmd();
   114 public:
   115 	inline int GetCommandClient()
   116 	{
   117 		return m_CmdClient;
   118 	}
   119 private:
   120 	Trie *m_pCmds;					/* command lookup */
   121 	Trie *m_pCmdGrps;				/* command group lookup */
   122 	List<ConCmdInfo *> m_CmdList;	/* command list */
   123 	int m_CmdClient;				/* current client */
   124 	BaseStringTable m_Strings;		/* string table */
   125 	ConVar *m_pServerCfgFile;		/* servercfgfile cvar */
   126 	ConCommand *m_pExecCmd;			/* "exec" command */
   127 	IForward *m_pServerCfgFwd;		/* server config forward */
   128 	bool m_bServerCfgDone;			/* marks whether a servercfg was detected */
   129 };
   130 
   131 extern ConCmdManager g_ConCmds;
   132 
   133 #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_