Exemple #1
0
if (!$user) {
    json_p(["success" => false, "This endpoint requires authentication."]);
}
$dbManager = new DatabaseManager();
if (!$dbManager->validateScope($scope)) {
    json_p("Invalid room name.");
}
switch ($level) {
    case "admin":
        if (!$dbManager->isOwner($user, $scope)) {
            json_p(['success' => false, 'reason' => "Only the room owner can appoint or demote admins."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, DatabaseManager::PERMISSION_LEVEL_ROOM_ADMIN));
        break;
    case "host":
    case "ban":
        if (!$dbManager->isOwnerOrAdmin($user, $scope)) {
            json_p(['success' => false, 'reason' => "You don't have permission to do this."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, $level === "host" ? DatabaseManager::PERMISSION_LEVEL_ROOM_HOST : DatabaseManager::PERMISSION_LEVEL_ROOM_BANNED));
        break;
    case "queue_ban":
    case "mute":
        if (!$dbManager->isHostOrAbove($user, $scope)) {
            json_p(['success' => false, 'reason' => "You don't have permission to do this."]);
        }
        json_p($dbManager->changePermission($type, $username, $scope, $level === "queue_ban" ? DatabaseManager::PERMISSION_LEVEL_ROOM_QUEUE_BANNED : DatabaseManager::PERMISSION_LEVEL_ROOM_MUTED));
        break;
    default:
        json_p($INVALID);
}