int Crash_delete_crashfile(struct char_data *ch) { char fname[MAX_INPUT_LENGTH]; struct rent_info rent; int numread; FILE *fl; int rentcode,timed,netcost,gold,account,nitems; char line[MAX_INPUT_LENGTH]; if (!get_filename(fname, sizeof(fname), CRASH_FILE, GET_NAME(ch))) return (0); if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) /* if it fails, NOT because of no file */ log("SYSERR: checking for crash file %s (3): %s", fname, strerror(errno)); return (0); } numread = get_line(fl,line); fclose(fl); if (numread == FALSE) return (0); sscanf(line,"%d %d %d %d %d %d",&rentcode,&timed,&netcost,&gold, &account,&nitems); if (rentcode == RENT_CRASH) Crash_delete_file(GET_NAME(ch)); if (rent.rentcode == RENT_CRASH) Crash_delete_file(GET_NAME(ch)); return (1); }
int Crash_delete_crashfile(struct char_data * ch) { char fname[MAX_INPUT_LENGTH]; FILE *fl; char input[MAX_INPUT_LENGTH + 1]; char tag[MAX_INPUT_LENGTH + 1]; char tag_arguments[MAX_INPUT_LENGTH + 1]; char *p; int val; if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) { return 0; } if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ sprintf(buf1, "SYSERR: checking for crash file %s (3)", fname); perror(buf1); } return 0; } while (get_line(fl, input)) { parse_pline(input, tag, tag_arguments); while ((p = strrchr(tag_arguments, '\n')) != NULL) { *p = '\0'; } val = atoi(tag_arguments); switch (tag[0]) { case 'r': case 'R': if (strcasecmp(tag, "rent_type") == 0) { fclose(fl); if (val == RENT_CRASH) { Crash_delete_file(GET_NAME(ch)); } return 1; } break; } } return 0; }
int Crash_delete_crashfile(struct char_data * ch) { char fname[MAX_INPUT_LENGTH]; struct rent_info rent; FILE *fl; if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) return 0; if (!(fl = fopen(fname, "rb"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ sprintf(buf1, "SYSERR: checking for crash file %s (3)", fname); perror(buf1); } return 0; } if (!feof(fl)) fread(&rent, sizeof(struct rent_info), 1, fl); fclose(fl); if (rent.rentcode == RENT_CRASH) Crash_delete_file(GET_NAME(ch)); return 1; }
void Crash_idlesave(struct char_data * ch) { char buf[MAX_INPUT_LENGTH]; struct rent_info rent; int j; int cost, cost_eq; FILE *fp; if (IS_NPC(ch)) return; if (!get_filename(GET_NAME(ch), buf, CRASH_FILE)) return; if (!(fp = fopen(buf, "wb"))) return; for (j = 0; j < NUM_WEARS; j++) if (GET_EQ(ch, j)) obj_to_char(unequip_char(ch, j), ch); Crash_extract_norents_from_equipped(ch); Crash_extract_norents(ch->carrying); cost_eq = 0; for (j = 0; j < NUM_WEARS; j++) Crash_calculate_rent(GET_EQ(ch,j), &cost_eq); cost = 0; Crash_calculate_rent(ch->carrying, &cost); cost <<= 1; /* forcerent cost is 2x normal rent */ cost_eq <<= 1; if (cost+cost_eq > GET_GOLD(ch) + GET_BANK_GOLD(ch)) { for (j = 0; j < NUM_WEARS; j++) /* unequip player with low money */ if (GET_EQ(ch,j)) obj_to_char(unequip_char(ch, j), ch); cost += cost_eq; cost_eq = 0; } while ((cost+cost_eq > GET_GOLD(ch) + GET_BANK_GOLD(ch)) && ch->carrying) { Crash_extract_expensive(ch->carrying); cost = 0; Crash_calculate_rent(ch->carrying, &cost); cost <<= 1; } if (!ch->carrying) { for (j = 0; j < NUM_WEARS && !(GET_EQ(ch,j)); j++) ; if (j == NUM_WEARS) { /* no eq nor inv */ fclose(fp); Crash_delete_file(GET_NAME(ch)); return; } } rent.net_cost_per_diem = cost; rent.rentcode = RENT_TIMEDOUT; rent.time = time(0); rent.gold = GET_GOLD(ch); rent.account = GET_BANK_GOLD(ch); if (!Crash_write_rentcode(ch, fp, &rent)) { fclose(fp); return; } for (j = 0; j < NUM_WEARS; j++) { if (GET_EQ(ch,j)) { if (!Crash_save(GET_EQ(ch,j), fp, j+1)) { fclose(fp); return; } Crash_restore_weight(GET_EQ(ch,j)); Crash_extract_objs(GET_EQ(ch,j)); } } if (!Crash_save(ch->carrying, fp, 0)) { fclose(fp); return; } fclose(fp); Crash_extract_objs(ch->carrying); }
int Crash_clean_file(char *name) { char fname[MAX_STRING_LENGTH], filetype[20]; struct rent_info rent; extern int rent_file_timeout, crash_file_timeout; FILE *fl; if (!get_filename(name, fname, CRASH_FILE)) return 0; /* * open for write so that permission problems will be flagged now, at boot * time. */ if (!(fl = fopen(fname, "r+b"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ sprintf(buf1, "SYSERR: OPENING OBJECT FILE %s (4)", fname); perror(buf1); } return 0; } if (!feof(fl)) fread(&rent, sizeof(struct rent_info), 1, fl); fclose(fl); #define LIMITED_ITEMS 0 #if LIMITED_ITEMS for (j = 0; j < rent.nitems; j++) if (IS_OBJ_STAT(obj_elem.extra_flags, ITEM_LIMITED)) { limited_objs[i] = obj_elem.item_number; i++; } #endif if ((rent.rentcode == RENT_CRASH) || (rent.rentcode == RENT_FORCED) || (rent.rentcode == RENT_TIMEDOUT)) { if (rent.time < time(0) - (crash_file_timeout * SECS_PER_REAL_DAY)) { Crash_delete_file(name); switch (rent.rentcode) { case RENT_CRASH: strcpy(filetype, "crash"); break; case RENT_FORCED: strcpy(filetype, "forced rent"); break; case RENT_TIMEDOUT: strcpy(filetype, "idlesave"); break; default: strcpy(filetype, "UNKNOWN!"); break; } sprintf(buf, " Deleting %s's %s file.", name, filetype); log(buf); return 1; } /* Must retrieve rented items w/in 30 days */ } else if (rent.rentcode == RENT_RENTED) if (rent.time < time(0) - (rent_file_timeout * SECS_PER_REAL_DAY)) { Crash_delete_file(name); sprintf(buf, " Deleting %s's rent file.", name); log(buf); return 1; } return (0); }
void Crash_idlesave(struct char_data *ch) { char buf[MAX_INPUT_LENGTH]; struct rent_info rent; int j; int cost, cost_eq; FILE *fp; if (IS_NPC(ch)) return; if (!get_filename(buf, sizeof(buf), CRASH_FILE, GET_NAME(ch))) return; if (!(fp = fopen(buf, "w"))) return; Crash_extract_norent_eq(ch); Crash_extract_norents(ch->carrying); cost = 0; Crash_calculate_rent(ch->carrying, &cost); cost_eq = 0; for (j = 0; j < NUM_WEARS; j++) Crash_calculate_rent(GET_EQ(ch, j), &cost_eq); cost += cost_eq; cost *= 2; /* forcerent cost is 2x normal rent */ if (cost > GET_GOLD(ch) + GET_BANK_GOLD(ch)) { for (j = 0; j < NUM_WEARS; j++) /* Unequip players with low gold. */ if (GET_EQ(ch, j)) obj_to_char(unequip_char(ch, j), ch); while ((cost > GET_GOLD(ch) + GET_BANK_GOLD(ch)) && ch->carrying) { Crash_extract_expensive(ch->carrying); cost = 0; Crash_calculate_rent(ch->carrying, &cost); cost *= 2; } } if (ch->carrying == NULL) { for (j = 0; j < NUM_WEARS && GET_EQ(ch, j) == NULL; j++) /* Nothing */ ; if (j == NUM_WEARS) { /* No equipment or inventory. */ fclose(fp); Crash_delete_file(GET_NAME(ch)); return; } } rent.net_cost_per_diem = cost; rent.rentcode = RENT_TIMEDOUT; rent.time = time(0); rent.gold = GET_GOLD(ch); rent.account = GET_BANK_GOLD(ch); fprintf(fp,"%d %d %d %d %d %d\r\n",rent.rentcode,rent.time, rent.net_cost_per_diem,rent.gold,rent.account,rent.nitems); for (j = 0; j < NUM_WEARS; j++) { if (GET_EQ(ch, j)) { if (!Crash_save(GET_EQ(ch, j), fp, j + 1)) { fclose(fp); return; } Crash_restore_weight(GET_EQ(ch, j)); Crash_extract_objs(GET_EQ(ch, j)); } } if (!Crash_save(ch->carrying, fp, 0)) { fclose(fp); return; } fprintf(fp, "$~\n"); fclose(fp); Crash_extract_objs(ch->carrying); }
int Crash_clean_file(char *name) { char fname[MAX_STRING_LENGTH], filetype[20]; struct rent_info rent; int numread; FILE *fl; int rentcode, timed, netcost, gold, account, nitems; char line[MAX_STRING_LENGTH]; if (!get_filename(fname, sizeof(fname), CRASH_FILE, name)) return (0); /* * open for write so that permission problems will be flagged now, at boot * time. */ if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) /* if it fails, NOT because of no file */ log("SYSERR: OPENING OBJECT FILE %s (4): %s", fname, strerror(errno)); return (0); } numread = get_line(fl,line); fclose(fl); if (numread == FALSE) return (0); sscanf(line, "%d %d %d %d %d %d",&rentcode,&timed,&netcost, &gold,&account,&nitems); rentcode = rent.rentcode; timed = rent.time; if ((rentcode == RENT_CRASH) || (rentcode == RENT_FORCED) || (rentcode == RENT_TIMEDOUT)) { if (timed < time(0) - (crash_file_timeout * SECS_PER_REAL_DAY)) { Crash_delete_file(name); switch (rentcode) { case RENT_CRASH: strcpy(filetype, "crash"); break; case RENT_FORCED: strcpy(filetype, "forced rent"); break; case RENT_TIMEDOUT: strcpy(filetype, "idlesave"); break; default: strcpy(filetype, "UNKNOWN!"); break; } log(" Deleting %s's %s file.", name, filetype); return (1); } /* Must retrieve rented items w/in 30 days */ } else if (rentcode == RENT_RENTED) if (timed < time(0) - (rent_file_timeout * SECS_PER_REAL_DAY)) { Crash_delete_file(name); log(" Deleting %s's rent file.", name); return (1); } return (0); }
int Crash_clean_file(char *name) { char fname[MAX_STRING_LENGTH]; char input[MAX_INPUT_LENGTH + 1]; char tag[MAX_INPUT_LENGTH + 1]; char tag_arguments[MAX_INPUT_LENGTH + 1]; int val; extern int rent_file_timeout, crash_file_timeout; FILE *fl; time_t rent_time = time(NULL); char *p; if (!get_filename(name, fname, CRASH_FILE)) { return 0; } if (!(fl = fopen(fname, "r"))) { if (errno != ENOENT) { /* if it fails, NOT because of no file */ sprintf(buf1, "SYSERR: OPENING OBJECT FILE %s (4)", fname); perror(buf1); } return 0; } while (get_line(fl, input)) { parse_pline(input, tag, tag_arguments); while ((p = strrchr(tag_arguments, '\n')) != NULL) { *p = '\0'; } val = atoi(tag_arguments); switch (tag[0]) { case 'r': case 'R': if (strcasecmp(tag, "rent_time") == 0) rent_time = val; else if (strcasecmp(tag, "rent_type") == 0) { fclose(fl); switch (val) { case RENT_CRASH: case RENT_FORCED: case RENT_TIMEDOUT: if (rent_time < (time(NULL) - (crash_file_timeout * SECS_PER_REAL_DAY))) { Crash_delete_file(name); switch (val) { case RENT_CRASH: sprintf(buf, " Deleting %s's crash file.", name); break; case RENT_FORCED: sprintf(buf, " Deleting %s's forced rent file.", name); break; case RENT_TIMEDOUT: sprintf(buf, " Deleting %s's idlesave file.", name); break; } stderr_log(buf); return 1; } break; case RENT_RENTED: case RENT_CAMPED: if (rent_time < (time(0) - (rent_file_timeout * SECS_PER_REAL_DAY))) { Crash_delete_file(name); switch (val) { case RENT_RENTED: sprintf(buf, " Deleting %s's rent file.", name); break; case RENT_CAMPED: sprintf(buf, " Deleting %s's camp file.", name); break; } stderr_log(buf); return 1; } } return 1; } break; } } return (0); }