This patch contains the differences between the upstream tarball and
the sources actually used for building the package.

Option single-debian-patch is used as the changes are tracked in git.

--- tf-4.0s1.orig/src/history.c
+++ tf-4.0s1/src/history.c
@@ -38,18 +38,6 @@
 #define LOCALSIZE      100	/* local history size */
 #define INPUTSIZE      100	/* command history buffer size */
 
-typedef struct History {	/* circular list of Alines, and logfile */
-    struct Aline **alines;
-    int size;			/* actual number of lines currently saved */
-    int maxsize;		/* maximum number of lines that can be saved */
-    int first;			/* position of first line in circular array */
-    int last;			/* position of last line in circular array */
-    int index;			/* current recall position */
-    int total;			/* total number of lines ever saved */
-    TFILE *logfile;
-    CONST char *logname;
-} History;
-
 #define empty(hist) (!(hist)->alines || !(hist)->size)
 
 static void     FDECL(alloc_history,(History *hist, int maxsize));
--- tf-4.0s1.orig/src/history.h
+++ tf-4.0s1/src/history.h
@@ -31,6 +31,18 @@ extern void   NDECL(free_histories);
 #define record_global(aline)  recordline(globalhist, (aline))
 #define record_local(aline)   recordline(localhist, (aline))
 
+typedef struct History {	/* circular list of Alines, and logfile */
+    struct Aline **alines;
+    int size;			/* actual number of lines currently saved */
+    int maxsize;		/* maximum number of lines that can be saved */
+    int first;			/* position of first line in circular array */
+    int last;			/* position of last line in circular array */
+    int index;			/* current recall position */
+    int total;			/* total number of lines ever saved */
+    TFILE *logfile;
+    CONST char *logname;
+} History;
+
 extern struct History globalhist[], localhist[];
 extern int log_count, norecord, nolog;
 
--- /dev/null
+++ tf-4.0s1/src/mccp.c
@@ -0,0 +1,426 @@
+/*
+ * Client decompression module for the mud client compression protocol.
+ * See http://homepages.ihug.co.nz/~icecube/compress/ for more details.
+ *
+ * mccpDecompress.c - module code. Link this with your client code.
+ *
+ * Oliver Jowett <icecube$ihug.co.nz>. Demangle address as needed.
+ *
+ * This code is placed in the public domain.
+ *
+ */
+
+/* Modified: 20000530 */
+
+/* See mccp.h for API information */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "config.h"
+#ifdef MUDCOMPRESS
+
+#include <zlib.h>
+
+#include "mccp.h"
+
+/* Telnet values we're interested in */
+
+#define IAC             255
+#define DONT            254
+#define DO              253
+#define WONT            252
+#define WILL            251
+#define SB              250
+#define SE              240
+
+#define TELOPT_COMPRESS 85
+#define TELOPT_COMPRESS2 86
+
+/* We say DO COMPRESS2 to WILL COMPRESS2, then DONT COMPRESS to WILL COMPRESS
+ * -or-
+ * We say DO COMPRESS to WILL COMPRESS if it arrives before any COMPRESS2.
+ *
+ * Later the server sends IAC SB COMPRESS IAC SE (v2) or IAC SB COMPRESS WILL
+ * SE (v1), and immediately following
+ * that, begins compressing
+ *
+ * Compression ends on a Z_STREAM_END, no other marker is used
+ */
+
+static char will_v1[] = { IAC, WILL, TELOPT_COMPRESS, 0 };
+static char do_v1[] =   { IAC, DO,   TELOPT_COMPRESS, 0 };
+static char dont_v1[] = { IAC, DONT, TELOPT_COMPRESS, 0 };
+static char on_v1[] =   { IAC, SB, TELOPT_COMPRESS, WILL, SE, 0 };
+
+static char will_v2[] = { IAC, WILL, TELOPT_COMPRESS2, 0 };
+static char do_v2[] =   { IAC, DO,   TELOPT_COMPRESS2, 0 };
+static char on_v2[] =   { IAC, SB, TELOPT_COMPRESS2, IAC, SE, 0 };
+
+/* "Opaque" state object */
+
+struct mc_state_s {
+    z_stream *stream;      /* stream we're using */
+
+    unsigned char *inbuf;  /* input buffer (data from mud) */
+    unsigned int insize;   /* .. and how much is used */
+    unsigned int inalloc;  /* .. and how much is allocated */
+
+    unsigned char *outbuf; /* output buffer (data to user) */
+    unsigned int outsize;  /* .. and how much is used */
+    unsigned int outalloc; /* .. and how much is allocated */
+
+    int error;
+    int resp_v1;  /* waiting to send IAC DO/DONT COMPRESS */
+    int resp_v2;  /* waiting to send IAC DO COMPRESS2 */
+    int got_v2;   /* responded to a IAC WILL COMPRESS2 already */
+
+    unsigned long comp;
+    unsigned long uncomp;
+};
+
+/* Initialise a new state object */
+mc_state *mudcompress_new(void)
+{
+    mc_state *state;
+
+    state = malloc(sizeof(*state));
+    state->stream   = NULL;   /* Not decompressing */
+    state->inalloc  = 2048;
+    state->outalloc = 2048;
+    state->inbuf    = malloc(state->inalloc);
+    state->outbuf   = malloc(state->outalloc);
+    state->insize   = 0;
+    state->outsize  = 0;
+    state->error    = 0;
+    state->comp     = 0;
+    state->uncomp   = 0;
+    state->resp_v1  = 0;
+    state->resp_v2  = 0;
+    state->got_v2   = 0;
+
+    return state;
+}
+
+/* Clean up a state object */
+void mudcompress_delete(mc_state *state)
+{
+    if (state->stream) {
+        inflateEnd(state->stream);
+        free(state->stream);
+    }
+
+    free(state->inbuf);
+    free(state->outbuf);
+    free(state);
+}
+
+/* zlib helpers */
+
+static void *zlib_alloc(void *opaque, unsigned int items, unsigned int size)
+{
+    return calloc(items, size);
+}
+
+static void zlib_free(void *opaque, void *address)
+{
+    free(address);
+}
+
+static void grow_inbuf(mc_state *state, int needed)
+{
+    int old = state->inalloc;
+
+    while (state->inalloc < state->insize + needed)
+        state->inalloc *= 2;
+
+    if (old != state->inalloc)
+        state->inbuf = realloc(state->inbuf, state->inalloc);
+}
+
+static void grow_outbuf(mc_state *state, int needed)
+{
+    int old = state->outalloc;
+
+    while (state->outalloc < state->outsize + needed)
+        state->outalloc *= 2;
+
+    if (old != state->outalloc)
+        state->outbuf = realloc(state->outbuf, state->outalloc);
+}
+
+static void decompress_inbuf(mc_state *state)
+{
+    int status;
+
+    /* We are now decompressing from inbuf to outbuf */
+
+    if (!state->insize)
+        return; /* nothing to decompress? */
+
+    state->stream->next_in = state->inbuf;
+    state->stream->next_out = state->outbuf + state->outsize;
+    state->stream->avail_in = state->insize;
+    state->stream->avail_out = state->outalloc - state->outsize;
+
+    status = inflate(state->stream, Z_PARTIAL_FLUSH);
+
+    if (status == Z_OK || status == Z_STREAM_END) {
+        /* Successful decompression */
+
+        /* Remove used data from inbuf */
+        state->comp += state->insize - state->stream->avail_in;
+        state->uncomp += state->stream->next_out - state->outbuf;
+
+        memmove(state->inbuf, state->stream->next_in, state->stream->avail_in);
+        state->insize = state->stream->avail_in;
+
+        /* Update outbuf pointers */
+        state->outsize = state->stream->next_out - state->outbuf;
+
+        /* Done */
+
+        if (status == Z_STREAM_END) {
+            /* Turn off compression too */
+
+            grow_outbuf(state, state->insize);
+
+            memcpy(state->outbuf + state->outsize, state->inbuf, state->insize);
+            state->outsize += state->insize;
+            state->insize = 0;
+
+            inflateEnd(state->stream);
+            free(state->stream);
+            state->stream = NULL;
+        }
+
+        return;
+    }
+
+    if (status == Z_BUF_ERROR) {
+        /* Full buffers? Maybe we need more output space.. */
+
+        if (state->outsize * 2 > state->outalloc) {
+            grow_outbuf(state, state->outalloc);
+            decompress_inbuf(state);
+        }
+
+        return;
+    }
+
+    /* Error */
+    state->error = 1;
+}
+
+/* We received some data */
+void mudcompress_receive(mc_state *state, const char *data, unsigned len)
+{
+    int i;
+
+    if (state->error)
+        return;
+
+    if (!state->stream) {
+        int residual = -1;
+        int clen;
+
+        /* Just copy to outbuf. Also copy any residual inbuf */
+
+        grow_outbuf(state, len + state->insize);
+        memcpy(state->outbuf + state->outsize, data, len);
+        state->outsize += len;
+        memcpy(state->outbuf + state->outsize, state->inbuf, state->insize);
+        state->outsize += state->insize;
+        state->insize = 0;
+
+        /* Check for Magic Marker. ugh this is messy */
+        for (i=0; i < state->outsize; i++) {
+            if (state->outbuf[i] == IAC) {
+                if (i + 1 < state->outsize && state->outbuf[i+1] == IAC) {
+                    /* IAC IAC - ignore */
+                    i++;
+                    continue;
+                }
+
+                clen = (i + strlen(will_v1) < state->outsize) ? strlen(will_v1) : state->outsize - i;
+
+                if (!memcmp(&state->outbuf[i], will_v1, clen)) {
+                    if (clen != strlen(will_v1)) {
+                        /* Partial match. Save it. */
+                        residual = i;
+                        break;
+                    }
+
+                    /* If we got WILL COMPRESS2 then refuse COMPRESS, otherwise
+                     * accept it
+                     */
+
+                    if (state->got_v2)
+                        state->resp_v1 = -1;
+                    else
+                        state->resp_v1 = 1;
+
+                    memmove(&state->outbuf[i],
+                            &state->outbuf[i + strlen(will_v1)],
+                            state->outsize - strlen(will_v1));
+                    state->outsize -= strlen(will_v1);
+                    i--;
+                    continue;
+                }
+
+                if (!memcmp(&state->outbuf[i], will_v2, clen)) {
+                    if (clen != strlen(will_v2)) {
+                        /* Partial match. Save it. */
+                        residual = i;
+                        break;
+                    }
+
+                    state->resp_v2 = 1;
+                    state->got_v2 = 1;
+
+                    memmove(&state->outbuf[i],
+                            &state->outbuf[i + strlen(will_v2)],
+                            state->outsize - strlen(will_v2));
+                    state->outsize -= strlen(will_v2);
+                    i--;
+                    continue;
+                }
+
+                clen = (i + strlen(on_v1) < state->outsize) ? strlen(on_v1) : state->outsize - i;
+
+                if ((!memcmp(&state->outbuf[i], on_v1, clen) && !state->got_v2) ||
+                    (!memcmp(&state->outbuf[i], on_v2, clen) && state->got_v2)) {
+                    if (clen != strlen(on_v1)) {
+                        /* Partial match. Save it. */
+                        residual = i;
+                        break;
+                    }
+
+                    /* Switch to compression */
+                    /* copy any compressible bits to our inbuf */
+
+                    grow_inbuf(state, state->outsize - i - strlen(on_v1));
+
+                    memcpy(state->inbuf,
+                           state->outbuf + i + strlen(on_v1),
+                           state->outsize - i - strlen(on_v1));
+
+                    state->insize = state->outsize - i - strlen(on_v1);
+
+                    /* clean up our output buffer */
+                    state->outsize = i;
+
+                    /* init stream */
+                    state->stream = malloc(sizeof(z_stream));
+                    state->stream->zalloc = zlib_alloc;
+                    state->stream->zfree = zlib_free;
+                    state->stream->opaque = NULL;
+
+                    if (inflateInit(state->stream) != Z_OK) {
+                        state->error = 1;
+                        free(state->stream);
+                        state->stream = NULL;
+                        return;
+                    }
+
+                    /* Continue with decompression */
+                    break;
+                }
+            }
+        }
+
+        if (!state->stream) { /* didn't start decompressing? */
+            /* We might have some residual, copy to inbuf for later checking */
+
+            if (residual != -1) {
+                grow_inbuf(state, state->outsize - residual);
+                memcpy(state->inbuf + state->insize, state->outbuf + residual, state->outsize - residual);
+                state->outsize = residual;
+            }
+
+            return;
+        }
+    } else {
+        /* New data to decompress. Copy to inbuf */
+        grow_inbuf(state, len);
+        memcpy(state->inbuf + state->insize, data, len);
+        state->insize += len;
+    }
+
+    decompress_inbuf(state);
+}
+
+/* How much data is available? */
+int mudcompress_pending(mc_state *state)
+{
+    return state->error ? 0 : state->outsize;
+}
+
+/* Was there an error? */
+int mudcompress_error(mc_state *state)
+{
+    return state->error;
+}
+
+/* Get some data */
+int mudcompress_get(mc_state *state, char *buf, int size)
+{
+    int copied;
+
+    if (state->error || !state->outsize)
+        return 0;
+
+    if (size > state->outsize)
+        copied = state->outsize;
+    else
+        copied = size;
+
+    memcpy(buf, state->outbuf, copied);
+    state->outsize -= copied;
+    if (state->outsize)
+        memmove(state->outbuf, state->outbuf + copied, state->outsize);
+
+    /* Do some more decompression */
+    decompress_inbuf(state);
+
+    return copied;
+}
+
+void mudcompress_stats(mc_state *state, unsigned long *comp, unsigned long *uncomp)
+{
+    *comp = state->comp;
+    *uncomp = state->uncomp;
+}
+
+const char *mudcompress_response(mc_state *state)
+{
+    if (state->resp_v1 == 1) {
+        state->resp_v1 = 0;
+        return do_v1;
+    }
+
+    if (state->resp_v1 == -1) {
+        state->resp_v1 = 0;
+        return dont_v1;
+    }
+
+    if (state->resp_v2) {
+        state->resp_v2 = 0;
+        return do_v2;
+    }
+
+    return NULL;
+}
+
+int mudcompress_compressing(mc_state *state)
+{
+    return (state->stream != NULL);
+}
+
+int mudcompress_v2(mc_state *state)
+{
+    return (state->stream != NULL && state->got_v2);
+}
+
+#endif	/* MUDCOMPRESS */
--- /dev/null
+++ tf-4.0s1/src/mccp.h
@@ -0,0 +1,141 @@
+/*
+ * Client decompression module for the mud client compression protocol.
+ * See http://homepages.ihug.co.nz/~icecube/compress/ for more details.
+ *
+ * mccpDecompress.h - header definitions. #include this in your client code.
+ *
+ * Oliver Jowett <icecube$ihug.co.nz>. Demangle address as needed.
+ *
+ * This code is placed in the public domain.
+ *
+ */
+
+/* Modified: 981203 */
+
+/*
+ *
+ * mc_state is an opaque type representing the current compression state of
+ * a connection. You should include a (mc_state *) in the information you
+ * store for a server connection.
+ *
+ * Initialization / cleanup:
+ *
+ *   When a connection is initiated, call mudcompress_new, and store the
+ *   resulting pointer in your server connection information. This pointer is
+ *   used as a handle for all other functions. This does NOT begin compression
+ *   - it just initialises various internal structures.
+ *
+ *   When a connection is terminated, call mudcompress_delete with the handle
+ *   to delete all memory allocated by the decompressor for the connection.
+ *
+ * Reading / writing:
+ *
+ *   Reading from the server connection must go through the decompressor at
+ *   all times. The decompressor handles both negotiation and decompression
+ *   transparently - it receives input directly from the server, then provides
+ *   the main client code with decompressed data, hiding all protocol details.
+ *
+ *   When data is received from the mud server, call mudcompress_receive,
+ *   passing it the handle for the connection, a pointer to the data read,
+ *   and the length of data read. It is VITAL that ALL data read is passed
+ *   to the decompressor - including data with embedded NULs!
+ *
+ *   After mudcompress_receive has been called, call mudcompress_pending() to
+ *   see if any decompressed data is available. It returns the number of
+ *   bytes pending.
+ *
+ *   If there is pending data waiting, call mudcompress_get to retrieve it.
+ *   This fills up to "size" bytes in the provided buffer "buf", and returns
+ *   the number of bytes copied. Your client can now process this data as if
+ *   it had been directly read from the server.
+ *
+ *   Be sure to check mudcompress_pending again after calling mudcompress_get!
+ *   Removing some data from the decompress buffer may have allowed the
+ *   decompressor to decompress some more data - in which case, you want to
+ *   process it immediately, rather than waiting for another read from the
+ *   mud server.
+ *
+ *   Regularly call mudcompress_response. If non-NULL, you need to write the
+ *   returned string to the mud server. This is needed when the decompressor
+ *   is negotiating compression with the server. When called,
+ *   mudcompress_response clears any pending string, so be sure to save its
+ *   return value!
+ *
+ * Status information:
+ *
+ *   mudcompress_error returns non-0 if there has been a (fatal) decompression
+ *   error. In this case, all you can do is tell the user that something went
+ *   wrong and close the connection.
+ *
+ *   mudcompress_stats fills in the two (unsigned long *) values passed, with
+ *   the number of compressed bytes read, and the number of bytes that they
+ *   decompressed to.
+ *
+ *   mudcompress_compressing returns non-0 if the connection is currently
+ *   using compression.
+ *
+ */
+
+#ifndef MUDCOMPRESS_H
+#define MUDCOMPRESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+    /*  Opaque handle for a decompressor. Details defined in Compress.c - you
+     *  should never need to see them externally.
+     */
+    struct mc_state_s;
+    typedef struct mc_state_s mc_state;
+
+    /*  Create a new decompressor. Return a handle to it.
+     */
+    mc_state *mudcompress_new(void);
+
+    /*  Deallocate a decompressor and associated data. 'state' is invalid
+     *  afterthis call.
+     */
+    void mudcompress_delete(mc_state *state);
+
+    /*  Perform decompression and negotiation on some received data.
+     *  'data' is a pointer to the received data, 'len' is its length.
+     */
+    void mudcompress_receive(mc_state *state, const char *data, unsigned len);
+
+    /*  Return the number of pending decompressed bytes that can currently
+     *  be read by mudcompress_get
+     */
+    int mudcompress_pending(mc_state *state);
+
+    /*  Return true (non-0) if this decompressor encountered a fatal error.
+     */
+    int mudcompress_error(mc_state *state);
+
+    /*  Read decompressed data from the decompressor into 'buf', up to a
+     *  maximum of 'size' bytes. Returns the number of bytes actually copied.
+     */
+    int mudcompress_get(mc_state *state, char *buf, int size);
+
+    /*  Set *comp to the number of compressed bytes read, and *uncomp to the
+     *  number of bytes they expanded to, for this decompressor.
+     */
+    void mudcompress_stats(mc_state *state, unsigned long *comp, unsigned long *uncomp);
+
+    /*  Check for a negotiation response. If this returns NULL, no output is
+     *  needed. If it returns non-NULL, it points to a NUL-terminated string
+     *  that should be sent to the mud server. Calling this function clears
+     *  the pending string (so be sure to save the result).
+     */
+    const char *mudcompress_response(mc_state *state);
+
+    /*  Return true (non-0) if this decompressor has successfully negotiated
+     *  compression and is currently performing decompression.
+     */
+    int mudcompress_compressing(mc_state *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- tf-4.0s1.orig/src/rules.mak
+++ tf-4.0s1/src/rules.mak
@@ -50,6 +50,7 @@ main.$O: main.c config.h port.h dstring.
 	variable.h tty.h $(BUILDERS)
 makehelp.$O: makehelp.c config.h port.h $(BUILDERS)
 malloc.$O: malloc.c config.h port.h signals.h malloc.h $(BUILDERS)
+mccp.$O: mccp.c mccp.h
 output.$O: output.c config.h port.h dstring.h $(TF_H) util.h tfio.h socket.h \
 	output.h macro.h search.h tty.h variable.h expr.h $(BUILDERS)
 process.$O: process.c config.h port.h dstring.h $(TF_H) util.h tfio.h \
@@ -59,7 +60,7 @@ signals.$O: signals.c config.h port.h ds
 	process.h tty.h output.h signals.h variable.h $(BUILDERS)
 socket.$O: socket.c config.h port.h dstring.h $(TF_H) util.h tfio.h tfselect.h \
 	history.h world.h socket.h output.h process.h macro.h keyboard.h \
-	commands.h command.h signals.h search.h $(BUILDERS)
+	commands.h command.h signals.h search.h mccp.h $(BUILDERS)
 tfio.$O: tfio.c config.h port.h dstring.h $(TF_H) util.h tfio.h tfselect.h \
 	output.h macro.h history.h search.h signals.h variable.h $(BUILDERS)
 tty.$O: tty.c config.h port.h $(TF_H) dstring.h util.h tty.h output.h macro.h \
--- tf-4.0s1.orig/src/socket.c
+++ tf-4.0s1/src/socket.c
@@ -67,6 +67,10 @@ struct sockaddr_in {
 #include "search.h"
 #include "variable.h"	/* set_var_by_*() */
 
+#ifdef MUDCOMPRESS
+#  include "mccp.h"
+#endif
+
 #ifdef _POSIX_VERSION
 # include <sys/wait.h>
 #endif
@@ -206,6 +210,9 @@ typedef struct Sock {		/* an open connec
     TIME_T time[2];		/* time of last receive/send */
     char state;			/* state of parser finite state automaton */
     long pid;			/* pid of name resolution process */
+#ifdef MUDCOMPRESS
+    mc_state *mccp;		/* mud compression struct */
+#endif
 } Sock;
 
 
@@ -806,6 +813,9 @@ int opensock(world, autologin, quietlogi
         tsock = *(tsock ? &tsock->next : &hsock) = xsock;
         xsock->activity = 0;
         Stringinit(xsock->buffer);
+#ifdef MUDCOMPRESS
+	xsock->mccp = mudcompress_new();
+#endif
         xsock->prompt = NULL;
         init_queue(xsock->queue = (Queue *)XMALLOC(sizeof(Queue)));
         xsock->next = NULL;
@@ -1297,6 +1307,9 @@ static void nukesock(sock)
 #endif /* NONBLOCKING_GETHOST */
     }
     Stringfree(sock->buffer);
+#ifdef MUDCOMPRESS
+    mudcompress_delete(sock->mccp);
+#endif
     if (sock->prompt) free_aline(sock->prompt);
     while(sock->queue->head)
         free_aline((Aline*)unlist(sock->queue->head, sock->queue));
@@ -1728,8 +1741,25 @@ static int handle_socket_input()
     }
 
     do {  /* while (n > 0 && !interrupted() && (received += count) < SPAM) */
-        do count = recv(xsock->fd, buffer, sizeof(buffer), 0);
-            while (count < 0 && errno == EINTR);
+#ifdef MUDCOMPRESS
+	if (!mudcompress_pending(xsock->mccp))
+	{
+	    do count = recv(xsock->fd, buffer, sizeof(buffer), 0);
+                while (count < 0 && errno == EINTR);
+
+	    if (count > 0) {
+		mudcompress_receive(xsock->mccp, buffer, count);
+		if (mudcompress_error(xsock->mccp)) {
+		    count = -1;
+		    errno = EIO;
+		}
+	    }
+	}
+#else
+	do count = recv(xsock->fd, buffer, sizeof(buffer), 0);
+	    while (count < 0 && errno == EINTR);
+#endif
+
         if (count <= 0) {
             int err = errno;
 #ifdef SUNOS_5_4
@@ -1761,6 +1791,25 @@ static int handle_socket_input()
             return received;
         }
 
+	received += count;
+	
+#ifdef MUDCOMPRESS
+	{
+	    const char *resp;
+	    
+	    count = 0;
+	    while (count < sizeof(buffer)
+		   && mudcompress_pending(xsock->mccp)) {
+		count += mudcompress_get(xsock->mccp, buffer + count,
+					 sizeof(buffer) - count);
+	    }
+	    
+	    resp = mudcompress_response(xsock->mccp);
+	    if (resp)
+		transmit(resp,strlen(resp));
+	} 
+#endif
+	
         for (place = buffer; place - buffer < count; place++) {
 
             /* We always accept 8-bit data, even though RFCs 854 and 1123
@@ -1958,7 +2007,6 @@ static int handle_socket_input()
         }
 
         /* See if anything arrived while we were parsing */
-
         FD_ZERO(&readfds);
         FD_SET(xsock->fd, &readfds);
         tv.tv_sec = tv.tv_usec = 0;
@@ -1976,7 +2024,13 @@ static int handle_socket_input()
             if (errno != EINTR) die("handle_socket_input: select", errno);
         }
 
-    } while (n > 0 && !interrupted() && (received += count) < SPAM);
+#ifdef MUDCOMPRESS
+	if (mudcompress_pending(xsock->mccp)) {
+	    n = 1;
+	}
+#endif
+
+    } while (n > 0 && !interrupted() && received < SPAM);
 
     /* If lpflag is on and we got a partial line from the fg world,
      * assume the line is a prompt.
--- tf-4.0s1.orig/src/socket.h
+++ tf-4.0s1/src/socket.h
@@ -13,7 +13,7 @@
 #define SOCK_RECV	0
 #define SOCK_SEND	1
 
-struct World   *world_decl;	/* declares struct World */
+struct World;	/* declares struct World */
 
 extern Aline *incoming_text;
 extern int quit_flag;
--- tf-4.0s1.orig/src/tf.1.catman
+++ tf-4.0s1/src/tf.1.catman
@@ -152,6 +152,8 @@ TF(1)
 
        Recall previously received text.
 
+       Support for the Mud Client Compression Protocol version 1 and 2.
+
 
 CCOONNFFIIGGUURRAATTIIOONN FFIILLEESS
        _T_F will attempt to read  two  files  when  starting.   The
--- tf-4.0s1.orig/src/tf.1.nroffman
+++ tf-4.0s1/src/tf.1.nroffman
@@ -112,6 +112,8 @@ Separate LP and Diku style prompts from
 Page output using a --More-- prompt.
 .sp
 Recall previously received text.
+.sp
+Support for Mud Client Compression Protocol versions 1 and 2.
 
 .SH "CONFIGURATION FILES"
 .PP
--- tf-4.0s1.orig/src/util.c
+++ tf-4.0s1/src/util.c
@@ -887,7 +887,7 @@ int ch_mailfile()
     CONST char *end;
 
     path = (TFMAILPATH && *TFMAILPATH) ? TFMAILPATH : MAIL;
-    while (*(name = stringarg(&path, &end))) {
+    while (path && *(name = stringarg(&path, &end))) {
         for (oldp = &maillist; *oldp; oldp = &(*oldp)->next) {
             if (strncmp(name, (*oldp)->name, end-name) == 0 &&
                 !(*oldp)->name[end-name])
--- tf-4.0s1.orig/src/vars.mak
+++ tf-4.0s1/src/vars.mak
@@ -15,14 +15,14 @@
 # Predefined variables:
 #   O - object file suffix (e.g., "o" or "obj")
 
-TFVER=40s1
+TFVER=40s1-mccp
 
 SOURCE = command.c dstring.c expand.c help.c history.c keyboard.c \
   macro.c main.c malloc.c output.c process.c search.c signals.c \
   socket.c tfio.c tty.c util.c variable.c world.c
 
 OBJS = command.$O dstring.$O expand.$O expr.$O help.$O history.$O keyboard.$O \
-  macro.$O main.$O malloc.$O output.$O process.$O search.$O signals.$O \
+  macro.$O main.$O malloc.$O mccp.$O output.$O process.$O search.$O signals.$O \
   socket.$O tfio.$O tty.$O util.$O variable.$O world.$O \
   regexp.$O $(OTHER_OBJS)
 
--- tf-4.0s1.orig/tf-lib/spell.tf
+++ tf-4.0s1/tf-lib/spell.tf
@@ -7,7 +7,7 @@
 
 /def -i spell_line = \
     /setenv ARGS=$(/recall -i 1)%; \
-    /let _errs=$(/quote -S -decho !echo $$ARGS | spell)%; \
+    /let _errs=$(/quote -S -decho !echo $$ARGS | ispell -l)%; \
     /if ( _errs !~ "" ) \
         /echo MISSPELLINGS: %_errs%; \
     /else \
--- tf-4.0s1.orig/unix/Config
+++ tf-4.0s1/unix/Config
@@ -33,8 +33,8 @@
 #   even if an old version is currently in use.  You can remove
 #   the old version manually later when it is no longer in use.
 
-# TF="/usr/local/bin/tf-${TFVER}"
-# LIBDIR="/usr/local/lib/tf-${TFVER}-lib"
+TF="/usr/games/tf"
+LIBDIR="/usr/share/games/tf"
 # SYMLINK="/usr/local/bin/tf"
 
 
@@ -44,8 +44,8 @@
 # uses nroff format; set MANTYPE=cat if your man uses pre-formatted
 # vt100 "catman" pages.  Default is "cat".
 
-# MANTYPE="nroff"
-# MANPAGE="/usr/local/man/man1/tf.1"
+MANTYPE="nroff"
+MANPAGE="/usr/man/man6/tf.6"
 
 
 ### Flags.
@@ -110,7 +110,7 @@ FLAGS=''
 # by removing the leading "#".
 
 # CC=cc
-# CCFLAGS="-g"
+CCFLAGS="-O2 -g -Wall"
 
 
 ### Stripping.
--- tf-4.0s1.orig/unix/tfconfig
+++ tf-4.0s1/unix/tfconfig
@@ -66,8 +66,12 @@ X=''
 if [ -z "$USER" ]; then USER=$LOGNAME; fi
 export USER
 
-UNAME=`{ uname -s && uname -v && uname -r || uname -a; } 2>/dev/null`
-echo "#define UNAME     " \"$UNAME\" >&4
+UNAME=`{ uname -smo; } 2>/dev/null`
+if test -n "$SOURCE_DATE_EPOCH"; then
+    echo "#define UNAME     \"\"" >&4
+else
+    echo "#define UNAME     " \"$UNAME\" >&4
+fi
 case "$UNAME" in
 "SunOS 5.4")
     echo "#define SUNOS_5_4" >&4
@@ -168,18 +172,18 @@ fi
 # The cd;pwd is needed to normalize the directory name in case of links, etc.
 
 DIR1=`echo $TF      | sed 's;/[^/]*$;;'`
-DIR1=`cd $DIR1 && pwd`
+#DIR1=`cd $DIR1 && pwd`
 DIR2=`echo $LIBDIR  | sed 's;/[^/]*$;;'`
-DIR2=`cd $DIR2 && pwd`
+#DIR2=`cd $DIR2 && pwd`
 DIR3=`echo $SYMLINK | sed 's;/[^/]*$;;'`
-DIR3=`cd $DIR3 && pwd`
+#DIR3=`cd $DIR3 && pwd`
 
-if [ -z "$DIR1" ] || [ -z "$DIR2" ] || [ -z "$DIR3" ]; then
+if [ -z "$DIR1" ] || [ -z "$DIR2" ]; then
     echo "Error in directory."
     exit 1;
 fi
 
-DIR1=`cd $DIR1 && pwd || { echo "Error in directory $DIR1."; false; }`
+#DIR1=`cd $DIR1 && pwd || { echo "Error in directory $DIR1."; false; }`
 
 BUILDTREE=`cd .. && pwd`
 if echo "${DIR1}/" | egrep "^${BUILDTREE}/" >/dev/null 2>&1 ||
@@ -482,6 +486,14 @@ else
     echo "I can't find <pwd.h>.  Filename '~user' expansion won't be supported."
 fi
 
+### Find zlib.h
+if echo '#include <zlib.h>' >test.c; ${CPP} test.c >/dev/null 2>&1; then
+    echo "#define MUDCOMPRESS" >&4
+    echo "Found <zlib.h>."
+else
+    echo "I can't find <zlib.h>.  The Mud Client Compression Protocol will not be supported."
+fi
+
 ### Figure out how to do varadic args.
 if [ "$STD_C" = "1" ] || [ "$GNU_C" = "1" ]; then
     if echo '#include <stdarg.h>' >test.c; ${CPP} test.c >/dev/null 2>&1; then
@@ -758,6 +770,12 @@ else
     echo "/* warning: tfconfig couldn't find connect() */" >&4
 fi
 
+### Test for zlib for mud compression
+if eval "${LIBTEST} -lz ${LIBS} >/dev/null 2>&1" && test -f ${AOUT}; then
+    echo "Will link with -lz."
+    LIBS="-lz $LIBS"
+fi
+
 ### Test for SOCKS firewall proxy server.
 if [ -n "$SOCKS" ]; then
     # SOCKS uses res_init(), so we need -lresolv if there is one.
--- tf-4.0s1.orig/unix/unix.mak
+++ tf-4.0s1/unix/unix.mak
@@ -14,7 +14,7 @@
 # unix section of src/Makefile.
 #
 
-CFLAGS     = $(FLAGS)
+#CFLAGS     = $(FLAGS)
 SHELL      = /bin/sh
 BUILDERS   = Makefile
 
@@ -52,13 +52,13 @@ _failmsg:
 
 regexp.o: $(BUILDERS) config.h
 	cd ./regexp; \
-	    $(MAKE) CC='$(CC)' CFLAGS='-O' O=o regexp.o >err 2>&1 || \
+	    $(MAKE) CC='$(CC)' CFLAGS='$(CFLAGS)' O=o regexp.o >err 2>&1 || \
 	    { cat err; rm err; exit 1; }
 	rm regexp/err
 	mv regexp/regexp.o .
 
 TF tf$(X):     $(OBJS) $(BUILDERS)
-	$(CC) $(CFLAGS) -o tf$(X) $(OBJS) $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o tf$(X) $(OBJS) $(LIBS)
 #	@# Some stupid linkers return ok status even if they fail.
 	@test -f tf$(X)
 #	@# ULTRIX's sh errors here if strip isn't found, despite "true".
@@ -114,7 +114,7 @@ LIBRARY $(LIBDIR): ../tf-lib/tf-help ../
 	rm -f worldqueue.tf;   ln -s  world-q.tf   worldqueue.tf;
 
 makehelp: makehelp.c
-	$(CC) $(CFLAGS) -o makehelp makehelp.c
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o makehelp makehelp.c
 
 __always__:
 
