Factorio Multiplayer Protocol

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

BBBBSammich
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sun Mar 07, 2021 8:45 am
Contact:

Factorio Multiplayer Protocol

Post by BBBBSammich »

I would like to make a proxy for Factorio which serves to redirect joining players to a server which is not necessarily running. It’s expensive for me to keep a factorion server running 24/7 and it makes financial sense to only run the server when someone is playing. I have done this for Minecraft, and it worked great. I believe Minecraft’s multiplayer protocol is reverse engineered by the community https://minecraft.wiki/w/Java_Edition_protocol. But I do not have the capacity to do so for Factorio, some attempts were made in the past, but not to a significant degree. It would be great if some insight could be given to the workings of the factorion multiplayer protocol, (specifically the server joining part). I know that maintaining documentation about the full protocol is impossible because of the way the game works.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15144
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Factorio Multiplayer Protocol

Post by Rseding91 »

The Factorio server auto paused by default when no one is online, so in that sense it will use virtually no CPU. Is that not the goal?
If you want to get ahold of me I'm almost always on Discord.
Tertius
Smart Inserter
Smart Inserter
Posts: 1148
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Factorio Multiplayer Protocol

Post by Tertius »

Is it really necessary to write a whole proxy service?
What do you need to start on demand, is it just a service (the Factorio server process) or do you need to start up a whole virtual machine?

With systemd, it's possible to listen on a port (in this case the Factorio udp port) with a *.socket unit and start a *.service unit that's supposed to serve this port. So the service isn't running as default, and if systemd detects activity on the port, it starts the associated *.service unit.

This *.service doesn't need to be the factorio server service, it can be any *.sh script. I guess you're able to start your vm from within, and if it is up, add an iptables rule to forward the local udp port to the vm udp port. This is actually your proxy: a corresponding iptables NAT rule for udp traffic on the given port. Don't need to look inside the packets.
BBBBSammich
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sun Mar 07, 2021 8:45 am
Contact:

Re: Factorio Multiplayer Protocol

Post by BBBBSammich »

Yes, it does have to do with starting a virtual machine. In my country at least, it is a lot cheaper to run a virtual machine on demand rather than using a hosting service or other solutions. I have so far written a discord bot where players can send a command to start the vm, but it is more convenient for players to start the vm by trying to join the server. I am a uni student hosting a game for my class, and it worked great with minecraft. Setting up the proxy was actually easier than the discord bot, as the edge cases were actually a lot fewer. I just had to look at the active TCP connections to see if anyone was online for instance. I know it's a bit different for UDP but I believe the principles stay the same.
Post Reply

Return to “Ideas and Suggestions”