diff -r -N -c socketmud/src/action_safe.c socketmud-1.1/src/action_safe.c *** socketmud/src/action_safe.c Sat Mar 9 19:49:38 2002 --- socketmud-1.1/src/action_safe.c Wed Feb 26 11:59:52 2003 *************** *** 146,157 **** } sprintf(buf, "\n\r <*> The world starts spinning <*>\n\r"); ! /* For each playing descriptor, save its state */ for (dsock = dsock_list; dsock ; dsock = dsock_next) { dsock_next = dsock->next; ! if (dsock->state != STATE_PLAYING) { text_to_socket(dsock, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r"); --- 146,159 ---- } sprintf(buf, "\n\r <*> The world starts spinning <*>\n\r"); ! /* For each playing descriptor, save its state */ for (dsock = dsock_list; dsock ; dsock = dsock_next) { dsock_next = dsock->next; ! ! compressEnd(dsock); ! if (dsock->state != STATE_PLAYING) { text_to_socket(dsock, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r"); *************** *** 159,172 **** } else { ! fprintf(fp, "%d %s %s %c\n", ! dsock->control, dsock->player->name, dsock->hostname, dsock->compressing); /* save the player */ save_player(dsock->player); text_to_socket(dsock, buf); - compressEnd(dsock); } } --- 161,173 ---- } else { ! fprintf(fp, "%d %s %s\n", ! dsock->control, dsock->player->name, dsock->hostname); /* save the player */ save_player(dsock->player); text_to_socket(dsock, buf); } } *************** *** 188,193 **** --- 189,195 ---- { D_MOBILE *xMob; char buf[MAX_BUFFER]; + bool found = FALSE; for (xMob = dmobile_list; xMob; xMob = xMob->next) { *************** *** 195,200 **** --- 197,206 ---- { sprintf(buf, "%s is linkdead.\n\r", xMob->name); text_to_mobile(dMob, buf); + found = TRUE; } } + + if (!found) + text_to_mobile(dMob, "Noone is currently linkdead.\n\r"); } diff -r -N -c socketmud/src/io.c socketmud-1.1/src/io.c *** socketmud/src/io.c Sat Mar 9 19:49:15 2002 --- socketmud-1.1/src/io.c Wed Feb 26 11:56:10 2003 *************** *** 24,40 **** */ void log(const char *txt, ...) { char buf[MAX_BUFFER]; ! char *strtime; va_list args; va_start(args, txt); vsprintf(buf, txt, args); va_end(args); ! strtime = get_time(); - fprintf(stderr, "%s: %s\n", strtime, buf); communicate(NULL, buf, COMM_LOG); } --- 24,52 ---- */ void log(const char *txt, ...) { + FILE *fp; + char logfile[MAX_BUFFER]; char buf[MAX_BUFFER]; ! char *strtime = get_time(); va_list args; va_start(args, txt); vsprintf(buf, txt, args); va_end(args); ! /* point to the correct logfile */ ! sprintf(logfile, "../log/%6.6s.log", strtime); ! ! /* try to open logfile */ ! if ((fp = fopen(logfile, "a")) == NULL) ! { ! communicate(NULL, "log: cannot open logfile", COMM_LOG); ! return; ! } ! ! fprintf(fp, "%s: %s\n", strtime, buf); ! fclose(fp); communicate(NULL, buf, COMM_LOG); } *************** *** 46,62 **** */ void bug(const char *txt, ...) { char buf[MAX_BUFFER]; va_list args; ! char *strtime; va_start(args, txt); vsprintf(buf, txt, args); va_end(args); ! strtime = get_time(); - fprintf(stderr, "%s: ***BUG*** %s ***BUG***\n", strtime, buf); communicate(NULL, buf, COMM_LOG); } --- 58,82 ---- */ void bug(const char *txt, ...) { + FILE *fp; char buf[MAX_BUFFER]; va_list args; ! char *strtime = get_time(); va_start(args, txt); vsprintf(buf, txt, args); va_end(args); ! /* try to open logfile */ ! if ((fp = fopen("../log/bugs.txt", "a")) == NULL) ! { ! communicate(NULL, "bug: cannot open bugfile", COMM_LOG); ! return; ! } ! ! fprintf(fp, "%s: %s\n", strtime, buf); ! fclose(fp); communicate(NULL, buf, COMM_LOG); } diff -r -N -c socketmud/src/mud.h socketmud-1.1/src/mud.h *** socketmud/src/mud.h Sat Mar 9 19:49:21 2002 --- socketmud-1.1/src/mud.h Wed Feb 26 11:06:52 2003 *************** *** 15,26 **** /* define TRUE and FALSE */ #ifndef FALSE ! #define FALSE 0 #endif #ifndef TRUE ! #define TRUE 1 #endif /* A few globals */ #define MAX_BUFFER 1024 /* seems like a decent amount */ #define MAX_OUTPUT 2048 /* well shoot me if it isn't enough */ --- 15,29 ---- /* define TRUE and FALSE */ #ifndef FALSE ! #define FALSE 0 #endif #ifndef TRUE ! #define TRUE 1 #endif + #define eTHIN 0 + #define eBOLD 1 + /* A few globals */ #define MAX_BUFFER 1024 /* seems like a decent amount */ #define MAX_OUTPUT 2048 /* well shoot me if it isn't enough */ diff -r -N -c socketmud/src/socket.c socketmud-1.1/src/socket.c *** socketmud/src/socket.c Sat Mar 9 19:49:26 2002 --- socketmud-1.1/src/socket.c Wed Feb 26 11:06:53 2003 *************** *** 510,523 **** */ void text_to_buffer(D_SOCKET *dsock, const char *txt) { ! static char output[8 * MAX_OUTPUT]; ! char *ptr; ! bool color = FALSE; ! int size; ! ! /* clear the output buffer, and set the pointer */ ! output[0] = '\0'; ! ptr = output; /* always start with a leading space */ if (dsock->top_output == 0) --- 510,557 ---- */ void text_to_buffer(D_SOCKET *dsock, const char *txt) { ! static char output[8 * MAX_BUFFER]; ! bool underline = FALSE, bold = FALSE; ! int iPtr = 0, last = -1, i = 0, j, k; ! int length = strlen(txt); ! ! /* the color struct */ ! struct sAnsiColor ! { ! const char cTag; ! const char * cString; ! int aFlag; ! }; ! ! /* the color table... */ ! const struct sAnsiColor ansiTable[] = ! { ! { 'd', "30", eTHIN }, ! { 'D', "30", eBOLD }, ! { 'r', "31", eTHIN }, ! { 'R', "31", eBOLD }, ! { 'g', "32", eTHIN }, ! { 'G', "32", eBOLD }, ! { 'y', "33", eTHIN }, ! { 'Y', "33", eBOLD }, ! { 'b', "34", eTHIN }, ! { 'B', "34", eBOLD }, ! { 'p', "35", eTHIN }, ! { 'P', "35", eBOLD }, ! { 'c', "36", eTHIN }, ! { 'C', "36", eBOLD }, ! { 'w', "37", eTHIN }, ! { 'W', "37", eBOLD }, ! ! /* the end tag */ ! { '\0', "", eTHIN } ! }; ! ! if (length >= MAX_BUFFER) ! { ! log("text_to_buffer: buffer overflow."); ! return; ! } /* always start with a leading space */ if (dsock->top_output == 0) *************** *** 527,669 **** dsock->top_output = 2; } ! while (*txt != '\0') { switch(*txt) { default: ! *ptr++ = *txt++; break; case '#': ! switch(*++txt) { ! default: ! *ptr++ = '#'; ! break; ! case 'n': // stock color ! txt++; color = FALSE; ! *ptr++ = 27; *ptr++ = '['; *ptr++ = '0'; ! *ptr++ = 'm'; ! break; ! case 'd': // Dark ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '0'; *ptr++ = 'm'; ! break; ! case 'D': // Bold Dark ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '0'; *ptr++ = 'm'; ! break; ! case 'r': // Red ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '1'; *ptr++ = 'm'; ! break; ! case 'R': // Bold Red ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '1'; *ptr++ = 'm'; ! break; ! case 'g': // Green ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '2'; *ptr++ = 'm'; ! break; ! case 'G': // Bold Green ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '2'; *ptr++ = 'm'; ! break; ! case 'y': // Yellow ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '3'; *ptr++ = 'm'; ! break; ! case 'Y': // Bold Yellow ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '3'; *ptr++ = 'm'; ! break; ! case 'b': // Blue ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '4'; *ptr++ = 'm'; ! break; ! case 'B': // Bold Blue ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '4'; *ptr++ = 'm'; ! break; ! case 'p': // Pink ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '5'; *ptr++ = 'm'; ! break; ! case 'P': // Bold Pink ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '5'; *ptr++ = 'm'; ! break; ! case 'c': // Cyan ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '6'; *ptr++ = 'm'; ! break; ! case 'C': // Bold Cyan ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '6'; *ptr++ = 'm'; ! break; ! case 'w': // White ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '0'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '7'; *ptr++ = 'm'; ! break; ! case 'W': // Bold White ! txt++; color = TRUE; ! *ptr++ = 27; *ptr++ = '['; ! *ptr++ = '1'; *ptr++ = ';'; ! *ptr++ = '3'; *ptr++ = '7'; *ptr++ = 'm'; ! break; } } } ! /* and terminate it with the standard color (White) */ ! if (color) { ! *ptr++ = 27; ! *ptr++ = '['; ! *ptr++ = '0'; ! *ptr++ = 'm'; } ! *ptr = '\0'; ! ! size = strlen(output); ! if (dsock->top_output + size >= MAX_OUTPUT) { bug("Text_to_buffer: ouput overflow on %s.", dsock->hostname); return; } strcpy(dsock->outbuf + dsock->top_output, output); ! dsock->top_output += size; } /* --- 561,724 ---- dsock->top_output = 2; } ! while (*txt != '\0' && i++ < length) { + /* simple bound checking */ + if (iPtr > (8 * MAX_BUFFER - 15)) + break; + switch(*txt) { default: ! output[iPtr++] = *txt++; break; case '#': ! i++; txt++; ! ! /* toggle underline on/off with #u */ ! if (*txt == 'u') { ! txt++; ! if (underline) ! { ! underline = FALSE; ! output[iPtr++] = 27; output[iPtr++] = '['; output[iPtr++] = '0'; ! if (bold) ! { ! output[iPtr++] = ';'; output[iPtr++] = '1'; ! } ! if (last != -1) ! { ! output[iPtr++] = ';'; ! for (j = 0; ansiTable[last].cString[j] != '\0'; j++) ! { ! output[iPtr++] = ansiTable[last].cString[j]; ! } ! } ! output[iPtr++] = 'm'; ! } ! else ! { ! underline = TRUE; ! output[iPtr++] = 27; output[iPtr++] = '['; ! output[iPtr++] = '4'; output[iPtr++] = 'm'; ! } } + + /* parse ## to # */ + else if (*txt == '#') + { + txt++; + output[iPtr++] = '#'; + } + + /* #n should clear all tags */ + else if (*txt == 'n') + { + txt++; + if (last != -1 || underline || bold) + { + underline = FALSE; + bold = FALSE; + output[iPtr++] = 27; output[iPtr++] = '['; + output[iPtr++] = '0'; output[iPtr++] = 'm'; + } + + last = -1; + } + + /* check for valid color tag and parse */ + else + { + bool validTag = FALSE; + + for (j = 0; ansiTable[j].cString[0] != '\0'; j++) + { + if (*txt == ansiTable[j].cTag) + { + validTag = TRUE; + + /* we only add the color sequence if it's needed */ + if (last != j) + { + bool cSequence = FALSE; + + /* escape sequence */ + output[iPtr++] = 27; output[iPtr++] = '['; + + /* remember if a color change is needed */ + if (last == -1 || last / 2 != j / 2) + cSequence = TRUE; + + /* handle font boldness */ + if (bold && ansiTable[j].aFlag == eTHIN) + { + output[iPtr++] = '0'; + bold = FALSE; + + if (underline) + { + output[iPtr++] = ';'; output[iPtr++] = '4'; + } + + /* changing to eTHIN wipes the old color */ + output[iPtr++] = ';'; + cSequence = TRUE; + } + else if (!bold && ansiTable[j].aFlag == eBOLD) + { + output[iPtr++] = '1'; + bold = TRUE; + + if (cSequence) + output[iPtr++] = ';'; + } + + /* add color sequence if needed */ + if (cSequence) + { + for (k = 0; ansiTable[j].cString[k] != '\0'; k++) + { + output[iPtr++] = ansiTable[j].cString[k]; + } + } + + output[iPtr++] = 'm'; + } + + /* remember the last color */ + last = j; + } + } + + /* it wasn't a valid color tag */ + if (!validTag) + output[iPtr++] = '#'; + else + txt++; + } + break; } } ! /* and terminate it with the standard color */ ! if (last != -1 || underline || bold) { ! output[iPtr++] = 27; output[iPtr++] = '['; ! output[iPtr++] = '0'; output[iPtr++] = 'm'; } ! output[iPtr] = '\0'; ! /* check to see if the socket can accept that much data */ ! if (dsock->top_output + iPtr >= MAX_OUTPUT) { bug("Text_to_buffer: ouput overflow on %s.", dsock->hostname); return; } + + /* add data to buffer */ strcpy(dsock->outbuf + dsock->top_output, output); ! dsock->top_output += iPtr; } /* diff -r -N -c socketmud/src/utils.c socketmud-1.1/src/utils.c *** socketmud/src/utils.c Sat Mar 9 19:50:10 2002 --- socketmud-1.1/src/utils.c Wed Feb 26 11:41:44 2003 *************** *** 147,153 **** D_MOBILE *dMob; D_SOCKET *dsock; FILE *fp; - unsigned char telopt; char name [100]; char host[MAX_BUFFER]; int desc; --- 147,152 ---- *************** *** 165,171 **** for (;;) { ! fscanf(fp, "%d %s %s %c\n", &desc, name, host, &telopt); if (desc == -1) break; --- 164,170 ---- for (;;) { ! fscanf(fp, "%d %s %s\n", &desc, name, host); if (desc == -1) break; *************** *** 176,185 **** dsock->next = dsock_list; dsock_list = dsock; - /* re-enable compression if it was enabled before */ - if (telopt == TELOPT_COMPRESS || telopt == TELOPT_COMPRESS2) - compressStart(dsock, telopt); - /* load player data */ if ((dMob = load_player(name)) != NULL) { --- 175,180 ---- *************** *** 208,213 **** --- 203,212 ---- dsock->bust_prompt = TRUE; dsock->lookup_status = TSTATE_DONE; dsock->state = STATE_PLAYING; + + /* negotiate compression */ + text_to_buffer(dsock, (char *) compress_will2); + text_to_buffer(dsock, (char *) compress_will); } fclose(fp); }