Add a param to register_*cmd() and get_*cmd() to indiquate info is a multilingual key + modify plugin

This commit is contained in:
Arkshine 2016-02-02 23:07:53 +01:00 committed by Arkshine
parent 664c25bdac
commit 9054643fe8
6 changed files with 77 additions and 31 deletions

View File

@ -30,7 +30,7 @@ CmdMngr::CmdMngr()
} }
CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags, CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags,
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo) int pfunc, bool pviewable, bool pinfo_ml, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
{ {
char szCmd[64], szArg[64]; char szCmd[64], szArg[64];
*szCmd = 0; *szArg = 0; *szCmd = 0; *szArg = 0;
@ -43,6 +43,7 @@ CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const
prefix = 0; prefix = 0;
function = pfunc; function = pfunc;
listable = pviewable; listable = pviewable;
info_ml = pinfo_ml;
parent = pparent; parent = pparent;
id = --uniqueid; id = --uniqueid;
} }
@ -52,9 +53,9 @@ CmdMngr::Command::~Command()
++uniqueid; ++uniqueid;
} }
CmdMngr::Command* CmdMngr::registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable) CmdMngr::Command* CmdMngr::registerCommand(CPluginMngr::CPlugin* plugin, int func, const char* cmd, const char* info, int level, bool listable, bool info_ml)
{ {
Command* b = new Command(plugin, cmd, info, level, func, listable, this); Command* b = new Command(plugin, cmd, info, level, func, listable, info_ml, this);
if (b == 0) return 0; if (b == 0) return 0;
setCmdLink(&sortedlists[0], b); setCmdLink(&sortedlists[0], b);

View File

@ -38,6 +38,7 @@ public:
ke::AString commandline; ke::AString commandline;
ke::AString info; ke::AString info;
bool info_ml;
bool listable; bool listable;
int function; int function;
int flags; int flags;
@ -46,7 +47,7 @@ public:
int prefix; int prefix;
static int uniqueid; static int uniqueid;
Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags, int pfunc, bool pviewable, CmdMngr* pparent); Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags, int pfunc, bool pviewable, bool pinfo_ml, CmdMngr* pparent);
~Command(); ~Command();
public: public:
inline const char* getCommand() { return command.chars(); } inline const char* getCommand() { return command.chars(); }
@ -59,6 +60,7 @@ public:
inline bool gotAccess(int f) const { return (!flags || ((flags & f) != 0)); } inline bool gotAccess(int f) const { return (!flags || ((flags & f) != 0)); }
inline CPluginMngr::CPlugin* getPlugin() { return plugin; } inline CPluginMngr::CPlugin* getPlugin() { return plugin; }
inline bool isViewable() const { return listable; } inline bool isViewable() const { return listable; }
inline bool isInfoML() const { return info_ml; }
inline int getFlags() const { return flags; } inline int getFlags() const { return flags; }
inline long int getId() const { return (long int)id; } inline long int getId() const { return (long int)id; }
@ -106,7 +108,7 @@ public:
void registerPrefix(const char* nn); void registerPrefix(const char* nn);
Command* registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable); Command* registerCommand(CPluginMngr::CPlugin* plugin, int func, const char* cmd, const char* info, int level, bool listable, bool info_ml);
Command* getCmd(long int id, int type, int access); Command* getCmd(long int id, int type, int access);
int getCmdNum(int type, int access); int getCmdNum(int type, int access);

View File

@ -1522,7 +1522,8 @@ static cell AMX_NATIVE_CALL get_pluginsnum(AMX *amx, cell *params)
return g_plugins.getPluginsNum(); return g_plugins.getPluginsNum();
} }
static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param */ // native register_concmd(const cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1, bool:info_ml = false);
static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params)
{ {
CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx);
int i, idx = 0; int i, idx = 0;
@ -1541,7 +1542,8 @@ static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param *
CmdMngr::Command* cmd; CmdMngr::Command* cmd;
int access = params[3]; int access = params[3];
bool listable = true; bool listable = true;
bool info_ml = *params / sizeof(cell) >= 6 && params[6] != 0 && i;
if (access < 0) // is access is -1 then hide from listing if (access < 0) // is access is -1 then hide from listing
{ {
access = 0; access = 0;
@ -1553,7 +1555,7 @@ static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param *
FlagMan.LookupOrAdd(temp,access,amx); FlagMan.LookupOrAdd(temp,access,amx);
} }
if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable, info_ml)) == NULL)
return 0; return 0;
if (CheckBadConList(temp, 1)) if (CheckBadConList(temp, 1))
@ -1567,7 +1569,8 @@ static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param *
return cmd->getId(); return cmd->getId();
} }
static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */ // native register_clcmd(const client_cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1, bool:info_ml = false);
static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params)
{ {
CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx);
int i, idx = 0; int i, idx = 0;
@ -1582,11 +1585,12 @@ static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */
} }
temp = get_amxstring(amx, params[1], 0, i); temp = get_amxstring(amx, params[1], 0, i);
char* info = get_amxstring(amx, params[4], 1, i); const char* info = get_amxstring(amx, params[4], 1, i);
CmdMngr::Command* cmd; CmdMngr::Command* cmd;
int access = params[3]; int access = params[3];
bool listable = true; bool listable = true;
bool info_ml = *params / sizeof(cell) >= 6 && params[6] != 0 && i;
if (access < 0) // is access is -1 then hide from listing if (access < 0) // is access is -1 then hide from listing
{ {
access = 0; access = 0;
@ -1598,7 +1602,7 @@ static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */
FlagMan.LookupOrAdd(temp,access,amx); FlagMan.LookupOrAdd(temp,access,amx);
} }
if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable, info_ml)) == NULL)
return 0; return 0;
cmd->setCmdType(CMD_ClientCommand); cmd->setCmdType(CMD_ClientCommand);
@ -1606,7 +1610,8 @@ static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */
return cmd->getId(); return cmd->getId();
} }
static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params) /* 2 param */ // native register_srvcmd(const server_cmd[], const function[], flags = -1, const info[] = "", bool:info_ml = false);
static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params)
{ {
CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx); CPluginMngr::CPlugin* plugin = g_plugins.findPluginFast(amx);
int i, idx = 0; int i, idx = 0;
@ -1621,18 +1626,19 @@ static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params) /* 2 param *
} }
temp = get_amxstring(amx, params[1], 0, i); temp = get_amxstring(amx, params[1], 0, i);
char* info = get_amxstring(amx, params[4], 1, i); const char* info = get_amxstring(amx, params[4], 1, i);
CmdMngr::Command* cmd; CmdMngr::Command* cmd;
int access = params[3]; int access = params[3];
bool listable = true; bool listable = true;
bool info_ml = *params / sizeof(cell) >= 5 && params[5] != 0 && i;
if (access < 0) // is access is -1 then hide from listing if (access < 0) // is access is -1 then hide from listing
{ {
access = 0; access = 0;
listable = false; listable = false;
} }
if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable)) == NULL) if ((cmd = g_commands.registerCommand(plugin, idx, temp, info, access, listable, info_ml)) == NULL)
return 0; return 0;
cmd->setCmdType(CMD_ServerCommand); cmd->setCmdType(CMD_ServerCommand);
@ -1641,7 +1647,8 @@ static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params) /* 2 param *
return cmd->getId(); return cmd->getId();
} }
static cell AMX_NATIVE_CALL get_concmd(AMX *amx, cell *params) /* 7 param */ // native get_concmd(index, cmd[], len1, &flags, info[], len2, flag, id = -1, &bool:info_ml = false);
static cell AMX_NATIVE_CALL get_concmd(AMX *amx, cell *params)
{ {
int who = params[8]; int who = params[8];
@ -1661,7 +1668,12 @@ static cell AMX_NATIVE_CALL get_concmd(AMX *amx, cell *params) /* 7 param */
set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]); set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]);
cell *cpFlags = get_amxaddr(amx, params[4]); cell *cpFlags = get_amxaddr(amx, params[4]);
*cpFlags = cmd->getFlags(); *cpFlags = cmd->getFlags();
if (*params / sizeof(cell) >= 9)
{
*get_amxaddr(amx, params[9]) = cmd->isInfoML();
}
return 1; return 1;
} }
@ -1687,7 +1699,8 @@ static cell AMX_NATIVE_CALL get_concmd_plid(AMX *amx, cell *params)
return cmd->getPlugin()->getId(); return cmd->getPlugin()->getId();
} }
static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params) /* 7 param */ // native get_clcmd(index, command[], len1, &flags, info[], len2, flag, &bool:info_ml = false);
static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params)
{ {
CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ClientCommand, params[7]); CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ClientCommand, params[7]);
@ -1696,12 +1709,19 @@ static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params) /* 7 param */
set_amxstring_utf8(amx, params[2], cmd->getCmdLine(), strlen(cmd->getCmdLine()), params[3]); set_amxstring_utf8(amx, params[2], cmd->getCmdLine(), strlen(cmd->getCmdLine()), params[3]);
set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]); set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]);
cell *cpFlags = get_amxaddr(amx, params[4]); cell *cpFlags = get_amxaddr(amx, params[4]);
*cpFlags = cmd->getFlags(); *cpFlags = cmd->getFlags();
if (*params / sizeof(cell) >= 8)
{
*get_amxaddr(amx, params[8]) = cmd->isInfoML();
}
return 1; return 1;
} }
// native get_srvcmd(index, server_cmd[], len1, &flags, info[], len2, flag, &bool:info_ml = false);
static cell AMX_NATIVE_CALL get_srvcmd(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_srvcmd(AMX *amx, cell *params)
{ {
CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ServerCommand, params[7]); CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ServerCommand, params[7]);
@ -1713,7 +1733,12 @@ static cell AMX_NATIVE_CALL get_srvcmd(AMX *amx, cell *params)
set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]); set_amxstring_utf8(amx, params[5], cmd->getCmdInfo(), strlen(cmd->getCmdInfo()), params[6]);
cell *cpFlags = get_amxaddr(amx, params[4]); cell *cpFlags = get_amxaddr(amx, params[4]);
*cpFlags = cmd->getFlags(); *cpFlags = cmd->getFlags();
if (*params / sizeof(cell) >= 8)
{
*get_amxaddr(amx, params[8]) = cmd->isInfoML();
}
return 1; return 1;
} }

View File

@ -78,7 +78,7 @@ public cmdHelp(id, level, cid)
console_print(id, "^n----- %L -----", id, "HELP_COMS") console_print(id, "^n----- %L -----", id, "HELP_COMS")
new info[128], cmd[32], eflags new info[128], cmd[32], eflags, bool:is_info_ml
new end = start + lHelpAmount new end = start + lHelpAmount
if (end > clcmdsnum) if (end > clcmdsnum)
@ -88,7 +88,13 @@ public cmdHelp(id, level, cid)
for (new i = start; i < end; i++) for (new i = start; i < end; i++)
{ {
get_concmd(i, cmd, charsmax(cmd), eflags, info, charsmax(info), flags, id) get_concmd(i, cmd, charsmax(cmd), eflags, info, charsmax(info), flags, id, is_info_ml)
if (is_info_ml)
{
LookupLangKey(info, charsmax(info), info, id);
}
console_print(id, "%3d: %s %s", i + 1, cmd, info) console_print(id, "%3d: %s %s", i + 1, cmd, info)
} }

View File

@ -78,8 +78,14 @@ stock cmd_access(id, level, cid, num, bool:accesssilent = false)
} }
if (read_argc() < num) if (read_argc() < num)
{ {
new hcmd[32], hinfo[128], hflag; new hcmd[32], hinfo[128], hflag, bool:info_ml;
get_concmd(cid, hcmd, charsmax(hcmd), hflag, hinfo, charsmax(hinfo), level); get_concmd(cid, hcmd, charsmax(hcmd), hflag, hinfo, charsmax(hinfo), level, info_ml);
if (info_ml)
{
LookupLangKey(hinfo, charsmax(hinfo), hinfo, id);
}
console_print(id, "%L: %s %s", id, "USAGE", hcmd, hinfo); console_print(id, "%L: %s %s", id, "USAGE", hcmd, hinfo);
return 0; return 0;
} }

View File

@ -1749,12 +1749,13 @@ native remove_user_flags(index, flags = -1, id = 0);
* @param info Command description * @param info Command description
* @param FlagManager 0 opts out of flag manager, 1 opts in, -1 selects * @param FlagManager 0 opts out of flag manager, 1 opts in, -1 selects
* automatically * automatically
* @param info_ml If true, the parameter "info" will be looked up as multilingual key
* *
* @return Command id, 0 on failure * @return Command id, 0 on failure
* @error If an invalid callback function is specified, an error * @error If an invalid callback function is specified, an error
* will be thrown. * will be thrown.
*/ */
native register_clcmd(const client_cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1); native register_clcmd(const client_cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1, bool:info_ml = false);
/** /**
* Registers a callback to be called when the client or server executes a * Registers a callback to be called when the client or server executes a
@ -1774,12 +1775,13 @@ native register_clcmd(const client_cmd[], const function[], flags = -1, const in
* @param info Command description * @param info Command description
* @param FlagManager 0 opts out of flag manager, 1 opts in, -1 selects * @param FlagManager 0 opts out of flag manager, 1 opts in, -1 selects
* automatically * automatically
* @param info_ml If true, the parameter "info" will be looked up as multilingual key
* *
* @return Command id, 0 on failure * @return Command id, 0 on failure
* @error If an invalid callback function is specified, an error * @error If an invalid callback function is specified, an error
* will be thrown. * will be thrown.
*/ */
native register_concmd(const cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1); native register_concmd(const cmd[], const function[], flags = -1, const info[] = "", FlagManager = -1, bool:info_ml = false);
/** /**
* Registers a callback to be called when the server executes a command from the * Registers a callback to be called when the server executes a command from the
@ -1792,12 +1794,13 @@ native register_concmd(const cmd[], const function[], flags = -1, const info[] =
* @param function Callback function * @param function Callback function
* @param flags Admin privilege flags required * @param flags Admin privilege flags required
* @param info Command description * @param info Command description
* @param info_ml If true, the parameter "info" will be looked up as multilingual key
* *
* @return Command id, 0 on failure * @return Command id, 0 on failure
* @error If an invalid callback function is specified, an error * @error If an invalid callback function is specified, an error
* will be thrown. * will be thrown.
*/ */
native register_srvcmd(const server_cmd[], const function[], flags = -1, const info[] = ""); native register_srvcmd(const server_cmd[], const function[], flags = -1, const info[] = "", bool:info_ml = false);
/** /**
* Retrieves information about a client command. * Retrieves information about a client command.
@ -1813,10 +1816,11 @@ native register_srvcmd(const server_cmd[], const function[], flags = -1, const i
* @param len2 Maximum description buffer size * @param len2 Maximum description buffer size
* @param flag Only considers commands that can be accessed with * @param flag Only considers commands that can be accessed with
* the specified privilege flags * the specified privilege flags
* @param info_ml Variable to store whether the parameter "info" is a multilingual key
* *
* @return 1 on success, 0 if command was not found * @return 1 on success, 0 if command was not found
*/ */
native get_clcmd(index, command[], len1, &flags, info[], len2, flag); native get_clcmd(index, command[], len1, &flags, info[], len2, flag, &bool:info_ml = false);
/** /**
* Returns number of registered client commands. * Returns number of registered client commands.
@ -1845,10 +1849,11 @@ native get_clcmdsnum(flag);
* @param len2 Maximum description buffer size * @param len2 Maximum description buffer size
* @param flag Only considers commands that can be accessed with * @param flag Only considers commands that can be accessed with
* the specified privilege flags * the specified privilege flags
* @param info_ml Variable to store whether the parameter "info" is a multilingual key
* *
* @return 1 on success, 0 if command was not found * @return 1 on success, 0 if command was not found
*/ */
native get_srvcmd(index, server_cmd[], len1, &flags, info[], len2, flag); native get_srvcmd(index, server_cmd[], len1, &flags, info[], len2, flag, &bool:info_ml = false);
/** /**
* Returns number of registered server commands. * Returns number of registered server commands.
@ -1880,10 +1885,11 @@ native get_srvcmdsnum(flag);
* @param id If set to 0 only server commands will be considered, * @param id If set to 0 only server commands will be considered,
* positive will only consider client commands, otherwise * positive will only consider client commands, otherwise
* all console commands will be considered * all console commands will be considered
* @param info_ml Variable to store whether the parameter "info" is a multilingual key
* *
* @return 1 on success, 0 if command was not found * @return 1 on success, 0 if command was not found
*/ */
native get_concmd(index, cmd[], len1, &flags, info[], len2, flag, id = -1); native get_concmd(index, cmd[], len1, &flags, info[], len2, flag, id = -1, &bool:info_ml = false);
/** /**
* Returns the parent plugin id of a console command. * Returns the parent plugin id of a console command.