Permalink
Browse files

New cmd /ping, sends a CTCP ping. Also, handling of responses

  • Loading branch information...
ec429
ec429 committed May 22, 2012
1 parent 3886d7d commit 9a76983532a92badf73333ecfcdd2bacd5083cc9
Showing with 65 additions and 3 deletions.
  1. +42 −0 input.c
  2. +1 −0 input.h
  3. +21 −1 irc.c
  4. +1 −0 irc.h
  5. +0 −2 plans
View
42 input.c
@@ -1231,6 +1231,48 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
}
return(0);
}
+ if(strcmp(cmd, "ping")==0)
+ {
+ if(!bufs[bufs[cbuf].server].handle)
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Must be run in the context of a server!", "/ping: ");
+ }
+ else
+ {
+ const char *dest=NULL;
+ if(args)
+ dest=strtok(args, " ");
+ if(!dest&&bufs[cbuf].type==PRIVATE)
+ dest=bufs[cbuf].bname;
+ if(dest)
+ {
+ if(bufs[bufs[cbuf].server].handle)
+ {
+ if(LIVE(cbuf))
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ char privmsg[64+strlen(dest)];
+ snprintf(privmsg, 64+strlen(dest), "PRIVMSG %s :\001PING %u %u\001", dest, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec);
+ irc_tx(bufs[bufs[cbuf].server].handle, privmsg);
+ }
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Tab not live, can't send", "/ping: ");
+ }
+ }
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Can't send - not connected!", "/ping: ");
+ }
+ }
+ else
+ {
+ add_to_buffer(cbuf, ERR, NORMAL, 0, false, "Must specify a recipient!", "/ping: ");
+ }
+ }
+ return(0);
+ }
if(strcmp(cmd, "amsg")==0)
{
if(!bufs[cbuf].server)
View
@@ -13,6 +13,7 @@
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
+#include <sys/time.h>
typedef struct
{
View
22 irc.c
@@ -1728,7 +1728,27 @@ int ctcp(const char *msg, const char *src, int b2, bool ha, bool notice, bool pr
if(notice)
{
if(priv) b2=makeptab(b, src);
- add_to_buffer(b2, NOTICE, NORMAL, 0, false, msg, src);
+ unsigned int t, u;
+ ssize_t n;
+ if((msg[4]==' ')&&(sscanf(msg+5, "%u%zn", &t, &n)==1))
+ {
+ double dt=0;
+ if((msg[5+n]==' ')&&(sscanf(msg+6+n, "%u", &u)==1))
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ dt=(tv.tv_sec-t)+1e-6*(tv.tv_usec-u);
+ }
+ else
+ dt=difftime(time(NULL), t);
+ char tm[32];
+ snprintf(tm, 32, "%gs", dt);
+ add_to_buffer(b2, STA, NORMAL, 0, false, tm, "/ping: ");
+ }
+ else
+ {
+ add_to_buffer(b2, NOTICE, NORMAL, 0, false, msg, src);
+ }
if(ha)
bufs[b2].hi_alert=5;
}
View
1 irc.h
@@ -19,6 +19,7 @@
#include <ctype.h>
#include <sys/socket.h>
#include <sys/utsname.h>
+#include <sys/time.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
View
2 plans
@@ -28,8 +28,6 @@ Improve the parsing of mirc-colour-codes (to fix things like \003124 which curre
/dump command. Pipes a screendump (or better still, unprocessed text) into program of choice.
-/ping command. Send CTCP PING.
-
/clear command.
Short commands (sufficient-prefix matching, like /cle).

0 comments on commit 9a76983

Please sign in to comment.