/***************************************************************************\ [*] ___ ____ ____ __ __ ____ [*] ROGUE: ROM With Attitude [*] [*] /#/ ) /#/ ) /#/ ) /#/ /#/ /#/ [*] All rights reserved [*] [*] /#/ < /#/ / /#/ _ /#/ /#/ /#/-- [*] Copyright(C) 2000-2001 [*] [*] /#/ \(#(__/ (#(__/ (#(__/#/ (#(___ [*] Kenneth Conley (Mendanbar) [*] [*] Expression of Digital Creativity.. [*] scmud@mad.scientist.com [*] [-]---------------------------------------+-+-----------------------------[-] [*] File: system.cpp [*] [*] Usage: Storing Valuable Information and Stats [*] \***************************************************************************/ #include "merc.h" #include "recycle.h" #include "staffcmds.h" struct SystemData { UInt32 all_time_max; char * time_of_max; UInt32 player_database; }; SystemData SData; void save_sys_data(void); void load_sys_data(void); #if defined(KEY) #undef KEY #endif #define SYS_FILE "../data/system.txt" #define KEY(literal, field, value) \ if (!str_cmp(word, literal)) \ { \ field = value; \ fMatch = TRUE; \ break; \ } void save_sys_data( void ) { FILE *fp; fclose(fpReserve); if (!(fp = fopen(SYS_FILE, "w"))) { mudlogf(BRF, LVL_STAFF, TRUE, "SYSERR: Unable to open %s file.", SYS_FILE); return; } fprintf(fp, "#SYSTEM\n"); fprintf(fp, "MaxHigh %d\n", SData.all_time_max); fprintf(fp, "HighTime %s~\n", SData.time_of_max); fprintf(fp, "End\n"); fclose(fp); fpReserve = fopen(NULL_FILE, "r"); } void load_sys_data( void ) { FILE *fp; char *word; bool fMatch = FALSE, drop_out = FALSE; if (!(fp = fopen(SYS_FILE, "r"))) { mudlogf(BRF, LVL_STAFF, TRUE, "SYSERR: Unable to open %s for reading." SYS_FILE); return; } fread_to_eol(fp); while (!drop_out) { word = feof(fp) ? str_dup("End") : fread_word(fp); fMatch = FALSE; switch (UPPER(word[0])) { default: case '*': fMatch = TRUE; fread_to_eol(fp); break; case 'H': KEY("HighTime", SData.time_of_max, fread_string(fp)); break; case 'M': KEY("MaxHigh", SData.all_time_max, fread_number(fp)); break; case 'E': if (!str_cmp(word, "End")) drop_out = TRUE; break; } if (!fMatch) fread_to_eol(fp); } fclose(fp); } void sys_update( void ) { CHAR_DATA *vch; DESCRIPTOR_DATA *d; UInt32 temp = 0; time_t ct = time(0); char buf[MAX_INPUT_LENGTH]; char *time_s = asctime(localtime(&ct)); *(time_s + strlen(time_s) - 1) = '\0'; for (d = descriptor_list; d != NULL; d = d->next) { if (STATE(d) == CON_PLAYING) temp++; } if (temp > SData.all_time_max) { SData.all_time_max = temp; sprintf(buf, "%-19.19s", time_s); SData.time_of_max = str_dup(buf); save_sys_data(); mudlogf(NRM, LVL_STAFF, TRUE, "BOOTHIGH: New record high of %d players.", SData.all_time_max); } if (SData.all_time_max >= 50) info(NULL, 0, "`y[`bINFO`y]`w Rogue has reached a record high %d players!`n\n\r", SData.all_time_max); } int get_record_high( void ) { return SData.all_time_max; } char *get_record_string( void ) { if (SData.time_of_max[0]) return SData.time_of_max; else return "(not recorded)"; } void set_player_database(int num) { SData.player_database = num; } int get_player_database( void ) { return SData.player_database; }