2004-03-05 21:03:14 +00:00
|
|
|
/* AMX Mod X
|
|
|
|
*
|
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*/
|
2004-01-31 20:56:22 +00:00
|
|
|
|
|
|
|
#ifndef COMMANDS_H
|
|
|
|
#define COMMANDS_H
|
|
|
|
|
|
|
|
// *****************************************************
|
|
|
|
// class CmdMngr
|
|
|
|
// *****************************************************
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
CMD_ConsoleCommand,
|
|
|
|
CMD_ClientCommand,
|
|
|
|
CMD_ServerCommand
|
|
|
|
};
|
|
|
|
|
|
|
|
class CmdMngr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Command;
|
|
|
|
friend class Command;
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
class Command
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
friend class CmdMngr;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
CPluginMngr::CPlugin* plugin;
|
|
|
|
CmdMngr* parent;
|
2004-08-15 10:53:48 +00:00
|
|
|
String command;
|
|
|
|
String argument;
|
|
|
|
String commandline;
|
|
|
|
String info;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
bool listable;
|
|
|
|
int function;
|
|
|
|
int flags;
|
|
|
|
int id;
|
|
|
|
int cmdtype;
|
|
|
|
int prefix;
|
|
|
|
static int uniqueid;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags, int pfunc, bool pviewable, CmdMngr* pparent);
|
2004-01-31 20:56:22 +00:00
|
|
|
~Command();
|
|
|
|
public:
|
2004-08-13 08:46:04 +00:00
|
|
|
inline const char* getCommand() { return command.c_str(); }
|
|
|
|
inline const char* getArgument() { return argument.c_str(); }
|
|
|
|
inline const char* getCmdInfo() { return info.c_str(); }
|
|
|
|
inline const char* getCmdLine() { return commandline.c_str(); }
|
2005-09-16 23:48:51 +00:00
|
|
|
inline bool matchCommandLine(const char* cmd, const char* arg) { return (!stricmp(command.c_str() + prefix, cmd + prefix) && (argument.empty() || !stricmp(argument.c_str(), arg))); }
|
2013-08-08 23:27:02 +00:00
|
|
|
inline bool matchCommand(const char* cmd) { return (!stricmp(command.c_str(), cmd)); }
|
2004-01-31 20:56:22 +00:00
|
|
|
inline int getFunction() const { return function; }
|
2008-04-10 05:42:06 +00:00
|
|
|
inline bool gotAccess(int f) const { return (!flags || ((flags & f) != 0)); }
|
2004-01-31 20:56:22 +00:00
|
|
|
inline CPluginMngr::CPlugin* getPlugin() { return plugin; }
|
|
|
|
inline bool isViewable() const { return listable; }
|
|
|
|
inline int getFlags() const { return flags; }
|
|
|
|
inline long int getId() const { return (long int)id; }
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
const char* getCmdType() const;
|
2005-09-09 23:54:15 +00:00
|
|
|
void setCmdType(int a);
|
2004-01-31 20:56:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct CmdPrefix;
|
|
|
|
friend struct CmdPrefix;
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
struct CmdLink
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
Command* cmd;
|
|
|
|
CmdLink* next;
|
|
|
|
CmdLink(Command* c): cmd(c), next(0) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
CmdLink* sortedlists[3];
|
|
|
|
CmdLink* srvcmdlist;
|
|
|
|
CmdLink* clcmdlist;
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
struct CmdPrefix
|
|
|
|
{
|
2004-08-15 10:53:48 +00:00
|
|
|
String name;
|
2004-04-01 05:53:22 +00:00
|
|
|
CmdMngr* parent;
|
2004-01-31 20:56:22 +00:00
|
|
|
CmdLink* list;
|
|
|
|
CmdPrefix* next;
|
2005-09-16 23:48:51 +00:00
|
|
|
CmdPrefix(const char* nn, CmdMngr* pp): name(nn), parent(pp), list(0), next(0) {}
|
2005-09-09 23:54:15 +00:00
|
|
|
~CmdPrefix() { parent->clearCmdLink(&list); }
|
2004-01-31 20:56:22 +00:00
|
|
|
} *prefixHead;
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
bool registerCmdPrefix(Command* cc);
|
|
|
|
CmdPrefix** findPrefix(const char* nn);
|
2004-01-31 20:56:22 +00:00
|
|
|
void clearPrefix();
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
void setCmdLink(CmdLink** a, Command* c, bool sorted = true);
|
|
|
|
void clearCmdLink(CmdLink** phead, bool pclear = false);
|
2004-01-31 20:56:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CmdMngr();
|
2005-09-09 23:54:15 +00:00
|
|
|
~CmdMngr() { clear(); }
|
2004-01-31 20:56:22 +00:00
|
|
|
|
|
|
|
// Interface
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
void registerPrefix(const char* nn);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
Command* registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable);
|
|
|
|
Command* getCmd(long int id, int type, int access);
|
|
|
|
int getCmdNum(int type, int access);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
void clearBufforedInfo();
|
|
|
|
void clear();
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
class iterator
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
CmdLink *a;
|
|
|
|
public:
|
|
|
|
iterator(CmdLink*aa = 0) : a(aa) {}
|
|
|
|
iterator& operator++() { a = a->next; return *this; }
|
|
|
|
bool operator==(const iterator& b) const { return a == b.a; }
|
|
|
|
bool operator!=(const iterator& b) const { return !operator==(b); }
|
|
|
|
operator bool () const { return a ? true : false; }
|
|
|
|
Command& operator*() { return *a->cmd; }
|
|
|
|
};
|
2005-09-09 23:54:15 +00:00
|
|
|
|
|
|
|
inline iterator clcmdprefixbegin(const char* nn)
|
|
|
|
{
|
2004-01-31 20:56:22 +00:00
|
|
|
CmdPrefix* a = *findPrefix(nn);
|
2005-09-09 23:54:15 +00:00
|
|
|
return iterator(a ? a->list : 0);
|
2004-01-31 20:56:22 +00:00
|
|
|
}
|
2005-09-09 23:54:15 +00:00
|
|
|
|
|
|
|
inline iterator clcmdbegin() const { return iterator(clcmdlist); }
|
|
|
|
inline iterator srvcmdbegin() const { return iterator(srvcmdlist); }
|
|
|
|
inline iterator begin(int type) const { return iterator(sortedlists[type]); }
|
2004-01-31 20:56:22 +00:00
|
|
|
inline iterator end() const { return iterator(0); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int buf_cmdid;
|
|
|
|
int buf_cmdtype;
|
|
|
|
int buf_cmdaccess;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
iterator buf_cmdptr;
|
|
|
|
|
|
|
|
int buf_id;
|
|
|
|
int buf_type;
|
|
|
|
int buf_access;
|
|
|
|
int buf_num;
|
|
|
|
};
|
|
|
|
|
2005-09-09 23:54:15 +00:00
|
|
|
#endif //COMMANDS_H
|
2004-01-31 20:56:22 +00:00
|
|
|
|