diff --git a/README.md b/README.md index bbecc89..b7954a9 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,9 @@ Raspberry Jam Mod for Minetest Implements most of Raspberry PI Minecraft API in Minetest. -Currently requires mod security to be turned off. +If you have secure.enable_security = true in minetest.conf, then make sure you have raspberryjammod +listed under secure.trusted_mods. Raspberry Jam Mod cannot be rewritten without needing to be trusted, +because of the following essential features: + - loading tcp/ip socket dynamic library + - executing and terminating python interpreter with /py command. + \ No newline at end of file diff --git a/raspberryjammod/LICENSE b/raspberryjammod/LICENSE index 6def647..57669cb 100644 --- a/raspberryjammod/LICENSE +++ b/raspberryjammod/LICENSE @@ -2,9 +2,9 @@ The MIT License (MIT) RaspberryJamMod Copyright (c) 2015 Alexander R. Pruss Lua Copyright (c) 1994–2015 Lua.org, PUC-Rio. -luasocket Copyright (c) Diego Nehab (with socket.lua changed by ARP to load x64/x86 as needed) -tools.lua adapted from lua-websockets Copyright (c) 2012 Gerhard Lipp (with base64 inactivated) -base64.lua Copyright (c) 2014 Mark Rogaski and (C) 2012 Paul Moore (changed by ARP to MIME encoding) +luasocket Copyright (c) Diego Nehab (with socket.lua changed by ARP to load x64/x86 as needed, and minetest compatibility) +tools.lua adapted from lua-websockets Copyright (c) 2012 Gerhard Lipp (with base64 inactivated and minetest compatibility) +base64.lua Copyright (c) 2014 Mark Rogaski and (C) 2012 Paul Moore (changed by ARP to MIME encoding and minetest compatibility) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/raspberryjammod/base64.lua b/raspberryjammod/base64.lua index 56fcbaf..e473ce8 100644 --- a/raspberryjammod/base64.lua +++ b/raspberryjammod/base64.lua @@ -1,3 +1,8 @@ +if minetest.request_insecure_environment then + ie = minetest.request_insecure_environment() +else + ie = _G +end --[[-------------------------------------------------------------------------- The MIT License (MIT) @@ -53,7 +58,7 @@ local Base64 = {} -- Imports ---------------------------------------------------------------------------- -require("bit") +bit = ie.require("bit") local band, bor, lshift, rshift = bit.band, bit.bor, bit.lshift, bit.rshift diff --git a/raspberryjammod/init.lua b/raspberryjammod/init.lua index 38062a1..838d522 100644 --- a/raspberryjammod/init.lua +++ b/raspberryjammod/init.lua @@ -3,10 +3,19 @@ -- Note: The x-coordinate is reversed in sign between minetest and minecraft, -- and the API compensates for this. -local source = debug.getinfo(1).source:sub(2) +if minetest.request_insecure_environment then + ie = minetest.request_insecure_environment() +else + ie = _G +end + +print(ie.package) +print(ie.package.path) + +local source = ie.debug.getinfo(1).source:sub(2) -- Detect windows via backslashes in paths local mypath = minetest.get_modpath(minetest.get_current_modname()) -local is_windows = (nil ~= string.find(package.path..package.cpath..source..mypath, "%\\%?")) +local is_windows = (nil ~= string.find(ie.package.path..ie.package.cpath..source..mypath, "%\\%?")) local path_separator if is_windows then path_separator = "\\" @@ -17,15 +26,15 @@ mypath = mypath .. path_separator local script_window_id = "minetest-rjm-python-script" -package.path = package.path .. ";" .. mypath .. "?.lua" +ie.package.path = ie.package.path .. ";" .. mypath .. "?.lua" if is_windows then - package.cpath = package.cpath .. ";" .. mypath .. "?.dll" + ie.package.cpath = ie.package.cpath .. ";" .. mypath .. "?.dll" else - package.cpath = package.cpath .. ";" .. mypath .. "?.so" + ie.package.cpath = ie.package.cpath .. ";" .. mypath .. "?.so" end -local block = require("block") -local socket = require("socket") +local block = ie.require("block") +local socket = ie.require("socket") local block_hits = {} local chat_record = {} @@ -38,7 +47,7 @@ max_player_id = 0 default_player_id = -1 world_immutable = false -local settings = Settings(mypath .. path_separator .. "settings.conf") +local settings = Settings(mypath .. "settings.conf") local update_settings = false python_interpreter = settings:get("python") if python_interpreter == nil then @@ -75,8 +84,8 @@ server:settimeout(0) local ws_server = nil if ws then - tools = require("tools") - base64 = require("base64") + tools = ie.require("tools") + base64 = ie.require("base64") ws_server = socket.bind(remote_address, 14711) ws_server:setoption('tcp-nodelay',true) ws_server:settimeout(0) @@ -491,13 +500,13 @@ function background_launch(window_identifier, cmd) if not is_windows then return false end local cmdline = 'start "' .. window_identifier .. '" /MIN ' .. cmd minetest.log("action", "launching ["..cmdline.."]") - os.execute(cmdline) + ie.os.execute(cmdline) end function kill(window_identifier) -- TODO: non-Windows minetest.log('taskkill /F /FI "WINDOWTITLE eq ' .. window_identifier .. '"') - os.execute('taskkill /F /FI "WINDOWTITLE eq ' .. window_identifier .. '"') + ie.os.execute('taskkill /F /FI "WINDOWTITLE eq ' .. window_identifier .. '"') end function safe_handle_command(source,line) diff --git a/raspberryjammod/socket.lua b/raspberryjammod/socket.lua index cc2f827..dcdae92 100644 --- a/raspberryjammod/socket.lua +++ b/raspberryjammod/socket.lua @@ -1,3 +1,8 @@ +if minetest.request_insecure_environment then + ie = minetest.request_insecure_environment() +else + ie = _G +end ----------------------------------------------------------------------------- -- LuaSocket helper module -- Author: Diego Nehab @@ -8,15 +13,15 @@ -- Declare module and import dependencies ----------------------------------------------------------------------------- local base = _G -local string = require("string") -local math = require("math") +local string = ie.require("string") +local math = ie.require("math") local socket -local status,err = pcall(function() socket = require("socket.core") end) +local status,err = pcall(function() socket = ie.require("socket.core") end) if not status then - socket = require("socket.cx64") + socket = ie.require("socket.cx64") end -module("socket") +ie.module("socket") ----------------------------------------------------------------------------- -- Exported auxiliar functions diff --git a/raspberryjammod/tools.lua b/raspberryjammod/tools.lua index f3aebc2..0631232 100644 --- a/raspberryjammod/tools.lua +++ b/raspberryjammod/tools.lua @@ -1,4 +1,10 @@ -local bit = require 'bit' +if minetest.request_insecure_environment then + ie = minetest.request_insecure_environment() +else + ie = _G +end + +local bit = ie.require 'bit' local rol = bit.rol local bxor = bit.bxor local bor = bit.bor