Not sure if anyone has noticed, but anytime that you execute a shell command ( compile, grep, etc) using the shell.c snippet installed in AFK and available on the download site, it turns off MCCP for obvious reasons, but does not re-initialize it if it was on. I'm using something like this:
void command_pipe(CHAR_DATA * ch, char *argument)
{
char buf[MAX_STRING_LENGTH];
FILE *fp;
#ifdef MCCP
int compressing = ch->desc->compressing;
compressEnd(ch->desc);
#endif
set_char_color(AT_RED, ch);
fp = popen(argument, "r"
;
fgetf(buf, MAX_STRING_LENGTH, fp);
send_to_pager(buf, ch);
pclose(fp);
#ifdef MCCP
if (compressing)
compressstart(ch->desc, compressing);
#endif
return;
}
CMDF do_mudexec(CHAR_DATA * ch, char *argument)
{
int desc;
int flags;
pid_t pid;
bool iafork = FALSE;
#ifdef MCCP
int compressing = 0;
#endif
if (!ch->desc)
return;
if (argument == NULL || argument[0] == '�')
return;
if (strncasecmp(argument, "ia ", 3) == 0)
{
argument += 3;
iafork = TRUE;
}
desc = ch->desc->descriptor;
set_char_color(AT_PLAIN, ch);
#ifdef MCCP
compressing = ch->desc->compressing;
compressEnd(ch->desc);
#endif
if ((pid = fork()) == 0)
{
char buf[1024];
char *p = argument;
#ifdef USEGLOB
glob_t g;
#else
char **argv;
int argc = 1;
#endif
#ifdef DEBUGGLOB
int argc = 0;
#endif
flags = fcntl(desc, F_GETFL, 0);
flags &= ~FNDELAY;
fcntl(desc, F_SETFL, flags);
if (iafork)
{
send_telcode(desc, WILL, TELOPT_SGA);
/*
* send_telcode( desc, DO, TELOPT_NAWS );
*/
send_telcode(desc, DO, TELOPT_LFLOW);
send_telcode(desc, DONT, TELOPT_LINEMODE);
send_telcode(desc, WILL, TELOPT_STATUS);
send_telcode(desc, DO, TELOPT_ECHO);
send_telcode(desc, WILL, TELOPT_ECHO);
read(desc, buf, 1024); /* read replies */
}
dup2(desc, STDIN_FILENO);
dup2(desc, STDOUT_FILENO);
dup2(desc, STDERR_FILENO);
setenv("TERM", "vt100", 1);
setenv("COLUMNS", "80", 1);
setenv("LINES", "24", 1);
#ifdef USEGLOB
g.gl_offs = 1;
p = strtok(argument, " "
;
if (p && (p = strtok(NULL, " "
) != NULL)
{
glob(p, GLOB_DOOFFS | GLOB_NOCHECK, NULL, &g);
if (!g.gl_pathv[g.gl_pathc - 1])
g.gl_pathv[g.gl_pathc - 1] = p;
}
else
{
glob(argument, GLOB_DOOFFS | GLOB_NOCHECK, NULL, &g);
++(g.gl_pathv);
// execvp( g.gl_pathv[0], ++(g.gl_pathv) );
}
while (p && (p = strtok(NULL, " "
) != NULL)
{
glob(p, GLOB_DOOFFS | GLOB_NOCHECK | GLOB_APPEND,
NULL, &g);
if (!g.gl_pathv[g.gl_pathc - 1])
g.gl_pathv[g.gl_pathc - 1] = p;
}
g.gl_pathv[0] = argument;
#ifdef DEBUGGLOB
for (argc = 0; argc desc, compressing);
#endif
fprintf(stderr, "Shell process: %s failed!\n", argument);
perror("mudexec"
;
exit(0);
}
else if (pid desc->process = pid;
ch->desc->connected = iafork ? CON_IAFORKED : CON_FORKED;
}
}
I added another structure field to store if it was compressed, and modifed the mccp to look something like this:
bool compressEnd(DESCRIPTOR_DATA * d)
{
unsigned char dummy[1];
if (!d->out_compress)
return TRUE;
/* bug("Stopping compression for descriptor %d", d->descriptor); */
d->out_compress->avail_in = 0;
d->out_compress->next_in = dummy;
if (deflate(d->out_compress, Z_FINISH) != Z_STREAM_END)
return FALSE;
if (!process_compressed(d)) /* try to send any residual data */
return FALSE;
deflateEnd(d->out_compress);
DISPOSE(d->out_compress_buf);
DISPOSE(d->out_compress);
d->shellcompressing = d->compressing;
d->compressing = 0;
return TRUE;
}
This tells it to re-initialize it later. There is also the original initializer in comm.c for the new field to set it to 0.
P.S. Damn, I started reading "The C++ programing Language" by Bjarne Stroustrup, and damn constructors and destructors for objects are a fantastic concept. Heh, still just at the beginning, though. Anyways, hope that helps someone.