Page 1 of 1

Possible to make http requests from mod?

Posted: Wed Aug 12, 2015 4:27 pm
by whatupdave
I noticed that io and http modules aren't available.

Re: Possible to make http requests from mod?

Posted: Wed Aug 12, 2015 4:39 pm
by FishSandwich
Am curious as to why you'd want that.

Re: Possible to make http requests from mod?

Posted: Wed Aug 12, 2015 4:55 pm
by GopherAtl
first obvious guess (for me): web service for sharing blueprints in-game?

Next guess (because people always make these, though I don't understand the appeal): inter-game chat/messaging system.

in any case, given the game's system of keeping peers entirely in sync, I don't see this being made available, certainly not outside of single-player games.

Re: Possible to make http requests from mod?

Posted: Wed Aug 12, 2015 9:08 pm
by whatupdave
First guess is spot on :) Looking at ways of sharing blueprints and easy screenshot sharing.

Re: Possible to make http requests from mod?

Posted: Fri Aug 14, 2015 2:50 pm
by Afforess
whatupdave wrote:I noticed that io and http modules aren't available.
Pretty sure this is intentional, so mods can not read your files, and send any passwords or documents off over the web.

Re: Possible to make http requests from mod?

Posted: Fri Aug 14, 2015 3:16 pm
by ratchetfreak
Afforess wrote:
whatupdave wrote:I noticed that io and http modules aren't available.
Pretty sure this is intentional, so mods can not read your files, and send any passwords or documents off over the web.
it's more so that different clients can't desync.

Re: Possible to make http requests from mod?

Posted: Thu Oct 22, 2015 8:50 pm
by Kalsius
Sorry to necro a thread but it is directly relevant.

I am also wondering if an interface can be provided for basic GET/POST interactivity. I started on a mod which would allow multiple players to contribute to a goal which could be tracked on a website. Simple information on # resources sent to the 'project' would be the main aim with some level of additional security information included. I am guessing the devs are baking in relevant .dlls into the .exe to allow the running of lua and therefore have excluded (the security point is a very good one) certain aspects of lua ( and extensions such as luasocket ) for various reasons.

Very open to a discussion on this one.

Re: Possible to make http requests from mod?

Posted: Thu Oct 22, 2015 9:40 pm
by prg
Kalsius wrote:Sorry to necro a thread but it is directly relevant.

I am also wondering if an interface can be provided for basic GET/POST interactivity. I started on a mod which would allow multiple players to contribute to a goal which could be tracked on a website. Simple information on # resources sent to the 'project' would be the main aim with some level of additional security information included. I am guessing the devs are baking in relevant .dlls into the .exe to allow the running of lua and therefore have excluded (the security point is a very good one) certain aspects of lua ( and extensions such as luasocket ) for various reasons.

Very open to a discussion on this one.
If you just want to get information out of Factorio, you can use game.write_file(path, data[, append]) to write it to a file, then write a program to watch that file for changes and post those to some website.

Re: Possible to make http requests from mod?

Posted: Fri Oct 23, 2015 12:26 am
by Zeblote
prg wrote:If you just want to get information out of Factorio, you can use game.write_file(path, data[, append]) to write it to a file, then write a program to watch that file for changes and post those to some website.
Note that this API is very suboptimal and will actually write a file on every client in a server.

Re: Possible to make http requests from mod?

Posted: Fri Oct 23, 2015 6:35 am
by Kalsius
prg wrote:.....

If you just want to get information out of Factorio, you can use game.write_file(path, data[, append]) to write it to a file, then write a program to watch that file for changes and post those to some website.
This was plan B. I can keep the data collection local within the mod and then use some interface functions to then export the data. File write is a suboptimal solution but means that if we get some level of io/http interface I can just write a different interface and not have to mess with the core mod so much.
Zeblote wrote:Note that this API is very suboptimal and will actually write a file on every client in a server.
This is slight issue. Ideally i just want the server to create/manage an output log file which i can write a lightweight export program for which uses the web service specification i will define. One minor advantage is that anyone could write this piece of the solution given the appropriate specifcations.

I would prefer to go direct from the mod however as it would be cleaner and easier to deploy/manage without a secondary component.

Do devs monitor these threads?

Re: Possible to make http requests from mod?

Posted: Fri Oct 23, 2015 9:25 am
by prg
Yeah I don't think there's currently an elegant solution for this. If someone doesn't want the file to be written, they can just symlink it to /dev/null or whatever the Windows equivalent is. Another possibility that would avoid intermediary files would be to write things to stdout, then pipe that to a program looking for lines matching a certain regex. No one else would notice since no one is running the game in a terminal and this doesn't go into the log file. But yes, this is kinda ugly of course.

Devs read at least the Modding interface requests forum, you might want to try there.

Re: Possible to make http requests from mod?

Posted: Fri Oct 23, 2015 9:46 am
by ratchetfreak
prg wrote:Yeah I don't think there's currently an elegant solution for this. If someone doesn't want the file to be written, they can just symlink it to /dev/null or whatever the Windows equivalent is. Another possibility that would avoid intermediary files would be to write things to stdout, then pipe that to a program looking for lines matching a certain regex. No one else would notice since no one is running the game in a terminal and this doesn't go into the log file. But yes, this is kinda ugly of course.

Devs read at least the Modding interface requests forum, you might want to try there.
Forcing people to create symlinks to avoid garbage being written is not a good idea

Re: Possible to make http requests from mod?

Posted: Fri Oct 23, 2015 10:19 am
by prg
ratchetfreak wrote:Forcing people to create symlinks to avoid garbage being written is not a good idea
Yeah, no shit. Hence "I don't think there's currently an elegant solution for this." Besides no one is forced to create such a symlink. "If someone doesn't want the file to be written" would require people to care about it. If the log only contains "$player contributed $amount $resource" I guess it could grow to a couple kilobytes after a while, maybe even hundreds of kilobytes. A reasonable strategy for dealing with that would be to just ignore it.

I'm not saying this is a great way of doing things, just a way of making this work right now.

Re: Possible to make http requests from mod?

Posted: Fri Jan 29, 2016 7:57 am
by devilwarriors
This mod manager is supposedly capable of loading mods in a multiplayer game without restarting -> https://forums.factorio.com/forum/vie ... 37&t=19454

couldn't the same thing they do be used, the mod create a text file, the server read it and delete it, then it create a new mod folder with the information it want to send back to the mod in-game and inject that mod into the running game.

it's a very horrible solution but you could make a blueprint manager that will refresh for everyone on the server when a new blueprint is added by someone, or something like that.

Re: Possible to make http requests from mod?

Posted: Fri Jan 29, 2016 8:17 am
by DaveMcW
devilwarriors wrote:mod manager is supposedly capable of loading mods in a multiplayer game without restarting
Nope. You must save/reload to change mods.

Re: Possible to make http requests from mod?

Posted: Fri Mar 17, 2017 11:28 am
by burisk
I noticed that this is old thread. Is there any news about posibility to make http/https requests from server mod? I want to make web statistics and so other a lot of things but this stops me.. and no, I don't want to write to file and watch them.. That's perverse. :D Or at least support for SQL/NoSQL drivers (redis pubsub/sqlite/mysql) only on server of course.

Re: Possible to make http requests from mod?

Posted: Fri Mar 17, 2017 12:24 pm
by daniel34
burisk wrote:I noticed that this is old thread. Is there any news about posibility to make http/https requests from server mod? Or at least support for SQL/NoSQL drivers (redis pubsub/sqlite/mysql) only on server of course.
No, no change. I also don't think anything in that direction is planned.
Zeblote wrote:
prg wrote:If you just want to get information out of Factorio, you can use game.write_file(path, data[, append]) to write it to a file, then write a program to watch that file for changes and post those to some website.
Note that this API is very suboptimal and will actually write a file on every client in a server.
For those using this function, game.write_file now has a for_player parameter where you can limit the file write to a single player or the server.

Re: Possible to make http requests from mod?

Posted: Tue Oct 09, 2018 7:55 pm
by der-dave.com
Found this via search engine:

Are there any updated/new plans to support SQL or HTTP?

Re: Possible to make http requests from mod?

Posted: Tue Oct 09, 2018 7:57 pm
by DaveMcW
No. But the headless server now supports console input, so you can write an external program to do it for you. See https://github.com/Bisa/factorio-init for an easy way to send console commands.

Re: Possible to make http requests from mod?

Posted: Thu Nov 08, 2018 10:31 am
by der-dave.com
Sorry for the delay: Thank you for this :)