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

Ladders arent working #1297

Open
officialdakari opened this issue Apr 18, 2024 · 3 comments
Open

Ladders arent working #1297

officialdakari opened this issue Apr 18, 2024 · 3 comments

Comments

@officialdakari
Copy link

officialdakari commented Apr 18, 2024

[v] The FAQ doesn't contain a resolution to my issue

Versions

  • minecraft-protocol: 1.47.0
  • server: paper 1.20.4
  • node: 18.19.1

Detailed description of a problem

Proxying through node-minecraft-protocol, ladders arent working

Current code

const tunKey = 'no';
const host = '192.168.0.158';
const port = 32323;

const mc = require('minecraft-protocol');
const ws = require('ws');

const sock = new ws.WebSocket('https://minecraft-tunneling.zelix.space/minecraft');

sock.on('open', async () => {
    sock.send(JSON.stringify({
        key: tunKey
    }));
});

function createText(msg, version) {
    if (['1.20.3', '1.20.4'].includes(version)) {
        return {
            type: 'string',
            value: msg
        };
    } else if (['1.19.4', '1.19.3', '1.19.2', '1.19.1'].includes(version)) {
        return JSON.stringify(msg);
    } else if (version == '1.19') {
        return JSON.stringify(msg);
    } else {
        return JSON.stringify(msg);
    }
}

function createChatPacket(msg, version) {
    if (['1.20.3', '1.20.4'].includes(version)) {
        return {
            name: 'system_chat',
            data: {
                content: msg,
                isActionBar: false
            }
        }
    } else if (['1.19.4', '1.19.3', '1.19.2', '1.19.1', '1.20.2', '1.20.1', '1.20'].includes(version)) {
        return {
            name: 'system_chat',
            data: {
                content: JSON.stringify(msg),
                isActionBar: false
            }
        };
    } else if (version == '1.19') {
        return {
            name: 'system_chat',
            data: {
                content: JSON.stringify(msg),
                type: 1
            }
        };
    } else {
        return {
            name: 'chat',
            data: {
                message: JSON.stringify(msg),
                position: 1,
                sender: NIL
            }
        };
    }
}

/**
 * @type {Object.<string, mc.Client>}
 */
const clients = {};
sock.on('message', async (msg) => {
    const j = JSON.parse(msg);
    if (j.ok) {
        console.log(`Tunneling to ${j.address}`);
    }

    if (j.connect) {
        const client = mc.createClient({
            username: j.username,
            version: j.version,
            host,
            port,
            keepAlive: false,
            disableChatSigning: true
        });

        clients[j.username] = client;
        console.log(`${j.username} connects from ${j.remoteAddress} [${j.version}]`);

        client.on('error', async (err) => {
            console.error(err);
        });

        client.on('end', async () => {
            console.log(`${j.username} disconnects`);
            sock.send(JSON.stringify({
                kick: true,
                username: j.username
            }));
            delete clients[j.username];
        });

        client.on('packet', async (data, meta) => {
            if (meta.state == mc.states.PLAY && meta.name != 'custom_payload') {
                if (client.version == '1.20.3' || client.version == '1.20.4') {
                    if (meta.name == 'player_chat') {
                        if (data.unsignedChatContent && data.type == 4) {
                            const packet = createChatPacket(data.unsignedChatContent, client.version);
                            meta.name = packet.name;
                            data = packet.data;
                        }
                    }
                }
                sock.send(JSON.stringify(
                    {
                        packet: meta.name,
                        state: meta.state,
                        data: JSON.stringify(data),
                        username: j.username
                    }
                ));
            }
        });
    }

    if (j.disconnect) {
        const c = clients[j.username];
        console.log(`${j.username} disconnected (request by server)`);
        if (!c) return;
        clients[j.username].end();
        delete clients[j.username];
    }

    if (j.name && j.username) {
        const c = clients[j.username];
        if (!c) {
            // sock.send(JSON.stringify({
            //     kick: true,
            //     username: j.username
            // }));
            return;
        }
        if (c.state == mc.states.PLAY && j.state == 'play') {
            if (j.name == 'custom_payload') return;
            c.write(j.name, JSON.parse(j.data));
        }
    }
});

Expected behavior

Ladders should work

Additional context

video (hosted on matrix)

@extremeheat
Copy link
Member

Hi, your video is inaccessible. This doesn't seem to be an issue with nmp, so you would need to do a packet log between a direct vanilla client-vanilla server and against the proxy to see what's going on wrong with your code.

You can try looking at pakkit packet logs which should use nmp as its backend.

@officialdakari
Copy link
Author

officialdakari commented May 27, 2024 via email

@extremeheat
Copy link
Member

Can you embed a video on github? Dragging the file here should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants