aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-19 22:19:52 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-19 22:19:52 +0200
commit953bc72e2b4696d4f89e8335426950a56a0b639f (patch)
tree4992b66e840acf2e628e416749971f7e647418ab
parent56ae38b19adf109973a4b081dbd7e0a61e06cc32 (diff)
downloadxK-953bc72e2b4696d4f89e8335426950a56a0b639f.tar.gz
xK-953bc72e2b4696d4f89e8335426950a56a0b639f.tar.xz
xK-953bc72e2b4696d4f89e8335426950a56a0b639f.zip
degesch: implement PRIVMSG handling
-rw-r--r--degesch.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index 20e1ff7..1d7bf96 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1849,7 +1849,52 @@ irc_handle_ping (struct app_context *ctx, const struct irc_message *msg)
static void
irc_handle_privmsg (struct app_context *ctx, const struct irc_message *msg)
{
- // TODO: log a message
+ if (!msg->prefix || msg->params.len < 2)
+ return;
+
+ const char *target = msg->params.vector[0];
+ const char *message = msg->params.vector[1];
+ struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, target);
+
+ if (irc_is_channel (ctx, target))
+ {
+ struct channel *channel = str_map_find (&ctx->irc_channels, target);
+ hard_assert ((channel && buffer) ||
+ (channel && !buffer) || (!channel && !buffer));
+
+ // This is weird, ignoring
+ if (!channel)
+ return;
+ }
+ else if (!buffer)
+ {
+ // Get or make a user object
+ char *nickname = irc_cut_nickname (msg->prefix);
+ struct user *user = str_map_find (&ctx->irc_users, nickname);
+ if (!user)
+ {
+ user = user_new ();
+ user->nickname = xstrdup (nickname);
+ str_map_set (&ctx->irc_users, user->nickname, user);
+ }
+
+ // Open a new buffer for the user
+ buffer = buffer_new ();
+ buffer->type = BUFFER_PM;
+ buffer->name = xstrdup (nickname);
+ buffer->user = user_ref (user);
+ LIST_APPEND_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
+ str_map_set (&ctx->irc_buffer_map, user->nickname, buffer);
+
+ free (nickname);
+ }
+
+ if (buffer)
+ {
+ // TODO: handle CTCP messages
+ buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
+ msg->prefix, NULL, "%s", message);
+ }
}
static void