Author Topic: Configuration Saver [API 2]  (Read 8857 times)

0 Members and 1 Guest are viewing this topic.

Offline ATAG

  • Scripter
  • Double Ace
  • ******
  • Posts: 111
  • Karma: +14/-0
  • secret things
    • Metin2 Hungarian Forum
Configuration Saver [API 2]
« on: 02 September, 2008, 15:57:44 »
PtokaX often forget to save changed configuration so here is the cure :)

Saves in evrey 5 minutes or you can use !save command (in main or PM to hub bot).

Code: [Select]
-- automatic configuration saver
-- tested on PtokaX 0.4.1.1
-- v 0.2
-- by ATAG
-- 2008.09.02.
-- idea by 11hh

function OnStartup()
tmr = TmrMan.AddTimer(300*1000)

-- create backup from Profiles.xml
local cur = io.open(Core.GetPtokaXPath().."cfg/Profiles.xml")
if not cur then return end

local back = io.open(Core.GetPtokaXPath().."cfg/Profiles.bak","w+")
if back then
back:write(cur:read("*a"))
back:flush()
back:close()
end
cur:close()
end

function OnTimer(tmr)
SetMan.Save()
RegMan.Save()
BanMan.Save()
ScriptMan.Refresh()
  SaveProfiles()
end

function ChatArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
if not sData:find("%b<> %psave|") then return false end
OnTimer()
Core.SendToUser(tUser,"<"..SetMan.GetHubBot().sNick.."> Settings saved. OK|")
return true
end

function ToArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
local _,_,to = sData:find("%$To: (.-) From:.-%$%b<> %psave|")
if not to then return false end

if to == SetMan.GetHubBot().sNick then
OnTimer()
Core.SendPmToUser(tUser,SetMan.GetHubBot().sNick, "Settings saved. OK|")
return true
end
end

function SaveProfiles()
local f = io.open( Core.GetPtokaXPath().."cfg/Profiles.xml","w+" )

local buf = {'<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>','<Profiles>'}

local profiles = ProfMan.GetProfiles()
for j in ipairs(profiles) do

table.insert(buf,'\t<Profile>')
table.insert(buf,'\t\t<Name>'..profiles[j].sProfileName..'</Name>')


local profilenumber = profiles[j].iProfileNumber
local permissions = ""

for i = 0, 55 do
permissions = permissions.. (ProfMan.GetProfilePermission(profilenumber,i) and '1' or '0')
end

permissions = permissions..string.rep('0', 200) -- 255 - 55


table.insert(buf,'\t\t<Permissions>'..permissions..'</Permissions>')
table.insert(buf,'\t</Profile>')

end
table.insert(buf,'</Profiles>')

f:write(table.concat(buf,"\n")..'\n')
f:flush()
f:close()
end


PS: Thx for report and idea to 11hh :)
« Last Edit: 16 November, 2008, 15:39:21 by ATAG »

PtokaX forum

Configuration Saver [API 2]
« on: 02 September, 2008, 15:57:44 »

Offline 11hh

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-1
Re: Configuration Saver [API 2]
« Reply #1 on: 02 September, 2008, 17:58:19 »
Very good this script, congratulate !
I recommend it to everybody !  :)
« Last Edit: 26 September, 2008, 21:51:39 by 11hh »

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: Configuration Saver [API 2]
« Reply #2 on: 09 December, 2008, 06:50:10 »
Very nice script. Thanx ATAG
Thanking You,

speedX

Offline ?[-?Genius?-]?

  • Double Ace
  • *
  • Posts: 118
  • Karma: +3/-1
Re: Configuration Saver [API 2]
« Reply #3 on: 22 February, 2009, 08:51:59 »
Hello Would it be possible that the bot is sending information in a PM to the operators where the settings are saved?

I like the idea of the script: D

Sory my bad inglish

Offline ATAG

  • Scripter
  • Double Ace
  • ******
  • Posts: 111
  • Karma: +14/-0
  • secret things
    • Metin2 Hungarian Forum
Re: Configuration Saver [API 2]
« Reply #4 on: 22 February, 2009, 13:15:38 »
Settings will be saved mostly by PtokaX, you can find all configuration files in the cfg folder. There's no special backup location to report.

Offline ?[-?Genius?-]?

  • Double Ace
  • *
  • Posts: 118
  • Karma: +3/-1
Re: Configuration Saver [API 2]
« Reply #5 on: 22 February, 2009, 19:27:05 »
Ok m8.

Tankx for fast reply.

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #6 on: 17 March, 2010, 16:07:01 »
My thought about this is, what happens if the ptokax craches and reboots, cause the script saves on script start, and if some regs have been lost on that crash, they will be lost anyway if this backup script saves on script start, Or maybe not, may differ on the situation, but i would feel much safer with the backup if you could remove save on script start. =) or a on/off switch on that...

Offline TiMeTrAVelleR

  • Scripter
  • Lord
  • ******
  • Posts: 311
  • Karma: +19/-0
Re: Configuration Saver [API 2]
« Reply #7 on: 17 March, 2010, 18:10:12 »
Saves in evrey 5 minutes or you can use !save command (in main or PM to hub bot).

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #8 on: 19 March, 2010, 09:41:05 »
Yes i know =) but it saves on start too, and that is what im triying to say that it would be nice if that could be removed.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 745
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Configuration Saver [API 2]
« Reply #9 on: 20 March, 2010, 23:53:54 »
Untested...

Code: [Select]
-- automatic configuration saver
-- tested on PtokaX 0.4.1.1
-- v 0.2
-- by ATAG
-- 2008.09.02.
-- idea by 11hh

-- Save on startup? (true/false)
SaveonStartup = true

function OnStartup()
tmr = TmrMan.AddTimer(300*1000)

-- create backup from Profiles.xml
local cur = io.open(Core.GetPtokaXPath().."cfg/Profiles.xml")
if not cur then return end
if SaveonStartup then
  local back = io.open(Core.GetPtokaXPath().."cfg/Profiles.bak","w+")
  if back then
  back:write(cur:read("*a"))
  back:flush()
  back:close()
  end
        end
cur:close()
end

function OnTimer(tmr)
SetMan.Save()
RegMan.Save()
BanMan.Save()
        SaveProfiles()
end

function ChatArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
if not sData:find("%b<> %psave|") then return false end
OnTimer()
Core.SendToUser(tUser,"<"..SetMan.GetHubBot().sNick.."> Settings saved. OK|")
return true
end

function ToArrival(tUser,sData)
if not Core.GetUserValue(tUser,11) then return false end
local _,_,to = sData:find("%$To: (.-) From:.-%$%b<> %psave|")
if not to then return false end

if to == SetMan.GetHubBot().sNick then
OnTimer()
Core.SendPmToUser(tUser,SetMan.GetHubBot().sNick, "Settings saved. OK|")
return true
end
end

function SaveProfiles()
local f = io.open( Core.GetPtokaXPath().."cfg/Profiles.xml","w+" )

local buf = {'<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>','<Profiles>'}

local profiles = ProfMan.GetProfiles()
for j in ipairs(profiles) do

table.insert(buf,'\t<Profile>')
table.insert(buf,'\t\t<Name>'..profiles[j].sProfileName..'</Name>')


local profilenumber = profiles[j].iProfileNumber
local permissions = ""

for i = 0, 55 do
permissions = permissions.. (ProfMan.GetProfilePermission(profilenumber,i) and '1' or '0')
end

permissions = permissions..string.rep('0', 200) -- 255 - 55


table.insert(buf,'\t\t<Permissions>'..permissions..'</Permissions>')
table.insert(buf,'\t</Profile>')

end
table.insert(buf,'</Profiles>')

f:write(table.concat(buf,"\n")..'\n')
f:flush()
f:close()
end
« Last Edit: 23 March, 2010, 17:51:29 by bastya_elvtars »
Everything could have been anything else and it would have just as much meaning.

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #10 on: 23 March, 2010, 13:36:41 »
It doesnt save at script start, that is good =)
and it doesnt save at all, so thats not good.

So that is the thing that has to be fixed now.

Regards

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 745
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Configuration Saver [API 2]
« Reply #11 on: 23 March, 2010, 17:53:08 »
Edited my above post, try again. If it does not work, I'll rewrite it later this evening.
BTW I have not done any changes that coul make the saving every X minutes stop. Are you sure that worked before?
Everything could have been anything else and it would have just as much meaning.

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #12 on: 23 March, 2010, 20:43:16 »
Im sure it worked before, i even did set it to save every second and it didnt save.
But when i changed to true on scrupt start it made a backup.
I will try the updated script in the mornin, dont have the time right now.
But thanks for the reply and changes

edit: some minutes later...

Okay so i couldnt keep myself from trying this script, and this is what i could come up with

When setting the Save on startup to true, the script saves on start but nothing more then that.
When setting the Save on startup to false, the script doesnt save on startup and nothing more either.

Regards// Dreams
« Last Edit: 23 March, 2010, 20:51:00 by Dreams »

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 745
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Configuration Saver [API 2]
« Reply #13 on: 23 March, 2010, 21:09:59 »
Wait. The script does make that .bak file _only_ on startup. Otherwise it writes right into the xml files, of which you ought to check the timestamp regularly.
Everything could have been anything else and it would have just as much meaning.

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #14 on: 23 March, 2010, 23:14:13 »
So what you are sayin is that when Save on startup is set to False, it creates the backup right into the RegisteredUsers.xml every 5 minutes?
And there aint a way to make a .bak file if Save on startup isnt set to true? or am i getting it wrong?

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 745
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Configuration Saver [API 2]
« Reply #15 on: 24 March, 2010, 16:53:41 »
Save on startup backs up Profiles.xml. The 5-minute backup thing overwrites the existing XMLs. So you won't see a .bak when you have the thing set to false, but the profiles will be saved. The .bak is just a safety solution, the real saving is done right into the XML files.
Everything could have been anything else and it would have just as much meaning.

Offline Dreams

  • Forum Ace
  • *****
  • Posts: 84
  • Karma: +1/-12
Re: Configuration Saver [API 2]
« Reply #16 on: 24 March, 2010, 23:05:18 »
Alright, thanks for the answers.. :) they have been most helpfull.

Offline [NL]Daddy-Bear?

  • Scripter
  • Double Ace
  • ******
  • Posts: 102
  • Karma: +70/-7
  • ?????? Its me Daddy-Bear? ?????
Re: Configuration Saver [API 2]
« Reply #17 on: 25 March, 2010, 21:04:07 »
I like this script thanks Atag.
I fint it Useful.

Greats [NL]Daddy-Bear?

 :D
???????????? Lets enjoy our Hobby ??????????

dchub://Daddys-Friends-Association.no-ip.org:4106

take a peek you are welcome :D

PtokaX forum

Re: Configuration Saver [API 2]
« Reply #17 on: 25 March, 2010, 21:04:07 »