25 Aug, 2013, Davenge wrote in the 1st comment:
Votes: 0
I'm not sure if this should be here or in the C specific discussion. This is for Smaug, written in C.

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!
25 Aug, 2013, plamzi wrote in the 2nd comment:
Votes: 0
Davenge said:
Any input will be greatly appreciated. Thanks!


First, I would double-check if pending commands are really sitting in a simple buffer like that. Most codebases I know stick them in a command queue.

Assuming that they do, and assuming the inbuf is a pre-allocated array of chars/bytes, then you can empty it the way you're showing. There's no memory operation in that, so no danger of a memory leak.
25 Aug, 2013, Rarva.Riendf wrote in the 3rd comment:
Votes: 0
I am not sure about it but it seems like it is like ROM.
Basically inbuf being the command sent, you dont really want to deallocate the buffer anyway. d->inbuf[0] = '\0' should not only be enough, but the perfectly right solution.

Is not inbuf the basic command queue Plamzi ?
Because when I coded an abort/resume command I do nothing more than copying inbuf in my new 'resume' comand queue, then clearing inbuf.

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;
}


inbuf is the command queue, inlast behing the last command send for me it seems.

by the way davenge I made a kill queue snippet somewhere…

You may want to look at it.

http://www.mudbytes.net/index.php?a=past...

need to check if the code is up to date…not sure if there was any bug in there when I posted it.
25 Aug, 2013, Davenge wrote in the 4th comment:
Votes: 0
That's great, if you don't mind, I might even borrow that pause and resume concept.

Thanks for the responses.
26 Aug, 2013, Rarva.Riendf wrote in the 5th comment:
Votes: 0
Ok the snippet code seems to be the one I use. No bug reported from it yet. you are welcome to use it of course.
0.0/5