void tedit_string_cleanup(struct descriptor_data *d, int terminator) { FILE *fl; char *storage = OLC_STORAGE(d); if (!storage) terminator = STRINGADD_ABORT; switch (terminator) { case STRINGADD_SAVE: if (!(fl = fopen(storage, "w"))) mudlog(CMP, LVL_IMPL, TRUE, "SYSERR: Can't write file '%s'.", storage); else { if (*d->str) { strip_cr(*d->str); fputs(*d->str, fl); } fclose(fl); mudlog(CMP, LVL_GOD, TRUE, "OLC: %s saves '%s'.", GET_NAME(d->character), storage); write_to_output(d, "Saved.\r\n"); } break; case STRINGADD_ABORT: write_to_output(d, "Edit aborted.\r\n"); act("$n stops editing some scrolls.", TRUE, d->character, 0, 0, TO_ROOM); break; default: log("SYSERR: tedit_string_cleanup: Unknown terminator status."); break; } /* Common cleanup code. */ cleanup_olc(d, CLEANUP_ALL); STATE(d) = CON_PLAYING; }
// For debugging void print_to_log_file(const char *format, ...) { #if CREATE_LOG FILE *f; va_list args; char path[256], buf[256]; time_t t; strcpy(path, "/Users/Shared/test_log.txt"); // strcpy(path, "/Users/"); // strcat(path, getlogin()); // strcat(path, "/Documents/test_log.txt"); f = fopen(path, "a"); if (!f) return; // freopen(buf, "a", stdout); // freopen(buf, "a", stderr); time(&t); strcpy(buf, asctime(localtime(&t))); strip_cr(buf); fputs(buf, f); fputs(" ", f); va_start(args, format); vfprintf(f, format, args); va_end(args); fputs("\n", f); fflush(f); fclose(f); chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); #endif }
void print_to_log_file(const char *format, ...) { #if CREATE_LOG va_list args; char buf[256]; time_t t; #if USE_SPECIAL_LOG_FILE safe_strcpy(buf, getenv("HOME")); safe_strcat(buf, "/Documents/test_log.txt"); FILE *f; f = fopen(buf, "a"); if (!f) return; // freopen(buf, "a", stdout); // freopen(buf, "a", stderr); #else #define f stderr #endif time(&t); safe_strcpy(buf, asctime(localtime(&t))); strip_cr(buf); fputs(buf, f); fputs(" ", f); va_start(args, format); vfprintf(f, format, args); va_end(args); fputs("\n", f); #if USE_SPECIAL_LOG_FILE fflush(f); fclose(f); #endif #endif }
// Returns true if the user name is in the nologinitems.txt, else false Boolean CheckDeleteFile(char *name) { FILE *f; char buf[64]; size_t len; f = fopen("/Library/Application Support/BOINC Data/nologinitems.txt", "r"); if (!f) return false; while (true) { *buf = '\0'; len = sizeof(buf); fgets(buf, len, f); if (feof(f)) break; strip_cr(buf); if (strcmp(buf, name) == 0) { fclose(f); return true; } } fclose(f); return false; }
static void print_to_log_file(const char *format, ...) { FILE *f; va_list args; char buf[256]; time_t t; f = fopen("/Users/Shared/test_log.txt", "a"); if (!f) return; // freopen(buf, "a", stdout); // freopen(buf, "a", stderr); time(&t); strcpy(buf, asctime(localtime(&t))); strip_cr(buf); fputs(buf, f); fputs(" ", f); va_start(args, format); vfprintf(f, format, args); va_end(args); fputs("\n", f); fflush(f); fclose(f); }
// For debugging void print_to_log_file(const char *format, ...) { FILE *f; va_list args; char buf[MAXPATHLEN]; time_t t; // strlcpy(buf, getenv("HOME"), sizeof(buf)); // strlcat(buf, "/Documents/test_log.txt", sizeof(buf)); snprintf(buf, sizeof(buf), "/tmp/%s/BOINC_Installer_Errors", tempDirName); f = fopen(buf, "a"); if (!f) return; // freopen(buf, "a", stdout); // freopen(buf, "a", stderr); time(&t); strlcpy(buf, asctime(localtime(&t)),sizeof(buf)); strip_cr(buf); fputs(buf, f); fputs(" ", f); va_start(args, format); vfprintf(f, format, args); va_end(args); fputs("\n", f); fflush(f); fclose(f); }
bool hash_dump( int hash ) { struct hashstr_data *ptr; char *str; int c, psize; if ( hash > STR_HASH_SIZE || hash < 0 ) { fprintf( stderr, "%s: invalid hash size\n", __FUNCTION__ ); return true; } psize = sizeof( struct hashstr_data ); for ( c = 0, ptr = string_hash[hash]; ptr; ptr = ptr->next, c++ ) { str = ( char * ) ( ( ( long ) ptr ) + psize ); fprintf( stderr, "Len: %4d Lnks: %5d Str: %s\r\n", ptr->length, ptr->links, strip_cr( str ) ); } if ( !mud_down || ( mud_down && c > 0 ) ) fprintf( stderr, "Total strings in hash %d: %d\r\n", hash, c ); if ( c > 0 ) return true; else return false; }
int write_mobile_record(mob_vnum mvnum, struct char_data *mob, FILE *fd) { char ldesc[MAX_STRING_LENGTH], ddesc[MAX_STRING_LENGTH]; ldesc[MAX_STRING_LENGTH - 1] = '\0'; ddesc[MAX_STRING_LENGTH - 1] = '\0'; strip_cr(strncpy(ldesc, GET_LDESC(mob), MAX_STRING_LENGTH - 1)); strip_cr(strncpy(ddesc, GET_DDESC(mob), MAX_STRING_LENGTH - 1)); fprintf(fd, "#%d\n" "%s%c\n" "%s%c\n" "%s%c\n" "%s%c\n", mvnum, GET_ALIAS(mob), STRING_TERMINATOR, GET_SDESC(mob), STRING_TERMINATOR, ldesc, STRING_TERMINATOR, ddesc, STRING_TERMINATOR ); fprintf(fd, "%ld %ld %d E\n" "%d %d %d %dd%d+%d %dd%d+%d\n", MOB_FLAGS(mob), AFF_FLAGS(mob), GET_ALIGNMENT(mob), GET_LEVEL(mob), 20 - GET_HITROLL(mob), GET_AC(mob) / 10, GET_HIT(mob), GET_MANA(mob), GET_MOVE(mob), GET_NDD(mob), GET_SDD(mob), GET_DAMROLL(mob) ); fprintf(fd, "%d %d\n" "%d %d %d\n", GET_GOLD(mob), GET_EXP(mob), GET_POS(mob), GET_DEFAULT_POS(mob), GET_SEX(mob) ); if (write_mobile_espec(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing E-specs for mobile #%d.", mvnum); script_save_to_disk(fd, mob, MOB_TRIGGER); #if CONFIG_GENOLC_MOBPROG if (write_mobile_mobprog(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing MobProgs for mobile #%d.", mvnum); #endif return TRUE; }
int write_mobile_mobprog(mob_vnum mvnum, struct char_data *mob, FILE *fd) { char wmmarg[MAX_STRING_LENGTH], wmmcom[MAX_STRING_LENGTH]; MPROG_DATA *mob_prog; for (mob_prog = GET_MPROG(mob); mob_prog; mob_prog = mob_prog->next) { wmmarg[MAX_STRING_LENGTH - 1] = '\0'; wmmcom[MAX_STRING_LENGTH - 1] = '\0'; strip_cr(strncpy(wmmarg, mob_prog->arglist, MAX_STRING_LENGTH - 1)); strip_cr(strncpy(wmmcom, mob_prog->comlist, MAX_STRING_LENGTH - 1)); fprintf(fd, "%s %s~\n" "%s%c\n", medit_get_mprog_type(mob_prog), wmmarg, wmmcom, STRING_TERMINATOR ); if (mob_prog->next == NULL) fputs("|\n", fd); } return TRUE; }
void fwrite_chap( CHAP_DATA * chap, FILE * fp ) { if ( !chap ) return; fprintf( fp, "%s", "#NCHAPTER\n" ); fprintf( fp, "Number %d\n", chap->number ); if ( chap->desc ) fprintf( fp, "Desc %s~\n", strip_cr( chap->desc ) ); if ( chap->bio ) fprintf( fp, "Bio %s~\n", chap->bio ); fprintf( fp, "Timelimit %d\n", chap->timelimit ); fprintf( fp, "Level %d\n", chap->level ); fprintf( fp, "KAmount %d\n", chap->kamount ); fprintf( fp, "#CHAPEND\n" ); }
void show_high_hash( int top ) { struct hashstr_data *ptr; int x, psize; char *str; psize = sizeof( struct hashstr_data ); for ( x = 0; x < STR_HASH_SIZE; x++ ) { for ( ptr = string_hash[x]; ptr; ptr = ptr->next ) { if ( ptr->links >= top ) { str = ( char * ) ( ( ( long ) ptr ) + psize ); fprintf( stderr, "Links: %5d String: >%s<\r\n", ptr->links, strip_cr( str ) ); } } } }
void tedit_string_cleanup(struct descriptor_data *d, int terminator) { FILE *fl; char *storage = (char *)d->olc; if (!storage) terminator = STRINGADD_ABORT; switch (terminator) { case STRINGADD_SAVE: if (!(fl = fopen(storage, "w"))) { sprintf(buf, "SYSERR: Can't write file '%s'.", storage); mudlog(buf, CMP, LVL_IMPL, TRUE); } else { if (*d->str) { strip_cr(*d->str); fputs(*d->str, fl); } fclose(fl); sprintf(buf, "OLC: %s saves '%s'.", GET_NAME(d->character), storage); mudlog(buf, CMP, LVL_GOD, TRUE); SEND_TO_Q("Saved.\r\n", d); } break; case STRINGADD_ABORT: SEND_TO_Q("Edit aborted.\r\n", d); act("$n stops editing some scrolls.", TRUE, d->character, 0, 0, TO_ROOM); break; default: log("SYSERR: tedit_string_cleanup: Unknown terminator status."); break; } /* Common cleanup code. */ if (d->olc) { free(d->olc); d->olc = NULL; } STATE(d) = CON_PLAYING; }
void write_news( ) { FILE *fpout; NEWS_DATA *news; if ( ( fpout = FileOpen( NEWS_FILE, "w" ) ) == NULL ) { bug( "Cannot open news.dat for writing." ); perror( NEWS_FILE ); return; } fptof( fpout, "#HTML\n" ); fprintf( fpout, "%d\n\n", USE_HTML_NEWS == TRUE ? 1 : 0 ); for ( news = first_news; news != NULL; news = news->next ) { fptof( fpout, "#News\n" ); fprintf( fpout, "TimeStamp %ld\n", news->time_stamp > 0 ? news->time_stamp : -1 ); fprintf( fpout, "NewsData %s~\n", strip_cr( news->data ) ); fptof( fpout, "End\n\n" ); } fptof( fpout, "#End\n" ); FileClose( fpout ); }
/* Write the quest. */ void fwrite_quest( QUEST_DATA * quest, FILE * fp ) { CHAP_DATA *chap; if ( !quest ) return; fprintf( fp, "%s", "#NQUEST\n" ); fprintf( fp, "Number %d\n", quest->number ); fprintf( fp, "SType %d\n", quest->stype ); fprintf( fp, "SVnum %d\n", quest->svnum ); fprintf( fp, "Glory %d\n", quest->glory ); fprintf( fp, "Name %s~\n", quest->name ); fprintf( fp, "Desc %s~\n", strip_cr( quest->desc ) ); fprintf( fp, "Timelimit %d\n", quest->timelimit ); fprintf( fp, "Level %d\n", quest->level ); fprintf( fp, "Chapters %d\n", quest->chapters ); if ( quest->skipchapters ) fprintf( fp, "%s", "SkipChapters\n" ); for ( chap = quest->first_chapter; chap; chap = chap->next ) fwrite_chap( chap, fp ); fprintf( fp, "End\n\n" ); }
int save_mobiles(zone_rnum rznum) { zone_vnum vznum; FILE *mobfd; room_vnum i; mob_rnum rmob; int written; char mobfname[64], usedfname[64]; #if CIRCLE_UNSIGNED_INDEX if (rznum == NOWHERE || rznum > top_of_zone_table) { #else if (rznum < 0 || rznum > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_mobiles: Invalid real zone number %d. (0-%d)", rznum, top_of_zone_table); return FALSE; } vznum = zone_table[rznum].number; snprintf(mobfname, sizeof(mobfname), "%s%d.new", MOB_PREFIX, vznum); if ((mobfd = fopen(mobfname, "w")) == NULL) { mudlog(BRF, LVL_GOD, TRUE, "SYSERR: GenOLC: Cannot open mob file for writing."); return FALSE; } for (i = genolc_zone_bottom(rznum); i <= zone_table[rznum].top; i++) { if ((rmob = real_mobile(i)) == NOBODY) continue; check_mobile_strings(&mob_proto[rmob]); if (write_mobile_record(i, &mob_proto[rmob], mobfd) < 0) log("SYSERR: GenOLC: Error writing mobile #%d.", i); } fputs("$\n", mobfd); written = ftell(mobfd); fclose(mobfd); snprintf(usedfname, sizeof(usedfname), "%s%d.mob", MOB_PREFIX, vznum); remove(usedfname); rename(mobfname, usedfname); if (in_save_list(vznum, SL_MOB)) remove_from_save_list(vznum, SL_MOB); log("GenOLC: '%s' saved, %d bytes written.", usedfname, written); return written; } int write_mobile_espec(mob_vnum mvnum, struct char_data *mob, FILE *fd) { if (GET_ATTACK(mob) != 0) fprintf(fd, "BareHandAttack: %d\n", GET_ATTACK(mob)); if (GET_STR(mob) != 11) fprintf(fd, "Str: %d\n", GET_STR(mob)); if (GET_ADD(mob) != 0) fprintf(fd, "StrAdd: %d\n", GET_ADD(mob)); if (GET_DEX(mob) != 11) fprintf(fd, "Dex: %d\n", GET_DEX(mob)); if (GET_INT(mob) != 11) fprintf(fd, "Int: %d\n", GET_INT(mob)); if (GET_WIS(mob) != 11) fprintf(fd, "Wis: %d\n", GET_WIS(mob)); if (GET_CON(mob) != 11) fprintf(fd, "Con: %d\n", GET_CON(mob)); if (GET_CHA(mob) != 11) fprintf(fd, "Cha: %d\n", GET_CHA(mob)); if (GET_SAVE(mob, SAVING_PARA) != 0) fprintf(fd, "SavingPara: %d\n", GET_SAVE(mob, SAVING_PARA)); if (GET_SAVE(mob, SAVING_ROD) != 0) fprintf(fd, "SavingRod: %d\n", GET_SAVE(mob, SAVING_ROD)); if (GET_SAVE(mob, SAVING_PETRI) != 0) fprintf(fd, "SavingPetri: %d\n", GET_SAVE(mob, SAVING_PETRI)); if (GET_SAVE(mob, SAVING_BREATH) != 0) fprintf(fd, "SavingBreath: %d\n", GET_SAVE(mob, SAVING_BREATH)); if (GET_SAVE(mob, SAVING_SPELL) != 0) fprintf(fd, "SavingSpell: %d\n", GET_SAVE(mob, SAVING_SPELL)); fputs("E\n", fd); return TRUE; } int write_mobile_record(mob_vnum mvnum, struct char_data *mob, FILE *fd) { char ldesc[MAX_STRING_LENGTH]; char ddesc[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH]; ldesc[MAX_STRING_LENGTH - 1] = '\0'; ddesc[MAX_STRING_LENGTH - 1] = '\0'; strip_cr(strncpy(ldesc, GET_LDESC(mob), MAX_STRING_LENGTH - 1)); strip_cr(strncpy(ddesc, GET_DDESC(mob), MAX_STRING_LENGTH - 1)); int n = snprintf(buf, MAX_STRING_LENGTH, "#%d\n" "%s%c\n" "%s%c\n" "%s%c\n" "%s%c\n", mvnum, GET_ALIAS(mob), STRING_TERMINATOR, GET_SDESC(mob), STRING_TERMINATOR, ldesc, STRING_TERMINATOR, ddesc, STRING_TERMINATOR ); if(n < MAX_STRING_LENGTH) { fprintf(fd, "%s", convert_from_tabs(buf)); fprintf(fd, "%d %d %d %d %d %d %d %d %d E\n" "%d %d %d %dd%d+%d %dd%d+%d\n", MOB_FLAGS(mob)[0], MOB_FLAGS(mob)[1], MOB_FLAGS(mob)[2], MOB_FLAGS(mob)[3], AFF_FLAGS(mob)[0], AFF_FLAGS(mob)[1], AFF_FLAGS(mob)[2], AFF_FLAGS(mob)[3], GET_ALIGNMENT(mob), GET_LEVEL(mob), 20 - GET_HITROLL(mob), GET_AC(mob) / 10, GET_HIT(mob), GET_MANA(mob), GET_MOVE(mob), GET_NDD(mob), GET_SDD(mob), GET_DAMROLL(mob)); fprintf(fd, "%d %d\n" "%d %d %d\n", GET_GOLD(mob), GET_EXP(mob), GET_POS(mob), GET_DEFAULT_POS(mob), GET_SEX(mob) ); if (write_mobile_espec(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing E-specs for mobile #%d.", mvnum); script_save_to_disk(fd, mob, MOB_TRIGGER); #if CONFIG_GENOLC_MOBPROG if (write_mobile_mobprog(mvnum, mob, fd) < 0) log("SYSERR: GenOLC: Error writing MobProgs for mobile #%d.", mvnum); #endif } else { mudlog(BRF,LVL_BUILDER,TRUE, "SYSERR: Could not save mobile #%d due to size (%d > maximum of %d)", mvnum, n, MAX_STRING_LENGTH); } return TRUE; }
int save_objects(zone_rnum zone_num) { char fname[128], buf[MAX_STRING_LENGTH]; char ebuf1[MAX_STRING_LENGTH], ebuf2[MAX_STRING_LENGTH]; char ebuf3[MAX_STRING_LENGTH], ebuf4[MAX_STRING_LENGTH]; char wbuf1[MAX_STRING_LENGTH], wbuf2[MAX_STRING_LENGTH]; char wbuf3[MAX_STRING_LENGTH], wbuf4[MAX_STRING_LENGTH]; char pbuf1[MAX_STRING_LENGTH], pbuf2[MAX_STRING_LENGTH]; char pbuf3[MAX_STRING_LENGTH], pbuf4[MAX_STRING_LENGTH]; int counter, counter2, realcounter; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; #if CIRCLE_UNSIGNED_INDEX if (zone_num == NOWHERE || zone_num > top_of_zone_table) { #else if (zone_num < 0 || zone_num > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } snprintf(fname, sizeof(fname), "%s%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(fname, "w+"))) { mudlog(BRF, LVL_IMMORT, TRUE, "SYSERR: OLC: Cannot open objects file %s!", fname); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = genolc_zone_bottom(zone_num); counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) != NOTHING) { if ((obj = &obj_proto[realcounter])->action_description) { strncpy(buf, obj->action_description, sizeof(buf) - 1); strip_cr(buf); } else *buf = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : "undefined", (obj->short_description && *obj->short_description) ? obj->short_description : "undefined", (obj->description && *obj->description) ? obj->description : "undefined", buf); sprintascii(ebuf1, GET_OBJ_EXTRA(obj)[0]); sprintascii(ebuf2, GET_OBJ_EXTRA(obj)[1]); sprintascii(ebuf3, GET_OBJ_EXTRA(obj)[2]); sprintascii(ebuf4, GET_OBJ_EXTRA(obj)[3]); sprintascii(wbuf1, GET_OBJ_WEAR(obj)[0]); sprintascii(wbuf2, GET_OBJ_WEAR(obj)[1]); sprintascii(wbuf3, GET_OBJ_WEAR(obj)[2]); sprintascii(wbuf4, GET_OBJ_WEAR(obj)[3]); sprintascii(pbuf1, GET_OBJ_PERM(obj)[0]); sprintascii(pbuf2, GET_OBJ_PERM(obj)[1]); sprintascii(pbuf3, GET_OBJ_PERM(obj)[2]); sprintascii(pbuf4, GET_OBJ_PERM(obj)[3]); fprintf(fp, "%d %s %s %s %s %s %s %s %s %s %s %s %s\n" "%d %d %d %d\n" "%d %d %d %d\n", GET_OBJ_TYPE(obj), ebuf1, ebuf2, ebuf3, ebuf4, wbuf1, wbuf2, wbuf3, wbuf4, pbuf1, pbuf2, pbuf3, pbuf4, GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj) ); /* * Do we have script(s) attached ? */ script_save_to_disk(fp, obj, OBJ_TRIGGER); /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog(BRF, LVL_IMMORT, TRUE, "SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!"); continue; } strncpy(buf, ex_desc->description, sizeof(buf) - 1); strip_cr(buf); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); snprintf(buf, sizeof(buf), "%s%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf); rename(fname, buf); if (in_save_list(zone_table[zone_num].number, SL_OBJ)) { remove_from_save_list(zone_table[zone_num].number, SL_OBJ); create_world_index(zone_table[zone_num].number, "obj"); log("GenOLC: save_objects: Saving objects '%s'", buf); } return TRUE; } /* * Free all, unconditionally. */ void free_object_strings(struct obj_data *obj) { #if 0 /* Debugging, do not enable. */ extern struct obj_data *object_list; struct obj_data *t; int i = 0; for (t = object_list; t; t = t->next) { if (t == obj) { i++; continue; } assert(obj->name != t->name); assert(obj->description != t->description); assert(obj->short_description != t->short_description); assert(obj->action_description != t->action_description); assert(obj->ex_description != t->ex_description); } assert(i <= 1); #endif if (obj->name) free(obj->name); if (obj->description) free(obj->description); if (obj->short_description) free(obj->short_description); if (obj->action_description) free(obj->action_description); if (obj->ex_description) free_ex_descriptions(obj->ex_description); } /* * For object instances that are not the prototype. */ void free_object_strings_proto(struct obj_data *obj) { int robj_num = GET_OBJ_RNUM(obj); if (obj->name && obj->name != obj_proto[robj_num].name) free(obj->name); if (obj->description && obj->description != obj_proto[robj_num].description) free(obj->description); if (obj->short_description && obj->short_description != obj_proto[robj_num].short_description) free(obj->short_description); if (obj->action_description && obj->action_description != obj_proto[robj_num].action_description) free(obj->action_description); if (obj->ex_description) { struct extra_descr_data *thised, *plist, *next_one; /* O(horrible) */ int ok_key, ok_desc, ok_item; for (thised = obj->ex_description; thised; thised = next_one) { next_one = thised->next; for (ok_item = ok_key = ok_desc = 1, plist = obj_proto[robj_num].ex_description; plist; plist = plist->next) { if (plist->keyword == thised->keyword) ok_key = 0; if (plist->description == thised->description) ok_desc = 0; if (plist == thised) ok_item = 0; } if (thised->keyword && ok_key) free(thised->keyword); if (thised->description && ok_desc) free(thised->description); if (ok_item) free(thised); } } }
int save_objects(zone_rnum zone_num) { int counter, counter2, realcounter; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; if (zone_num < 0 || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } sprintf(buf, "%s/%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(buf, "w+"))) { mudlog("SYSERR: OLC: Cannot open objects file!", BRF, LVL_IMMORT, TRUE); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = zone_table[zone_num].number * 100; counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) >= 0) { if ((obj = &obj_proto[realcounter])->action_description) { buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, obj->action_description, MAX_STRING_LENGTH - 1); strip_cr(buf1); } else *buf1 = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n" "%d %d %d %ld\n" "%d %d %d %d\n" "%d %d %d %d\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : "undefined", (obj->short_description && *obj->short_description) ? obj->short_description : "undefined", (obj->description && *obj->description) ? obj->description : "undefined", buf1, GET_OBJ_TYPE(obj), GET_OBJ_EXTRA(obj), GET_OBJ_WEAR(obj), GET_OBJ_PERM(obj), GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj)); script_save_to_disk(fp, obj, OBJ_TRIGGER); /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog("SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!", BRF, LVL_IMMORT, TRUE); continue; } buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, ex_desc->description, MAX_STRING_LENGTH - 1); strip_cr(buf1); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); /* And now the spec-proc */ if (obj_index[realcounter].func != NULL) fprintf(fp, "S\n%s\n", obj_procs[get_spec_name(obj_procs, obj_index[realcounter].func)].name); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); sprintf(buf2, "%s/%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[zone_num].number, SL_OBJ); return TRUE; }
int save_rooms(zone_rnum rzone) { int i; int dflag = 0; struct room_data *room; FILE *sf; char buf[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; if (rzone == NOWHERE || rzone > top_of_zone_table) { log("SYSERR: GenOLC: save_rooms: Invalid zone number %d passed! (0-%d)", rzone, top_of_zone_table); return FALSE; } log("GenOLC: save_rooms: Saving rooms in zone #%d (%d-%d).", zone_table[rzone].number, genolc_zone_bottom(rzone), zone_table[rzone].top); sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number); if (!(sf = fopen(buf, "w"))) { perror("SYSERR: save_rooms"); return FALSE; } for (i = genolc_zone_bottom(rzone); i <= zone_table[rzone].top; i++) { int rnum; if ((rnum = real_room(i)) != NOWHERE) { int j; room = (world + rnum); /* * Copy the description and strip off trailing newlines. */ strcpy(buf, room->description ? room->description : "Empty room."); strip_cr(buf); /* * Save the numeric and string section of the file. */ sprintasciilong(buf2, room->room_flags); fprintf(sf, "#%d\n" "%s%c\n" "%s%c\n" "%d %s %d %d %d %d %d\n", room->number, room->name ? room->name : "Untitled", STRING_TERMINATOR, buf, STRING_TERMINATOR, zone_table[room->zone].number, buf2, room->sector_type, room->size, room->nat_light, room->min_level, room->max_level ); /* * Now you write out the exits for the room. */ for (j = 0; j < NUM_OF_DIRS; j++) { if (R_EXIT(room, j)) { if (R_EXIT(room, j)->general_description) { strcpy(buf, R_EXIT(room, j)->general_description); strip_cr(buf); } else *buf = '\0'; /* * Figure out door flag. */ if (IS_SET(R_EXIT(room, j)->exit_info, EX_ISDOOR)) { dflag = 1; if (IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF) && !IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN)) dflag = 2; if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) && !IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 3; if (IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN) && IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 4; } else if (!IS_SET(R_EXIT(room, j)->exit_info, EX_HIDDEN)) dflag = 0; if (R_EXIT(room, j)->keyword) strcpy(buf1, R_EXIT(room, j)->keyword); else *buf1 = '\0'; /* * Now write the exit to the file. */ fprintf(sf, "D%d\n" "%s~\n" "%s~\n" "%d %d %d\n", j, buf, buf1, dflag, R_EXIT(room, j)->key, R_EXIT(room, j)->to_room != -1 ? world[R_EXIT(room, j)->to_room].number : -1); } } if (room->ex_description) { struct extra_descr_data *xdesc; for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) { strcpy(buf, xdesc->description); strip_cr(buf); fprintf(sf, "E\n" "%s~\n" "%s~\n", xdesc->keyword, buf); } } if (room->pain_message) { fprintf(sf, "P\n" "%s~\n" "%d~\n" "%d~\n", room->pain_message, room->pain_damage, room->pain_rate ); } if (room->nomagic_message_room && room->nomagic_message_caster ) { fprintf(sf, "N\n" "%s~\n" "%s~\n", room->nomagic_message_caster, room->nomagic_message_room ); } if (room->min_level_message || room->max_level_message ) { fprintf(sf, "F\n" "%s~\n" "%s~\n", room->min_level_message, room->max_level_message ); } fprintf(sf, "S\n"); script_save_to_disk(sf, room, WLD_TRIGGER); } } /* * Write the final line and close it. */ fprintf(sf, "$~\n"); fclose(sf); /* New file we just made. */ sprintf(buf, "%s/%d.new", WLD_PREFIX, zone_table[rzone].number); /* Old file we're replacing. */ sprintf(buf2, "%s/%d.wld", WLD_PREFIX, zone_table[rzone].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[rzone].number, SL_WLD); return TRUE; }
int save_quests(zone_rnum zone_num) { FILE *sf; char filename[128], oldname[128], quest_flags[MAX_STRING_LENGTH]; char quest_desc[MAX_STRING_LENGTH], quest_info[MAX_STRING_LENGTH]; char quest_done[MAX_STRING_LENGTH], quest_quit[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH]; int i, num_quests = 0; #if CIRCLE_UNSIGNED_INDEX if (zone_num == NOWHERE || zone_num > top_of_zone_table) { #else if (zone_num < 0 || zone_num > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_quests: Invalid zone number %d passed! (0-%d)", zone_num, top_of_zone_table); return FALSE; } log("GenOLC: save_quests: Saving quests in zone #%d (%d-%d).", zone_table[zone_num].number, genolc_zone_bottom(zone_num), zone_table[zone_num].top); snprintf(filename, sizeof(filename), "%s/%d.new", QST_PREFIX, zone_table[zone_num].number); if (!(sf = fopen(filename, "w"))) { perror("SYSERR: save_quests"); return FALSE; } for (i = genolc_zone_bottom(zone_num); i <= zone_table[zone_num].top; i++) { qst_rnum rnum; if ((rnum = real_quest(i)) != NOTHING) { /* Copy the text strings and strip off trailing newlines. */ strncpy(quest_desc, QST_DESC(rnum) ? QST_DESC(rnum) : "undefined", sizeof(quest_desc)-1 ); strncpy(quest_info, QST_INFO(rnum) ? QST_INFO(rnum) : "undefined", sizeof(quest_info)-1 ); strncpy(quest_done, QST_DONE(rnum) ? QST_DONE(rnum) : "undefined", sizeof(quest_done)-1 ); strncpy(quest_quit, QST_QUIT(rnum) ? QST_QUIT(rnum) : "undefined", sizeof(quest_quit)-1 ); strip_cr(quest_desc); strip_cr(quest_info); strip_cr(quest_done); strip_cr(quest_quit); /* Save the quest details to the file. */ sprintascii(quest_flags, QST_FLAGS(rnum)); sprintf(buf, "#%d\n" "%s%c\n" "%s%c\n" "%s%c\n" "%s%c\n" "%s%c\n" "%d %d %s %d %d %d %d\n" "%d %d %d %d %d %d %d\n" "%d %d %d\n" "S\n", QST_NUM(rnum), QST_NAME(rnum) ? QST_NAME(rnum) : "Untitled", STRING_TERMINATOR, quest_desc, STRING_TERMINATOR, quest_info, STRING_TERMINATOR, quest_done, STRING_TERMINATOR, quest_quit, STRING_TERMINATOR, QST_TYPE(rnum), QST_MASTER(rnum) == NOBODY ? -1 : QST_MASTER(rnum), quest_flags, QST_TARGET(rnum) == NOTHING ? -1 : QST_TARGET(rnum), QST_PREV(rnum) == NOTHING ? -1 : QST_PREV(rnum), QST_NEXT(rnum) == NOTHING ? -1 : QST_NEXT(rnum), QST_PREREQ(rnum) == NOTHING ? -1 : QST_PREREQ(rnum), QST_POINTS(rnum), QST_PENALTY(rnum), QST_MINLEVEL(rnum), QST_MAXLEVEL(rnum), QST_TIME(rnum), QST_RETURNMOB(rnum) == NOBODY ? -1 : QST_RETURNMOB(rnum), QST_QUANTITY(rnum), QST_GOLD(rnum), QST_EXP(rnum), QST_OBJ(rnum) ); fprintf(sf, convert_from_tabs(buf), 0); num_quests++; } } /* Write the final line and close it. */ fprintf(sf, "$~\n"); fclose(sf); /* Old file we're replacing. */ snprintf(oldname, sizeof(oldname), "%s/%d.qst", QST_PREFIX, zone_table[zone_num].number); remove(oldname); rename(filename, oldname); /* Do we need to update the index file? */ if (num_quests > 0) create_world_index(zone_table[zone_num].number, "qst"); if (in_save_list(zone_table[zone_num].number, SL_QST)) remove_from_save_list(zone_table[zone_num].number, SL_QST); return TRUE; }
int save_rooms(zone_rnum zone_num) { int i; struct room_data *room; FILE *sf; char filename[128]; char buf[MAX_STRING_LENGTH], buf1[MAX_STRING_LENGTH]; char rbuf1[MAX_STRING_LENGTH], rbuf2[MAX_STRING_LENGTH]; char rbuf3[MAX_STRING_LENGTH], rbuf4[MAX_STRING_LENGTH]; #if CIRCLE_UNSIGNED_INDEX if (zone_num == NOWHERE || zone_num > top_of_zone_table) { #else if (zone_num < 0 || zone_num > top_of_zone_table) { #endif log("SYSERR: GenOLC: save_rooms: Invalid zone number %d passed! (0-%d)", zone_num, top_of_zone_table); return FALSE; } log("GenOLC: save_rooms: Saving rooms in zone #%d (%d-%d).", zone_table[zone_num].number, genolc_zone_bottom(zone_num), zone_table[zone_num].top); snprintf(filename, sizeof(filename), "%s%d.new", WLD_PREFIX, zone_table[zone_num].number); if (!(sf = fopen(filename, "w"))) { perror("SYSERR: save_rooms"); return FALSE; } for (i = genolc_zone_bottom(zone_num); i <= zone_table[zone_num].top; i++) { room_rnum rnum; if ((rnum = real_room(i)) != NOWHERE) { int j; room = (world + rnum); /* * Copy the description and strip off trailing newlines. */ strncpy(buf, room->description ? room->description : "Empty room.", sizeof(buf)-1 ); strip_cr(buf); /* * Save the numeric and string section of the file. */ sprintascii(rbuf1, room->room_flags[0]); sprintascii(rbuf2, room->room_flags[1]); sprintascii(rbuf3, room->room_flags[2]); sprintascii(rbuf4, room->room_flags[3]); fprintf(sf, "#%d\n" "%s%c\n" "%s%c\n" "%d %s %s %s %s %d\n", room->number, room->name ? room->name : "Untitled", STRING_TERMINATOR, buf, STRING_TERMINATOR, zone_table[room->zone].number, rbuf1, rbuf2, rbuf3, rbuf4, room->sector_type ); /* * Now you write out the exits for the room. */ for (j = 0; j < NUM_OF_DIRS; j++) { if (R_EXIT(room, j)) { int dflag; if (R_EXIT(room, j)->general_description) { strncpy(buf, R_EXIT(room, j)->general_description, sizeof(buf)-1); strip_cr(buf); } else *buf = '\0'; /* * Figure out door flag. */ if (IS_SET(R_EXIT(room, j)->exit_info, EX_ISDOOR)) { if (IS_SET(R_EXIT(room, j)->exit_info, EX_SECRET) && IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 4; else if (IS_SET(R_EXIT(room, j)->exit_info, EX_SECRET)) dflag = 3; else if (IS_SET(R_EXIT(room, j)->exit_info, EX_PICKPROOF)) dflag = 2; else dflag = 1; } else dflag = 0; if (R_EXIT(room, j)->keyword) strncpy(buf1, R_EXIT(room, j)->keyword, sizeof(buf1)-1 ); else *buf1 = '\0'; /* * Now write the exit to the file. */ fprintf(sf, "D%d\n" "%s~\n" "%s~\n" "%d %d %d\n", j, buf, buf1, dflag, R_EXIT(room, j)->key != NOTHING ? R_EXIT(room, j)->key : -1, R_EXIT(room, j)->to_room != NOWHERE ? world[R_EXIT(room, j)->to_room].number : -1); } } if (room->ex_description) { struct extra_descr_data *xdesc; for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) { strncpy(buf, xdesc->description, sizeof(buf)); strip_cr(buf); fprintf(sf, "E\n" "%s~\n" "%s~\n", xdesc->keyword, buf); } } fprintf(sf, "S\n"); script_save_to_disk(sf, room, WLD_TRIGGER); } } /* * Write the final line and close it. */ fprintf(sf, "$~\n"); fclose(sf); /* Old file we're replacing. */ snprintf(buf, sizeof(buf), "%s%d.wld", WLD_PREFIX, zone_table[zone_num].number); remove(buf); rename(filename, buf); if (in_save_list(zone_table[zone_num].number, SL_WLD)) { remove_from_save_list(zone_table[zone_num].number, SL_WLD); create_world_index(zone_table[zone_num].number, "wld"); log("GenOLC: save_rooms: Saving rooms '%s'", buf); } return TRUE; } int copy_room(struct room_data *to, struct room_data *from) { free_room_strings(to); *to = *from; copy_room_strings(to, from); /* Don't put people and objects in two locations. Am thinking this shouldn't be done here... */ from->people = NULL; from->contents = NULL; return TRUE; }
static void archive_file(const std::string& path, const std::string& fname, config& cfg) { cfg["name"] = fname; const bool is_cfg = (fname.size() > 4 ? (fname.substr(fname.size() - 4) == ".cfg") : false); cfg["contents"] = encode_binary(strip_cr(read_file(path + '/' + fname),is_cfg)); }
/* * NOTE: This clobbers all of the global variable strings. Do not * save anything in them around calls to this function. * * buf, buf1, buf2, arg */ int save_objects(zone_rnum zone_num) { char buf[MAX_STRING_LENGTH]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char buf3[MAX_STRING_LENGTH]; char arg[MAX_STRING_LENGTH]; int counter, counter2, realcounter, i; FILE *fp; struct obj_data *obj; struct extra_descr_data *ex_desc; if (zone_num == NOTHING || zone_num > top_of_zone_table) { log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table); return FALSE; } sprintf(buf, "%s/%d.new", OBJ_PREFIX, zone_table[zone_num].number); if (!(fp = fopen(buf, "w+"))) { mudlog(BRF, LVL_SAINT, TRUE, "SYSERR: OLC: Cannot open objects file!"); return FALSE; } /* * Start running through all objects in this zone. */ for (counter = genolc_zone_bottom(zone_num); counter <= zone_table[zone_num].top; counter++) { if ((realcounter = real_object(counter)) != NOTHING) { if ((obj = &obj_proto[realcounter])->action_description) { buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, obj->action_description, MAX_STRING_LENGTH - 1); strip_cr(buf1); } else *buf1 = '\0'; fprintf(fp, "#%d\n" "%s~\n" "%s~\n" "%s~\n" "%s~\n", GET_OBJ_VNUM(obj), (obj->name && *obj->name) ? obj->name : STRING_UNDEFINED, (obj->short_description && *obj->short_description) ? obj->short_description : STRING_UNDEFINED, (obj->description && *obj->description) ? obj->description : STRING_UNDEFINED, buf1); sprintasciilong(buf1, GET_OBJ_EXTRA(obj)); sprintasciilong(buf3, GET_OBJ_CLASS(obj)); sprintascii(buf2, GET_OBJ_WEAR(obj)); sprintasciilong(arg, GET_OBJ_PERM(obj)); fprintf(fp, "%d %s %s %s %s\n" "%d %d %d %d %d\n" "%d %d %d %d %d\n", GET_OBJ_TYPE(obj), buf1, buf2, arg, buf3, GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3), GET_OBJ_SIZE(obj), GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj), GET_OBJ_MAX_LEVEL(obj) ); /* * Do we have script(s) attached ? */ script_save_to_disk(fp, obj, OBJ_TRIGGER); /* save resists */ for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->resist[i] == 1) fprintf(fp, "R\n%d %d\n",i, obj->resist[i]); } for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->vulnerable[i] == 1) fprintf(fp, "V\n%d %d\n",i, obj->vulnerable[i]); } for (i = 0; i < MAX_ATTACK_TYPES; i++) { if(obj->immune[i] == 1) fprintf(fp, "I\n%d %d\n",i, obj->immune[i]); } /* * Do we have extra descriptions? */ if (obj->ex_description) { /* Yes, save them too. */ for (ex_desc = obj->ex_description; ex_desc; ex_desc = ex_desc->next) { /* * Sanity check to prevent nasty protection faults. */ if (!ex_desc->keyword || !ex_desc->description || !*ex_desc->keyword || !*ex_desc->description) { mudlog(BRF, LVL_SAINT, TRUE, "SYSERR: OLC: oedit_save_to_disk: Corrupt ex_desc!"); continue; } buf1[MAX_STRING_LENGTH - 1] = '\0'; strncpy(buf1, ex_desc->description, MAX_STRING_LENGTH - 1); strip_cr(buf1); fprintf(fp, "E\n" "%s~\n" "%s~\n", ex_desc->keyword, buf1); } } /* * Do we have affects? */ for (counter2 = 0; counter2 < MAX_OBJ_AFFECT; counter2++) if (obj->affected[counter2].modifier) fprintf(fp, "A\n" "%d %d\n", obj->affected[counter2].location, obj->affected[counter2].modifier); } } /* * Write the final line, close the file. */ fprintf(fp, "$~\n"); fclose(fp); sprintf(buf2, "%s/%d.obj", OBJ_PREFIX, zone_table[zone_num].number); remove(buf2); rename(buf, buf2); remove_from_save_list(zone_table[zone_num].number, SL_OBJ); return TRUE; }