core/ConCmdManager.h
changeset 579 3c25cd99fb05
child 723 60395a16ddea
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/ConCmdManager.h	Tue Mar 06 06:15:19 2007 +0000
     1.3 @@ -0,0 +1,121 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ===============================================================
     1.7 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     1.8 + * ===============================================================
     1.9 + *
    1.10 + * This file is not open source and may not be copied without explicit
    1.11 + * written permission of AlliedModders LLC.  This file may not be redistributed 
    1.12 + * in whole or significant part.
    1.13 + * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    1.14 + *
    1.15 + * Version: $Id$
    1.16 + */
    1.17 +
    1.18 +#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
    1.19 +#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
    1.20 +
    1.21 +#include "sm_globals.h"
    1.22 +#include "sourcemm_api.h"
    1.23 +#include "ForwardSys.h"
    1.24 +#include "sm_trie.h"
    1.25 +#include "sm_memtable.h"
    1.26 +#include <sh_list.h>
    1.27 +#include <sh_string.h>
    1.28 +#include <IRootConsoleMenu.h>
    1.29 +#include <IAdminSystem.h>
    1.30 +
    1.31 +using namespace SourceHook;
    1.32 +
    1.33 +enum CmdType
    1.34 +{
    1.35 +	Cmd_Server,
    1.36 +	Cmd_Console,
    1.37 +	Cmd_Admin,
    1.38 +};
    1.39 +
    1.40 +struct AdminCmdInfo
    1.41 +{
    1.42 +	AdminCmdInfo()
    1.43 +	{
    1.44 +		cmdGrpId = -1;
    1.45 +		flags = 0;
    1.46 +		eflags = 0;
    1.47 +	}
    1.48 +	int cmdGrpId;			/* index into cmdgroup string table */
    1.49 +	FlagBits flags;			/* default flags */
    1.50 +	FlagBits eflags;		/* effective flags */
    1.51 +};
    1.52 +
    1.53 +struct CmdHook
    1.54 +{
    1.55 +	CmdHook()
    1.56 +	{
    1.57 +		pf = NULL;
    1.58 +		pAdmin = NULL;
    1.59 +	}
    1.60 +	IPluginFunction *pf;	/* function hook */
    1.61 +	String helptext;		/* help text */
    1.62 +	AdminCmdInfo *pAdmin;	/* admin requirements, if any */
    1.63 +};
    1.64 +
    1.65 +struct ConCmdInfo
    1.66 +{
    1.67 +	ConCmdInfo()
    1.68 +	{
    1.69 +		sourceMod = false;
    1.70 +		pCmd = NULL;
    1.71 +	}
    1.72 +	bool sourceMod;					/**< Determines whether or not concmd was created by a SourceMod plugin */
    1.73 +	ConCommand *pCmd;				/**< Pointer to the command itself */
    1.74 +	List<CmdHook *> srvhooks;		/**< Hooks as a server command */
    1.75 +	List<CmdHook *> conhooks;		/**< Hooks as a console command */
    1.76 +};
    1.77 +
    1.78 +class ConCmdManager :
    1.79 +	public SMGlobalClass,
    1.80 +	public IRootConsoleCommand,
    1.81 +	public IPluginsListener
    1.82 +{
    1.83 +	friend void CommandCallback();
    1.84 +public:
    1.85 +	ConCmdManager();
    1.86 +	~ConCmdManager();
    1.87 +public: //SMGlobalClass
    1.88 +	void OnSourceModAllInitialized();
    1.89 +	void OnSourceModShutdown();
    1.90 +public: //IPluginsListener
    1.91 +	void OnPluginDestroyed(IPlugin *plugin);
    1.92 +public: //IRootConsoleCommand
    1.93 +	void OnRootConsoleCommand(const char *command, unsigned int argcount);
    1.94 +public:
    1.95 +	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    1.96 +	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    1.97 +	bool AddAdminCommand(IPluginFunction *pFunction, 
    1.98 +						 const char *name, 
    1.99 +						 const char *group,
   1.100 +						 int adminflags,
   1.101 +						 const char *description, 
   1.102 +						 int flags);
   1.103 +	ResultType DispatchClientCommand(int client, ResultType type);
   1.104 +	void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
   1.105 +private:
   1.106 +	void InternalDispatch();
   1.107 +	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
   1.108 +	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
   1.109 +	void SetCommandClient(int client);
   1.110 +	void AddToCmdList(ConCmdInfo *info);
   1.111 +	void RemoveConCmd(ConCmdInfo *info);
   1.112 +	void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
   1.113 +	bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
   1.114 +private:
   1.115 +	Trie *m_pCmds;					/* command lookup */
   1.116 +	Trie *m_pCmdGrps;				/* command group lookup */
   1.117 +	List<ConCmdInfo *> m_CmdList;	/* command list */
   1.118 +	int m_CmdClient;				/* current client */
   1.119 +	BaseStringTable m_Strings;		/* string table */
   1.120 +};
   1.121 +
   1.122 +extern ConCmdManager g_ConCmds;
   1.123 +
   1.124 +#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_