diff options
Diffstat (limited to '')
-rw-r--r-- | contexts.c | 2 | ||||
-rw-r--r-- | default.css | 9 | ||||
-rw-r--r-- | events.c | 2 | ||||
-rw-r--r-- | html.c | 101 | ||||
-rw-r--r-- | server.h | 1 |
5 files changed, 105 insertions, 10 deletions
diff --git a/contexts.c b/contexts.c index be48628..69afcdc 100644 --- a/contexts.c +++ b/contexts.c @@ -134,7 +134,7 @@ enum kcgi_err contextsPage(struct kreq *req) { || khtml_puts(&html, "MOTD") || khtml_closeelem(&html, 1) || khtml_elem(&html, KELEM_PRE) - || khtml_puts(&html, sqlite3_column_text(stmt.motd, 0)) + || htmlIRC(&html, sqlite3_column_text(stmt.motd, 0)) || khtml_closeelem(&html, 1); if (error) return error; result = sqlite3_step(stmt.motd); diff --git a/default.css b/default.css index 1d3d3e5..5902ae5 100644 --- a/default.css +++ b/default.css @@ -122,6 +122,15 @@ td.message { width: 100%; overflow-wrap: anywhere; } +tr.join td.message, +tr.part td.message, +tr.quit td.message, +tr.kick td.message, +tr.nick td.message, +tr.ban td.message, +tr.unban td.message { + color: var(--dark); +} footer { color: var(--dark); diff --git a/events.c b/events.c index a8c2be0..2f4b0f3 100644 --- a/events.c +++ b/events.c @@ -171,7 +171,7 @@ enum kcgi_err eventsPage(struct kreq *req) { || khtml_elem(&html, KELEM_THEAD) || khtml_attr(&html, KELEM_TR, KATTR_CLASS, "topic", KATTR__MAX) || khtml_attr(&html, KELEM_TH, KATTR_COLSPAN, "3", KATTR__MAX) - || khtml_puts(&html, sqlite3_column_text(stmt.topic, 0)) + || htmlIRC(&html, sqlite3_column_text(stmt.topic, 0)) || khtml_closeelem(&html, 3); if (error) return error; result = sqlite3_step(stmt.topic); diff --git a/html.c b/html.c index 0433d29..2d987f8 100644 --- a/html.c +++ b/html.c @@ -256,10 +256,13 @@ static int hash(const char *str) { return 2 + hash % 74; } -static enum kcgi_err eventNick(struct khtmlreq *html, struct Event event) { - char color[sizeof("fg99")]; - snprintf(color, sizeof(color), "fg%02d", hash(event.user)); +static const char *colorClass(int color) { + static char class[sizeof("fg99")]; + snprintf(class, sizeof(class), "fg%02d", color); + return class; +} +static enum kcgi_err eventNick(struct khtmlreq *html, struct Event event) { char *mask = NULL; asprintf(&mask, "%s!%s@%s", event.nick, event.user, event.host); if (!mask) err(EX_OSERR, "asprintf"); @@ -268,7 +271,7 @@ static enum kcgi_err eventNick(struct khtmlreq *html, struct Event event) { || khtml_attr(html, KELEM_TD, KATTR_CLASS, "nick", KATTR__MAX) || khtml_attr( html, KELEM_SPAN, - KATTR_CLASS, color, + KATTR_CLASS, colorClass(hash(event.user)), KATTR_TITLE, mask, KATTR__MAX ) @@ -279,14 +282,89 @@ static enum kcgi_err eventNick(struct khtmlreq *html, struct Event event) { return error; } -static enum kcgi_err eventMessage(struct khtmlreq *html, struct Event event) { - if (!event.message) return KCGI_OK; +static enum kcgi_err typeJoin(struct khtmlreq *html, struct Event event) { + (void)event; + return khtml_puts(html, "joined"); +} + +static enum kcgi_err typePart(struct khtmlreq *html, struct Event event) { + if (!event.message) return khtml_puts(html, "left"); + return 0 + || khtml_puts(html, "left (") + || htmlIRC(html, event.message) + || khtml_puts(html, ")"); +} + +static enum kcgi_err typeQuit(struct khtmlreq *html, struct Event event) { + if (!event.message) return khtml_puts(html, "quit"); return 0 - || khtml_attr(html, KELEM_TD, KATTR_CLASS, "message", KATTR__MAX) - || khtml_puts(html, event.message) + || khtml_puts(html, "quit (") + || htmlIRC(html, event.message) + || khtml_puts(html, ")"); +} + +static enum kcgi_err typeKick(struct khtmlreq *html, struct Event event) { + if (!event.target) return KCGI_OK; + if (!event.message) return khtml_printf(html, "kicked %s", event.target); + return 0 + || khtml_printf(html, "kicked %s (", event.target) + || htmlIRC(html, event.message) + || khtml_puts(html, ")"); +} + +static enum kcgi_err typeNick(struct khtmlreq *html, struct Event event) { + if (!event.target) return KCGI_OK; + return 0 + || khtml_puts(html, "changed nick to ") + || khtml_attr( + html, KELEM_SPAN, + KATTR_CLASS, colorClass(hash(event.user)), + KATTR__MAX + ) + || khtml_puts(html, event.target) || khtml_closeelem(html, 1); } +static enum kcgi_err typeTopic(struct khtmlreq *html, struct Event event) { + if (!event.message) return KCGI_OK; + return 0 + || khtml_puts(html, "set the topic: ") + || htmlIRC(html, event.message); +} + +static enum kcgi_err typeBan(struct khtmlreq *html, struct Event event) { + if (!event.target) return KCGI_OK; + return khtml_printf(html, "banned %s", event.target); +} + +static enum kcgi_err typeUnban(struct khtmlreq *html, struct Event event) { + if (!event.target) return KCGI_OK; + return khtml_printf(html, "unbanned %s", event.target); +} + +static enum kcgi_err eventMessage(struct khtmlreq *html, struct Event event) { + enum kcgi_err error = khtml_attr( + html, KELEM_TD, + KATTR_CLASS, "message", + KATTR__MAX + ); + if (error) return error; + switch (event.type) { + break; case Join: error = typeJoin(html, event); + break; case Part: error = typePart(html, event); + break; case Quit: error = typeQuit(html, event); + break; case Kick: error = typeKick(html, event); + break; case Nick: error = typeNick(html, event); + break; case Topic: error = typeTopic(html, event); + break; case Ban: error = typeBan(html, event); + break; case Unban: error = typeUnban(html, event); + break; default: { + if (event.message) error = htmlIRC(html, event.message); + } + } + return error || khtml_closeelem(html, 1); +} + static const char *Types[TypesLen] = { #define X(id, name) [id] = name, ENUM_TYPE @@ -310,3 +388,10 @@ htmlEvent(struct khtmlreq *html, struct Scope scope, struct Event event) { || eventMessage(html, event) || khtml_closeelem(html, 1); } + +enum kcgi_err htmlIRC(struct khtmlreq *html, const char *str) { + return 0 + || khtml_attr(html, KELEM_SPAN, KATTR_CLASS, "irc", KATTR__MAX) + || khtml_puts(html, str) + || khtml_closeelem(html, 1); +} diff --git a/server.h b/server.h index c1943ce..f8b7126 100644 --- a/server.h +++ b/server.h @@ -183,6 +183,7 @@ enum kcgi_err htmlHead(struct khtmlreq *html, const char *title); enum kcgi_err htmlScopeFields(struct khtmlreq *html, struct Scope scope); enum kcgi_err htmlNav(struct khtmlreq *html, struct Scope scope); enum kcgi_err htmlFooter(struct khtmlreq *html); +enum kcgi_err htmlIRC(struct khtmlreq *html, const char *str); enum kcgi_err htmlEvent( struct khtmlreq *html, struct Scope scope, struct Event event ); |