aboutsummaryrefslogtreecommitdiff
path: root/kike.c
diff options
context:
space:
mode:
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