@verb #555:"_reboot_producer" this none this rxdo #789
@program #555:"_reboot_producer" this none this
caller == this || raise(E_PERM)
if (!this.db_files)
player:tell("Not proceeding with reboot of ", this.name, " since there aren't any databases.")
elseif (typeof(this.db_files) == $STR)
this.db_files = {this.db_files}
endif
this:filewrite("errors.txt", {})
this:jabber("Starting reboot at: ", ctime())
if (this:fileexists("head.cfg"))
this:jabber("Reading \"head.cfg\"...")
pagehead = this:trimwhite(this:fileread("head.cfg"))
else
this:jabber("WARNING! Can't find \"head.cfg\". No heads will be added to topics.")
pagehead = {}
endif
if (this:fileexists("tail.cfg"))
this:jabber("Reading \"tail.cfg\"...")
pagetail = this:trimwhite(this:fileread("tail.cfg"))
else
this:jabber("WARNING! Can't find \"tail.cfg\". No tails will be added to topics.")
pagetail = {}
endif
warning = ""
pagehead = {@pagehead, "", warning, ""}
pagetail = {"", warning, "", @pagetail}
if (this:fileexists("multipage.cfg"))
this:jabber("Reading \"multipage.cfg\"...")
this._multipage = this:trimwhite(this:fileread("multipage.cfg"))
else
this:jabber("WARNING! Can't find \"multipage.cfg\". The 'multiple hits' page will look rather plain.")
this._multipage = {"
", this.name, "", "Multiple hits:"}
endif
if ($recycler:valid(this._reboot_thing))
this:jabber("Curious, the temporary object from the previous reboot is still here. Did the previous reboot blow-up? You may wish to tell someone about this hiccup. It doesn't matter though, I'll just recycle the object and continue.")
$recycler:recycle(this._reboot_thing)
endif
reboot_thing = `$recycler:create($thing, this.owner) ! ANY'
if (typeof(reboot_thing) != OBJ || !$recycler:valid(reboot_thing))
this:jabber("ERROR! There was an error while trying to create a dummy object. '", toliteral(reboot_thing), "' was returned instead of an object. Complain!")
this:jabber("Fortunately, there is a contingency plan for this. ", this.name, " will continue to reboot, but she won't be able to answer questions properly until the reboot is finished.")
reboot_thing = this
this:jabber("Deleting all .htm and .html files from ", this.name, "...
")
for victim in ($list_utils:choose_match(".%.htm", this:filelist()))
this:filedelete(victim)
$command_utils:suspend_if_needed()
endfor
else
reboot_thing.name = "temporary Candid Candice object"
endif
this._reboot_thing = reboot_thing
this:fileappend("log.txt", "*** REBOOT! *** " + ctime())
this._reboot_db = {}
at_least_one_file = 0
for filename in (this.db_files)
suspend(0)
if (!(filename = $su:trim(filename)))
continue
endif
this:jabber("Looking up \"", filename, "\"...")
file = `$network:confirm_URL(filename) ! ANY'
if (file)
this:jabber("Loading database file, and parsing the topics:")
at_least_one_file = 1
elseif (file == 0)
this:jabber("WARNING! Can't find \"", filename, "\". Skipping this database file.")
continue
else
this:jabber("ERROR! Something evil (", file, ") happened while trying to load ", filename, ". Skipping this database file. Complain!")
continue
endif
this._reboot_buffer = {}
fork consumer (0)
"Fork off a task that will chew on the data while it is loaded"
this:_reboot_consumer(pagehead, pagetail)
endfork
{wedge, site, port, path} = $network:parse_URL(filename)
con = `open_network_connection(site, port) ! ANY'
if (typeof(con) == $ERR)
this:jabber("Error! Got a '", con, "' error when trying to open a connection to '", site, "' on port '", port, "'. I shouldn't be getting this error, complain!")
endif
notify(con, tostr("GET ", path, " HTTP/1.0"))
notify(con, "Host: " + site)
notify(con, "User-Agent: Candid Candice")
notify(con, "")
while ((line = `read(con) ! E_INVARG') != E_INVARG)
this._reboot_buffer = listappend(this._reboot_buffer, line)
$command_utils:suspend_if_needed()
endwhile
`boot_player(con) ! ANY'
this._reboot_buffer = listappend(this._reboot_buffer, "***NEW: EOF")
"Wait for the consumer to finish."
while ($code_utils:task_valid(consumer))
suspend(60)
endwhile
endfor
if (!at_least_one_file)
this:jabber("WARNING! No database files could be read. ", this.name, " isn't going to be able to answer anything.")
endif
suspend(0)
if (valid(reboot_thing) && reboot_thing != this)
move_me = $list_utils:choose_match(".%.htm", reboot_thing:filelist())
this:jabber("Moving ", length(move_me), " new .htm and .html files to ", this.name, "...")
for victim in (move_me)
`this:filedelete(victim) ! ANY'
reboot_thing:filemove(victim, this)
suspend(0)
endfor
this.db = this._reboot_db
delete_me = $set_utils:diff($list_utils:choose_match(".%.htm", this:filelist()), move_me)
this:jabber("Deleting ", length(delete_me), " old .htm and .html files from ", this.name, "...")
for victim in (delete_me)
this:filedelete(victim)
suspend(0)
endfor
$recycler:recycle(reboot_thing)
else
this.db = this._reboot_db
endif
this._reboot_db = {}
this._reboot_thing = #-1
this:jabber("Finished reboot at: ", ctime())
this:jabber("Have a nice day!")
"Last modified by Dax (#789) on Tue May 3 13:45:57 2005 MDT."
.