egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trivia scores randomly delete on reboot..

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Wed Oct 18, 2006 7:19 pm    Post subject: Trivia scores randomly delete on reboot.. Reply with quote

Sorry if I posted in wrong spot..

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?
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Wed Oct 18, 2006 7:50 pm    Post subject: Reply with quote

Moved to: Scripting Help (for want of a better location)
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Wed Oct 18, 2006 7:51 pm    Post subject: Reply with quote

I tried, said only moderators can post there.
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Wed Oct 18, 2006 7:52 pm    Post subject: Reply with quote

cache wrote:
I tried, said only moderators can post there.

Tried what exactly?
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Wed Oct 18, 2006 7:57 pm    Post subject: Reply with quote

odd it works now, I tried to post in scripting help 1st place and I got the error 'only moderatrors can start a post here' but it works now.

so can anyone help with ideas on first post? thanks
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Wed Oct 18, 2006 7:57 pm    Post subject: Re: Trivia scores randomly delete on reboot.. Reply with quote

cache wrote:
Sorry if I posted in wrong spot..

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
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Wed Oct 18, 2006 8:04 pm    Post subject: Reply with quote

well it deletes the whole trivia.scores file of all 100+ players. heres some of code on how it saves... I use triviaplus from tcl archives.

Code:
#  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
}
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Oct 19, 2006 1:50 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Thu Oct 19, 2006 2:35 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Oct 19, 2006 3:30 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Oct 19, 2006 7:47 am    Post subject: Reply with quote

Could prolly catch the kill signal and make the bot do some stuff like closing files before shutting down. From the 'bind' commands:

(42) EVNT (stackable)
bind evnt <flags> <type> <proc>
proc-name <type>

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
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Thu Oct 19, 2006 5:13 pm    Post subject: Reply with quote

Thanks guys.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber