misuzu/src/SharpChat/SharpChatPerms.php
flash 383e2ed0e0 Rewrote the user information class.
This one took multiple days and it pretty invasive into the core of Misuzu so issue might (will) arise, there's also some features that have gone temporarily missing in the mean time and some inefficiencies introduced that will be fixed again at a later time.
The old class isn't gone entirely because I still have to figure out what I'm gonna do about validation, but for the most part this knocks out one of the "layers of backwards compatibility", as I've been referring to it, and is moving us closer to a future where Flashii actually gets real updates.
If you run into anything that's broken and you're inhibited from reporting it through the forum, do it through chat or mail me at flashii-issues@flash.moe.
2023-08-02 22:12:47 +00:00

55 lines
2.4 KiB
PHP

<?php
namespace Misuzu\SharpChat;
use Misuzu\Users\UserInfo;
final class SharpChatPerms {
private const P_KICK_USER = 0x00000001;
private const P_BAN_USER = 0x00000002;
//private const P_SILENCE_USER = 0x00000004;
private const P_BROADCAST = 0x00000008;
private const P_SET_OWN_NICK = 0x00000010;
private const P_SET_OTHER_NICK = 0x00000020;
private const P_CREATE_CHANNEL = 0x00000040;
private const P_DELETE_CHANNEL = 0x00010000;
private const P_SET_CHAN_PERMA = 0x00000080;
private const P_SET_CHAN_PASS = 0x00000100;
private const P_SET_CHAN_HIER = 0x00000200;
private const P_JOIN_ANY_CHAN = 0x00020000;
private const P_SEND_MESSAGE = 0x00000400;
private const P_DELETE_OWN_MSG = 0x00000800;
private const P_DELETE_ANY_MSG = 0x00001000;
private const P_EDIT_OWN_MSG = 0x00002000;
private const P_EDIT_ANY_MSG = 0x00004000;
private const P_VIEW_IP_ADDR = 0x00008000;
private const PERMS_DEFAULT = self::P_SEND_MESSAGE | self::P_DELETE_OWN_MSG | self::P_EDIT_OWN_MSG;
private const PERMS_MANAGE_USERS = self::P_SET_OWN_NICK | self::P_SET_OTHER_NICK | self::P_DELETE_ANY_MSG
| self::P_EDIT_ANY_MSG | self::P_VIEW_IP_ADDR | self::P_BROADCAST;
private const PERMS_CHANGE_BACKG = self::P_SET_OWN_NICK | self::P_CREATE_CHANNEL | self::P_SET_CHAN_PASS;
private const PERMS_MANAGE_FORUM = self::P_CREATE_CHANNEL | self::P_SET_CHAN_PERMA | self::P_SET_CHAN_PASS
| self::P_SET_CHAN_HIER | self::P_DELETE_CHANNEL | self::P_JOIN_ANY_CHAN;
public static function convert(UserInfo $userInfo): int {
$userInfo = (int)$userInfo->getId();
$perms = self::PERMS_DEFAULT;
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_USERS))
$perms |= self::PERMS_MANAGE_USERS;
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_WARNINGS))
$perms |= self::P_KICK_USER;
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_BANS))
$perms |= self::P_BAN_USER;
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_CHANGE_BACKGROUND))
$perms |= self::PERMS_CHANGE_BACKG;
if(perms_check_user(MSZ_PERMS_FORUM, $userInfo, MSZ_PERM_FORUM_MANAGE_FORUMS))
$perms |= self::PERMS_MANAGE_FORUM;
return $perms;
}
}