added logging

This commit is contained in:
Sokomine 2021-05-14 22:10:04 +02:00
parent 26e3655c10
commit 2096912134

View File

@ -10,7 +10,6 @@ yl_sokomine["q_apple_explorer"] = {}
-- chat option: "That was all. I'm finished with giving you new orders. Remember them!"
-- -> ends edit mode
--
-- TODO: log changes to the npc in the server logfile
--###
-- Init
@ -148,6 +147,7 @@ end
--Load and Save
--###
-- we can't really log changes here in this function because we don't know *what* has been changed
local function save_dialog(n_id, dialog)
if type(n_id) ~= "string" or type(dialog) ~= "table" then
return false
@ -352,6 +352,7 @@ local function delete_option(n_id, d_id, o_id)
save_dialog(n_id, dialog)
end
-- TODO: this function is unused (remove it?)
local function delete_prerequisite(n_id, d_id, o_id, p_id)
if d_id == yl_speak_up.text_new_dialog_id then
return false
@ -370,6 +371,7 @@ local function delete_prerequisite(n_id, d_id, o_id, p_id)
save_dialog(n_id, dialog)
end
-- TODO: this function is unused (remove it?)
local function delete_result(n_id, d_id, o_id, r_id)
if d_id == yl_speak_up.text_new_dialog_id then
return false
@ -1779,6 +1781,8 @@ minetest.register_on_player_receive_fields(
local r_id = yl_speak_up.text_new_result_id
delete_option(fields.n_id, fields.d_id, fields.o_id)
yl_speak_up.log_change(pname, n_id,
"(staff) Deleted option "..tostring(fields.o_id).." in dialog "..tostring(fields.d_id)..".")
minetest.show_formspec(
pname,
"yl_speak_up:optiondialog",
@ -1872,6 +1876,9 @@ minetest.register_on_player_receive_fields(
local temp_dialog = options_to_dialog(pname)
save_dialog(n_id, temp_dialog)
-- TODO: a better change detection would be good - because name, description and owner can change here
yl_speak_up.log_change(pname, n_id,
"(staff) Saved dialog "..tostring(fields.d_id)..".")
minetest.show_formspec(
pname,
@ -1938,6 +1945,9 @@ minetest.register_on_player_receive_fields(
if fields.button_save and fields.d_id then
local dialog = fields_to_dialog(pname, fields)
save_dialog(n_id, dialog)
-- TODO: a better change detection would be great (name, description, owner can be changed as well)
yl_speak_up.log_change(pname, n_id,
"(staff) Saved dialog "..tostring(fields.d_id)..".")
yl_speak_up.speak_to[pname].dialog = dialog
if yl_speak_up.speak_to[pname].obj then
@ -1967,6 +1977,8 @@ minetest.register_on_player_receive_fields(
"yl_speak_up:setdialog",
get_fs_setdialog(player, n_id, yl_speak_up.text_new_dialog_id)
)
yl_speak_up.log_change(pname, n_id,
"(staff) Deleted dialog "..tostring(fields.d_id)..".")
end
-- Change in Dropdown List: Show dialog formspec again with different dialog selected
@ -2031,6 +2043,10 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
elseif(edit_mode and fields.save_dialog_changes) then
-- actually save the dialog (the one the NPC currently has)
save_dialog(n_id, yl_speak_up.speak_to[pname].dialog)
-- log all the changes
for i, c in ipairs(yl_speak_up.npc_was_changed[ n_id ]) do
yl_speak_up.log_change(pname, n_id, c)
end
-- clear list of changes
yl_speak_up.npc_was_changed[ n_id ] = {}
@ -2053,11 +2069,13 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
-- is in the "new dialog" state again
local next_id = tonumber(string.sub( d_id, 3))
yl_speak_up.add_new_dialog(dialog, pname, next_id)
yl_speak_up.log_change(pname, n_id, "Saved new dialog "..tostring( d_id )..".")
need_to_save = true
end
if(not(dialog.n_dialogs[ target_dialog ])) then
-- restore the new target dialog
dialog.n_dialogs[ target_dialog ] = target_dialog_data
yl_speak_up.log_change(pname, n_id, "Saved new dialog "..tostring( target_dialog )..".")
need_to_save = true
end
if(need_to_save) then
@ -2436,6 +2454,8 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
dialog.n_dialogs[ d_id ] = nil
-- ..and store it to disk
delete_dialog(n_id, d_id)
yl_speak_up.log_change(pname, n_id,
"Deleted dialog "..tostring(d_id)..".")
-- switch to another dialog (this one was deleted after all)
fields["d_id"] = new_dialog
fields["show_new_dialog"] = nil
@ -2687,12 +2707,22 @@ minetest.register_on_player_receive_fields(
local dialog = fields_to_dialog(pname, f)
save_dialog(n_id, dialog)
yl_speak_up.speak_to[pname].dialog = dialog
yl_speak_up.log_change(pname, n_id,
"Initial config saved. "..
"NPC name: \""..tostring(fields.n_npc)..
"\" Description: \""..tostring(fields.n_description).."\"")
-- just change name and description
else
dialog = yl_speak_up.speak_to[pname].dialog
dialog.n_npc = fields.n_npc
dialog.n_description = fields.n_description
save_dialog(n_id, dialog)
yl_speak_up.log_change(pname, n_id,
"Name and/or description changed. "..
"NPC name: \""..tostring(fields.n_npc)..
"\" Description: \""..tostring(fields.n_description).."\"")
end
dialog = yl_speak_up.speak_to[pname].dialog
@ -3450,6 +3480,8 @@ minetest.register_on_player_receive_fields( --fashion
for _, v in pairs(capetable) do
if(v == fields.set_cape) then
textures[1] = fields.set_cape
yl_speak_up.log_change(pname, n_id,
"(fashion) cape changed to "..tostring(fields.set_cape)..".")
-- we have found it
break
end
@ -3462,6 +3494,8 @@ minetest.register_on_player_receive_fields( --fashion
for _, v in pairs(maintable) do
if(v == fields.set_skin) then
textures[2] = fields.set_skin
yl_speak_up.log_change(pname, n_id,
"(fashion) skin changed to "..tostring(fields.set_skin)..".")
-- we have found it
break
end
@ -3469,9 +3503,13 @@ minetest.register_on_player_receive_fields( --fashion
end
if fields.set_shield then
textures[3] = fields.set_shield
yl_speak_up.log_change(pname, n_id,
"(fashion) shield changed to "..tostring(fields.set_shield)..".")
end
if fields.set_sword then
textures[4] = fields.set_sword
yl_speak_up.log_change(pname, n_id,
"(fashion) sword changed to "..tostring(fields.set_sword)..".")
end
if fields.button_save then
@ -3480,6 +3518,8 @@ minetest.register_on_player_receive_fields( --fashion
-- save textures
yl_speak_up.speak_to[pname].skins = textures2skin(textures)
set_textures(obj, textures)
yl_speak_up.log_change(pname, n_id,
"(fashion) saved changes.")
end
end
@ -3604,3 +3644,27 @@ yl_speak_up.replace_vars_in_text = function(text, dialog, pname)
return text
end
-- log changes done by players or admins to NPCs
yl_speak_up.log_change = function(pname, n_id, text)
-- make sure all variables are defined
if(not(pname)) then
pname = "- unkown player -"
end
if(not(n_id)) then
n_id = "- unknown NPC -"
end
if(not(text)) then
text = "- no text given -"
end
-- we don't want newlines in the texts
text = string.gsub(text, "\n", "\\n")
local log_text = "<"..tostring(n_id).."> ["..tostring(pname).."]: "..text
-- log in general logfile
minetest.log("yl_speak_up "..log_text)
-- log with timestamp
local log_text = tostring(os.time())..log_text
-- TODO: log in a file for each npc and show it on demand?
end