好吧,澄清一下,pawn 是一种与 C++ 非常相似的语言。我正在编写一个需要位掩码权限(在 php 中)的管理控制面板,我实际上不知道我是否将权限正确转换(因为这是我从未做过的事情)到 PHP。我使用 define() 来定义权限。这是它最初的样子(典当):
//Pawn
enum EAdminFlags (<<= 1) {
EAdminFlags_None = 0,
EAdminFlags_BasicAdmin = 1, //kick, fine, etc 0
EAdminFlags_CanGiveGuns, //1
EAdminFlags_HouseAdmin, //2
EAdminFlags_IRCAdmin, //3
EAdminFlags_BusinessAdmin, //4
EAdminFlags_AdminManage, //5 can see invisible admins/manipulate admin flags
EAdminFlags_Scripter, //getpvars, reloadcmds, stuff only scripters should need 6
EAdminFlags_HelperManage, // 7 manage helpers/teachers
EAdminFlags_Unbannable, //unbanable under ANY circumstances 8
EAdminFlags_CanRefundSelf, //can refund himself
EAdminFlags_VehicleAdmin, //10 can manipulate player vehicles
EAdminFlags_AntiCheat, //immune to the anticheat 11
EAdminFlags_BigEars, //can /bigears, /bigfamilyears, /bigmouth
EAdminFlags_SetName, //13
EAdminFlags_CanHide, //can toggle/untoggle hidden on themselves 14
EAdminFlags_Invisible, //Invisible on admins list(like 9999s before) 15
EAdminFlags_GiveDrugs, //server manager, can restart the server/do rcon cmds, create job cars 16
EAdminFlags_Unban, //can unban, oban, oprison people 17
EAdminFlags_WeatherManage, //can manage weather/time 18
EAdminFlags_GiveRestrictedGun, //can give restircted guns 19
EAdminFlags_TeleportOthers, //can teleport other people 20
EAdminFlags_CanBanAdmins, //can ban other admins(or any punishments) 21
EAdminFlags_GiveMats, //can give materials 22
EAdminFlags_StatsManage, //23 /setstat, /sethp, /setarmor
EAdminFlags_FamilyAdmin, //24
EAdminFlags_FactionAdmin, //25
EAdminFlags_MassCmds, //26 can do /masstphere, /massmoney, /masskick, /massnuke
EAdminFlags_Nuke, //27 can do things like /nuke, sparta, rangeban
EAdminFlags_RangeBan, //28 can range ban
EAdminFlags_GiveMoney, //29 can /givemoney /money
EAdminFlags_Donations, //30 can give DPS/set donate rank
EAdminFlags_ServerManager, //can restart the server, etc, use /noooc, /nopms, /nonewb
EAdminFlags_All = -1,
};
现在这就是我在 PHP 中定义它的方式:
define("EAdminFlags_None",0);
define("EAdminFlags_BasicAdmin",1);
define("EAdminFlags_CanGiveGuns",1 << 0);
define("EAdminFlags_HouseAdmin",1 << 1);
define("EAdminFlags_IRCAdmin",1 << 2);
define("EAdminFlags_BusinessAdmin",1 << 3);
define("EAdminFlags_AdminManage",1 << 4);
define("EAdminFlags_Scripter",1 << 5);
define("EAdminFlags_HelperManage",1 << 6);
define("EAdminFlags_Unbannable",1 << 7);
define("EAdminFlags_CanRefundSelf",1 << 8);
define("EAdminFlags_VehicleAdmin",1 << 9);
define("EAdminFlags_AntiCheat",1 << 10);
define("EAdminFlags_BigEars",1 << 11);
define("EAdminFlags_SetName",1 << 12);
define("EAdminFlags_CanHide",1 << 13);
define("EAdminFlags_Invisible",1 << 14);
define("EAdminFlags_GiveDrugs",1 << 15);
define("EAdminFlags_Unban",1 << 16);
define("EAdminFlags_WeatherManage",1 << 17);
define("EAdminFlags_GiveRestrictedGun",1 << 18);
define("EAdminFlags_TeleportOthers",1 << 19);
define("EAdminFlags_CanBanAdmins",1 << 20);
define("EAdminFlags_GiveMats",1 << 21);
define("EAdminFlags_StatsManage",1 << 22);
define("EAdminFlags_FamilyAdmin",1 << 23);
define("EAdminFlags_FactionAdmin",1 << 24);
define("EAdminFlags_MassCmds",1 << 25);
define("EAdminFlags_Nuke",1 << 26);
define("EAdminFlags_RangeBan",1 << 27);
define("EAdminFlags_GiveMoney",1 << 28);
define("EAdminFlags_Donations",1 << 29);
define("EAdminFlags_ServerManager",1 << 30);
define("EAdminFlags_All",-1);
我比较了位标志,大多数时候它只识别EAdminFlags_All
权限以及EAdminFlags_None
和EAdminFlags_BasicAdmin
。所以我在 PHP 中定义它的方式可能存在问题。权限存储在数据库中,并保存为原始整数值,例如:51531777
然后将其加载到 PHP 中并进行比较,如下所示:
$account = new Account(Auth::getUserID());
echo "Welcome ".$account->getUsername()."<br>";
if($account->getAdminPerms(EAdminFlags_FamilyAdmin)) {
echo "You are a family admin."; //testing purposes
//If the person has those permissions set then display he / she is a family admin but even if the permissions are set to EAdminFlags_BasicAdmin, it will still display it wrong
}
public function getAdminLevel() {
return $this->adminlevel; //This holds the integer value "51531777"
}
public function getAdminPerms($n) {
return ($this->adminlevel & (1 << $n)) != 0;
}
事先感谢您的帮助,我真的很感激。