I have started working on a potential TAS and was looking at using RCON to control the game. The original idea was to try to use python-valve to do that, however I have run into an handful of issues.
In a document from valve describing the protocol, they describe the multipart behavior (which python-valve implements). In summary, the way I understand this is the following:
Client sends a EXECCOMMAND and a RESPONSE_VALUE to server. The EXECCOMMAND response may be many packets (call them EC1..ECN). RESPONSE_VALUE request from client is invalid, but server in this case is expected to return two responses to it. One empty and one (call it RV1) with 4 specific bytes of content (RV2). The packets are also expected to be in order they are received.
The reason this is done, is because then, we would get the following responses in order: EC1, EC2, ..., ECN, RV1, RV2
So in multiple EXECCOMMAND are executed, we would be able to tell their output apart using the (RV1, RV2) pair as markers.
Issues I have run into:
- Factorio does not seem to implement the RESPONSE_VALUE at all, instead printing an error in its console and not responding at all. This is mentioned in other libraries found on google aimed at connecting to factorio's RCON.
- It seems to me like the commands responses are not in order: I tried to use a trick to reproduce the expected behavior with python-valve: I send the command (which may be a slow-ish lua script), then '/silent-command rcon.print("TOKEN1")' and '/silent-command rcon.print("TOKEN2")'; I then translate TOKEN1 and TOKEN2 into the RV1 and RV2, however I receive the responses in the following order: ???, RV1, RV2, EC1...