明確にするために、ポーンは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
許可を認識するだけです。したがって、PHPでこれをどのように定義したかにはおそらく問題があります。アクセス許可はデータベースに保存され、次のように生の整数値として保存されます。
次に、PHPにロードされ、次のように比較されます。EAdminFlags_None
EAdminFlags_BasicAdmin
51531777
$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;
}
よろしくお願いします。