2022-09-13 13:14:49 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu\SharpChat;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
use Misuzu\Users\UserInfo;
|
2022-09-13 13:14:49 +00:00
|
|
|
|
|
|
|
final class SharpChatPerms {
|
|
|
|
private const P_KICK_USER = 0x00000001;
|
|
|
|
private const P_BAN_USER = 0x00000002;
|
2023-07-23 21:47:15 +00:00
|
|
|
//private const P_SILENCE_USER = 0x00000004;
|
2022-09-13 13:14:49 +00:00
|
|
|
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;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
public static function convert(UserInfo $userInfo): int {
|
|
|
|
$userInfo = (int)$userInfo->getId();
|
2022-09-13 13:14:49 +00:00
|
|
|
$perms = self::PERMS_DEFAULT;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_USERS))
|
2022-09-13 13:14:49 +00:00
|
|
|
$perms |= self::PERMS_MANAGE_USERS;
|
2023-07-26 22:46:35 +00:00
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_WARNINGS))
|
2023-07-26 22:46:35 +00:00
|
|
|
$perms |= self::P_KICK_USER;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_MANAGE_BANS))
|
2023-07-26 22:46:35 +00:00
|
|
|
$perms |= self::P_BAN_USER;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(perms_check_user(MSZ_PERMS_USER, $userInfo, MSZ_PERM_USER_CHANGE_BACKGROUND))
|
2022-09-13 13:14:49 +00:00
|
|
|
$perms |= self::PERMS_CHANGE_BACKG;
|
2023-07-26 22:46:35 +00:00
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(perms_check_user(MSZ_PERMS_FORUM, $userInfo, MSZ_PERM_FORUM_MANAGE_FORUMS))
|
2022-09-13 13:14:49 +00:00
|
|
|
$perms |= self::PERMS_MANAGE_FORUM;
|
|
|
|
|
|
|
|
return $perms;
|
|
|
|
}
|
|
|
|
}
|