Server Status API

Place to get help with not working mods / modding interface.
Parakoopa
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 01, 2016 12:07 pm
Contact:

Server Status API

Post 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
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Server Status API

Post 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.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Server Status API

Post 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.
quick links: log file | graphical issues | wiki
Parakoopa
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 01, 2016 12:07 pm
Contact:

Re: Server Status API

Post 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.
Post Reply

Return to “Modding help”