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, Bing

Members: 0
Guests: 14
Stats
Files
Topics
Posts
Members
Newest Member
481
3,740
19,396
629
DarrenPayn
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » SmaugFUSS Bugfix List » [Enh] MCCP Support
Forum Rules | Mark all | Recent Posts

[Enh] MCCP Support
< Newer Topic :: Older Topic >

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

Samson
Black Hand
GroupAdministrators
Posts3,644
JoinedJan 1, 2002

Enhancement: MCCP Support
Purpose: Reduces outgoing bandwidth sent by the MUD for supporting clients
Provided by: Oliver Jowett
Applies to: SmaugFUSS

This enhancement requires the use of the zlib package

---

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

Makefile

After mapout.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;


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\rYou cannot enter the same command more than 20 consecutive times!\n\r",
                           0 );


Change to:
      write_to_descriptor( d, "\n\r*** PUT A LID ON IT!!! ***\n\rYou cannot enter the same command more than 20 consecutive times!\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, "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\rYou cannot enter the same command more than 20 consecutive times!\n\r",
                                 0 );


Change to:
            write_to_descriptor( d,
                                 "\n\r*** PUT A LID ON IT!!! ***\n\rYou cannot enter the same command more than 20 consecutive times!\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( xIS_SET( ch->act, PLR_ANSI ) )
      if( write_to_descriptor( d->descritor, ANSI_LBLUE, 0 ) == FALSE )
         return FALSE;
   if( ( ret = write_to_descriptor( d->descriptor,
                                    "(C)ontinue, (N)on-stop, (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:
#ifdef MCCP
      write_to_descriptor( ch->desc, "\033[0m", 0 );
#else
      write_to_descriptor( ch->desc->descriptor, "\033[0m", 0 );
#endif


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


Locate:
#ifdef MCCP
         write_to_descriptor( d, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0 );
#else
         write_to_descriptor( d->descriptor, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0 );
#endif


Change to:
         write_to_descriptor( d, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0 );


Locate:
         fprintf( fp, "%d %d %d %d %d %s %s\n", d->descriptor,
#ifdef MCCP
                  d->can_compress,
#else
                  0,
#endif
                  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->descriptor,
                  d->can_compress, och->in_room->vnum, d->port, d->idle, och->name, d->host );


Locate:
#ifdef MCCP
         write_to_descriptor( d, buf, 0 );
         compressEnd( d );
#else
         write_to_descriptor( d->descriptor, buf, 0 );
#endif


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


hotboot_recover

Locate:
#ifdef MCCP
      if( !dcompress && !write_to_descriptor_old( desc, "\n\rThe ether swirls in chaos.\n\r", 0 ) )
#else
      if( !write_to_descriptor( desc, "\n\rThe ether swirls in chaos.\n\r", 0 ) )
#endif


Change to:
      if( !dcompress && !write_to_descriptor_old( desc, "\n\rThe ether swirls in chaos.\n\r", 0 ) )


Locate:
#ifdef MCCP
      d->can_compress = dcompress;
      if( d->can_compress )
         compressStart( d );
#endif


Change to:
      CREATE( d->mccp, MCCP, 1 );
      d->can_compress = dcompress;
      if( d->can_compress )
         compressStart( d );


Locate:
#ifdef MCCP
         write_to_descriptor( d, "\n\rSomehow, your character was lost during hotboot. Contact the immortals ASAP.\n\r", 0 );
#else
         write_to_descriptor( d->descriptor,
                              "\n\rSomehow, your character was lost during hotboot. Contact the immortals ASAP.\n\r", 0 );
#endif
         close_socket( d, FALSE );
      }
      else  /* ok! */
      {
#ifdef MCCP
         write_to_descriptor( d, "\n\rTime resumes its normal flow.\n\r", 0 );
#else
         write_to_descriptor( d->descriptor, "\n\rTime resumes its normal flow.\n\r", 0 );
#endif


Change to:
         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, "\n\rTime resumes its normal flow.\n\r", 0 );


Once this is installed, it will reduce your outgoing bandwidth for supporting clients significantly. The more people using it, the better.
       
Pages:<< prev 1 next >>