Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player.setPermLevel does not seem to be synchronized with the client #1194

Closed
MnyaCat opened this issue Apr 14, 2023 · 8 comments
Closed

Player.setPermLevel does not seem to be synchronized with the client #1194

MnyaCat opened this issue Apr 14, 2023 · 8 comments
Labels
bug Related to software malfunction priority: medium Needs attention

Comments

@MnyaCat
Copy link

MnyaCat commented Apr 14, 2023

Exceptions module

ScriptEngine

Operating System

Windows 11

LiteLoader version

2.12.3

BDS version

1.19.73

What happened?

When I use Player.setPermLevel to manipulate the PermLevel of a player to 1, it is treated as an operator (/give and /kill can be executed), but the following phenomenon occurs.

  • Command suggestions are not displayed.
  • In the menu, the user is displayed as a member.

It is inconvenient that the suggestions are not displayed, and it is strange that you are displayed as a member even though you are an operator.
Is there any way to make the suggestions show up and show me as an operator in the menu?

Translated with www.DeepL.com/Translator (free version)

Steps to reproduce?

  1. load the plugin (code below).
  2. make sure /give @s diamond is not executable
  3. run /sudo @s and set permLevel to 1.
  4. /give @s diamond is executable, but does not show suggestions, and does not appear as an operator
// oprequest_ll.js
// Amethyst-Plugin
"use strict";
// LiteLoader-AIDS automatic generated
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="c:\Users\MnyaCat\LiteLoaderBDS/dts/HelperLib-master/src/index.d.ts"/>

mc.listen("onServerStarted", () => {
    (0, registerCommand)();
    log("registed oprequest");
});

function grantsOperator(target) {
    target.setPermLevel(1);
}

function revokesOperator(target) {
    target.setPermLevel(0);
}

function registerCommand() {
    const oprequest = mc.newCommand("oprequest", "プレイヤーに一時的にオペレーターのステータスを与えます。このステータスは300秒後に解除されます。", PermType.Any);
    oprequest.setAlias("sudo");
    oprequest.mandatory("targets", ParamType.Player);
    oprequest.overload(["targets"]);
    oprequest.setCallback((_cmd, origin, output, result) => {
        const admin = Permission.getRole("admin");
        if (origin.player != null && admin.hasMember(origin.player.xuid)) {
            const targets = result.targets;
            targets.forEach((player) => {
                grantsOperator(player);
                setTimeout(revokesOperator, 300000, player);
            });
            output.success("OP権限を付与しました。300秒後に解除されます。");
            return;
        }
        output.error("このコマンドを使用する権限がありません。adminロールが必要です。");
    });
    oprequest.setup();
}

ll.registerPlugin(
/* name */ "Amethyst-Plugin",
/* introduction */ "",
/* version */ [0, 1, 0],
/* otherInformation */ {});

Relevant log output

19:04:50 INFO [Command] <MnyaCat> /sudo @s
19:04:50 INFO [Permissions] <MnyaCat> Any(0) -> GameMasters(1)
permission list  
19:04:58 INFO [Server] ###* {"command":"ops","result":[]}
19:04:58 INFO [Server]  *###
19:04:58 INFO [Server] ###* {"command":"permissions","result":[{"permission":"member","xuid":"2535408593350225"}]}
19:04:58 INFO [Server]  *###
deop MnyaCat
19:05:24 INFO [Permissions] <MnyaCat> GameMasters(1) -> Any(0)
19:05:24 INFO [Server] De-opped: MnyaCat
op MnyaCat
19:05:27 INFO [Permissions] <MnyaCat> Any(0) -> GameMasters(1)
19:05:27 INFO [Server] Opped: MnyaCat
permission list
19:05:30 INFO [Server] ###* {"command":"ops","result":["2535408593350225"]}
19:05:30 INFO [Server]  *###
19:05:30 INFO [Server] ###* {"command":"permissions","result":[{"permission":"operator","xuid":"2535408593350225"}]}
19:05:30 INFO [Server]  *###

Plugin list

ll list
19:35:07 INFO [Server] プラグインの一覧 [6]
19:35:07 INFO [Server] - PermissionAPI [v2.9.0] (PermissionAPI.dll)
19:35:07 INFO [Server]   Builtin & Powerful permission API for LiteLoaderBDS
19:35:07 INFO [Server] - ScriptEngine-QuickJs [v2.12.3] (LiteLoader.Js.dll)
19:35:07 INFO [Server]   Javascript ScriptEngine for LiteLoaderBDS
19:35:07 INFO [Server] - ScriptEngine-Python [v2.12.3] (LiteLoader.Python.dll)
19:35:07 INFO [Server]   Python ScriptEngine for LiteLoaderBDS
19:35:07 INFO [Server] - Amethyst-Plugin [v0.1.0] (oprequest_ll.js)
19:35:07 INFO [Server]
19:35:07 INFO [Server] - ScriptEngine-NodeJs [v2.12.3] (LiteLoader.NodeJs.dll)
19:35:07 INFO [Server]   Node.js ScriptEngine for LiteLoaderBDS
19:35:07 INFO [Server] - ScriptEngine-Lua [v2.12.3] (LiteLoader.Lua.dll)
19:35:07 INFO [Server]   Lua ScriptEngine for LiteLoaderBDS
19:35:07 INFO [Server]
19:35:07 INFO [Server]
19:35:07 INFO [Server] * 詳細については、コマンド "ll list <Plugin Name>" を使用してください
@MnyaCat
Copy link
Author

MnyaCat commented Apr 14, 2023

Here is a video of the actual reproduction.

issue.mp4

@ShrBox ShrBox added bug Related to software malfunction status: to do priority: medium Needs attention labels Apr 15, 2023
@ReallocAll
Copy link

After testing, this problem also occurs when calling Player::setPermissions directly from a plugin written with LL-CPP-SDK
One possible solution is to send an UpdateAbilitiesPacket packet to the player immediately after setting permissions to refresh the client's permissions

void PluginInit()
{
    Event::PlayerJoinEvent::subscribe([](const Event::PlayerJoinEvent &event)
    {
        Player *player = event.mPlayer;
        player->setPermissions((CommandPermissionLevel)1);
        UpdateAbilitiesPacket pkt(player->getUniqueID(), player->getAbilities());
        player->sendNetworkPacket(pkt);
        return true;
    });
}

@MnyaCat
Copy link
Author

MnyaCat commented Apr 16, 2023

Sorry, how do I send UpdateAbilitiesPacket in JavaScript?
I know to use BinaryStream to create the packet and Player.sendPacket to send it.

@ReallocAll
Copy link

Sorry, how do I send UpdateAbilitiesPacket in JavaScript? I know to use BinaryStream to create the packet and Player.sendPacket to send it.

Until LiteLoaderBDS fixes the problem, you can use this method to solve the problem for now.

@MnyaCat
Copy link
Author

MnyaCat commented Apr 17, 2023

Sorry for repeating myself.
I don't know what to write in the BinaryStream or what the Packet ID is.

@ReallocAll
Copy link

Sorry for repeating myself. I don't know what to write in the BinaryStream or what the Packet ID is.

I looked at the logic of bds writing to the UpdateAbilitiesPacket binary stream through disassembly and unfortunately there are some bds internal function calls involved which are relatively tricky to implement in llse. So, please be patient until the issue is fixed

@MnyaCat
Copy link
Author

MnyaCat commented Apr 18, 2023

Thank you very much.
Until the problem is fixed, we will run the op command on the server to address the issue.

ReallocAll pushed a commit to ReallocAll/LiteLoaderBDS that referenced this issue Apr 18, 2023
ReallocAll pushed a commit to ReallocAll/LiteLoaderBDS that referenced this issue Apr 18, 2023
@ReallocAll ReallocAll mentioned this issue Apr 18, 2023
ShrBox added a commit that referenced this issue Apr 21, 2023
@ShrBox
Copy link
Member

ShrBox commented Apr 21, 2023

Fixed in 74528cb

@ShrBox ShrBox closed this as completed Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Related to software malfunction priority: medium Needs attention
Development

No branches or pull requests

3 participants