This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Trivia scores randomly delete on reboot..

Help for those learning Tcl or writing their own scripts.
Post Reply
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Trivia scores randomly delete on reboot..

Post by cache »

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?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Moved to: Scripting Help (for want of a better location)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

I tried, said only moderators can post there.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

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
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Re: Trivia scores randomly delete on reboot..

Post by Alchera »

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
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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: Select all

#  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
}
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

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
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Thanks guys.
Post Reply