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

* Add rdprintf() for remote dprintf

Bryan Drewery 16 лет назад
Родитель
Сommit
e545647319
3 измененных файлов с 47 добавлено и 5 удалено
  1. 11 0
      src/botcmd.c
  2. 32 2
      src/dccutil.c
  3. 4 3
      src/dccutil.h

+ 11 - 0
src/botcmd.c

@@ -1359,8 +1359,19 @@ static void bot_rsimr(char *botnick, char *code, char *msg)
   }
 }
 
+static void bot_rd(char* botnick, char* code, char* msg)
+{
+  size_t len = atoi(newsplit(&msg));
+  if (msg[0]) {
+    int idx = atoi(newsplit(&msg));
+    if (msg[0])
+      dprintf_real(idx, msg, len, len);
+  }
+}
+
 static cmd_t my_bot[] = 
 {
+  {"rd",	"",	(Function) bot_rd,	NULL, 0},
   {"r-sr",	"",	(Function) bot_rsimr,	NULL, HUB},
   {"r-s",	"",	(Function) bot_rsim,	NULL, 0},
   {NULL, 	NULL, 	NULL, 			NULL, 0}

+ 32 - 2
src/dccutil.c

@@ -46,6 +46,7 @@
 #include "botcmd.h"
 #include <errno.h>
 #include "chan.h"
+#include "botmsg.h"
 #include "tandem.h"
 #include "core_binds.h"
 #include "egg_timer.h"
@@ -257,6 +258,31 @@ void dumplots(int idx, const char *prefix, const char *data)
     dprintf(idx, "%s%s\n", prefix, p);  /* Last trailing bit */
 }
 
+void
+rdprintf(const char* target, int idx, const char *format, ...)
+{
+  char buf[1024] = "";
+  size_t len = 0;
+  va_list va;
+
+  va_start(va, format);
+  int vlen = egg_vsnprintf(buf, sizeof(buf), format, va);
+  va_end(va);
+
+  if (unlikely(vlen < 0)) {
+    // Error parsing format..
+    return;
+  }
+
+  if (size_t(vlen) > (sizeof(buf) - 1)) {
+    len = sizeof(buf) - 1;
+    buf[len] = 0;
+  } else {
+    len = size_t(vlen);
+  }
+  dprintf_real(idx, buf, len, sizeof(buf), target);
+}
+
 void
 dprintf(int idx, const char *format, ...)
 {
@@ -283,11 +309,15 @@ dprintf(int idx, const char *format, ...)
 }
 
 void
-dprintf_real(int idx, char* buf, size_t len, size_t bufsiz)
+dprintf_real(int idx, char* buf, size_t len, size_t bufsiz, const char* target)
 {
 /* this is for color on dcc :P */
 
-  if (unlikely(idx < 0)) {
+  if (unlikely(target)) {
+    char pbot[1024] = "";
+    simple_snprintf(pbot, sizeof(pbot), "rd %zu %d %s", len, idx, buf);
+    putbot(target, pbot);
+  } else if (unlikely(idx < 0)) {
     tputs(-idx, buf, len);
   } else if (idx > 0x7FF0) {
     if (unlikely(idx == DP_STDOUT || idx == DP_STDOUT)) {

+ 4 - 3
src/dccutil.h

@@ -5,8 +5,6 @@
 #include "dcc.h"
 #include "auth.h"
 
-#define dprintf dprintf_eggdrop
-
 /* Public structure for the listening port map */
 struct portmap {
   port_t realport;
@@ -18,6 +16,8 @@ namespace bd {
   class Stream;
 }
 
+#define dprintf dprintf_eggdrop
+
 /* Fake idx's for dprintf - these should be ridiculously large +ve nums
  */
 #define DP_STDOUT       0x7FF1
@@ -38,8 +38,9 @@ namespace bd {
 
 void init_dcc(void);
 void dumplots(int, const char *, const char *);
+void rdprintf(const char*, int, const char *, ...) __attribute__((format(printf, 3, 4)));
 void dprintf(int, const char *, ...) __attribute__((format(printf, 2, 3)));
-void dprintf_real(int, char*, size_t, size_t);
+void dprintf_real(int, char*, size_t, size_t, const char* = NULL);
 void chatout(const char *, ...) __attribute__((format(printf, 1, 2)));
 void chanout_but(int, int, const char *, ...) __attribute__((format(printf, 3, 4)));
 void dcc_chatter(int);