Page 1 of 1

Server Status API

Posted: Sun May 01, 2016 12:14 pm
by Parakoopa
Hi everyone! I really love Factorio and I have already played around with making my own little mods.

What I need now is some kind of way to get data from my server like, how many players are connected. For this I would need Factorio to write it's server status to a file or send it to a server, or anything like that.

While I think that might be possible with the mods, I know that there is no way to have server-only mods, but I don't want my players to download a server status mod that is completely useless to them.

Is there any way of modding the dedicated server in a way that I can get status information from it? Or does something like this already exist? Any help is appreciated. :D

Re: Server Status API

Posted: Sun May 01, 2016 6:18 pm
by Adil
There are cryptic mentions from dev team about server utilities coming with june the 1st.
There already is log file which among other things contains records of players connecting and disconnecting. (factorio-current.log)
There are vague promises of making mod download for multiplayer easier. Nowadays it's customary for host to provide zip of mods used on server anyway. Though the main problem with service mods is that every output mechanism, be it print() or game.write_file() is performed on all instances of factorio.

Re: Server Status API

Posted: Sun May 01, 2016 8:58 pm
by daniel34
Parakoopa wrote:While I think that might be possible with the mods, I know that there is no way to have server-only mods, but I don't want my players to download a server status mod that is completely useless to them.
There is a way to have semi-server-only mods.
You can take any mod that only uses a control.lua or files called from it (any mod that doesn't add new entities/items/technologies) and put the contents into the savegame's control.lua.
I've used this to provide a player color gui on my servers without requiring the clients to install any mods.

So you could write a mod that writes a file with map/server statistics to the disk every few seconds and use your own tools to periodically read this file.
If you place it in control.lua of the savegame it will be called by all peers, but they won't notice that.

I've actually written a ban-vote-script using that method. It creates a new ban-vote GUI in Factorio where people can vote to ban someone, 2 or more (depending on the player-count) votes are required.
If the votecount for one player is reached a file is written to script-output, where an external tool is listening and adding the exclusion to the iptables firewall --> player is dropped.
That being said, I only tested it small scale (headless server with 2/3 clients on LAN, it worked) but never actually used it online because I thought about it more and came to the conclusion that there's always the possibility of a griefer connecting twice and banning everybody else / changing his IP...

Another reason is that with 0.13 there will be (AFAIK) verification of clients (do they actually own the game) and the possibility to whitelist/ban clients. Or something along those lines.

Re: Server Status API

Posted: Mon May 02, 2016 2:00 pm
by Parakoopa
daniel34 wrote: You can take any mod that only uses a control.lua or files called from it (any mod that doesn't add new entities/items/technologies) and put the contents into the savegame's control.lua.
I've used this to provide a player color gui on my servers without requiring the clients to install any mods.
Wow thanks! That's a great workaround actually. So far I was using logparsing but I thought a lua script would provide more functionality.