core/ConCmdManager.h
author Phong Dang <teame06@gmail.com>
Wed Aug 01 07:29:40 2007 +0000 (2007-08-01)
changeset 1241 2e8046793bc9
parent 1231 17badaf66ce4
child 1330 ab94316bb52b
permissions -rw-r--r--
Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
ds@579
     1
/**
ds@579
     2
 * vim: set ts=4 :
dvander@1231
     3
 * ================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
dvander@1231
     6
 * ================================================================
ds@579
     7
 *
dvander@1231
     8
 * This program is free software; you can redistribute it and/or 
dvander@1231
     9
 * modify it under the terms of the GNU General Public License, 
dvander@1231
    10
 * version 3.0, as published by the Free Software Foundation.
dvander@1231
    11
 * 
dvander@1231
    12
 * This program is distributed in the hope that it will be useful,
dvander@1231
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dvander@1231
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dvander@1231
    15
 * GNU General Public License for more details.
dvander@1231
    16
 *
dvander@1231
    17
 * You should have received a copy of the GNU General Public License
dvander@1231
    18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
dvander@1231
    20
 * As a special exception, AlliedModders LLC gives you permission to 
dvander@1231
    21
 * link the code of this program (as well as its derivative works) to 
dvander@1231
    22
 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
dvander@1231
    23
 * Game MODs that run on software by the Valve Corporation.  You must 
dvander@1231
    24
 * obey the GNU General Public License in all respects for all other 
dvander@1231
    25
 * code used. Additionally, AlliedModders LLC grants this exception 
dvander@1231
    26
 * to all derivative works. AlliedModders LLC defines further 
dvander@1231
    27
 * exceptions, found in LICENSE.txt (as of this writing, version 
dvander@1231
    28
 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
ds@579
    29
 *
ds@579
    30
 * Version: $Id$
ds@579
    31
 */
ds@579
    32
ds@579
    33
#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
ds@579
    34
#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
ds@579
    35
ds@579
    36
#include "sm_globals.h"
ds@579
    37
#include "sourcemm_api.h"
ds@579
    38
#include "ForwardSys.h"
ds@579
    39
#include "sm_trie.h"
ds@579
    40
#include "sm_memtable.h"
ds@579
    41
#include <sh_list.h>
ds@579
    42
#include <sh_string.h>
ds@579
    43
#include <IRootConsoleMenu.h>
ds@579
    44
#include <IAdminSystem.h>
ds@579
    45
ds@579
    46
using namespace SourceHook;
ds@579
    47
ds@579
    48
enum CmdType
ds@579
    49
{
ds@579
    50
	Cmd_Server,
ds@579
    51
	Cmd_Console,
ds@579
    52
	Cmd_Admin,
ds@579
    53
};
ds@579
    54
ds@579
    55
struct AdminCmdInfo
ds@579
    56
{
ds@579
    57
	AdminCmdInfo()
ds@579
    58
	{
ds@579
    59
		cmdGrpId = -1;
ds@579
    60
		flags = 0;
ds@579
    61
		eflags = 0;
ds@579
    62
	}
ds@579
    63
	int cmdGrpId;			/* index into cmdgroup string table */
ds@579
    64
	FlagBits flags;			/* default flags */
ds@579
    65
	FlagBits eflags;		/* effective flags */
ds@579
    66
};
ds@579
    67
ds@579
    68
struct CmdHook
ds@579
    69
{
ds@579
    70
	CmdHook()
ds@579
    71
	{
ds@579
    72
		pf = NULL;
ds@579
    73
		pAdmin = NULL;
ds@579
    74
	}
ds@579
    75
	IPluginFunction *pf;	/* function hook */
ds@579
    76
	String helptext;		/* help text */
ds@579
    77
	AdminCmdInfo *pAdmin;	/* admin requirements, if any */
ds@579
    78
};
ds@579
    79
ds@579
    80
struct ConCmdInfo
ds@579
    81
{
ds@579
    82
	ConCmdInfo()
ds@579
    83
	{
ds@579
    84
		sourceMod = false;
ds@579
    85
		pCmd = NULL;
ds@579
    86
	}
ds@579
    87
	bool sourceMod;					/**< Determines whether or not concmd was created by a SourceMod plugin */
ds@579
    88
	ConCommand *pCmd;				/**< Pointer to the command itself */
ds@579
    89
	List<CmdHook *> srvhooks;		/**< Hooks as a server command */
ds@579
    90
	List<CmdHook *> conhooks;		/**< Hooks as a console command */
dvander@1119
    91
	AdminCmdInfo admin;				/**< Admin info, if any */
ds@579
    92
};
ds@579
    93
ds@579
    94
class ConCmdManager :
ds@579
    95
	public SMGlobalClass,
ds@579
    96
	public IRootConsoleCommand,
ds@579
    97
	public IPluginsListener
ds@579
    98
{
ds@579
    99
	friend void CommandCallback();
ds@579
   100
public:
ds@579
   101
	ConCmdManager();
ds@579
   102
	~ConCmdManager();
ds@579
   103
public: //SMGlobalClass
ds@579
   104
	void OnSourceModAllInitialized();
ds@579
   105
	void OnSourceModShutdown();
ds@579
   106
public: //IPluginsListener
ds@579
   107
	void OnPluginDestroyed(IPlugin *plugin);
ds@579
   108
public: //IRootConsoleCommand
ds@579
   109
	void OnRootConsoleCommand(const char *command, unsigned int argcount);
ds@579
   110
public:
ds@579
   111
	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
ds@579
   112
	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
ds@579
   113
	bool AddAdminCommand(IPluginFunction *pFunction, 
ds@579
   114
						 const char *name, 
ds@579
   115
						 const char *group,
ds@579
   116
						 int adminflags,
ds@579
   117
						 const char *description, 
ds@579
   118
						 int flags);
ds@579
   119
	ResultType DispatchClientCommand(int client, ResultType type);
ds@579
   120
	void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits);
dvander@893
   121
	bool LookForSourceModCommand(const char *cmd);
dvander@1119
   122
	bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
ds@579
   123
private:
ds@579
   124
	void InternalDispatch();
ds@579
   125
	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
ds@579
   126
	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
ds@579
   127
	void SetCommandClient(int client);
ds@579
   128
	void AddToCmdList(ConCmdInfo *info);
ds@579
   129
	void RemoveConCmd(ConCmdInfo *info);
ds@579
   130
	void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
ds@579
   131
	bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
dvander@769
   132
public:
dvander@769
   133
	inline int GetCommandClient()
dvander@769
   134
	{
dvander@769
   135
		return m_CmdClient;
dvander@769
   136
	}
dvander@1119
   137
	inline const List<ConCmdInfo *> & GetCommandList()
dvander@1119
   138
	{
dvander@1119
   139
		return m_CmdList;
dvander@1119
   140
	}
ds@579
   141
private:
ds@579
   142
	Trie *m_pCmds;					/* command lookup */
ds@579
   143
	Trie *m_pCmdGrps;				/* command group lookup */
ds@579
   144
	List<ConCmdInfo *> m_CmdList;	/* command list */
ds@579
   145
	int m_CmdClient;				/* current client */
ds@579
   146
	BaseStringTable m_Strings;		/* string table */
ds@579
   147
};
ds@579
   148
ds@579
   149
extern ConCmdManager g_ConCmds;
ds@579
   150
ds@579
   151
#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_