degesch: make a "struct user" for ourselves
This commit is contained in:
parent
a43051132a
commit
3fa9a67a59
36
degesch.c
36
degesch.c
@ -417,8 +417,9 @@ struct app_context
|
|||||||
struct str_map irc_channels; ///< IRC channel data
|
struct str_map irc_channels; ///< IRC channel data
|
||||||
struct str_map irc_buffer_map; ///< Maps IRC identifiers to buffers
|
struct str_map irc_buffer_map; ///< Maps IRC identifiers to buffers
|
||||||
|
|
||||||
char *irc_nickname; ///< Current nickname
|
struct user *irc_user; ///< Our own user
|
||||||
char *irc_user_mode; ///< Current user mode
|
char *irc_user_mode; ///< Our current user mode
|
||||||
|
char *irc_user_host; ///< Our current user@host
|
||||||
|
|
||||||
// Events:
|
// Events:
|
||||||
|
|
||||||
@ -535,8 +536,9 @@ app_context_free (struct app_context *self)
|
|||||||
str_map_free (&self->irc_channels);
|
str_map_free (&self->irc_channels);
|
||||||
str_map_free (&self->irc_buffer_map);
|
str_map_free (&self->irc_buffer_map);
|
||||||
|
|
||||||
free (self->irc_nickname);
|
user_unref (self->irc_user);
|
||||||
free (self->irc_user_mode);
|
free (self->irc_user_mode);
|
||||||
|
free (self->irc_user_host);
|
||||||
|
|
||||||
poller_free (&self->poller);
|
poller_free (&self->poller);
|
||||||
|
|
||||||
@ -1246,7 +1248,7 @@ static bool
|
|||||||
irc_is_this_us (struct app_context *ctx, const char *prefix)
|
irc_is_this_us (struct app_context *ctx, const char *prefix)
|
||||||
{
|
{
|
||||||
char *nick = irc_cut_nickname (prefix);
|
char *nick = irc_cut_nickname (prefix);
|
||||||
bool result = !irc_strcmp (nick, ctx->irc_nickname);
|
bool result = !irc_strcmp (nick, ctx->irc_user->nickname);
|
||||||
free (nick);
|
free (nick);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1596,7 +1598,7 @@ make_prompt (struct app_context *ctx, struct str *output)
|
|||||||
str_append (output, "(disconnected)");
|
str_append (output, "(disconnected)");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str_append (output, ctx->irc_nickname);
|
str_append (output, ctx->irc_user->nickname);
|
||||||
if (*ctx->irc_user_mode)
|
if (*ctx->irc_user_mode)
|
||||||
str_append_printf (output, "(%s)", ctx->irc_user_mode);
|
str_append_printf (output, "(%s)", ctx->irc_user_mode);
|
||||||
}
|
}
|
||||||
@ -1846,8 +1848,6 @@ irc_handle_nick (struct app_context *ctx, const struct irc_message *msg)
|
|||||||
if (!msg->prefix || msg->params.len < 1)
|
if (!msg->prefix || msg->params.len < 1)
|
||||||
return;
|
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);
|
char *nickname = irc_cut_nickname (msg->prefix);
|
||||||
struct user *user = str_map_find (&ctx->irc_users, nickname);
|
struct user *user = str_map_find (&ctx->irc_users, nickname);
|
||||||
free (nickname);
|
free (nickname);
|
||||||
@ -1857,11 +1857,6 @@ irc_handle_nick (struct app_context *ctx, const struct irc_message *msg)
|
|||||||
const char *new_nickname = msg->params.vector[0];
|
const char *new_nickname = msg->params.vector[0];
|
||||||
if (irc_is_this_us (ctx, msg->prefix))
|
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
|
// Log a message in all open buffers on this server
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter;
|
||||||
str_map_iter_init (&iter, &ctx->irc_buffer_map);
|
str_map_iter_init (&iter, &ctx->irc_buffer_map);
|
||||||
@ -1897,6 +1892,9 @@ irc_handle_nick (struct app_context *ctx, const struct irc_message *msg)
|
|||||||
// Finally rename the user
|
// Finally rename the user
|
||||||
free (user->nickname);
|
free (user->nickname);
|
||||||
user->nickname = xstrdup (new_nickname);
|
user->nickname = xstrdup (new_nickname);
|
||||||
|
|
||||||
|
// We might have renamed ourselves
|
||||||
|
refresh_prompt (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2104,7 +2102,7 @@ irc_process_message (const struct irc_message *msg,
|
|||||||
// TODO: parse any response and store the result for us in app_context;
|
// TODO: parse any response and store the result for us in app_context;
|
||||||
// this enables proper message splitting on output;
|
// this enables proper message splitting on output;
|
||||||
// we can also use WHOIS if it's not supported (optional by RFC 2812)
|
// we can also use WHOIS if it's not supported (optional by RFC 2812)
|
||||||
irc_send (ctx, "USERHOST %s", ctx->irc_nickname);
|
irc_send (ctx, "USERHOST %s", ctx->irc_user->nickname);
|
||||||
|
|
||||||
const char *autojoin = str_map_find (&ctx->config, "autojoin");
|
const char *autojoin = str_map_find (&ctx->config, "autojoin");
|
||||||
if (autojoin)
|
if (autojoin)
|
||||||
@ -2485,7 +2483,7 @@ send_message_to_target (struct app_context *ctx,
|
|||||||
// TODO: autosplit
|
// TODO: autosplit
|
||||||
irc_send (ctx, "PRIVMSG %s :%s", target, message);
|
irc_send (ctx, "PRIVMSG %s :%s", target, message);
|
||||||
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
|
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
|
||||||
ctx->irc_nickname, NULL, "%s", message);
|
ctx->irc_user->nickname, NULL, "%s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2646,10 +2644,12 @@ on_irc_disconnected (struct app_context *ctx)
|
|||||||
xclose (ctx->irc_fd);
|
xclose (ctx->irc_fd);
|
||||||
ctx->irc_fd = -1;
|
ctx->irc_fd = -1;
|
||||||
ctx->irc_ready = false;
|
ctx->irc_ready = false;
|
||||||
free (ctx->irc_nickname);
|
user_unref (ctx->irc_user);
|
||||||
ctx->irc_nickname = NULL;
|
ctx->irc_user = NULL;
|
||||||
free (ctx->irc_user_mode);
|
free (ctx->irc_user_mode);
|
||||||
ctx->irc_user_mode = NULL;
|
ctx->irc_user_mode = NULL;
|
||||||
|
free (ctx->irc_user_host);
|
||||||
|
ctx->irc_user_host = NULL;
|
||||||
|
|
||||||
ctx->irc_event.closed = true;
|
ctx->irc_event.closed = true;
|
||||||
poller_fd_reset (&ctx->irc_event);
|
poller_fd_reset (&ctx->irc_event);
|
||||||
@ -2813,8 +2813,10 @@ irc_connect (struct app_context *ctx, struct error **e)
|
|||||||
irc_send (ctx, "USER %s 8 * :%s", username, realname);
|
irc_send (ctx, "USER %s 8 * :%s", username, realname);
|
||||||
|
|
||||||
// XXX: maybe we should wait for the first message from the server
|
// XXX: maybe we should wait for the first message from the server
|
||||||
ctx->irc_nickname = xstrdup (nickname);
|
ctx->irc_user = user_new ();
|
||||||
|
ctx->irc_user->nickname = xstrdup (nickname);
|
||||||
ctx->irc_user_mode = xstrdup ("");
|
ctx->irc_user_mode = xstrdup ("");
|
||||||
|
ctx->irc_user_host = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user