summaryrefslogtreecommitdiff
path: root/kike.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-31 20:06:45 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-31 21:43:23 +0100
commit10a264ec3d189ba0fc00e4c6f7b0e7e4a8043aff (patch)
treef6c260517176021690268a8e88d9bb4c5a409d6c /kike.c
parent2ec6258ff38747b72f55a0d19370dd5841e3be02 (diff)
downloadxK-10a264ec3d189ba0fc00e4c6f7b0e7e4a8043aff.tar.gz
xK-10a264ec3d189ba0fc00e4c6f7b0e7e4a8043aff.tar.xz
xK-10a264ec3d189ba0fc00e4c6f7b0e7e4a8043aff.zip
kike: add support for IRCv3.2 server-time
Diffstat (limited to 'kike.c')
-rw-r--r--kike.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/kike.c b/kike.c
index 1e65318..3aeb2b8 100644
--- a/kike.c
+++ b/kike.c
@@ -307,7 +307,8 @@ enum
IRC_CAP_MULTI_PREFIX = (1 << 0),
IRC_CAP_INVITE_NOTIFY = (1 << 1),
IRC_CAP_ECHO_MESSAGE = (1 << 2),
- IRC_CAP_USERHOST_IN_NAMES = (1 << 3)
+ IRC_CAP_USERHOST_IN_NAMES = (1 << 3),
+ IRC_CAP_SERVER_TIME = (1 << 4)
};
struct client
@@ -832,9 +833,22 @@ client_send_str (struct client *c, const struct str *s)
hard_assert (!c->closing_link);
size_t old_sendq = c->write_buffer.len;
+
+ // So far there's only one message tag we use, so we can do it simple;
+ // note that a 512-character limit applies to messages with tags on
+ if (c->caps_enabled & IRC_CAP_SERVER_TIME)
+ {
+ long milliseconds; char buf[32]; struct tm tm;
+ time_t now = unixtime_msec (&milliseconds);
+ if (soft_assert (strftime (buf, sizeof buf,
+ "%Y-%m-%dT%T", gmtime_r (&now, &tm))))
+ str_append_printf (&c->write_buffer,
+ "@time=%s.%03ldZ ", buf, milliseconds);
+ }
+
// TODO: kill the connection above some "SendQ" threshold (careful!)
str_append_data (&c->write_buffer, s->str,
- s->len > IRC_MAX_MESSAGE_LENGTH ? IRC_MAX_MESSAGE_LENGTH : s->len);
+ MIN (s->len, IRC_MAX_MESSAGE_LENGTH));
str_append (&c->write_buffer, "\r\n");
// XXX: we might want to move this elsewhere, so that it doesn't get called
// as often; it's going to cause a lot of syscalls with epoll.
@@ -1251,6 +1265,7 @@ irc_cap_table[] =
{ IRC_CAP_INVITE_NOTIFY, "invite-notify" },
{ IRC_CAP_ECHO_MESSAGE, "echo-message" },
{ IRC_CAP_USERHOST_IN_NAMES, "userhost-in-names" },
+ { IRC_CAP_SERVER_TIME, "server-time" },
};
static void
@@ -1263,7 +1278,7 @@ irc_handle_cap_ls (struct client *c, struct irc_cap_args *a)
c->cap_negotiating = true;
client_send (c, ":%s CAP %s LS :multi-prefix invite-notify echo-message"
- " userhost-in-names", c->ctx->server_name, a->target);
+ " userhost-in-names server-time", c->ctx->server_name, a->target);
}
static void