Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 Couple bugs
Yesterday, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, DotBot, Google

Members: 0
Guests: 19
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWR FUSS » SWR MCCP
Forum Rules | Mark all | Recent Posts

SWR MCCP
< Newer Topic :: Older Topic > How to add it

Pages:<< prev 1 next >>
Post is unread #1 Sep 14, 2005, 5:11 pm   Last edited Mar 10, 2008, 7:02 pm by Samson
Go to the top of the page
Go to the bottom of the page

Greven
Magician
GroupMembers
Posts204
JoinedMar 5, 2005

This is the instructions that Samson gave on how to add MCCP to a SMAUGFUSS, but modified to fit with SWRFUSS.

This enhancement requires the use of the zlib package

---

Put the mccp.c and mccp.h files in your src directory.
Makefile

After makeobjs.c, add: mccp.c and make sure you leave a space before the \

Locate:
L_FLAGS = $(PROF) $(SOLARIS_LINK)

Change to:
L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz


mud.h

In struct descriptor_data, locate:
   DESCRIPTOR_DATA *next;
   DESCRIPTOR_DATA *prev;
   DESCRIPTOR_DATA *snoop_by;
   CHAR_DATA *character;
   CHAR_DATA *original;


Below that, add:
   struct mccp_data *mccp; /* Mud Client Compression Protocol */
   bool can_compress;


Locate:
DECLARE_DO_FUN( do_compare );

Below, add:
DECLARE_DO_FUN( do_compress );


comm.c

Locate:
#include "mud.h"
#include "md5.h"

Below that, add:
#include "mccp.h"


Locate:
bool write_to_descriptor args( ( int desc, char *txt, int length ) );

Change to:
bool write_to_descriptor( DESCRIPTOR_DATA * d, char *txt, int length );

Locate the write_to_descriptor function, and replace it with the following:
/*
* This is the MCCP version. Use write_to_descriptor_old to send non-compressed
* text.
* Updated to run with the block checks by Orion... if it doesn't work, blame
* him.;P -Orion
*/
bool write_to_descriptor( DESCRIPTOR_DATA * d, char *txt, int length )
{
   int iStart = 0;
   int nWrite = 0;
   int nBlock;
   int iErr;
   int len;

   if( length <= 0 )
      length = strlen( txt );

   if( d && d->mccp->out_compress )
   {
      d->mccp->out_compress->next_in = ( unsigned char * )txt;
      d->mccp->out_compress->avail_in = length;

      while( d->mccp->out_compress->avail_in )
      {
         d->mccp->out_compress->avail_out =
            COMPRESS_BUF_SIZE - ( d->mccp->out_compress->next_out - d->mccp->out_compress_buf );

         if( d->mccp->out_compress->avail_out )
         {
            int status = deflate( d->mccp->out_compress, Z_SYNC_FLUSH );

            if( status != Z_OK )
               return FALSE;
         }

         len = d->mccp->out_compress->next_out - d->mccp->out_compress_buf;
         if( len > 0 )
         {
            for( iStart = 0; iStart < len; iStart += nWrite )
            {
               nBlock = UMIN( len - iStart, 4096 );
               nWrite = send( d->descriptor, d->mccp->out_compress_buf + iStart, nBlock, 0 );
               if( nWrite == -1 )
               {
                  iErr = errno;
                  if( iErr == EWOULDBLOCK )
                  {
                     /*
                      * This is a SPAMMY little bug error. I would suggest
                      * not using it, but I've included it in case. -Orion
                      *
                      perror( "Write_to_descriptor: Send is blocking" );
                      */
                     nWrite = 0;
                     continue;
                  }
                  else
                  {
                     perror( "Write_to_descriptor" );
                     return FALSE;
                  }
               }

               if( !nWrite )
                  break;
            }

            if( !iStart )
               break;

            if( iStart < len )
               memmove( d->mccp->out_compress_buf, d->mccp->out_compress_buf + iStart, len - iStart );

            d->mccp->out_compress->next_out = d->mccp->out_compress_buf + len - iStart;
         }
      }
      return TRUE;
   }

   for( iStart = 0; iStart < length; iStart += nWrite )
   {
      nBlock = UMIN( length - iStart, 4096 );
      nWrite = send( d->descriptor, txt + iStart, nBlock, 0 );
      if( nWrite == -1 )
      {
         iErr = errno;
         if( iErr == EWOULDBLOCK )
         {
            /*
             * This is a SPAMMY little bug error. I would suggest
             * not using it, but I've included it in case. -Orion
             *
             perror( "Write_to_descriptor: Send is blocking" );
             */
            nWrite = 0;
            continue;
         }
         else
         {
            perror( "Write_to_descriptor" );
            return FALSE;
         }
      }
   }
   return TRUE;
}

/*
 *
 * Added block checking to prevent random booting of the descriptor. Thanks go
 * out to Rustry for his suggestions. -Orion
 */
bool write_to_descriptor_old( int desc, char *txt, int length )
{
   int iStart = 0;
   int nWrite = 0;
   int nBlock = 0;
   int iErr = 0;

   if( length <= 0 )
      length = strlen( txt );

   for( iStart = 0; iStart < length; iStart += nWrite )
   {
      nBlock = UMIN( length - iStart, 4096 );
      nWrite = send( desc, txt + iStart, nBlock, 0 );

      if( nWrite == -1 )
      {
         iErr = errno;
         if( iErr == EWOULDBLOCK )
         {
            /*
             * This is a SPAMMY little bug error. I would suggest
             * not using it, but I've included it in case. -Orion
             *
             perror( "Write_to_descriptor: Send is blocking" );
             */
            nWrite = 0;
            continue;
         }
         else
         {
            perror( "Write_to_descriptor" );
            return FALSE;
         }
      }
   }
   return TRUE;
}

game_loop

Locate:
            write_to_descriptor( d->descriptor, "Idle timeout... disconnecting.\n\r", 0 );

Change to:
            write_to_descriptor( d, "Idle timeout... disconnecting.\n\r", 0 );

new_descriptor

Locate:
   dnew->port = ntohs( sock.sin_port );
   dnew->newstate = 0;
   dnew->prevcolor = 0x07;

Below that, add:
   dnew->can_compress = FALSE;
   CREATE( dnew->mccp, MCCP, 1 );

Locate:
      write_to_descriptor( desc, "Your site has been banned from this Mud.\n\r", 0 );

Change to:
      write_to_descriptor( dnew, "Your site has been banned from this Mud.\n\r", 0 );

Locate:
   LINK( dnew, first_descriptor, last_descriptor, next, prev );

Below that, add:
   /*
    * MCCP Compression 
    */
   write_to_buffer( dnew, will_compress2_str, 0 );

read_from_descriptor

Locate:
      write_to_descriptor( d->descriptor, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );

Change to:
      write_to_descriptor( d, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );

read_from_buffer

Locate:
   int i, j, k;

Change to:
   int i, j, k, iac = 0;

Locate:
   /*
    * Canonical input processing.
    */
   for( i = 0, k = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++ )
   {
      if( k >= 254 )
      {
         write_to_descriptor( d->descriptor, "Line too long.\n\r", 0 );

         /*
          * skip the rest of the line 
          */
         /*
          * for ( ; d->inbuf[i] != '\0' || i>= MAX_INBUF_SIZE ; i++ )
          * {
          * if ( d->inbuf[i] == '\n' || d->inbuf[i] == '\r' )
          * break;
          * }
          */
         d->inbuf[i] = '\n';
         d->inbuf[i + 1] = '\0';
         break;
      }

      if( d->inbuf[i] == '\b' && k > 0 )
         --k;
      else if( isascii( d->inbuf[i] ) && isprint( d->inbuf[i] ) )
         d->incomm[k++] = d->inbuf[i];
   }

Change to:
   /*
    * Canonical input processing.
    */
   for( i = 0, k = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++ )
   {
      if( k >= 254 )
      {
         write_to_descriptor( d, "Line too long.\n\r", 0 );

         /*
          * skip the rest of the line 
          */
         /*
          * for ( ; d->inbuf[i] != '\0' || i>= MAX_INBUF_SIZE ; i++ )
          * {
          * if ( d->inbuf[i] == '\n' || d->inbuf[i] == '\r' )
          * break;
          * }
          */
         d->inbuf[i] = '\n';
         d->inbuf[i + 1] = '\0';
         break;
      }

      if( d->inbuf[i] == ( signed char )IAC )
         iac = 1;
      else if( iac == 1
               && ( d->inbuf[i] == ( signed char )DO || d->inbuf[i] == ( signed char )DONT
                    || d->inbuf[i] == ( signed char )WILL ) )
         iac = 2;
      else if( iac == 2 )
      {
         iac = 0;
         if( d->inbuf[i] == ( signed char )TELOPT_COMPRESS2 )
         {
            if( d->inbuf[i - 1] == ( signed char )DO )
               compressStart( d );
            else if( d->inbuf[i - 1] == ( signed char )DONT )
               compressEnd( d );
         }
      }
      else if( d->inbuf[i] == '\b' && k > 0 )
         --k;
      else if( isascii( d->inbuf[i] ) && isprint( d->inbuf[i] ) )
         d->incomm[k++] = d->inbuf[i];
   }

Locate:
            write_to_descriptor( d->descriptor, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );

Change to:
            write_to_descriptor( d, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0 );


free_desc

Locate:
   if( d->pagebuf )
      DISPOSE( d->pagebuf );
   DISPOSE( d );

Change to:
   if( d->pagebuf )
      DISPOSE( d->pagebuf );
   compressEnd( d );
   DISPOSE( d->mccp );
   DISPOSE( d );



flush_buffer

Locate:
      if( !write_to_descriptor( d->descriptor, buf, 512 ) )

Change to:
      if( !write_to_descriptor( d, buf, 512 ) )

Locate:
   if( !write_to_descriptor( d->descriptor, d->outbuf, d->outtop ) )


Change to:
   if( !write_to_descriptor( d, d->outbuf, d->outtop ) )

pager_output

Locate:
      if( !write_to_descriptor( d->descriptor, d->pagepoint, ( last - d->pagepoint ) ) )

Change to:
      if( !write_to_descriptor( d, d->pagepoint, ( last - d->pagepoint ) ) )

Locate:
   if( IS_SET( ch->act, PLR_ANSI ) )
      if( write_to_descriptor( d->descriptor, ANSI_LBLUE, 0 ) == FALSE )
         return FALSE;
   if( ( ret = write_to_descriptor( d->descriptor, "(C)ontinue, (R)efresh, (B)ack, (Q)uit: © ", 0 ) ) == FALSE )
      return FALSE;


Change to:
   if( xIS_SET( ch->act, PLR_ANSI ) )
      if( write_to_descriptor( d, ANSI_LBLUE, 0 ) == FALSE )
         return FALSE;
   if( ( ret = write_to_descriptor( d, "(C)ontinue, (N)on-stop, (R)efresh, (B)ack, (Q)uit: © ", 0 ) ) == FALSE )
      return FALSE;

Locate:
      ret = write_to_descriptor( d->descriptor, buf, 0 );

Change to:
      ret = write_to_descriptor( d, buf, 0 );

close_socket

Locate:
   if( !DoNotUnlink )
   {
      /*
       * make sure loop doesn't get messed up 
       */
      if( d_next == dclose )
         d_next = d_next->next;
      UNLINK( dclose, first_descriptor, last_descriptor, next, prev );
   }

Below that, add:
   compressEnd( dclose );

hotboot.c

Locate:
#include "mud.h"

Below that, add:
#include "mccp.h"


Locate:
#ifdef MCCP
bool write_to_descriptor( DESCRIPTOR_DATA * d, char *txt, int length );
bool write_to_descriptor_old( int desc, char *txt, int length );
#else
bool write_to_descriptor( int desc, char *txt, int length );
#endif

Change to:
bool write_to_descriptor( DESCRIPTOR_DATA * d, char *txt, int length );
bool write_to_descriptor_old( int desc, char *txt, int length );

do_hotboot

Locate:
   if( ch && ch->desc )
      write_to_descriptor( ch->desc->descriptor, "\e[0m", 0 );

Change to:
   if( ch && ch->desc )
      write_to_descriptor( ch->desc, "\e[0m", 0 );


Locate:
      if( !d->character || d->connected < CON_PLAYING )  /* drop those logging on */
      {
         write_to_descriptor( d->descriptor, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0 );
         close_socket( d, FALSE );  /* throw'em out */
      }


Change to:
      if( !d->character || d->connected < CON_PLAYING )  /* drop those logging on */
      {
         write_to_descriptor( d, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0 );
         close_socket( d, FALSE );  /* throw'em out */
      }

Locate:
         fprintf( fp, "%d %d %d %d %s %s\n", d->descriptor, och->in_room->vnum, d->port, d->idle, och->name, d->host );

Change to:
         fprintf( fp, "%d %d %d %d %d %s %s\n", d->can_compress, d->descriptor, och->in_room->vnum, d->port, d->idle, och->name, d->host );


Locate:
         write_to_descriptor( d->descriptor, buf, 0 );

Change to:
         write_to_descriptor( d, buf, 0 );
         compressEnd( d );

hotboot_recover

Locate:
   int desc, room, dport, idle, maxp = 0;

Change to:
   int desc, room, dport, idle, dcompress, maxp = 0;

Locate:
      fscanf( fp, "%d %d %d %d %s %s\n", &desc, &room, &dport, &idle, name, host );

Change to:
      fscanf( fp, "%d %d %d %d %d %s %s\n", &dcompress, &desc, &room, &dport, &idle, name, host );

Locate:
      if( !write_to_descriptor( desc, "\n\rThe Force swirls around you.\n\r", 0 ) )
      {
         close( desc ); /* nope */
         continue;
      }

Change to:
      if( !write_to_descriptor_old( desc, "\n\rThe Force swirls around you.\n\r", 0 ) )
      {
         close( desc ); /* nope */
         continue;
      }

Locate:
      CREATE( d, DESCRIPTOR_DATA, 1 );

Below that, add:
      CREATE( d->mccp, MCCP, 1 );

Locate:
      LINK( d, first_descriptor, last_descriptor, next, prev );
      d->connected = CON_COPYOVER_RECOVER;   /* negative so close_socket will cut them off */

Below that, add:
      d->can_compress = dcompress;
      if( d->can_compress )
         compressStart( d );


Locate:
      if( !fOld ) /* Player file not found?! */
      {
         write_to_descriptor( d->descriptor,
                              "\n\rSomehow, your character was lost during hotboot. Contact the immortals ASAP.\n\r", 0 );
         close_socket( d, FALSE );
      }
      else  /* ok! */
      {
         write_to_descriptor( d->descriptor,
                              "Suddenly, you remember nothing as the Force continues into the Galaxy.\n\r", 0 );



Change to:
      if( !fOld ) /* Player file not found?! */
      {
         write_to_descriptor( d,
                              "\n\rSomehow, your character was lost during hotboot. Contact the immortals ASAP.\n\r", 0 );
         close_socket( d, FALSE );
      }
      else  /* ok! */
      {
         write_to_descriptor( d,
                              "Suddenly, you remember nothing as the Force continues into the Galaxy.\n\r", 0 );

tables.c

Locate:
         if( !str_cmp( name, "do_compare" ) )
            return do_compare;

Below, add:
         if( !str_cmp( name, "do_compress" ) )
            return do_compress;

Lcoate:
   if( skill == do_compare )
      return "do_compare";

Below, add:
   if( skill == do_compress )
      return "do_compress";



Couple things that I noticed though, if you are on a non-mccp compatable client, and you try to start it, Bad Things(tm) happen. There are a couple ways to check it, I guess. The first would be to just toggle the can_compess bool upon connection, and based on a config turn mccp on/off. If during creation the players client report mccp compatable, set it to on, other wise off(the config, that is). You could start compression at this point as well. Then when loading the character at future times, set the bool again, and then based on the saved config value start or don't start mccp. This also allows players that do not want mccp on, but are capable of it, to control this. do_compress would just check against the bool before compressStart, and would toggle the config flag.

The second suggestion is simply have do_compress send the will_compress_str and will_compress2_str strings. This requires the least amount of change, and you could even put a check to see if the character is already in game (invoking the compress command) and if so, send them a message from read_from_buffer. Just a few thoughts.

If there are any issues with these modifications, please let me know.
       
Pages:<< prev 1 next >>