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