1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 01:30:38 +01:00

Updated ROFL and SQLextract: Ready for first attempt

This commit is contained in:
LeMagnesium 2015-07-11 19:20:29 +02:00
parent ac6929f41a
commit 5005ce3ecc
2 changed files with 88 additions and 32 deletions

View File

@ -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,

View File

@ -7,7 +7,7 @@ from cStringIO import StringIO
home = os.environ.get("HOME")
db = "%s/rollback/rollback.sqlite" % (home)
#[id=16000;actor=crabman;type=2;list=main,index=13,add=1, stacknode=default:glass,stackquantity=9,nodemeta=0;x=None, y=None,z=None,oldnode=,oldparam1=None,oldparam2=None,oldmeta=None:newnode=,newparam1=None,newparam2=None,newmeta=None]
#[id=6,actor=Mg,type=1;list=None,index=None,add=None,stacknode=None,stackquantity=None;x=252,y=59,z=-401;newnode=air,newparam1=15,newparam2=None,newmeta=None]
class Convert_id(object):
def __init__(self, base):
@ -75,7 +75,8 @@ def select_all_nodes(startstamp, endstamp):
print(err)
sys.exit(1)
try:
cur.execute("SELECT * FROM action WHERE (NOT nodeMeta OR newNode) AND timestamp >=:startstamp AND timestamp < :endstamp", {"startstamp":startstamp, "endstamp":endstamp})
# x because we need position
cur.execute("SELECT * FROM action WHERE x AND timestamp >=:startstamp AND timestamp < :endstamp", {"startstamp":startstamp, "endstamp":endstamp})
except sqlite3.OperationalError as err:
print(err)
sys.exit(1)
@ -132,14 +133,8 @@ def to_table(node):
table += ',add=%s' % node[6]
table += ',stacknode=%s' % Id.get_node_name(node[7])
table += ',stackquantity=%s' % node[8]
table += ',nodemeta=%s' % node[9]
# Position
table += ';x=%s,y=%s,z=%s' % (node[10], node[11], node[12])
# Old node
table += ';oldnode=%s' % Id.get_node_name(node[13])
table += ',oldparam1=%s' % node[14]
table += ',oldparam2=%s' % ston(node[15])
table += ',oldmeta=%s' % decode(node[16])
# New node
table += ';newnode=%s' % Id.get_node_name(node[17])
table += ',newparam1=%s' % ston(node[18])
@ -170,13 +165,18 @@ def write_list(nodes, i):
if __name__ == '__main__':
Id = Convert_id(db)
#select all nodes player as set i where time >= time
timestamp = 1426978800
#timestamp = 1426978800
timestamp = 0
i = 0
while timestamp <= calendar.timegm(time.gmtime()):
while timestamp <= time.time():
all_nodes = select_all_nodes(timestamp, timestamp+24*60*60)
if len(all_nodes) > 0:
write_list(all_nodes, i)
i += 1
print("%s to %s => %s entries" % (timestamp, timestamp+24*60*60, len(all_nodes)))
print("%s (%s) to %s (%s) => %s entries" % (
time.strftime("%m/%d/%Y", time.gmtime(timestamp)), timestamp,
time.strftime("%m/%d/%Y", time.gmtime(timestamp+24*60*60)), timestamp+24*60*60,
len(all_nodes))
)
timestamp += 24*60*60