conqp / rcon

Python RCON client library
GNU General Public License v3.0
84 stars 15 forks source link

Issues with DayZ RCon #32

Open fugma313 opened 6 months ago

fugma313 commented 6 months ago

I use this module to keep a local player database in a text file, among other things.

Here's some of the code

while True:
    try:
        with Client(rcon_server_address, int(rcon_server_port), passwd=rcon_server_password, timeout=5) as client:
            print(f"Connected to the DayZ server at {rcon_server_address}:{rcon_server_port}")
            while True:

                response = client.run("players")
                if len(response) < 1: # If this is removed, we forever transmit without a reply...
                    raise Exception("Disconnected")
                lines = response.split("\n")
                for line in lines:
                    if "." in line and ":" in line: 
                    ...

If I don't raise that exception, I will forever transmit the "players" command which will be ignored by the RCon server.

Judging by the network traffic, something is wrong. The server sends "RCon admin #0 (IP:port) logged in", and I see a reply of b'0200', but this doesn't seem to be what the RCon server is expecting. Because it will transmit this same login message up to 5 times, after which it will start ignoring any commands sent to it, forcing me to re-auth with RCon to continue executing commands. This is becoming a problem as my DayZ server console is flooded with "BattlEye Server: RCon admin #0 (127.0.0.1:52368) logged in"

Edit: Upon comparing the network traffic between this and DaRT, it looks like the reply (0200) is missing the BE RCon protocol header.

conqp commented 6 months ago

Thanks for the report. I'm currently on vacation for the next two weeks, so I cannot work on this before 2024-06-03. I will try to reproduce this asap after that and provide a fix if applicable.

Blenderpics commented 3 months ago

I can confirm that the the library indeed looses connection frequently to the BE server, so you need to manually reconnect the client.

conqp commented 1 month ago

I am not sure that I understand the original issue.

The log messages you see come from the RCon server and afaik are always logged when a remote RCon command is executed. Since this is a property of DayZ's BE RCon server, there's nothing I can do about that.

Can you maybe share the full script you're using so that I may try to reproduce it (I'm running a DayZ server myself).

Blenderpics commented 1 month ago

The RCon Client basically looses connection immediately after you connected to the server. The connection isn't held up. Which means you need to perform a login for every command you want to execute. This results in the server log beeing spammed with login messages (which is not the main issue, as far as i am concerned)

The BE Client should keep the connection alive by sending the correct ACK packages.

I haven't debugged the network traffic myself, but what i understand based on @fugma313 's comment is that your client isn't working correctly. For server messages, which need to be acknowledged by sending 'B'(0x42) | 'E'(0x45) | 0x02, your client is only sending 0x02. The BE RCON specification states that server messages that are not correctly acknowledged will result in the connection beeing droped, which is what seems to be happening here.

Blenderpics commented 1 month ago

To further elaborate: A BE Client login event will trigger a Server Message that gets broadcasted to all connected clients, containing the same string that lands in the server log (RCon admin #0 (127.0.0.1:52368) logged in)

Since that message is not acknowledged correctly, the client will be disconnected quickly after it authenticated.

conqp commented 1 month ago

For server messages, which need to be acknowledged by sending 'B'(0x42) | 'E'(0x45) | 0x02, your client is only sending 0x02.

Thank you for pointing out this bug.

Can you please check, whether https://github.com/conqp/rcon/commit/f88f9dbf11a6080773debf2e58c4b28ca1eb3412 fixes this issue?

conqp commented 1 month ago

Hotfix in https://github.com/conqp/rcon/commit/41e0b6b9ff9331fe02f56fef23e320242975bc2f