How to trust mod

diabolusUmarov
Member
 
Posts: 121
Joined: Sat Jun 24, 2017 14:27
In-game: diabolusUmarov

How to trust mod

by diabolusUmarov » Mon Feb 26, 2018 18:08

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?
Last edited by diabolusUmarov on Mon Feb 26, 2018 18:50, edited 1 time in total.
 

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

Re: How to trust mod

by sofar » Mon Feb 26, 2018 18:39

What is the error message that minetest generates?
 

diabolusUmarov
Member
 
Posts: 121
Joined: Sat Jun 24, 2017 14:27
In-game: diabolusUmarov

Re: How to trust mod

by diabolusUmarov » Mon Feb 26, 2018 18:52

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
 

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

Re: How to trust mod

by rubenwardy » Mon Feb 26, 2018 18:56

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.
 

diabolusUmarov
Member
 
Posts: 121
Joined: Sat Jun 24, 2017 14:27
In-game: diabolusUmarov

Re: How to trust mod

by diabolusUmarov » Mon Feb 26, 2018 19:05

I dont want to write in a world file. The file should place in a directory out of world/mod
 

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

Re: How to trust mod

by rubenwardy » Mon Feb 26, 2018 20:25

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
 

diabolusUmarov
Member
 
Posts: 121
Joined: Sat Jun 24, 2017 14:27
In-game: diabolusUmarov

Re: How to trust mod

by diabolusUmarov » Mon Feb 26, 2018 20:55

But I want to show the players online on the blog and so I need the file in the html directory.
 

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

Re: How to trust mod

by sofar » Wed Feb 28, 2018 04:25

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.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 2 guests