How to trust mod

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

How to trust mod

by diabolusUmarov » Post

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: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to trust mod

by sofar » Post

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

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: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How to trust mod

by rubenwardy » Post

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.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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

Re: How to trust mod

by diabolusUmarov » Post

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: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How to trust mod

by rubenwardy » Post

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
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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

Re: How to trust mod

by diabolusUmarov » Post

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

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

Re: How to trust mod

by sofar » Post

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests