Possible to make http requests from mod?

Place to get help with not working mods / modding interface.
Post Reply
whatupdave
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Aug 12, 2015 4:24 pm
Contact:

Possible to make http requests from mod?

Post by whatupdave »

I noticed that io and http modules aren't available.

FishSandwich
Smart Inserter
Smart Inserter
Posts: 1847
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: Possible to make http requests from mod?

Post by FishSandwich »

Am curious as to why you'd want that.

GopherAtl
Fast Inserter
Fast Inserter
Posts: 177
Joined: Sat Jan 31, 2015 7:54 pm
Contact:

Re: Possible to make http requests from mod?

Post 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.
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections

whatupdave
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Aug 12, 2015 4:24 pm
Contact:

Re: Possible to make http requests from mod?

Post by whatupdave »

First guess is spot on :) Looking at ways of sharing blueprints and easy screenshot sharing.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 422
Joined: Tue May 05, 2015 6:07 pm
Contact:

Re: Possible to make http requests from mod?

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

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 950
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Possible to make http requests from mod?

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

Kalsius
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Oct 16, 2015 5:24 am
Contact:

Re: Possible to make http requests from mod?

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

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Possible to make http requests from mod?

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: Possible to make http requests from mod?

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

Kalsius
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Oct 16, 2015 5:24 am
Contact:

Re: Possible to make http requests from mod?

Post 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?

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Possible to make http requests from mod?

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 950
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Possible to make http requests from mod?

Post 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

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Possible to make http requests from mod?

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

devilwarriors
Filter Inserter
Filter Inserter
Posts: 311
Joined: Sat Jan 09, 2016 1:11 am
Contact:

Re: Possible to make http requests from mod?

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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Possible to make http requests from mod?

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

User avatar
burisk
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sun Mar 12, 2017 1:58 pm
Contact:

Re: Possible to make http requests from mod?

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

daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Possible to make http requests from mod?

Post 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.
quick links: log file | graphical issues | wiki

der-dave.com
Inserter
Inserter
Posts: 28
Joined: Sat May 07, 2016 3:57 pm
Contact:

Re: Possible to make http requests from mod?

Post by der-dave.com »

Found this via search engine:

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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Possible to make http requests from mod?

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

der-dave.com
Inserter
Inserter
Posts: 28
Joined: Sat May 07, 2016 3:57 pm
Contact:

Re: Possible to make http requests from mod?

Post by der-dave.com »

Sorry for the delay: Thank you for this :)

Post Reply

Return to “Modding help”