conqp / rcon

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

Session Always timing out #25

Closed thejcpalma closed 7 months ago

thejcpalma commented 7 months ago

Description

I'm trying to implement this module in my code but I'm always getting session timeout, on every machine I tested, even when the server is on the same network.

Tried the rcon-cli and it works, and other rcon tools as well from the machines tested.

Code

from rcon.source import Client

with Client('server.address', 5000, passwd='secret') as client:
    response = client.run('command')

print(response)

Expected Behavior

Server response

Actual Behavior

    ...
    raise SessionTimeout()
rcon.exceptions.SessionTimeout

Steps to Reproduce the Problem

  1. Install module -> pip install rcon:2.4.4
  2. Create simple python file with the code above
  3. Run file

Specifications

conqp commented 7 months ago

What kind of rcon Server is running at server.address:5000?

thejcpalma commented 7 months ago

What kind of rcon Server is running at server.address:5000? Palworld server by jammsen but also tested with cs2 official server and same error

conqp commented 7 months ago

And you are absolutely certain that there's a Source RCON Server running on that port, which is also opened in a possible firewall?

thejcpalma commented 7 months ago

And you are absolutely certain that there's a Source RCON Server running on that port, which is also opened in a possible firewall?

Yes, tested using both rcon-cli, this website, and another rcon tool. Right now I'm using this package py-rcon as a filler but i would want your preferably

conqp commented 7 months ago

Instead of 2.4.4 could you try the latest commit in this repo? Does it work for you? Is the server response possibly quite large?

thejcpalma commented 7 months ago

Instead of 2.4.4 could you try the latest commit in this repo? Does it work for you? Is the server response possibly quite large?

As soon as I get home I'll test it.

Server response is a 30 char string average for the info of the server so doesn't seem that large of a payload.

liamsmith86 commented 7 months ago

I have the same issue also attempting rcon to palworld server with the latest commit. I used telnet to verify connection could be established to the ip/port.

I installed git+https://github.com/conqp/rcon.git@cc40e9c1bcb936c4ea52325aa23de857f142bd34 with pip

Strace of python script attempting to connect

socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 6
ioctl(6, FIONBIO, [1])                  = 0
connect(6, {sa_family=AF_INET, sin_port=htons(25575), sin_addr=inet_addr("192.168.50.111")}, 16) = -1 EINPROGRESS (Operation now in progress)
epoll_ctl(3, EPOLL_CTL_ADD, 6, {events=EPOLLOUT, data={u32=6, u64=140054588555270}}) = 0
epoll_wait(3, [{events=EPOLLOUT, data={u32=6, u64=140054588555270}}], 2, -1) = 1
getsockopt(6, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
epoll_wait(3, [{events=EPOLLOUT, data={u32=6, u64=140054588555270}}], 2, 0) = 1
epoll_ctl(3, EPOLL_CTL_DEL, 6, 0x7ffff4766e34) = 0
ioctl(6, FIONBIO, [1])                  = 0
getsockname(6, {sa_family=AF_INET, sin_port=htons(45192), sin_addr=inet_addr("ip_redacted")}, [16]) = 0
getpeername(6, {sa_family=AF_INET, sin_port=htons(25575), sin_addr=inet_addr("ip_redacted")}, [16]) = 0
setsockopt(6, SOL_TCP, TCP_NODELAY, [1], 4) = 0
epoll_wait(3, [], 1, 0)                 = 0
epoll_ctl(3, EPOLL_CTL_ADD, 6, {events=EPOLLIN, data={u32=6, u64=140054588555270}}) = 0
epoll_wait(3, [], 2, 0)                 = 0
sendto(6, "\27\0\0\0\316\357\3329\3\0\0\0password_redacted\0\0", 27, 0, NULL, 0) = 27
epoll_wait(3,
conqp commented 7 months ago

Since this seems to be an issue only with Palworld, I suspect that the issue lies with the server's RCON implementation: https://github.com/jammsen/docker-palworld-dedicated-server/issues/77 I currently do not own a copy of Palworld, so I cannot investigate this further. I'd be happy to receive patches, though, if you decide to debug this yourselves.

@liamsmith86 This shows, that the client is waiting for a response from the server, which it is not receiving.

thejcpalma commented 7 months ago

Same issue as @liamsmith86 .

The strange thing is it working with other rcon utilities/modules, ence I don't think it is an issue with the server's RCON implementation.

Can't guarantee I'll look further into this to patch it but if someone need help debugging I'll gladly help.

fossum commented 7 months ago

I ran into the same issue. The problem is the ID on the response is zero for everything I've seen except login. Just tested with rcon==2.4.4 and in run when it checks ID, this is my packet.

print(response) Packet(id=0, type=<Type.SERVERDATA_RESPONSE_VALUE: 0>, payload=b'Welcome to Pal Server[v0.1.3.0] Venture Pals\n', terminator=b'\x00\x00')

I'd like to put up a PR to allow ignoring ID for servers not following spec.

fossum commented 7 months ago

With PR, this is the output with enforcement off/on.

PS C:\development\rcon_tem
p>  c:; cd 'c:\development\rcon_temp'; & 'c:\Users\fossu\.virtualenvs\rcon_temp-qP-3rIEP\Scripts\python.exe' 'c:\Users\fossu\.vscode\extensions\ms-python.debugpy-2023.3.13341008-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '55575' '--' 'C:\development\rcon_temp\temp.py' 
Welcome to Pal Server[v0.1.3.0] Venture Pals

PS C:\development\rcon_temp>  c:; cd 'c:\development\rcon_temp'; & 'c:\Users\fossu\.virtualenvs\rcon_temp-qP-3rIEP\Scripts\python.exe' 'c:\Users\fossu\.vscode\extensions\ms-python.debugpy-2023.3.13341008-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '55587' '--' 'C:\development\rcon_temp\temp.py' 
Traceback (most recent call last):
  File "C:\development\rcon_temp\temp.py", line 15, in <module>
    print(client.run('info', enforce_id=True))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\development\github\rcon\rcon\source\client.py", line 73, in run
    raise SessionTimeout("packet ID mismatch")
rcon.exceptions.SessionTimeout: packet ID mismatch
conqp commented 7 months ago

Fixed in https://github.com/conqp/rcon/commit/c38431171a502370ccf8c447c7ecbfe807384d71 Thanks to @fossum

BonkaBonka commented 7 months ago

Hey, I see that this is part of v2.4.6 - any chance you could push that version out to PyPi? It thinks 2.4.4 is still the latest. Thanks!

conqp commented 7 months ago

Done. Sorry it took so long. I had to deal with the new 2FA and the new token authentication.

BonkaBonka commented 7 months ago

Thank you so much!