diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-20 00:08:18 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-20 00:08:18 +0200 |
commit | 8e7412eb970437541fc4b184e7429231a6384860 (patch) | |
tree | 651338e7ee02a4758c73faf969d04366a51f0ab3 /degesch.c | |
parent | 8b279dde81198c7ebe95e4913e319fecb6fd57da (diff) | |
download | xK-8e7412eb970437541fc4b184e7429231a6384860.tar.gz xK-8e7412eb970437541fc4b184e7429231a6384860.tar.xz xK-8e7412eb970437541fc4b184e7429231a6384860.zip |
degesch: halfplement NICK and QUIT handlers
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 94 |
1 files changed, 89 insertions, 5 deletions
@@ -1835,9 +1835,57 @@ irc_handle_mode (struct app_context *ctx, const struct irc_message *msg) static void irc_handle_nick (struct app_context *ctx, const struct irc_message *msg) { - // TODO: rename the user in all relevant channels - // TODO: if it's us, rename ourselves - // TODO: log a message in all relevant channels + if (!msg->prefix || msg->params.len < 1) + return; + + // FIXME: make sure we have an associated user; + // we might be able to get rid of "irc_nickname" then + char *nickname = irc_cut_nickname (msg->prefix); + struct user *user = str_map_find (&ctx->irc_users, nickname); + free (nickname); + if (!user) + return; + + const char *new_nickname = msg->params.vector[0]; + if (irc_is_this_us (ctx, msg->prefix)) + { + // Update user information + free (ctx->irc_nickname); + ctx->irc_nickname = xstrdup (new_nickname); + refresh_prompt (ctx); + + // Log a message in all open buffers on this server + struct str_map_iter iter; + str_map_iter_init (&iter, &ctx->irc_buffer_map); + struct buffer *buffer; + while ((buffer = str_map_iter_next (&iter))) + { + // TODO: log a "You are now known as" message + } + } + else + { + // Log a message in any PM buffer + struct buffer *buffer = + str_map_find (&ctx->irc_buffer_map, user->nickname); + if (buffer) + { + // TODO: log a message in the buffer + // TODO: rename the buffer, and if it collides, merge them + } + + // Log a message in all channels the user is in + LIST_FOR_EACH (struct user_channel, iter, user->channels) + { + buffer = str_map_find (&ctx->irc_buffer_map, iter->channel->name); + hard_assert (buffer != NULL); + // TODO: log a message in the buffer + } + } + + // Finally rename the user + free (user->nickname); + user->nickname = xstrdup (new_nickname); } static void @@ -1916,8 +1964,44 @@ irc_handle_privmsg (struct app_context *ctx, const struct irc_message *msg) static void irc_handle_quit (struct app_context *ctx, const struct irc_message *msg) { - // TODO: remove user from all channels - // TODO: log a message + if (!msg->prefix) + return; + + // What the fuck + if (irc_is_this_us (ctx, msg->prefix)) + return; + + char *nickname = irc_cut_nickname (msg->prefix); + struct user *user = str_map_find (&ctx->irc_users, nickname); + free (nickname); + if (!user) + return; + + const char *message = NULL; + if (msg->params.len > 0) + message = msg->params.vector[0]; + + // Log a message in any PM buffer + struct buffer *buffer = + str_map_find (&ctx->irc_buffer_map, user->nickname); + if (buffer) + { + // TODO: log a message in the buffer + } + + // Log a message in all channels the user is in + LIST_FOR_EACH (struct user_channel, iter, user->channels) + { + buffer = str_map_find (&ctx->irc_buffer_map, iter->channel->name); + hard_assert (buffer != NULL); + // TODO: log a message in the buffer + + // TODO: remove the "channel_user" link from iter->channel + // TODO: remove the link from the list and free it + } + + // TODO: check reference count on the user and if it's just one, + // remove him from "irc_users" } static void |