Initial commit
This commit is contained in:
commit
0f27dc05f4
12 changed files with 6681 additions and 0 deletions
49
init.lua
Normal file
49
init.lua
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
local http = minetest.request_http_api()
|
||||
if http == nil then
|
||||
error("Please add g1_bridge to secure.http_mods")
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("g1", {
|
||||
func = function(name, param)
|
||||
local args = {}
|
||||
for arg in string.gmatch(param,"%S+") do
|
||||
if #args >= 3 then
|
||||
break
|
||||
end
|
||||
table.insert(args, arg)
|
||||
end
|
||||
if #args >= 1 then
|
||||
core.chat_send_player(name, "args >= 1")
|
||||
if args[1] == "send" and #args == 3 and string.find(args[2],"^[%da-zA-Z]+$") and string.find(args[3],"^%d+$") then
|
||||
local address = args[2]
|
||||
local amount = tonumber(args[3])
|
||||
-- This version Lua does not have any way to check if a number is represented as an integer or a float,
|
||||
-- because it explicitely doesn't care.
|
||||
-- Hence, this program won't care if the player writes an invalid number,
|
||||
-- as there is no need to ensure arithmetic rules are respected. (as Lua's manual pretends)
|
||||
-- As the pattern excludes "." and nobody should have billions of items,
|
||||
-- it should still be safe. I hope.
|
||||
if type(amount) ~= "number" then
|
||||
return
|
||||
end
|
||||
local inv = core.get_inventory({type="player", name=name})
|
||||
local wanted_stack = "currency:minegeld "..amount
|
||||
local balanced = inv:contains_item("main", ItemStack(wanted_stack))
|
||||
if balanced then
|
||||
inv:remove_item("main", wanted_stack)
|
||||
http.fetch({url="http://127.0.0.1:30061/send/"..address.."/"..amount, method="GET"},
|
||||
function(res)
|
||||
if res.code == 200 then
|
||||
core.chat_send_player(name, "Transfer sent")
|
||||
else
|
||||
core.chat_send_player(name, "Error during transfer")
|
||||
end
|
||||
end
|
||||
)
|
||||
else
|
||||
core.chat_send_player(name, "Not enough currency")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue