implement hard reset of configuration

closes https://gitlab.com/4w/mtimer/-/issues/21
This commit is contained in:
Dirk Sohler 2021-12-10 08:35:12 +01:00
parent 7188f890c7
commit 59f973d480
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
9 changed files with 102 additions and 13 deletions

@ -3,7 +3,6 @@
# mTimer Configuration Names # mTimer Configuration Names
Open Main Menu=Hauptmenü öffnen Open Main Menu=Hauptmenü öffnen
Reset Everything=Alles zurücksetzen
mTimer Configuration=mTimer-Konfiguration mTimer Configuration=mTimer-Konfiguration
@ -99,6 +98,19 @@ Stop stop custom timer=Individuellen Timer anhalten
Restart the custom timer=Individuellen Timer neu starten Restart the custom timer=Individuellen Timer neu starten
# Dialog: Reset Everything (also messages)
Reset Everything=Alles zurücksetzen
Soft-reset all values to their defaults=Alle Werte auf die definierten Standards setzen
Request hard-reset (kicks you from the server!)=Löschen anfordern (führt einen Kick vom Server aus!)
All configuration was reset. Server time of the requested: @1=Alle Konfiguration wurde zurückgesetzt. Serverzeit der Anfrage: @1
You requested a hard reset of the mTimer configuration. This request was stored. As described, you were kicked from the server in order to have the hard reset performed. Please rejoin the server. On rejoin all previously stored configuration regarding mTimer will be deleted.=Ein hartes Zurücksetzen der mTimer-Konfiguration wurde angefordert. Die Anfrage wurde gespeichert. Wie beschrieben wurde ein Kick vom Server ausgeführt. Um das harte Zurücksetzen der Konfiguration abzuschließen ist ein Neuverbinden zum Server erforderlich. Dabei wird die gesamte mTimer-bezogene Konfiguration entfernt.
Cancel reset and return to main menu=Zurücksetzen abbrechen und zurück zum Hauptmenü
For resetting the configuration you have two options.=Für das zurücksetzen der Konfiguration bestehen zwei Optionen.
Usually using a soft reset is enough. The soft reset sets all values based on mTimer functionality to the default values while staying connected.=Üblicher weise reicht ein sanftes Zurücksetzen. Dies setzt direkt alle Werte mittels mTimer-Funktionen auf die entsprecheden Standardwerte.
If the soft reset does not work you can hard reset the configuration. This stores a request and then kicks you from the server. On rejoining mTimer forcefully removes all stored configuration and sets the current default values.=Sollte dies nicht funktionieren kann ein hartes Zurücksetzen angefordert werden. Es wird ein entsprechender Eintrag gesetzt und eine Trennung vom Server ausgeführt. Beim Neuverbinden wird zwangsweise die Standardkonfiguration geladen.
# Default custom timer status messages # Default custom timer status messages
The custom timer is already running=Der individuelle Timer läuft bereits The custom timer is already running=Der individuelle Timer läuft bereits
The custom timer is not running=Der individuelle Timer läuft nicht The custom timer is not running=Der individuelle Timer läuft nicht

@ -37,13 +37,14 @@ end
-- os OffSet d.hud_element_offset(name) -- os OffSet d.hud_element_offset(name)
-- tf timer format d.timer_format(name) -- tf timer format d.timer_format(name)
-- ct custom timer d.custom_timer(name) -- ct custom timer d.custom_timer(name)
-- re reset everything d.reset_everything(name)
-- ------------------------------------------------------------------- -- -------------------------------------------------------------------
-- help Prints the help output showing the parameters -- help Prints the help output showing the parameters
-- --
-- Providing unknown parameters has no effect. -- Providing unknown parameters has no effect.
minetest.register_chatcommand('mtimer', { minetest.register_chatcommand('mtimer', {
description = S('Configure timer display'), description = S('Configure timer display'),
params = '<vi/po/co/tz/in/re/ht/st/sd/hs/os/tf/ct/help>', params = '<vi/po/co/tz/in/re/ht/st/sd/hs/os/tf/ct/re/help>',
func = function(name, parameters) func = function(name, parameters)
local action = parameters:match('%a+') local action = parameters:match('%a+')
@ -63,6 +64,7 @@ minetest.register_chatcommand('mtimer', {
if action == 'os' then d.hud_element_offset(name) end if action == 'os' then d.hud_element_offset(name) end
if action == 'tf' then d.timer_format(name) end if action == 'tf' then d.timer_format(name) end
if action == 'ct' then d.custom_timer(name) end if action == 'ct' then d.custom_timer(name) end
if action == 're' then d.reset_everything(name) end
if action == 'ctstart' then mtimer.update_custom_timer(name, { action = 'start' }) end if action == 'ctstart' then mtimer.update_custom_timer(name, { action = 'start' }) end
if action == 'ctstop' then mtimer.update_custom_timer(name, { action = 'stop' }) end if action == 'ctstop' then mtimer.update_custom_timer(name, { action = 'stop' }) end
@ -83,6 +85,7 @@ minetest.register_chatcommand('mtimer', {
command('hs')..S('HUD Element Scale'), command('hs')..S('HUD Element Scale'),
command('os')..S('HUD Element Offset'), command('os')..S('HUD Element Offset'),
command('tf')..S('Timer Format'), command('tf')..S('Timer Format'),
command('re')..S('Reset Everything'),
'', '',
command('ct ')..S('Configure the custom timer'), command('ct ')..S('Configure the custom timer'),
command('ctstart ')..S('Start the custom timer'), command('ctstart ')..S('Start the custom timer'),

@ -146,3 +146,41 @@ mtimer.dialog.timer_format = function (player_name)
} }
}) })
end end
mtimer.dialog.reset_everything = function (player_name)
local td = mtimer.get_timer_data(player_name)
local infotext = table.concat({
S('For resetting the configuration you have two options.'),
S('Usually using a soft reset is enough. The soft reset sets all values based on mTimer functionality to the default values while staying connected.'),
S('If the soft reset does not work you can hard reset the configuration. This stores a request and then kicks you from the server. On rejoining mTimer forcefully removes all stored configuration and sets the current default values.')
}, '\n\n')
mtimer.show_formspec('mtimer:reset_everything', {
title = S('Reset Everything'),
show_to = player_name,
width = 10,
height = 6.3,
hide_buttons = true,
formspec = {
'textarea[0,0;+contentWidth,3.5;;;'..esc(infotext)..']',
'container[0,3.8]',
line(0, '-'),
mtimer.get_icon_button('reset_soft', {
width = 10,
label = S('Soft-reset all values to their defaults')
}),
mtimer.get_icon_button('reset_hard', {
label = S('Request hard-reset (kicks you from the server!)'),
width = 10,
container = { top = 1 }
}),
mtimer.get_icon_button('reset_cancel', {
label = S('Cancel reset and return to main menu'),
width = 10,
container = { top = 2 }
}),
'container_end[]',
}
})
end

@ -126,3 +126,7 @@ set('timer_format', table.concat({
S('Session Start: @1', '{st}'), S('Session Start: @1', '{st}'),
S('Session Duration: @1', '{sd}') S('Session Duration: @1', '{sd}')
}, '{_n}'), false, { n = '\n' }) }, '{_n}'), false, { n = '\n' })
-- Hard reset indicator
set('hard_reset_everything', 'false')

@ -3,19 +3,37 @@ local m = mtimer
-- When a player joins -- When a player joins
-- --
-- 1. Set default values if not set -- 1. Check if a hard reset was requested and perform it if it was
-- 2. Set session start timestamp -- 2. Set default values if not set
-- 3. Set “empty” HUD element and write ID to meta data for later use -- 3. Set session start timestamp
-- 4. Set “empty” HUD element and write ID to meta data for later use
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local meta = player:get_meta() local meta = player:get_meta()
local name = player:get_player_name()
local re = meta:get_int('mtimer:hard_reset_everything')
-- Forecefully remove all meta data set in the player object that starts
-- with `mtimer:` prefix (perform the requested reset everything).
if re > 0 then
local message = m.translator('All configuration was reset. Server time of the requested: @1', os.date('%c', re))
for fname,fvalue in pairs(meta:to_table().fields) do
if fname:sub(1,7) == 'mtimer:' then
meta:set_string(fname, '')
end
end
minetest.chat_send_player(name, '[mTimer] '..message)
end
-- Set all unset metadata to their defined default values
for _,def in pairs(m.meta) do for _,def in pairs(m.meta) do
local current = meta:get_string(def.key) local current = meta:get_string(def.key)
if current == '' then meta:set_string(def.key, def.default) end if current == '' then meta:set_string(def.key, def.default) end
end end
-- Always set session start timestamp for using it within the custom timer
meta:set_string('mtimer:session_start', os.time()) meta:set_string('mtimer:session_start', os.time())
-- Initially set empty HUD element to store the ID for updates
meta:set_string('mtimer:hud_id', player:hud_add({ meta:set_string('mtimer:hud_id', player:hud_add({
hud_elem_type = 'text', hud_elem_type = 'text',
text = '', text = '',

@ -31,6 +31,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.hud_element_offset then d.hud_element_offset(name) end if fields.hud_element_offset then d.hud_element_offset(name) end
if fields.timer_format then d.timer_format(name) end if fields.timer_format then d.timer_format(name) end
if fields.custom_timer then d.custom_timer(name) end if fields.custom_timer then d.custom_timer(name) end
if fields.reset_everything then d.reset_everything(name) end
end end
@ -320,17 +321,30 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
-- Back to menu from all formspecs and conditionally update timer
if fields.main_menu then d.main_menu(name) end
if formname ~= 'mtimer:main_menu' then m.update_timer(name) end
-- Reset everything -- Reset everything
if fields.reset_everything then if formname == 'mtimer:reset_everything' then
for _,def in pairs(m.meta) do local kick_message = m.translator('You requested a hard reset of the mTimer configuration. This request was stored. As described, you were kicked from the server in order to have the hard reset performed. Please rejoin the server. On rejoin all previously stored configuration regarding mTimer will be deleted.')
meta:set_string(def.key, def.default)
-- Perform a soft reset
if fields.reset_soft then
for _,def in pairs(m.meta) do
meta:set_string(def.key, def.default)
end
end end
-- Request hard reset and kick the player with informational message
if fields.reset_hard then
meta:set_int(m.meta.hard_reset_everything.key, os.time())
minetest.kick_player(name, kick_message)
end
-- Show main menu formspec when cancelled or close on fields.quit
if fields.reset_cancel then d.main_menu(name) return end
if not fields.quit then d.reset_everything(name) end
end end
-- Back to menu from all formspecs and conditionally update timer
if fields.main_menu then d.main_menu(name) end
if formname ~= 'mtimer:main_menu' then m.update_timer(name) end
end) end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB