Просмотр исходного кода

* Fixed some bugs in dprintf()
-Re-wrote some of the color routines
* Re-wrote show_banner to use dumplots()
* Re-wrote show_motd to use dumplots()


svn: 195

Bryan Drewery 22 лет назад
Родитель
Сommit
833edc2365
4 измененных файлов с 76 добавлено и 73 удалено
  1. 1 1
      src/botcmd.c
  2. 8 7
      src/cmds.c
  3. 56 59
      src/dccutil.c
  4. 11 6
      src/misc.c

+ 1 - 1
src/botcmd.c

@@ -1517,7 +1517,7 @@ void bounce_simul(int idx, char *buf)
     return;
   }
 
-  snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].ridx, buf);          /* remote-simul[r]eturn idx buf */
+  snprintf(rmsg, sizeof rmsg, "r-sr %d %s", dcc[idx].simul, buf);          /* remote-simul[r]eturn idx buf */
 
   putbot(dcc[idx].simulbot, rmsg);
 }

+ 8 - 7
src/cmds.c

@@ -565,7 +565,7 @@ static void cmd_motd(struct userrec *u, int idx, char *par)
   if (par[0] && (u->flags & USER_MASTER)) {
     char *s;
 
-    s = nmalloc(strlen(par) + 20);
+    s = nmalloc(strlen(par) + 1 + HANDLEN + 3); /* +3: '() ' */
     sprintf(s, STR("(%s) %s"), dcc[idx].nick, par);
     set_cfg_str(NULL, "motd", s);
     nfree(s);
@@ -574,6 +574,7 @@ static void cmd_motd(struct userrec *u, int idx, char *par)
     show_motd(idx);
   }
 }
+
 static void cmd_about(struct userrec *u, int idx, char *par)
 {
   putlog(LOG_CMDS, "*", STR("#%s# about"), dcc[idx].nick);
@@ -2348,7 +2349,7 @@ static void cmd_chat(struct userrec *u, int idx, char *par)
   }
 }
 
-int exec_str(struct userrec *u, int idx, char *cmd) {
+int exec_str(int idx, char *cmd) {
   char *out, *err, *p, *np;
   if (shell_exec(cmd, NULL, &out, &err)) {
     if (out) {
@@ -2390,7 +2391,7 @@ static void cmd_exec(struct userrec *u, int idx, char *par) {
     return;
   }
 #endif
-  if (exec_str(u, idx, par))
+  if (exec_str(idx, par))
     dprintf(idx, STR("Exec completed\n"));
   else
     dprintf(idx, STR("Exec failed\n"));
@@ -2398,7 +2399,7 @@ static void cmd_exec(struct userrec *u, int idx, char *par) {
 
 static void cmd_w(struct userrec *u, int idx, char *par) {
   putlog(LOG_CMDS, "*", STR("#%s# w"), dcc[idx].nick);
-  if (!exec_str(u, idx, "w"))
+  if (!exec_str(idx, "w"))
     dprintf(idx, STR("Exec failed\n"));
 }
 
@@ -2412,7 +2413,7 @@ static void cmd_ps(struct userrec *u, int idx, char *par) {
   }
   buf=nmalloc(strlen(par)+4);
   sprintf(buf, STR("ps %s"), par);
-  if (!exec_str(u, idx, buf))
+  if (!exec_str(idx, buf))
     dprintf(idx, STR("Exec failed\n"));
   nfree(buf);
 }
@@ -2439,7 +2440,7 @@ static void cmd_last(struct userrec *u, int idx, char *par) {
     return;
   }
   sprintf(buf, STR("last %s"), user);
-  if (!exec_str(u, idx, buf))
+  if (!exec_str(idx, buf))
     dprintf(idx, STR("Failed to execute /bin/sh last\n"));
 }
 
@@ -3505,7 +3506,7 @@ static void cmd_netlast(struct userrec * u, int idx, char * par) {
 
 void crontab_show(struct userrec * u, int idx) {
   dprintf(idx, STR("Showing current crontab:\n"));
-  if (!exec_str(u, idx, STR("crontab -l | grep -v \"^#\"")))
+  if (!exec_str(idx, STR("crontab -l | grep -v \"^#\"")))
     dprintf(idx, STR("Exec failed"));
 }
 

+ 56 - 59
src/dccutil.c

@@ -93,14 +93,14 @@ extern void (*qserver) (int, char *, int);
 
 void dprintf EGG_VARARGS_DEF(int, arg1)
 {
-  static char buf[1624];
-  char *format, buf3[1624] = "", buf2[1624] = "", c; 
-  int idx, len, id;
+  static char buf[1024];
+  char *format; 
+  int idx, len;
   va_list va;
 
   idx = EGG_VARARGS_START(int, arg1, va);
   format = va_arg(va, char *);
-  egg_vsnprintf(buf, 1623, format, va);
+  egg_vsnprintf(buf, 1023, format, va);
   va_end(va);
   /* We can not use the return value vsnprintf() to determine where
    * to null terminate. The C99 standard specifies that vsnprintf()
@@ -114,54 +114,6 @@ void dprintf EGG_VARARGS_DEF(int, arg1)
   len = strlen(buf);
 
 /* this is for color on dcc :P */
-id = idx;
-if (id < 0) { id = idx + 7; id = -id; }
-
-if ((id < 0x7FF0) && (dcc[id].status & STAT_COLOR) && 
- (dcc[id].type == &DCC_CHAT)) {
- int i, a = 0, m = 0;
- if (dcc[id].status & STAT_COLORM) 
-  m = 1;
- else if (dcc[id].status & STAT_COLORA)
-  a = 1;
-if (!a && !m) { goto broke; }
- buf3[0] = '\0';
- for (i = 0 ; i < len ; i++) {
-   c = buf[i];
-   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);
-   } 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);
-   } else {
-      sprintf(buf2, "%c", c);
-   }
-
-   sprintf(buf3, "%s%s", buf3 ? buf3 : "", buf2 ? buf2 : "");
- }
- buf3[strlen(buf3)] = '\0';
- strcpy(buf, buf3);
-}
-broke:
-  buf[sizeof(buf)-1] = 0;
-  len = strlen(buf);
 
   if (idx < 0) {
     tputs(-idx, buf, len);
@@ -179,32 +131,77 @@ broke:
     case DP_SERVER:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
     case DP_HELP:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
     case DP_MODE:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
     case DP_MODE_NEXT:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
     case DP_SERVER_NEXT:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
     case DP_HELP_NEXT:
 #ifdef HUB
      return;
-#endif
+#endif /* HUB */
       qserver(idx, buf, len);
       break;
     }
     return;
-  } else {
+  } 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';
+      for (i = 0 ; i < len ; i++) {
+        c = buf[i];
+        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);
+        } 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);
+        } else {
+          sprintf(buf2, "%c", c);
+        }
+        sprintf(buf3, "%s%s", buf3 ? buf3 : "", buf2 ? buf2 : "");
+      }
+      buf3[strlen(buf3)] = '\0';
+      strcpy(buf, buf3);
+    }
+    buf[sizeof(buf)-1] = 0;
+    len = strlen(buf);
+
     if (len > 1000) {		/* Truncate to fit */
       buf[1000] = 0;
       strcat(buf, "\n");

+ 11 - 6
src/misc.c

@@ -447,7 +447,7 @@ char *wbanner() {
 
 void show_banner(int idx)
 {
-  dprintf(idx, "%s", wbanner());
+  dumplots(-dcc[idx].sock, "", wbanner()); /* we use sock so that colors aren't applied to banner */
   dprintf(idx, "\n \n");
   dprintf(idx, STR("info, bugs, suggestions, comments:\n- http://www.shatow.net/wraith/ -\n"));
 }
@@ -455,11 +455,16 @@ void show_banner(int idx)
 /* show motd to dcc chatter */
 void show_motd(int idx)
 {
-  dprintf(idx, STR("Motd: "));
-  if (CFG_MOTD.gdata && *(char *) CFG_MOTD.gdata)
-    dprintf(idx, STR("%s\n"), (char *) CFG_MOTD.gdata);
-  else
-    dprintf(idx, STR("none\n"));
+  if (CFG_MOTD.gdata && *(char *) CFG_MOTD.gdata) {
+    /* char *buf; 
+
+    * buf = nmalloc(strlen((char *)CFG_MOTD.gdata) + 1);
+    * strcpy(buf, (char *)CFG_MOTD.gdata);
+    */
+    dumplots(idx, "Motd: ", (char *)CFG_MOTD.gdata);
+    /* nfree(buf); */
+  } else
+    dprintf(idx, STR("Motd: none\n"));
 }
 
 void show_channels(int idx, char *handle)