Przeglądaj źródła

* Added color(idx, TYPE, C_COLOR);
* Fixed console to only have ON/OFF for color


svn: 460

Bryan Drewery 22 lat temu
rodzic
commit
57cacca5f3
8 zmienionych plików z 134 dodań i 112 usunięć
  1. 4 4
      misc/help.txt
  2. 5 21
      src/cmds.c
  3. 1 2
      src/dcc.c
  4. 16 32
      src/dccutil.c
  5. 27 3
      src/eggdrop.h
  6. 66 17
      src/misc.c
  7. 14 33
      src/mod/console.mod/console.c
  8. 1 0
      src/proto.h

+ 4 - 4
misc/help.txt

@@ -648,10 +648,9 @@ See also: chhandle, chpass
    ** Only permanent owners specified in the binary COMPILE config file **
    ** can use this cmd.                                                 **
 ::color:
-###  %bcolor%b <on/off> <mIRC/ANSI>
-   Enables or disables misc coloring over DCC. Chosing mIRC will display
-   color codes in mIRC format using ^K^B, etc.. while ANSI will use escape
-   chars to generate the color output.
+###  %bcolor%b <on/off>
+   Enables or disables misc coloring over DCC. mIRC or ANSI method is
+   chosen automatically.
  
 See also: echo, page, strip
 ::comment
@@ -770,6 +769,7 @@ See also: down
    letters mean that the flag is on, and lowercase letters mean that the flag
    is off. The flags for 'CHAT' are:
      %bC%b  in file area, but allowed to return to party line
+     %bK%b  color is on
      %bP%b  party line access only
      %bT%b  telnet connection (instead of dcc chat)
      %bE%b  echo is on

+ 5 - 21
src/cmds.c

@@ -2649,44 +2649,28 @@ static void cmd_color(struct userrec *u, int idx, char *par)
 {
   module_entry *me;
 
-  char *type, *of;
+  char *of;
   putlog(LOG_CMDS, "*", STR("#%s# color %s"), dcc[idx].nick, par);
 
   if (!par[0]) {
-    dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
+    dprintf(idx, STR("Usage: color <on/off>\n"));
     if (dcc[idx].status & STAT_COLOR) 
-      dprintf(idx, STR("Color is currently on (%s).\n"), dcc[idx].status & STAT_COLORM ? "mIRC" : "ANSI");
+      dprintf(idx, STR("Color is currently on.\n"));
     else
       dprintf(idx, STR("Color is currently off.\n"));
     return;
   }
   of = newsplit(&par);
-  type = newsplit(&par);
 
   if (!egg_strcasecmp(of, "on")) {
-    if (!type) {
-      dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
-      return;
-    }
-    if (!egg_strcasecmp(type, "mirc")) {
-      dcc[idx].status &= ~STAT_COLORA;
-      dcc[idx].status |= (STAT_COLOR | STAT_COLORM);
-      dprintf(idx, STR("Color turned on (mIRC).\n"));
-    } else if (!egg_strcasecmp(type, "ansi")) {
-      dcc[idx].status &= ~STAT_COLORM;
-      dcc[idx].status |= (STAT_COLOR | STAT_COLORA);
-      dprintf(idx, STR("Color turned on (ANSI).\n"));
-    } else {
-      return;
-    }
+    dcc[idx].status |= STAT_COLOR;
   } else if (!egg_strcasecmp(of, "off")) {
-    dcc[idx].status &= ~(STAT_COLOR | STAT_COLORM | STAT_COLORA);
+    dcc[idx].status &= ~(STAT_COLOR);
     dprintf(idx, STR("Color turned off.\n"));
   } else {
     return;
   }
 
-  /* New style autosave here too -- rtc, 09/28/1999*/
   if ((me = module_find("console", 0, 0))) {
     Function *func = me->funcs;
     (func[CONSOLE_DOSTORE]) (idx);

+ 1 - 2
src/dcc.c

@@ -1163,8 +1163,7 @@ static void display_dcc_chat(int idx, char *buf)
   buf[i++] = dcc[idx].status & STAT_TELNET ? 'T' : 't';
   buf[i++] = dcc[idx].status & STAT_ECHO ? 'E' : 'e';
   buf[i++] = dcc[idx].status & STAT_PAGE ? 'P' : 'p';
-  buf[i++] = dcc[idx].status & STAT_COLORM ? 'M' : 'm';
-  buf[i++] = dcc[idx].status & STAT_COLORA ? 'A' : 'a';
+  buf[i++] = dcc[idx].status & STAT_COLOR ? 'K' : 'k';
 #ifdef USE_IPV6
   if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].addr6[0])
     buf[i++] = '6';

+ 16 - 32
src/dccutil.c

@@ -157,16 +157,11 @@ void dprintf EGG_VARARGS_DEF(int, arg1)
     }
     return;
   } else { /* normal chat text */
-    if ((dcc[idx].status & STAT_COLOR) && (dcc[idx].type == &DCC_CHAT)
-        && ((dcc[idx].status & STAT_COLORM) || (dcc[idx].status & STAT_COLORA))) {
-      int i, a = 0, m = 0;
-      char buf3[1024] = "", buf2[1024] = "", c;
-
-      if (dcc[idx].status & STAT_COLORM) 
-        m = 1;
-      else if (dcc[idx].status & STAT_COLORA)
-        a = 1;
-      buf3[0] = '\0';
+    if ((dcc[idx].status & STAT_COLOR) && (dcc[idx].type == &DCC_CHAT)) {
+      int i;
+      char buf3[1024], buf2[1024], c;
+
+      buf3[0] = buf2[0] = 0;
       for (i = 0 ; i < len ; i++) {
 /* FIXME: Trying to fix bug where you do .color on ANSI, then .bc <bot> help help OVER TELNET
         if (buf[i] == '\033') {
@@ -177,37 +172,26 @@ void dprintf EGG_VARARGS_DEF(int, arg1)
         }
 */
         c = buf[i];
-        buf2[0] = '\0';
+        buf2[0] = 0;
 
         if (c == ':') {
-          if (a)
-            sprintf(buf2, "\e[%d;%dm%c\e[0m", 0, 37, c);
-          else
-            sprintf(buf2, "\003%d%c\003\002\002", 15, c);
+          sprintf(buf2, "%s%c%s", color(idx, COLOR_OPEN, C_LIGHTGREY), c, color(idx, COLOR_CLOSE, 0));
         } else if (c == '@') {
-          if (a)
-            sprintf(buf2, "\e[1m%c\e[0m", c);
-          else
-            sprintf(buf2, "\002%c\002", c);
-        } else if (c == ']' || c == '>' || c == ')') {
-          if (a)
-            sprintf(buf2, "\e[%d;%dm%c\e[0m", 0, 32, c);
-          else
-            sprintf(buf2, "\00303%c\003\002\002", c);
-        } else if (c == '[' || c == '<' || c == '(') {
-          if (a)
-            sprintf(buf2, "\e[%d;%dm%c\e[0m", 0, 32, c);
-          else
-            sprintf(buf2, "\00303%c\003\002\002", c);
+          sprintf(buf2, "%s%c%s", color(idx, BOLD_OPEN, 0), c, color(idx, BOLD_CLOSE, 0));
+//        } else if (c == ']' || c == '>' || c == ')' || c == '[' || c == '<' || c == '(') {
+        } else if (c == '>' || c == ')' || c == '<' || c == '(') {
+          sprintf(buf2, "%s%c%s", color(idx, COLOR_OPEN, C_GREEN), c, color(idx, COLOR_CLOSE, 0));
         } else {
           sprintf(buf2, "%c", c);
         }
-        sprintf(buf3, "%s%s", buf3 ? buf3 : "", buf2 ? buf2 : "");
+//        sprintf(buf3, "%s%s", buf3 ? buf3 : "", buf2 ? buf2 : "");
+        sprintf(buf3, "%s%s", (buf3 && buf3[0]) ? buf3 : "", (buf2 && buf2[0]) ? buf2 : "");
       }
-      buf3[strlen(buf3)] = '\0';
+      buf3[strlen(buf3)] = 0;
       strcpy(buf, buf3);
+//      strncpyz(buf, buf2, sizeof buf);
     }
-    buf[sizeof(buf)-1] = 0;
+    buf[sizeof(buf) - 1] = 0;
     len = strlen(buf);
 
     if (len > 1000) {		/* Truncate to fit */

+ 27 - 3
src/eggdrop.h

@@ -104,6 +104,32 @@
 #define ERR_BADCONF 14
 #define ERR_MAX 15
 
+#define C_BLACK                 1
+#define C_BLUE                  2
+#define C_GREEN                 3
+#define C_CYAN                  4
+#define C_RED                   5
+#define C_PURPLE                6
+#define C_BROWN                 7
+#define C_LIGHTGREY             8
+#define C_DARKGREY              9
+#define C_LIGHTBLUE             10
+#define C_LIGHTGREEN            11
+#define C_LIGHTCYAN             12
+#define C_LIGHTRED              13
+#define C_LIGHTPURPLE           14
+#define C_YELLOW                15
+#define C_WHITE                 16
+#define BOLD_OPEN               1
+#define BOLD_CLOSE              2
+#define UNDERLINE_OPEN          3
+#define UNDERLINE_CLOSE         4
+#define COLOR_OPEN              5
+#define COLOR_CLOSE             6
+#define FLASH_OPEN              7
+#define FLASH_CLOSE             8
+
+
 /*
  *     The 'configure' script should make this next part automatic,
  *     so you shouldn't need to adjust anything below.
@@ -534,9 +560,7 @@ struct dupwait_info {
 #define STAT_BOTONLY 0x00020	/* telnet on bots-only connect		*/
 #define STAT_USRONLY 0x00040	/* telnet on users-only connect		*/
 #define STAT_PAGE    0x00080	/* page output to the user		*/
-#define STAT_COLORM  0x00100    /* show crazy colors to user mIRC */
-#define STAT_COLORA  0x00200    /* show crazy colors to user ANSI */
-#define STAT_COLOR   0x00400    /* Color enabled for user */
+#define STAT_COLOR   0x00100    /* Color enabled for user */
 
 /* For stripping out mIRC codes
  */

+ 66 - 17
src/misc.c

@@ -2053,7 +2053,6 @@ char *btoh(const unsigned char *md, int len)
 #define HELP_REV   2
 #define HELP_UNDER 4
 #define HELP_FLASH 8
-#define HELP_IRC   16
 
 void showhelp (int idx, struct flag_record *flags, char *string)
 {
@@ -2061,7 +2060,6 @@ void showhelp (int idx, struct flag_record *flags, char *string)
   struct flag_record tr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
   static char helpstr[8092] = "", tmp[2] = "", flagstr[10] = "";
   int ok = 1;
-  if (!help_flags) help_flags = (dcc[idx].status & STAT_TELNET) ? 0 : HELP_IRC;
 Context;
   helpstr[0] = 0;
   while ((string) && (string[0])) {
@@ -2107,33 +2105,23 @@ Context;
         }
       } else if (*(string + 1) == 'b') {
         string += 2;
-        if (help_flags & HELP_IRC) {
-          sprintf(tmp, "\002");
-        } else if (help_flags & HELP_BOLD) {
+        if (help_flags & HELP_BOLD) {
           help_flags &= ~HELP_BOLD;
-         sprintf(tmp, "\033[0m");
+          strcat(helpstr, color(idx, BOLD_CLOSE, 0));
         } else {
           help_flags |= HELP_BOLD;
-          sprintf(tmp, "\033[1m");
+          strcat(helpstr, color(idx, BOLD_OPEN, 0));
         }
-        strcat(helpstr, tmp);
       } else if (*(string + 1) == 'f') {
         string += 2;
         
         if (help_flags & HELP_FLASH) {
-          if (help_flags & HELP_IRC)
-            sprintf(tmp, "\002\037");
-          else
-            sprintf(tmp, "\033[0m");
+          strcat(helpstr, color(idx, FLASH_CLOSE, 0));
           help_flags &= ~HELP_FLASH;
         } else {
           help_flags |= HELP_FLASH;
-          if (help_flags & HELP_IRC)
-            sprintf(tmp, "\002\037");
-          else
-            sprintf(tmp, "\033[5m");
+          strcat(helpstr, color(idx, FLASH_OPEN, 0));
         }
-        strcat(helpstr, tmp);
       } else if (*(string + 1) == 'd') {
         string += 2;
         strcat(helpstr, dcc_prefix);        
@@ -2198,3 +2186,64 @@ void shuffle(char *string, char *delim)
   string[strlen(string)] = 0;
 }
 
+char *color(int idx, int type, int color)
+{
+  int ansi = 0;
+   
+  /* if user is connected over TELNET or !backgrd, show ANSI
+   * if they are relaying, they are most likely on an IRC client and should have mIRC codes
+   */
+  if (((dcc[idx].type != &DCC_RELAYING) && (dcc[idx].status & STAT_TELNET)) || !backgrd) ansi++;
+
+  if (type == BOLD_OPEN) {
+    if (ansi) return "\033[1m";
+    return "\002";
+  } else if (type == BOLD_CLOSE) {
+    if (ansi) return "\033[22m";
+    return "\002";
+   } else if (type == UNDERLINE_OPEN) {
+    if (ansi) return "\033[4m";
+    return "\037";
+  } else if (type == UNDERLINE_CLOSE) {
+    if (ansi) return "\033[24m";
+    return "\037";
+  } else if (type == FLASH_OPEN) {
+    if (ansi) return "\033[5m";
+    return "\002\037";
+  } else if (type == FLASH_CLOSE) {
+    if (ansi) return "\033[0m";
+    return "\037\002";
+  } else if (type == COLOR_OPEN) {
+    if (color == C_BLACK) {
+      if (ansi) return "\033[30m";
+      return "\00301";
+    } else if (color == C_RED) {
+      if (ansi) return "\033[31m";
+      return "\00304";
+    } else if (color == C_GREEN) {
+      if (ansi) return "\033[32m";
+      return "\00303";
+    } else if (color == C_YELLOW) {
+      if (ansi) return "\033[33m";
+      return "\00308";
+    } else if (color == C_BLUE) {
+      if (ansi) return "\033[34m";
+      return "\00302";
+    } else if (color == C_PURPLE) {
+      if (ansi) return "\033[35m";
+      return "\00306";
+    } else if (color == C_CYAN) {
+      if (ansi) return "\033[36m";
+      return "\00309";
+    } else if (color == C_WHITE) {
+      if (ansi) return "\033[37m";
+      return "\00300";
+    }
+  } else if (type == COLOR_CLOSE) {
+    if (ansi) return "\033[0m";
+    return "\003";
+  } 
+  /* This should never be reached.. */
+  return "";
+}
+

+ 14 - 33
src/mod/console.mod/console.c

@@ -167,16 +167,10 @@ static int console_gotshare(struct userrec *u, struct user_entry *e, char *par,
         if (!dcc[i].u.chat->line_count)
           dcc[i].u.chat->current_lines = 0;
       }
-      if (ci->color) {
-        if (ci->color == 1) {
-          dcc[i].status &= ~STAT_COLORA;
-          dcc[i].status |= (STAT_COLOR | STAT_COLORM);
-        } else if (ci->color == 2) {
-          dcc[i].status &= ~STAT_COLORM;
-          dcc[i].status |= (STAT_COLOR | STAT_COLORA);
-        }
-      } else
-         dcc[i].status &= ~(STAT_COLOR | STAT_COLORA | STAT_COLORM);
+      if (ci->color)
+        dcc[i].status |= (STAT_COLOR);
+      else
+        dcc[i].status &= ~(STAT_COLOR);
     }
   }
   return 1;
@@ -259,9 +253,7 @@ static void console_display(int idx, struct user_entry *e, struct userrec *u)
             i->conchan % GLOBAL_CHANS);
     sprintf(tmp, "    Color:");
     if (i->color == 1)
-     sprintf(tmp, "%s mIRC", tmp);
-    else if (i->color == 2)
-     sprintf(tmp, "%s ANSI", tmp);
+     sprintf(tmp, "%s on", tmp);
     else
      sprintf(tmp, "%s off", tmp);
     dprintf(idx, "%s\n", tmp);
@@ -319,16 +311,10 @@ static int console_chon(char *handle, int idx)
 	if (!dcc[idx].u.chat->line_count)
 	  dcc[idx].u.chat->current_lines = 0;
       }
-      if (i->color) {
-        if (i->color == 1) {
-         dcc[idx].status &= ~STAT_COLORA;
-         dcc[idx].status |= (STAT_COLOR | STAT_COLORM);
-        } else if (i->color == 2) {
-         dcc[idx].status &= ~STAT_COLORM;
-         dcc[idx].status |= (STAT_COLOR | STAT_COLORA);
-        }
-      } else
-         dcc[idx].status &= ~(STAT_COLOR | STAT_COLORA | STAT_COLORM);
+      if (i->color)
+        dcc[idx].status |= (STAT_COLOR);
+      else
+        dcc[idx].status &= ~(STAT_COLOR);
     }
     if ((dcc[idx].u.chat->channel >= 0) &&
 	(dcc[idx].u.chat->channel < GLOBAL_CHANS)) {
@@ -374,13 +360,10 @@ static int console_store(struct userrec *u, int idx, char *par)
     i->page = dcc[idx].u.chat->max_line;
   else
     i->page = 0;
-  if (dcc[idx].status & STAT_COLOR) {
-    if (dcc[idx].status & STAT_COLORM)
-      i->color = 1;
-    else if (dcc[idx].status & STAT_COLORA)
-      i->color = 2;
-  } else
-   i->color = 0;
+  if (dcc[idx].status & STAT_COLOR)
+    i->color = 1;
+  else
+    i->color = 0;
   i->conchan = dcc[idx].u.chat->channel;
   if (par) {
     char tmp[100];
@@ -394,9 +377,7 @@ static int console_store(struct userrec *u, int idx, char *par)
             CONSOLE_CHANNEL2, i->conchan);
     sprintf(tmp, "    Color:");
     if (i->color == 1)
-     sprintf(tmp, "%s mIRC", tmp);
-    else if (i->color == 2)
-     sprintf(tmp, "%s ANSI", tmp);
+     sprintf(tmp, "%s on", tmp);
     else
      sprintf(tmp, "%s off", tmp);
     dprintf(idx, "%s\n", tmp);

+ 1 - 0
src/proto.h

@@ -229,6 +229,7 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 
 /* misc.c */
+char *color(int, int, int);
 void shuffle(char *, char *);
 void showhelp(int, struct flag_record *, char *);
 char *btoh(const unsigned char *, int);