diff options
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 47 |
1 files changed, 46 insertions, 1 deletions
@@ -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 |