mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-06-28 14:16:06 +02:00
Updated ROFL and SQLextract: Ready for first attempt
This commit is contained in:
@ -1,13 +1,11 @@
|
||||
----------------------------
|
||||
-- Rollbacks Out of FiLes.
|
||||
--------------------------------------
|
||||
-- Rollbacks, go Out of those FiLes!
|
||||
-- ROFL
|
||||
--
|
||||
|
||||
rofl = {}
|
||||
rofl.func = {}
|
||||
rofl.datas = {}
|
||||
rofl.datas.filepath = minetest.get_worldpath() .. "/rollback/"
|
||||
rofl.queue = {}
|
||||
local filepath = minetest.get_worldpath() .. "/rollback/"
|
||||
local patchsegs = 0
|
||||
local patchtotp = 100
|
||||
|
||||
local function none(v)
|
||||
if not v or v == "None" then
|
||||
@ -17,26 +15,63 @@ local function none(v)
|
||||
end
|
||||
end
|
||||
|
||||
local function metaread(v)
|
||||
|
||||
--[[
|
||||
|
||||
Eg. : channel-in="keyboard",channel-out="terminal",formspec="field[text;;${command}]"
|
||||
|
||||
]]
|
||||
|
||||
if not v or v == "None" or v == "[]" then return nil end
|
||||
v = string.sub(v,2,string.len(v)-1)
|
||||
-- Meta extraction
|
||||
local cursor = 0
|
||||
local metas = {}
|
||||
while cursor <= string.len(v) do
|
||||
local key, value
|
||||
local keybeg, keyend, valbeg, valend = cursor, cursor, cursor, cursor
|
||||
|
||||
keyend = string.find(v, "=\"", cursor)-1
|
||||
key = string.sub(v,keybeg,keyend)
|
||||
|
||||
valbeg = keyend+3
|
||||
valend = (string.find(v, "\",", valbeg) or string.len(v))-1
|
||||
value = string.sub(v,valbeg,valend)
|
||||
|
||||
cursor = valend+3
|
||||
metas[key] = value
|
||||
end
|
||||
return metas
|
||||
end
|
||||
|
||||
local function parser(fields)
|
||||
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("rofl", {
|
||||
description = "Save MFF",
|
||||
privs = {server = true},
|
||||
func = function(name)
|
||||
func = function(name, param)
|
||||
-- Alert
|
||||
minetest.chat_send_all("*** Server Freezing")
|
||||
|
||||
-- The main loop
|
||||
local i = 0
|
||||
if tonumber(param) then
|
||||
i = tonumber(param)
|
||||
end
|
||||
local vm = minetest.get_voxel_manip()
|
||||
while true do
|
||||
local file = io.open(rofl.datas.filepath .. "/database-output." .. i .. ".txt", "r")
|
||||
local file = io.open(filepath .. "/database-output." .. i .. ".txt", "r")
|
||||
if not file then
|
||||
break
|
||||
end
|
||||
minetest.log("action", "[ROFL] Opened file database-output." .. i .. ".txt ... Extracting datas")
|
||||
-- [
|
||||
-- id=155,actor=Mg,type=1;
|
||||
-- list=None,index=None,add=None,stacknode=None,stackquantity=None,nodemeta=None;
|
||||
-- x=-18,y=29,z=31;
|
||||
-- oldnode=default:stonebrick,oldparam1=0,oldparam2=None,oldmeta=None;
|
||||
-- newnode=air,newparam1=13,newparam2=None,newmeta=None
|
||||
-- ]
|
||||
for fields in file:lines() do
|
||||
@ -48,23 +83,22 @@ minetest.register_chatcommand("rofl", {
|
||||
local index = none(tonumber(string.sub(fields, string.find(fields, "index=")+string.len("index="), string.find(fields, ",add")-1)))
|
||||
local add = none(tonumber(string.sub(fields, string.find(fields, "add=")+string.len("add="), string.find(fields, ",stacknode")-1)))
|
||||
local stacknode = none(string.sub(fields, string.find(fields, "stacknode=")+string.len("stacknode="), string.find(fields, ",stackquantity")-1))
|
||||
local stackquantity = none(tonumber(string.sub(fields, string.find(fields, "stackquantity=")+string.len("stackquantity="), string.find(fields, ",nodemeta")-1)))
|
||||
local nodemeta = none(string.sub(fields, string.find(fields, "nodemeta=")+string.len("nodemeta="), string.find(fields, ";x=")-1))
|
||||
local stackquantity = none(tonumber(string.sub(fields, string.find(fields, "stackquantity=")+string.len("stackquantity="), string.find(fields, ";x=")-1)))
|
||||
|
||||
local x = none(tonumber(string.sub(fields, string.find(fields, ";x=")+string.len(";x="), string.find(fields, ",y=")-1)))
|
||||
local y = none(tonumber(string.sub(fields, string.find(fields, ",y=")+string.len(",y="), string.find(fields, ",z=")-1)))
|
||||
local z = none(tonumber(string.sub(fields, string.find(fields, ",z=")+string.len(",z="), string.find(fields, ";oldnode=")-1)))
|
||||
|
||||
local oldnode = none(string.sub(fields, string.find(fields, "oldnode=")+string.len("oldnode="), string.find(fields, ",oldparam1")-1))
|
||||
local oldparam1 = none(tonumber(string.sub(fields, string.find(fields, "oldparam1=")+string.len("oldparam1="), string.find(fields, ",oldparam2")-1)))
|
||||
local oldparam2 = none(tonumber(string.sub(fields, string.find(fields, "oldparam2=")+string.len("oldparam2="), string.find(fields, ",oldmeta=")-1)))
|
||||
--local oldmeta
|
||||
local z = none(tonumber(string.sub(fields, string.find(fields, ",z=")+string.len(",z="), string.find(fields, ";newnode=")-1)))
|
||||
|
||||
local newnode = none(string.sub(fields, string.find(fields, "newnode=")+string.len("newnode="), string.find(fields, ",newparam1")-1))
|
||||
local newparam1 = none(tonumber(string.sub(fields, string.find(fields, "newparam1=")+string.len("newparam1="), string.find(fields, ",newparam2")-1)))
|
||||
local newparam2 = none(tonumber(string.sub(fields, string.find(fields, "newparam2=")+string.len("newparam2="), string.find(fields, ",newmeta=")-1)))
|
||||
--local newmeta
|
||||
local newmeta = none(metaread(string.sub(fields, string.find(fields, ",newmeta=")+string.len(",newmeta="), string.len(fields)-1)))
|
||||
|
||||
minetest.log("action","[ROFL] Applying id = " .. id)
|
||||
if patchsegs % patchtotp == 0 then
|
||||
minetest.get_player_by_name(name):setpos({x = x, y = y, z = z})
|
||||
patchsegs = 0
|
||||
end
|
||||
if action_type == 1 then -- TYPE_SETNODE
|
||||
local forced = minetest.forceload_block({x = x, y = y, z = z})
|
||||
if forced then
|
||||
@ -73,16 +107,38 @@ minetest.register_chatcommand("rofl", {
|
||||
else
|
||||
minetest.log("error", "[ROFL] Couldn't forceplace block " .. minetest.pos_to_string({x = x, y = y, z = z}))
|
||||
end
|
||||
if newmeta then
|
||||
local meta = minetest.get_meta({x = x, y = y, z = z})
|
||||
for key,value in ipairs(newmeta) do
|
||||
if tonumber(value) then
|
||||
meta:set_int(key, value)
|
||||
else
|
||||
meta:set_string(key,value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif action_type == 2 then -- TYPE_MODIFY_INVENTORY_STACK
|
||||
|
||||
local inv = minetest.get_meta({x = x, y = y, z = z}):get_inventory()
|
||||
local stack = inv:get_stack(list, index)
|
||||
if add == 1 then
|
||||
stack:set_name(stacknode)
|
||||
stack:set_count(stackquantity)
|
||||
else
|
||||
stack:take_item(stackquantity)
|
||||
end
|
||||
inv:set_stack(list, index, stack)
|
||||
|
||||
else -- TYPE_NOTHING
|
||||
print("W.T.F. is type " .. (action_type or "nil"))
|
||||
|
||||
end
|
||||
patchsegs = patchsegs + 1
|
||||
end
|
||||
i = i + 1
|
||||
io.close(file)
|
||||
if tonumber(param) then
|
||||
break
|
||||
end
|
||||
end
|
||||
minetest.chat_send_all("*** Server Up")
|
||||
end,
|
||||
|
Reference in New Issue
Block a user