Low level operations in a Mod

carloslfu
New member
 
Posts: 1
Joined: Sun Feb 25, 2018 05:37
GitHub: carloslfu
IRC: carloslfu
In-game: carloslfu

Low level operations in a Mod

by carloslfu » Sun Feb 25, 2018 14:03

Hi. There is a way for performing low level operations such as fetching an url, write a file, setup an http server inside a Minetest mod?

Thanks in advance.
 

User avatar
orwell
Member
 
Posts: 694
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
In-game: orwell

Re: Low level operations in a Mod

by orwell » Wed Mar 21, 2018 21:41

Fetching an URL works via the curl HTTP API. Look into lua_api.txt how to obtain this. In every case your mod then needs to be trusted to use HTTP (added to the secure.http_mods list)
Writing to a file uses the standard Lua io library, but without the insecure environment (also needs to be explicitly enabled via secure.trusted_mods) you can only write into the world directory and read from there and the mod directory
setting up an HTTP server: why? No, there won't be a way to do this because you won't need it and it is a security issue
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
Linuxdirk
Member
 
Posts: 1600
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: Low level operations in a Mod

by Linuxdirk » Thu Mar 22, 2018 17:17

orwell wrote:setting up an HTTP server: why? No, there won't be a way to do this because you won't need it and it is a security issue

if you find a way to implement HTTP in plain Lua then it would of course work.
 

User avatar
sorcerykid
Member
 
Posts: 844
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
GitHub: sorcerykid
In-game: Nemo

Re: Low level operations in a Mod

by sorcerykid » Thu Mar 22, 2018 17:43

carloslfu wrote:Hi. There is a way for performing low level operations such as fetching an url, write a file, setup an http server inside a Minetest mod?


An HTTP server needs to be asynchronous. That would require a Lua coroutine for the socket and the I/O operations. Unless you need realtime client-server communication, you might be better off finding some way to accomplish this through IPC (such as an independent CGI-script polling a FIFO).
Last edited by sorcerykid on Thu Mar 22, 2018 17:45, edited 1 time in total.
 

User avatar
rubenwardy
Moderator
 
Posts: 5470
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Low level operations in a Mod

by rubenwardy » Thu Mar 22, 2018 17:44

Don't run a web server from Minetest, there's no need and it will cause massive performance issues. Instead run a server separately, and have Minetest poll it.

Use the HTTP API to make HTTP requests

Use the built-in Lua IO library for writing to a file, however I recommend avoiding that and using mod_storage instead

Linuxdirk wrote:
orwell wrote:setting up an HTTP server: why? No, there won't be a way to do this because you won't need it and it is a security issue

if you find a way to implement HTTP in plain Lua then it would of course work.


No, that's not how you'd do it if you needed to, which you don't
 

sofar
Developer
 
Posts: 1698
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Low level operations in a Mod

by sofar » Thu Mar 22, 2018 18:27

I could see some value in remote debugging capabilities if there was some sort of object model that could be inspected while a server was running, especially if it included the entire Lua context.

But I'd likely just link libmicrohttpd and then some really hard and complex work would have to be done to safely expose the available data over that interface. That seems not worth it, considering the vagueness of your question.
 

User avatar
Linuxdirk
Member
 
Posts: 1600
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: Low level operations in a Mod

by Linuxdirk » Fri Mar 23, 2018 09:26

rubenwardy wrote:
Linuxdirk wrote:if you find a way to implement HTTP in plain Lua then it would of course work.


No, that's not how you'd do it if you needed to, which you don't

So you know what I want for fun and entertainment? That's great. Thanks for telling me.

Not.
 

User avatar
rubenwardy
Moderator
 
Posts: 5470
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Low level operations in a Mod

by rubenwardy » Fri Mar 23, 2018 09:52

You can't write a HTTP implementation in plain Lua, as Lua doesn't support sockets. You'd need to depend on sockets at which point you might as well use a http library

Also, I said need. Not want
 

User avatar
Linuxdirk
Member
 
Posts: 1600
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: Low level operations in a Mod

by Linuxdirk » Fri Mar 23, 2018 14:40

rubenwardy wrote:You can't write a HTTP implementation in plain Lua, as Lua doesn't support sockets.

Mmmh, challenge accepted :)

Having something like an HTTP server (at least the general idea behind HTTP) inside Minetest should be easy to do using some Lua magic ad the Minetest API.
 

sofar
Developer
 
Posts: 1698
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Low level operations in a Mod

by sofar » Fri Mar 23, 2018 17:36

Linuxdirk wrote:Having something like an HTTP server (at least the general idea behind HTTP) inside Minetest should be easy to do using some Lua magic ad the Minetest API.


There is some scientific value in doing this - you can learn from it, figure out why it's not a good idea, and that on a production server it most likely will cause significant lag to players if you're trying to push any significant amount of data through it. Of course, you could push it a lot further and solve the underlying problems too and come up with a full async Lua environment that could handle this, and learn from that experience as well.

However, if you have significant amount of data that needs to be available to other processes, you're much better off storing that data in a shared storage "thing" that other processes can already access at the same time. This has been proven successful on serveral servers and this is what e.g. ITB does to calculate player scores and publish the ITB website stats.

This design is much more reliable and actually far simpler. You'd make MT more complex by attaching functionality to it that doesn't need to be in the same process space, and can safely live in a separate process. Ultimately not doing this is a better scaling approach than stuffing everything in the same process space.
 

User avatar
Linuxdirk
Member
 
Posts: 1600
Joined: Wed Sep 17, 2014 11:21
Location: Germany
In-game: Linuxdirk

Re: Low level operations in a Mod

by Linuxdirk » Fri Mar 23, 2018 17:49

sofar wrote:figure out why it's not a good idea, and that on a production server it most likely will cause significant lag to players if you're trying to push any significant amount of data through it.

It's a stupid idea trying to add an HTTP server to Minetest via mods (even adding something working like an HTTP server within Minetest would be stupid), yes. But it sounds like a fun weekend project :)
 

Byakuren
Member
 
Posts: 809
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Low level operations in a Mod

by Byakuren » Wed Apr 11, 2018 07:34

Linuxdirk wrote:
sofar wrote:figure out why it's not a good idea, and that on a production server it most likely will cause significant lag to players if you're trying to push any significant amount of data through it.

It's a stupid idea trying to add an HTTP server to Minetest via mods (even adding something working like an HTTP server within Minetest would be stupid), yes. But it sounds like a fun weekend project :)

Did you ever get around to trying this out?
Every time a mod API is left undocumented, a koala dies.
 


Return to Modding Discussion



Who is online

Users browsing this forum: texmex and 1 guest