As we established in a PM conversation, having 0 as the default command flag causes some issues when it comes to checking whether it's an admin command or not. Having it as anything else but 0 seems to works to a certain extent.
I did some further testing and it seems like the default command flag isn't included in commands with flags. The following command can be executed by players but not by administrators:
PHP код:
command(commands, cmdid, playerid, params[]) {
new cmdList[512], bool:need_frmt = true;
if(need_frmt) {
for(new i = GetTotalCommandCount(); --i >= 0;) {
if(i == cmdid)
continue;
if(GetCommandFlags(i) == 0) {
new cmd[28];
GetCommandName(i, cmd);
strcat(cmdList, cmd);
strcat(cmdList, "\n");
}
}
need_frmt = false;
}
Dialog_Show(playerid, admin_commands, DIALOG_STYLE_LIST, COMMUNITY_NAME" - Commands", cmdList, "Select", "Cancel");
return CMD_SUCCESS;
}
Probably worth noting that I'm using the following method of checking for admin commands:
PHP код:
public OnPlayerCommandReceived(cmdid, playerid, cmdtext[]) {
new const acmdFlags[7] = {CMD_FLAG_PLAYER, ACMD_LEVEL_MIN_1, ACMD_LEVEL_MIN_2, ACMD_LEVEL_MIN_3, ACMD_LEVEL_MIN_4, ACMD_LEVEL_MIN_5, ACMD_LEVEL_MIN_DEV};
if(cmdid == INVALID_COMMAND_ID) {
Player_SendTaggedMessage(playerid, TYPE_ERROR, "The specified command does not exist! Use /cmds to see all available commands.");
return CMD_FAILURE;
}
printf("Flags:%b AdminLevel:%d AdminFlag:%b", GetCommandFlags(cmdid), Player[playerid][epd_Admin], acmdFlags[Player[playerid][epd_Admin]]);
//if(GetCommandFlags(cmdid) != 0 || acmdFlags[Player[playerid][epd_Admin]] != 0) {
if(!(GetCommandFlags(cmdid) & acmdFlags[Player[playerid][epd_Admin]])) {
Player_SendTaggedMessage(playerid, TYPE_ERROR, "The specified command is reserved for administrative players.");
return CMD_FAILURE;
}
//}
return CMD_SUCCESS;
}
While the extra check (commented in the code above) works as it should, I wanted to make the default command flag work without needing an extra check. For that, I defined DEFAULT_CMD_FLAG as:
I could include my data module first and then use the enumerator CMD_FLAG_PLAYER instead of redeclaring it there:
PHP код:
enum (<<= 1) {
CMD_FLAG_ADMIN = 1,
CMD_FLAG_PLAYER,
ACMD_LEVEL_1,
ACMD_LEVEL_2,
ACMD_LEVEL_3,
ACMD_LEVEL_4,
ACMD_LEVEL_5,
ACMD_LEVEL_DEV
};
#define ACMD_LEVEL_MIN_DEV ACMD_LEVEL_DEV
#define ACMD_LEVEL_MIN_5 ACMD_LEVEL_5 | ACMD_LEVEL_MIN_DEV
#define ACMD_LEVEL_MIN_4 ACMD_LEVEL_4 | ACMD_LEVEL_MIN_5
#define ACMD_LEVEL_MIN_3 ACMD_LEVEL_3 | ACMD_LEVEL_MIN_4
#define ACMD_LEVEL_MIN_2 ACMD_LEVEL_2 | ACMD_LEVEL_MIN_3
#define ACMD_LEVEL_MIN_1 ACMD_LEVEL_1 | ACMD_LEVEL_MIN_2
Is it possible to include the default CMD flag in every single command? The only reason why flags are used is to add an extra layer of permissions to a command or am I wrong on that?
While I'm at it, I seem to have another issue with this method of checking. Administrators can utilise commands that are above their rank.
Little sidenote: there's a little typo in one of the examples:
Код:
enum (<<=1)
{
VIP_CMD = 1,
RCON_CMD,
PLAYER_CMD.
ACMD1,
ACMD2,
ACMD3,
ACMD4,
ACMD5
}