Save Mud Time [by Chuck Reed]
Snippet Posted Wednesday, August 12th @ 11:36:25 PM, by George Greer in the Utils dept.
Added Apr 27, 1998. Click the link below to read it or download it.

From: Chuck Reed <creed@I-55.COM>
Subject: Date saving upon reboot/crash

Hey, I noticed that the mud's date always reset when the game restarted.
This is what I did to fix that.

Add this to structs.h:
----------------------

struct time_write {
   int year, month, day;
 };


Put this right under the line "tics++" in comm.c:
-------------------------------------------------
write_mud_date_to_file();

Add this function and prototype it in comm.c:
---------------------------------------------

void write_mud_date_to_file(void)
{
   FILE *f;
   struct time_write date;

   f = fopen("etc/date_record", "w");
   date.year = time_info.year;
   date.month = time_info.month;
   date.day   = time_info.day;
   fwrite(&date,sizeof(struct time_write),1,f);
   fclose(f);
}

Add this line in the reset time function right after time_info = <blah> in
db.c:
----------------------------------------------------------------------------
read_mud_date_from_file();

Add this function and prototype it in db.c:
-------------------------------------------
void read_mud_date_from_file(void)
{
   FILE *f;
   struct time_write read_date;

   f = fopen("etc/date_record", "r");
   if(!f) {
      log("SYSERR: File etc/date_record not found, mud date will be reset
to default!");
      return;
   }

   fread(&read_date, sizeof(struct time_write), 1, f);
   time_info.year = read_date.year;
   time_info.month = read_date.month;
   time_info.day   = read_date.day;
   fclose(f);
}

Chuck


<< Same Mob EXP limits [by Andrey Fidrya] | Reply | View as text | Flattened | Scan Skill [by Mark Gerritsen] >>

 


Related Links
  download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.