]> jfr.im git - solanum.git/blobdiff - modules/cap_server_time.c
Combine stats A output parameters (#35)
[solanum.git] / modules / cap_server_time.c
index 73fce0170ebc96fff8880bd8452bcdbc711a0ca5..1fd383fd3bd048fad2785730e67e43b6f371922d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * charybdis: an advanced ircd.
+ * Solanum: a slightly advanced ircd
  * cap_server_time.c: implement the server-time IRCv3.2 capability
  *
  * Copyright (c) 2016 William Pitcock <nenolod@dereferenced.org>
@@ -53,12 +53,18 @@ static void
 cap_server_time_process(hook_data *data)
 {
        static char buf[BUFSIZE];
-       time_t ts = rb_current_time();
        struct MsgBuf *msgbuf = data->arg1;
+       struct timeval tv;
 
-       strftime(buf, sizeof buf, "%Y-%m-%dT%H:%M:%S.000Z", gmtime(&ts));
+       if (!rb_gettimeofday(&tv, NULL)) {
+               if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.", gmtime(&tv.tv_sec)) == 0)
+                       return;
 
-       msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME);
+               if (rb_snprintf_append(buf, sizeof(buf), "%03uZ", (int)tv.tv_usec / 1000) < 0)
+                       return;
+
+               msgbuf_append_tag(msgbuf, "time", buf, CLICAP_SERVER_TIME);
+       }
 }
 
 DECLARE_MODULE_AV2(cap_server_time, NULL, NULL, NULL, NULL, cap_server_time_hfnlist, cap_server_time_cap_list, NULL, cap_server_time_desc);