sometimes when I reboot my computer or power goes out, some bots trivia files (scores) randomly delete... don't always happen...
anyone else ever had this problem?
If these scores are being saved (via a timer) when the power outtage &c happens then it is quite possible the relevant files will be deleted rather than saved. Might be an idea to keep backups.
Add [SOLVED] to the thread title if your issue has been. Search | FAQ | RTM
# The full path to the file which tracks the scores. The account
# the bot runs on must have read & write access to this file. If
# the file does not exist, it will be created when needed.
set tgscf "scripts/trivia.scores"
#read current scores from file, sort and store in variable.
proc tggetscores {} {
global tgscf tgscorestotal tgscores tgscoresbyname tgranksbyname tgranksbynum
global tgrealnames tgscoresbyrank
if {[file exists $tgscf]&&[file size $tgscf]>2} {
set _sfile [open $tgscf r]
set tgscores [lsort -dict -decreasing [split [gets $_sfile]]]
close $_sfile
set tgscorestotal [llength $tgscores]
} else {
set tgscores ""
set tgscorestotal 0
}
if {[info exists tgscoresbyname]} {unset tgscoresbyname}
if {[info exists tgranksbyname]} {unset tgranksbyname}
if {[info exists tgrealnames]} {unset tgrealnames}
if {[info exists tgranksbynum]} {unset tgranksbynum}
set i 0
while {$i<[llength $tgscores]} {
set _item [lindex $tgscores $i]
set _nick [lindex [split $_item ,] 2]
set _lwrnick [lindex [split $_item ,] 3]
set _score [lindex [split $_item ,] 0]
set tgscoresbyname($_lwrnick) $_score
set tgrealnames($_lwrnick) $_nick
set tgranksbyname($_lwrnick) [expr $i+1]
set tgranksbynum([expr $i+1]) $_lwrnick
set tgscoresbyrank([expr $i+1]) $_score
incr i
}
return
}
#increment someone's score.
proc tgincrscore {who} {
global tgscores tgscf tgpointsperanswer tgscorestotal tgscoresbyname
tggetscores
if {$tgscorestotal>0} {
set i 0
if {![info exists tgscoresbyname([strlwr $who])]} {
append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who] "
}
while {$i<[llength $tgscores]} {
set _item [lindex $tgscores $i]
set _nick [lindex [split $_item ,] 2]
set _time [lindex [split $_item ,] 1]
set _score [lindex [split $_item ,] 0]
if {[strlwr $who]==[strlwr $_nick]} {
append _newscores "[expr $_score+$tgpointsperanswer],[expr 1000000000000.0/[unixtime]],$who,[strlwr $who][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
} else {
append _newscores "$_score,$_time,$_nick,[strlwr $_nick][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
}
incr i
}
} else {
append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who]"
}
set _sfile [open $tgscf w]
puts $_sfile "$_newscores"
close $_sfile
return
}
What platform is this on? If it's windows, then yes likely it could still have the file cached at the time of the crash, and so the file is never saved to disk. I don't know if adding an explicit 'flush' cmd before the 'close' cmd would help in that situation.
A possible work around would be to write data to a tempfile, flush/close, then copy the tempfile overwriting the scorefile. But I suspect you'd still end up with the same problem, since the file is cached in memory before being written to disk. :/
Best to get yourself a stable platform (*bsd, linux, etc) and a UPS backup power supply so you're not experiencing crashes.
It's just a simple reboot... I'm thinking when I click restart in middle of someone winning a point and bot saving it at same time is maybe like improper shut down and deletes.
cache wrote:It's just a simple reboot... I'm thinking when I click restart in middle of someone winning a point and bot saving it at same time is maybe like improper shut down and deletes.
I would suggest you properly have your bot 'die' (via DCC) before hitting that magic little Reboot button of Windows.
eggdrop just may flush everything and you may not loose data.
Add [SOLVED] to the thread title if your issue has been. Search | FAQ | RTM
Description: triggered whenever one of these events happen. flags
are ignored; valid events are:
sighup - called on a kill -HUP <pid>
sigterm - called on a kill -TERM <pid>
sigill - called on a kill -ILL <pid>
sigquit - called on a kill -QUIT <pid>
save - called when the userfile is saved
rehash - called just after a rehash
prerehash - called just before a rehash
prerestart - called just before a restart