Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, DotBot

Members: 0
Guests: 8
Stats
Files
Topics
Posts
Members
Newest Member
481
3,739
19,386
625
OmarHarrim
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Smaug Snippets » MCCP and Shell code
Forum Rules | Mark all | Recent Posts

MCCP and Shell code
< Newer Topic :: Older Topic > Not sure if this is known...

Pages:<< prev 1 next >>
Post is unread #1 Jun 12, 2004, 11:29 pm   Last edited Nov 18, 2007, 4:53 pm by Samson
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

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.
       
Post is unread #2 Jun 13, 2004, 9:39 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002


it turns off MCCP for obvious reasons, but does not re-initialize it if it was on.


It should turn it back on again after you're done in the shell and you type something. It always has for myself anyway. If this is not happening anymore then it's a bug somewhere and it will need to be found.

At the end of DESCRIPTOR_DATA, there is a field called can_compress which is already keeping track of the connection's ability to compress. In read_from_buffer this value is checked, and if TRUE, it restarts compression on the descriptor at that point.
       
Post is unread #3 Jun 13, 2004, 9:59 pm
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

My bad, I should not have said AFK, only the snippet itself. Since having compression restarted at the beginning of write_to_descriptor is not in my code ( don't have a clue about other MCCP base ), I wrongly assumed that no one did that. Still though, if it happened to me, its possible that someone else using the shell snippet on a non-AFK mud codebase may have this issue, I thought it would be worth bringing up.

Perhaps someone should come up with a full SMAUG MCCP snippet. I don't think I've ever seen one, only pulling from other code bases and a few website describing it. I'd be more than willing, if people would be interested, assuming there is not one available in other places.
       
Pages:<< prev 1 next >>