Welcome to the Builder Academy

Question Clan Withdraw crashing game

More
21 Jun 2022 06:20 #10087 by Nero
Having an issue where when trying to do the cwithdraw it crashes the game but only if the user is not applying to a clan.
For example, if a player applies to a clan then withdraws it works, but if they do the same command again it crashes the game.
I am not sure what I am missing here:
Code:
/* Reject an applicant from a clan/Withdraw an application */  void do_creject( struct char_data *ch, struct clan_type *cptr, struct char_data *vict)  {    int i=0;    long leader;    char buf[MAX_STRING_LENGTH];     if (vict != ch) {      if (vict != NULL) {        /* send some sort of mail to player notifying him/her of rejection */        sprintf(buf, "Your application to %s has been removed from consideration by %s.\r\n",          cptr->name, cptr->leadersname);        send_to_char(vict, buf);      }    } else {          for (i=0; i<MAX_APPLICANTS; i++) {          if (!str_cmp(cptr->applicants[i], GET_NAME(vict))) {           send_to_char(vict, "You aren't applying to the clan...\r\n");           break;          }        }        leader = get_id_by_name(cptr->leadersname);        sprintf(buf, "I have withdrawn my application from the clan.\r\n",          cptr->leadersname, GET_NAME(ch));          send_to_char(ch, buf);      }    GET_CLAN(vict) = CLAN_NONE;    GET_CLAN_RANK(vict) = 0;    save_char(vict, NOWHERE);    /* now remove the player from the petition list */    remove_applicant(cptr, vict);    save_clans();    return;  }
Code:
/*** cwithdraw ***/    case SCMD_CLAN_WITHDRAW:      skip_spaces(&argument);      if (!*argument) {        send_to_char(ch, "Withdraw application to which clan?\r\n");        return;      }      if (!is_number(argument)) {        send_to_char(ch, "You cannot withdraw someone else's application.\r\n");      }      for (cptr = clan_info; cptr && cptr->number != atoi(argument); cptr = cptr->next);      if (cptr == NULL) {        send_to_char(ch, "That clan does not exist.\r\n");        return;      }      do_creject( ch, cptr, ch );      return;      break;

Please Log in or Create an account to join the conversation.

More
21 Jun 2022 20:04 - 21 Jun 2022 20:07 #10088 by thomas
Replied by thomas on topic Clan Withdraw crashing game
The logic is a bit off - str_cmp returns 0 if the strings are the same. This means this bit doesn't work:

Code:
for (i=0; i<MAX_APPLICANTS; i++) { if (!str_cmp(cptr->applicants[ i], GET_NAME(vict))) { send_to_char(vict, "You aren't applying to the clan...\r\n"); break; } }


Here, you're looping the list of applicants, and if you find the name, you're printing the message and breaking. But if you don't find the name, you are continuing the loop. And I figure there's a NULL in that list, making str_cmp fail.
What you were probably aiming for is this:

Code:
for (i=0; i<MAX_APPLICANTS; i++) { if (cptr->applicants[ i] && !str_cmp(cptr->applicants[ i], GET_NAME(vict))) {   break; } } if (i == MAX_APPLICANTS) { send_to_char(vict, "You aren't applying to the clan...\r\n"); return; }


or something like that.
Last edit: 21 Jun 2022 20:07 by thomas. Reason: typo
The following user(s) said Thank You: Nero

Please Log in or Create an account to join the conversation.

More
22 Jun 2022 00:08 #10089 by Nero
Replied by Nero on topic Clan Withdraw crashing game
Looks like this may be working thanks! Will continue to further test

Please Log in or Create an account to join the conversation.

More
22 Jun 2022 08:39 #10090 by Nero
Replied by Nero on topic Clan Withdraw crashing game
Thanks it seems to be working now
One last thing for clans that I seem to be stuck on is purging them
I had to create a new menu called cledit.c
One issue with it is that if I am creating a clan and decide to use Q to quit, it still saves the clan in the clist
if I go back and try to use P to purge the account it does some real wonky stuff that requires a boot in order to remove the stuff from clist or it crashes
Code:
/* external functions */  extern struct char_data *find_clan_char(struct char_data *ch, char *arg);  /******************************************************************************/ /** Internal Functions                                                       **/ /******************************************************************************/ void cedit_clan_menu(struct descriptor_data *d); void cedit_setup_new(struct descriptor_data *d); void cedit_save_to_disk( void ); void save_config( IDXTYPE nowhere );  ACMD(do_oasis_cledit) {   int number = 0, save = 0, real_num;   struct descriptor_data *d;   struct clan_type *cptr = NULL;   char buf1[MAX_STRING_LENGTH];     /****************************************************************************/   /** Parse any arguments.                                                   **/   /****************************************************************************/   one_argument(argument, buf1);     if (!*buf1) {     send_to_char(ch, "Specify a clan VNUM to edit.\r\n");     return;   } else if (!isdigit(*buf1)) {     if (str_cmp("save", buf1) == 0) {       save = TRUE;       number = 0;     }else{       send_to_char(ch, "Yikes!  Stop that, someone will get hurt!\r\n");       return;     }   }   /****************************************************************************/   /** If a numeric argument was given (like a room number), get it.          **/   /****************************************************************************/   if (number == 0)     number = atoi(buf1);     /****************************************************************************/   /** Check that whatever it is isn't already being edited.                  **/   /****************************************************************************/   for (d = descriptor_list; d; d = d->next) {     if (STATE(d) == CON_CLEDIT) {       if (d->olc && OLC_CLAN(d) == number) {         send_to_char(ch, "That clan is currently being edited by %s.\r\n",           GET_NAME(d->character));         return;        }     }   }          d = ch->desc;     /****************************************************************************/   /** Give descriptor an OLC structure.                                      **/   /****************************************************************************/   if (d->olc) {     mudlog(BRF, LVL_IMMORT, TRUE,       "SYSERR: do_oasis_cledit: Player already had olc structure.");     free(d->olc);   }     CREATE(d->olc, struct oasis_olc_data, 1);     /****************************************************************************/   /** If save is TRUE, save the mobiles.                                     **/   /****************************************************************************/   if (save) {     send_to_char(ch, "Saving all clans\r\n");     mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(ch)), TRUE,       "OLC: %s saves clans.",       GET_NAME(ch));          /**************************************************************************/     /** Save the clans.                                                    **/     /**************************************************************************/     save_clans();          /**************************************************************************/     /** Free the olc structure stored in the descriptor.                     **/     /**************************************************************************/     free(d->olc);     d->olc = NULL;     return;     }       OLC_CLAN(d) = number;     /****************************************************************************/   /** If this is a new mobile, setup a new one, otherwise, setup the         **/   /** existing mobile.                                                       **/   /****************************************************************************/   if (number == 0) {        cedit_setup_new(d);   }     else {        for (cptr = clan_info; cptr && cptr->number != number; cptr=cptr->next);         if (cptr && (cptr->number == number)) {           OLC_CLAN(d) = cptr;           cedit_clan_menu(d);         } else {           send_to_char(d->character, "Invalid clan number!\r\n");           return;           }     }        STATE(d) = CON_CLEDIT;     /****************************************************************************/   /** Display the OLC messages to the players in the same room as the        **/   /** builder and also log it.                                               **/   /****************************************************************************/   act("$n starts using OLC.", TRUE, d->character, 0, 0, TO_ROOM);   SET_BIT_AR(PLR_FLAGS(ch), PLR_WRITING);     mudlog(BRF, MAX(LVL_IMPL, GET_INVIS_LEV(d->character)), TRUE,"OLC: %s starts editing clans",     GET_NAME(ch)); } void cedit_clan_menu(struct descriptor_data * d)  {   char buf[MAX_STRING_LENGTH];       if (!OLC_CLAN(d))      cedit_setup_new(d);      get_char_colors(d->character);  write_to_output(d,      "-- Clan number : [%s%d%s]\r\n"      "%s1%s) Name        : %s%s\r\n"      "%s2%s) Leader      : %s%s\r\n"      "%s4%s) Clan Abbrev : %s%s\r\n"      "%sP%s) Purge this Clan\r\n"      "%sQ%s) Quit\r\n"      "Enter choice : ",            cyn, OLC_CLAN(d)->number, nrm,      grn, nrm, yel, OLC_CLAN(d)->name,      grn, nrm, yel, OLC_CLAN(d)->leadersname,      grn, nrm, yel, OLC_CLAN(d)->member_look_str ?      OLC_CLAN(d)->member_look_str : OLC_CLAN(d)->name,      grn, nrm,      grn, nrm      );    OLC_MODE(d) = CEDIT_CLAN_MENU;  }    void cedit_free_clan(struct clan_type *cptr)  {    dequeue_clan(cptr->number);  }    void cledit_parse(struct descriptor_data *d, char *arg)  {    char buf[MAX_STRING_LENGTH];    switch (OLC_MODE(d)) {    case CEDIT_CONFIRM_SAVE:      switch (*arg) {      case 'y':      case 'Y':        save_clans();           mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE,                  "OLC: %s modifies the game configuration.", GET_NAME(d->character));           cleanup_olc(d, CLEANUP_CONFIG);       if (CONFIG_AUTO_SAVE) {          save_clans();         write_to_output(d, "Game configuration saved to disk.\r\n");       } else           write_to_output(d, "Game configuration saved to memory.\r\n");           return;      case 'n':      case 'N':        /* free everything up, including strings etc */        cleanup_olc(d, CLEANUP_STRUCTS);        break;      default:        write_to_output(d, "Invalid choice!\r\nDo you wish to save your changes? : ");        break;      }      return;      case CEDIT_CLAN_MENU:        switch (*arg) {        case '1':          write_to_output(d, "Enter clan name:-\r\n| ");          OLC_MODE(d) = CEDIT_NAME;          break;        case '2':          write_to_output(d, "Enter clan leader's name: ");          OLC_MODE(d) = CEDIT_LEADERSNAME;          break;        case '4':          write_to_output(d, "Enter clan member who string:-\r\n| ");          OLC_MODE(d) = CEDIT_MBR_LOOK_STR;          break;        case 'p':        case 'P':          if (GET_LEVEL(d->character) >= LVL_IMPL) {            newclan = OLC_CLAN(d)->number;  /* next new clan will get this one's number  */            /* free everything up, including strings etc */            cleanup_olc(d, CLEANUP_ALL);            cnum--;            write_to_output(d, "Clan purged.\r\n");          } else {            write_to_output(d, "Sorry you are not allowed to do that at this time.\r\n");            cedit_clan_menu(d);          }          return;                  case 'q':         case 'Q':          if (OLC_VAL(d)) {           write_to_output(d, "Do you wish to save the configuration? (y/n) : ");           OLC_MODE(d) = CEDIT_CONFIRM_SAVE;            } else            cleanup_olc(d, CLEANUP_STRUCTS);           return;        default:          write_to_output(d, "Invalid choice!");          cedit_clan_menu(d);          break;        }        return;        case CEDIT_NAME:          if (OLC_CLAN(d)->name)            free(OLC_CLAN(d)->name);          OLC_CLAN(d)->name = str_udup(arg);          break;        case CEDIT_LEADERSNAME:          if (OLC_CLAN(d)->leadersname)            free(OLC_CLAN(d)->leadersname);          OLC_CLAN(d)->leadersname = str_udup(arg);          break;        case CEDIT_MBR_LOOK_STR:          if (OLC_CLAN(d)->member_look_str)            free(OLC_CLAN(d)->member_look_str);          OLC_CLAN(d)->member_look_str = str_udup(arg);          break;                  default:          /* we should never get here */          mudlog("SYSERR: Reached default case in cledit_parse",BRF,LVL_GOD,TRUE);          break;     }     /* If we get this far, something has been changed */     OLC_VAL(d) = 1;     cedit_clan_menu(d);  }    /*  * Create a new clan with some default strings.  */  void cedit_setup_new(struct descriptor_data *d)  {    int i;    if ((OLC_CLAN(d) = enqueue_clan()) != NULL) {      OLC_CLAN(d)->name = str_udup("Unfinished Clan");      OLC_CLAN(d)->number = newclan;      OLC_CLAN(d)->leadersname = str_udup("NoOne");      OLC_CLAN(d)->member_look_str = NULL;      OLC_CLAN(d)->clan_entr_room = 1;      OLC_CLAN(d)->clan_password = str_udup("none");      OLC_CLAN(d)->gold = 0;      for (i = 0; i < 20; i++)        OLC_CLAN(d)->applicants[i] = NULL;    } else      fprintf(stderr, "SYSERR: Unable to create new clan!\r\n");    cnum++;    if (newclan == cnum)      newclan++;    else      newclan = cnum;    cedit_clan_menu(d);    OLC_VAL(d) = 0;  } [attachment=232]clan.PNG[/attachment] [attachment=233]clan2.PNG[/attachment]
 

Please Log in or Create an account to join the conversation.

More
22 Jun 2022 18:07 #10091 by thomas
Replied by thomas on topic Clan Withdraw crashing game
I haven't looked too much on the actual state machine, but I'm pretty sure you don't want the call to cedit_clan_menu(d); in the cedit_setup_new function.

Please Log in or Create an account to join the conversation.

More
20 Jul 2022 22:38 #10105 by cunning
Replied by cunning on topic Clan Withdraw crashing game
You dont, but i havent used that code in a long time.

Nero i know Thomas is an expert. However, the rest of us might need the core output debug to know what to look at and what was going on :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.225 seconds