libpurple/protocols/irc/parse.c

changeset 40001
a63721e6215f
parent 39961
d508d5b5dd22
parent 40000
0eeff970bcdd
child 40052
cc03b5af25ea
equal deleted inserted replaced
39993:0d18609d0d01 40001:a63721e6215f
554 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice) 554 char *irc_parse_ctcp(struct irc_conn *irc, const char *from, const char *to, const char *msg, int notice)
555 { 555 {
556 PurpleConnection *gc; 556 PurpleConnection *gc;
557 const char *cur = msg + 1; 557 const char *cur = msg + 1;
558 char *buf, *ctcp; 558 char *buf, *ctcp;
559 time_t timestamp;
560 559
561 /* Note that this is NOT correct w.r.t. multiple CTCPs in one 560 /* Note that this is NOT correct w.r.t. multiple CTCPs in one
562 * message and low-level quoting ... but if you want that crap, 561 * message and low-level quoting ... but if you want that crap,
563 * use a real IRC client. */ 562 * use a real IRC client. */
564 563
570 buf = g_strdup_printf("/me %s", cur); 569 buf = g_strdup_printf("/me %s", cur);
571 buf[strlen(buf) - 1] = '\0'; 570 buf[strlen(buf) - 1] = '\0';
572 return buf; 571 return buf;
573 } else if (!strncmp(cur, "PING ", 5)) { 572 } else if (!strncmp(cur, "PING ", 5)) {
574 if (notice) { /* reply */ 573 if (notice) { /* reply */
574 gint64 timestamp;
575 gc = purple_account_get_connection(irc->account); 575 gc = purple_account_get_connection(irc->account);
576 if (!gc) 576 if (!gc)
577 return NULL; 577 return NULL;
578 /* TODO: Should this read in the timestamp as a double? */ 578 if (sscanf(cur, "PING %" G_GINT64_FORMAT, &timestamp) == 1) {
579 if (sscanf(cur, "PING %lu", &timestamp) == 1) { 579 buf = g_strdup_printf(_("Reply time from %s: %f seconds"), from,
580 buf = g_strdup_printf(_("Reply time from %s: %lu seconds"), from, time(NULL) - timestamp); 580 (g_get_monotonic_time() - timestamp) /
581 (gdouble)G_USEC_PER_SEC);
581 purple_notify_info(gc, _("PONG"), 582 purple_notify_info(gc, _("PONG"),
582 _("CTCP PING reply"), buf, 583 _("CTCP PING reply"), buf,
583 purple_request_cpar_from_connection(gc)); 584 purple_request_cpar_from_connection(gc));
584 g_free(buf); 585 g_free(buf);
585 } else 586 } else

mercurial