Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
void parse_quest(FILE *quest_file, int vnum)
{
  static int i = 0;

  struct char_data *mob = NULL;
  char line[MAX_INPUT_LENGTH];
  char value[MAX_INPUT_LENGTH];
  char field[20];
  int numval = 0;
  int nummsgs = 0;
  int numneeds = 0;
  int mob_rnum = 0;

  i++;
  mob_rnum = real_mobile(vnum);
  if (mob_rnum == -1) {
    stderr_log("Error trying to assign quest to non-existant mob.");
    fflush(NULL);
    exit(1);
  }
  mob = (mob_proto + mob_rnum);
  GET_MOB_QUEST_NUM(mob) = i;
  (mob_quests + i)->maxlevel = 51;
  (mob_quests + i)->qnum = i;
  while (get_line(quest_file, line)) {
    if (line[0] == 'S') {
      return;
    }
    parse_pline(line, field, value);
    numval = atoi(value);

    switch (UPPER(*field)) {
      case 'A':
        if (strcmp(field, "amount") == 0) {
          (mob_quests + i)->needs[numneeds].amount = numval;
          numneeds++;
          (mob_quests + i)->maxneeds = numneeds;
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'C':
        if (strcmp(field, "classlist") == 0) {
          (mob_quests + i)->classlist = asciiflag_conv(value);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'D':
        if (strcmp(field, "destroy") == 0) {
          if (strcasecmp(value, "no") == 0) {
            (mob_quests + i)->needs[numneeds].destroy = 0;
          }
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'F':
        if (strcmp(field, "flags") == 0) {
          (mob_quests + i)->flags = asciiflag_conv(value);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'G':
        if (strcmp(field, "goal") == 0) {
          (mob_quests + i)->goal = search_block(value, goal_list, FALSE);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'K':
        if (strcmp(field, "keywords") == 0) {
          RECREATE((mob_quests + i)->messages, struct quest_message_data, nummsgs + 1);
          (mob_quests + i)->messages[nummsgs].keywords = strdup(value);
        } else if (strcmp(field, "knowledge") == 0) {
          line[0] = '\0';
          (mob_quests + i)->knowledge = fread_string(quest_file, line);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'M':
        if (strcmp(field, "maxlevel") == 0) {
          (mob_quests + i)->maxlevel = numval;
        } else if (strcmp(field, "message") == 0) {
          line[0] = '\0';
          (mob_quests + i)->messages[nummsgs].message = fread_string(quest_file, line);
          nummsgs++;
          (mob_quests + i)->maxmsgs = nummsgs;
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'N':
        if (strcmp(field, "needs") == 0) {
          RECREATE((mob_quests + i)->needs, struct quest_needs_data, numneeds + 1);
          (mob_quests + i)->needs[numneeds].destroy = 1;
          (mob_quests + i)->needs[numneeds].participants = NULL;
          (mob_quests + i)->needs[numneeds].type = search_block(value, needs_list, FALSE);
          (mob_quests + i)->needs[numneeds].complete = 0;
          (mob_quests + i)->needs[numneeds].needs_complete_msg = NULL;
          (mob_quests + i)->needs[numneeds].need_more_msg = NULL;
        } else if (strcmp(field, "need_more_msg") == 0) {
Exemplo n.º 3
0
/* return values:
 0 - successful load, keep char in rent room.
 1 - load failure or load of crash items -- put char in temple.
 2 - rented equipment lost (no $)
 */
int Crash_load(struct char_data * ch)
{
  void Crash_save(struct char_data * ch, int type);
  FILE *fl;
  char fname[MAX_STRING_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char input[MAX_INPUT_LENGTH + 1];
  char tag[MAX_INPUT_LENGTH + 1];
  char tag_arguments[MAX_INPUT_LENGTH + 1];
  int val;
  struct obj_data *tmpobj = NULL;
  struct obj_data *tmpobj2;
  struct obj_data *next_obj;
  int found_begin = 0;
  int affect_counter = 0;
  int found;
  char *p;
  struct corpse_obj_save *crash_load_stack = NULL;
  struct corpse_obj_save *temp_stack = NULL;
  struct corpse_obj_save *temp_stack_next = NULL;
  int chg;
  int ovnum = 0;
  int j;

  if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) {
    return 1;
  }
  if (!(fl = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING OBJECT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n********************* NOTICE *********************\r\n"
          "There was a problem loading your objects from disk.\r\n"
          "Contact a God for assistance.\r\n", ch);
    }
    sprintf(buf, "%s entering game with no equipment.", GET_NAME(ch));
    mudlog(buf, 'R', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
    return 1;
  }

  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[4]) {
      case 'a':
      case 'A':
        if (strcasecmp(tag, "obj_affect_loc") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].location = val;
        } else if (strcasecmp(tag, "obj_affect_mod") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].modifier = val;
          affect_counter++;
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'b':
      case 'B':
        if (strcasecmp(tag, "obj_begin") == 0) {
          if (found_begin) {
            send_to_char("\r\n********************* NOTICE *********************\r\n"
                "There was a problem loading your objects from disk.\r\n"
                "Contact a God for assistance.\r\n", ch);
            return 1;
          }
          found_begin = 1;
        } else if (strcasecmp(tag, "obj_bitvector") == 0) {
          GET_OBJ_BITV(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_bitvector2") == 0) {
          GET_OBJ_BITV2(tmpobj) = asciiflag_conv(tag_arguments);
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'e':
      case 'E':
        if (strcasecmp(tag, "obj_extra_flags") == 0) {
          GET_OBJ_EXTRA(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_end") == 0) {
          if (ovnum >= 0) {
            if (!found_begin) {
              send_to_char("\r\n********************* NOTICE *********************\r\n"
                  "There was a problem loading your objects from disk.\r\n"
                  "Contact a God for assistance.\r\n", ch);
              return 1;
            }
            found_begin = 0;
            affect_counter = 0;

            CREATE(crash_load_stack, struct corpse_obj_save, 1);
            crash_load_stack->level = 0;
            crash_load_stack->prev = NULL;

            for (tmpobj2 = ch->carrying, found = 0; tmpobj2 && !found; tmpobj2 = next_obj) {
              next_obj = tmpobj2->next_content;
              if (tmpobj2->objnum == tmpobj->inobj) {
                obj_to_obj(tmpobj, tmpobj2);
                found = 1;
              }
              if (tmpobj2->contains) {
                crash_load_stack->next_obj = next_obj;
                CREATE(temp_stack, struct corpse_obj_save, 1);
                temp_stack->level = crash_load_stack->level + 1;
                temp_stack->prev = crash_load_stack;
                crash_load_stack = temp_stack;
                next_obj = tmpobj2->contains;
                if (tmpobj2 == next_obj) {
                  /* infinite loop */
                  next_obj = NULL;
                  continue;
                }
              } else if (next_obj == NULL && crash_load_stack->level > 0) {
                temp_stack = crash_load_stack;
                crash_load_stack = crash_load_stack->prev;
                FREE(temp_stack);
                next_obj = crash_load_stack->next_obj;
              }
            }
            for (temp_stack = crash_load_stack; temp_stack; temp_stack = temp_stack_next) {
              temp_stack_next = temp_stack->prev;
              FREE(temp_stack);
            }
            if (!found) {
              obj_to_char(tmpobj, ch);
            }
          } else {
            extract_obj(tmpobj);
            found_begin = 0;
            affect_counter = 0;
            ovnum = 0;
          }
        } else {
Exemplo n.º 4
0
void Crash_listrent(struct char_data * ch, char *name)
{
  FILE *fl;
  char fname[MAX_INPUT_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char input[MAX_INPUT_LENGTH + 1];
  char tag[MAX_INPUT_LENGTH + 1];
  char tag_arguments[MAX_INPUT_LENGTH + 1];
  char *p;
  struct obj_data *obj;
  int val = 0;
  time_t rent_time;
  int d;
  int h;
  int m;

  if (!get_filename(name, fname, CRASH_FILE)) {
    return;
  }
  if (!(fl = fopen(fname, "r"))) {
    sprintf(buf, "%s has no rent file.\r\n", name);
    send_to_char(buf, ch);
    return;
  }

  sprintf(buf, "%s\r\n", fname);
  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 'o':
      case 'O':
        if (strcasecmp(tag, "obj_number") == 0) {
          if (real_object(val) > -1) {
            obj = read_object_q(val, VIRTUAL);
            sprintf(buf, "%s [%5d] %-20s\r\n", buf, val, obj->short_description);
            extract_obj_q(obj);
          }
        }
        break;
      case 'r':
      case 'R':
        if (strcasecmp(tag, "rent_version") == 0) {
          sprintf(buf, "%sVersion: %d\r\n", buf, val);
        } else if (strcasecmp(tag, "rent_time") == 0) {
          rent_time = time(0) - val;
          d = rent_time / 86400;
          h = (rent_time / 3600) % 24;
          m = (rent_time / 60) % 60;
          sprintf(buf, "%sRented %d day%s, %d hour%s, %d minute%s ago.\r\n", buf, d, ((d == 1) ? "" : "s"), h, ((h == 1) ? "" : "s"), m, ((m == 1) ? "" : "s"));
        } else if (strcasecmp(tag, "rent_type") == 0)
          switch (val) {
            case RENT_RENTED:
              sprintf(buf, "%sType: Rent\r\n", buf);
              break;
            case RENT_CRASH:
              sprintf(buf, "%sType: Crash\r\n", buf);
              break;
            case RENT_CRYO:
              sprintf(buf, "%sType: Cryo\r\n", buf);
              break;
            case RENT_TIMEDOUT:
            case RENT_FORCED:
              sprintf(buf, "%sType: TimedOut\r\n", buf);
              break;
            case RENT_CAMPED:
              sprintf(buf, "%sType: Camped\r\n", buf);
              break;
            default:
              sprintf(buf, "%sType: Undef\r\n", buf);
              break;
          }
        break;
    }
  }
  page_string(ch->desc, buf, 1);
  fclose(fl);
}
Exemplo n.º 5
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);
}