janispritzkau / rcon-client

A simple and modern RCON client made to work with Minecraft
62 stars 17 forks source link

Tried to communicate with Palworld dedicated Linux Server #25

Open neosmatrix321 opened 4 months ago

neosmatrix321 commented 4 months ago

I try to connect to a Palworld dedicated linux server v0.1.4.1. this is my script:

import { Rcon } from "rcon-client"

const rcon = await Rcon.connect({
    host: "192.168.228.7", port: 25575, password: "pw"
});
rcon.on("authenticated", () => console.log("authenticated"));
// console.log(await rcon.send("Info"));

let responses = await Promise.all([
    rcon.send("Info"),
    rcon.send("Broadcast **OK_don-t_ignore_this_anyway_only_a_test**")
])

for (let response of responses) {
    console.log(response);
}

I get this error:

/home/websocket_client/node_modules/rcon-client/lib/rcon.js:117 reject(new Error(Timeout for packet id ${id})); ^

Error: Timeout for packet id 1 at Timeout._onTimeout (/home/websocket_client/node_modules/rcon-client/lib/rcon.js:117:28) at listOnTimeout (node:internal/timers:569:17) at process.processTimers (node:internal/timers:512:7)

Node.js v18.19.0

But the Broadcast gets still delievered and I can see the message on the server. I don't get any response from "Info" or "ShowPlayers" commands. I tested many other clients, but sadly no client works for me.

I also use ARRCON shell utility, which is able to send & recieve messages from server without a problem. Any chance to get this fixed?

Regards, Sascha

janispritzkau commented 4 months ago

Thanks for the report. I did mention in the README that this library was specifically built for Minecraft, but could you try the new alpha version anyway?

https://www.npmjs.com/package/rcon-client/v/5.0.0-alpha.2

I've changed and simplified the code quite a lot, so it should be worth a try.

neosmatrix321 commented 4 months ago

Hey, thanks for the reply. I know that this is optimized for minecraft server, but since the rcon protocoll is pretty universal, I thought I give it a try. I installed the alpha 2 and did some console.log modification (hope you don't mind). Think you will understand whats going on there.

id: 0 type: 3 payload Uint8Array(9) [ , , , , , , , , * ] message **** # <--- my password reqId 1 id: 1 type: 2 payload Uint8Array(4) [ 105, 110, 102, 111 ] message info res { id: 0, type: 0, message: 'Welcome to Pal Server[v0.1.4.1] Dator Community\n' } /home/websocket_client/node_modules/rcon-client/dist/client.js:85 throw new Error(Invalid response id (expected ${reqId}, got ${res.id})); ^

Error: Invalid response id (expected 1, got 0) at RconClient.cmd (/home/websocket_client/node_modules/rcon-client/dist/client.js:85:23) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///home/websocket_client/index.js:24:14

Node.js v18.19.0

EDIT: I've set the password request ID to 0, so he doen't count up the auth process id, it now works (atleast in this commandline tool) with this quick hack.

./index.js "info" Welcome to Pal Server[v0.1.4.1] Dator Community

janispritzkau commented 4 months ago

Technically, since I process each command sequentially, I could use the same request ID everywhere. This issue sounds like a server bug. What exactly did you change in the client?

neosmatrix321 commented 4 months ago
diff /home/orig/node_modules/rcon-client/dist/client.js /home/websocket/node_modules/rcon-client/dist/client.js
47c47
<             const reqId = this.#nextReqId();
---
>             const reqId = 0;

EDIT: this works for me too

diff /home/orig/node_modules/rcon-client/dist/client.js /home/websocket_client/node_modules/rcon-client/dist/client.js
10c10
<     #reqId = 0;
---
>     #reqId = -1;
52c52
<             if (res.id == -1)
---
>             if (res.id == -2)
likecyber commented 4 months ago

It seems like Palworld's RCON implementation is different from Source's RCON Protocol. It always returns ID: 0 for whatever ID you sent after you authorized. Forcing ID to always be 0 seems to fix this issue.