[英]What are possible ways of converting these bitmask definitions from pawn language to PHP?
Well, to clarify, pawn is a language that is pretty similar to C++. 好吧,澄清一下,pawn是一种与C ++非常相似的语言。 I'm programming an Admin Control Panel that requires bit mask permissions (in php) and I actually don't know if I converted the permissions properly (since it's something I have never done) to PHP. 我正在编程一个需要位掩码权限(在php中)的管理控制面板,实际上我不知道我是否将权限正确转换(因为我从未做过)到PHP。 I used define() to define permissions. 我使用define()定义权限。 Here's how it originally is (in pawn): 原来是这样(在典当中):
//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,
};
Now this is how I defined it in PHP: 现在这就是我在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);
I compared the bitflags and most of the time it just recognizes the EAdminFlags_All
permission along with EAdminFlags_None
and EAdminFlags_BasicAdmin
. 我比较了这些位标志,并且在大多数情况下,它只识别EAdminFlags_All
权限以及EAdminFlags_None
和EAdminFlags_BasicAdmin
权限。 So there is probably an issue with how I defined this in PHP. 因此,我在PHP中的定义方式可能存在问题。 The permissions are stored in a database and they are saved as a raw integer value for example: 51531777
Then it's loaded into PHP and compared like so: 权限存储在数据库中,并保存为原始整数值,例如: 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;
}
Thank you for your help beforehand, I really appreciate it. 预先感谢您的帮助,我非常感谢。
define("EAdminFlags_BasicAdmin",1);
define("EAdminFlags_CanGiveGuns",1 << 0);
these two are equivalent... shifting by 0 is basically a null operation, so "cangiveguns" has the same value as basicadmin 这两个是等效的...移0基本上是一个空操作,因此“ cangiveguns”与basicadmin具有相同的值
Assuming that your shift operations on the constants are right, there is an error in your detection of a particular rights flag: 假设对常量的移位操作正确,则检测到特定的权限标志时将出错:
public function getAdminPerms($n) {
return ($this->adminlevel & (1 << $n)) != 0;
}
Input is the flag value, which is only a 1 bit set at the correct position. 输入的是标志值,仅在正确位置设置一个1位。 You incorrectly shift again, but all you need to do is AND the integer value with the one read from the database: 您再次错误地进行了移位,但是您所要做的就是将整数值与从数据库中读取的值相乘:
public function getAdminPerms($n) {
return ($this->adminlevel & $n)) != 0;
}
The way back works the same. 返回的方式相同。 Starting from a zero value, you can add all admin rights flags with bit-OR-ing all the constant values without shifting: 从零值开始,您可以对所有常量值进行位或运算而无需移位即可添加所有管理员权限标志:
$newAdmin = EAdminFlags_AntiCheat | EAdminFlags_CanGiveGuns;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.