void kill_queue(CHAR_DATA *ch) {
if ( !ch || !ch->desc)
return;
ch->desc->inbuf[0] = '\0';
ch->desc->resume[0] = '\0';
ch->lastBloodRoom = NULL; //<– this one is done here to avoid doing it everytime in track/bloodtrack skill
ch->lastTrackRoom = NULL;
}
void save_queue(CHAR_DATA *ch, bool isLast) {
if (!ch || !ch->desc)
return;
if (isLast)
sprintf(ch->desc->resume, "%s\n\r%s", ch->desc->inlast, ch->desc->inbuf);
else
sprintf(ch->desc->resume, "%s", ch->desc->inbuf);
ch->desc->inbuf[0] = '\0';
}
bool do_resume(CHAR_DATA *ch, char *argument) {
if ( !ch || !ch->desc)
return FALSE;
if (argument[0] != '\0') {
if ( !str_cmp(argument, "list")) {
if (ch->desc->resume[0] == '\0')
send_to_char("Your todo list is empty.\n\r", ch);
else
chprintf(ch, "Your todo list:\n\r%s", ch->desc->resume);
return TRUE;
}
if ( !str_cmp(argument, "clear")) {
if (ch->position != POS_DEAD)
send_to_char(ch->desc->resume[0] == '\0' ? "Your todo list was already empty.\n\r" : "Ok, todo list cleared.\n\r", ch);
ch->desc->resume[0] = '\0';
return TRUE;
}
send_to_char("Valid arguments: <list> <clear>\n\r", ch);
return FALSE;
}
if (ch->desc->resume[0] == '\0') {
send_to_char("Your todo list is empty.\n\r", ch);
return FALSE;
}
strcpy(ch->desc->inbuf, ch->desc->resume);
ch->desc->resume[0] = '\0';
return TRUE;
}
Basically, the command will clear your inbuf. Hence, aborting any commands you may have had stacked. It will happen on read_from_descriptor where it checks what it just read in and if its "abort" or maybe it has to be "abort\r\n"(not sure yet) it will clear the inbuf and tell the player it cleared the input after any wait_states expire.
I'm pretty sure how I will go about doing this, however, since I've really only used pre-written functions to deal with memory allocations and deallocations… I'm not sure how to clear the inbuf without causing a memory leak.
Can I just set d->inbuf[0] = '\0' ? I don't think I can use STRFREE on d->inbuf, but that's just because I don't know how d->inbuf is technically allocated since it uses the read() command.
Any input will be greatly appreciated. Thanks!