Page 1 of 1

How to trust mod

PostPosted: Mon Feb 26, 2018 18:08
by diabolusUmarov
Hi!

I try to write a simple mod to show the online-player on my blog. The mod isnt the problem but I should save in a specific drawer.

The mod is in the secure.trusted_mods and this is the code:

Code: Select all
minetest.register_on_joinplayer(function(player)
      
   local ie = _G minetest.request_insecure_environment()

   online[player:get_player_name()] = player:get_player_name()

   local onlineString = minetest.serialize(online)
   
   if ie then
      local input = ie.io.open("online.txt", "w")
      input:write(onlineString)
      input:close()
   else
      minetest.chat_send_all("Fehler")
   end
   
end)



Whats wrong?

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 18:39
by sofar
What is the error message that minetest generates?

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 18:52
by diabolusUmarov
Code: Select all
2018-02-26 19:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Mod security: Blocked attempted write to online.txt


This is the error

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 18:56
by rubenwardy
That's the wrong place to request an insecure environment, and that's also the wrong way to reference a file - you're missing minetest.get_worldpath()

You don't need an ie to write to a world file.

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 19:05
by diabolusUmarov
I dont want to write in a world file. The file should place in a directory out of world/mod

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 20:25
by rubenwardy
Where though? You can't reliably depend on where the working directory of Minetest is. It's much better practice to just write to the world dir

Re: How to trust mod

PostPosted: Mon Feb 26, 2018 20:55
by diabolusUmarov
But I want to show the players online on the blog and so I need the file in the html directory.

Re: How to trust mod

PostPosted: Wed Feb 28, 2018 04:25
by sofar
diabolusUmarov wrote:But I want to show the players online on the blog and so I need the file in the html directory.


You can solve that by e.g. symlinking the file from the world folder to the right location in your webroot, and configuring your web server to read the symlink properly. Or just regularly copy the file periodically. Or using a server redirect to redirect the file content to the one in the world folder....

Writing outside the world folder isn't a good reason to disable the secure mods checks, so you should avoid it and consider some of the alternatives I've listed above.