kike: implement USERHOST

This commit is contained in:
Přemysl Eric Janouch 2014-08-02 22:58:18 +02:00
parent 559bedad65
commit 97f35bedfd
1 changed files with 45 additions and 11 deletions

View File

@ -626,6 +626,7 @@ enum
IRC_RPL_LUSERCHANNELS = 254,
IRC_RPL_LUSERME = 255,
IRC_RPL_USERHOST = 302,
IRC_RPL_VERSION = 351,
IRC_RPL_MOTD = 372,
IRC_RPL_MOTDSTART = 375,
@ -660,6 +661,7 @@ static const char *g_default_replies[] =
[IRC_RPL_LUSERCHANNELS] = "%d :channels formed",
[IRC_RPL_LUSERME] = ":I have %d clients and %d servers",
[IRC_RPL_USERHOST] = ":%s",
[IRC_RPL_VERSION] = "%s.%d %s :%s",
[IRC_RPL_MOTD] = ":- %s",
[IRC_RPL_MOTDSTART] = ":- %s Message of the day - ",
@ -863,6 +865,37 @@ irc_handle_user (const struct irc_message *msg, struct client *c)
irc_try_finish_registration (c);
}
static void
irc_handle_userhost (const struct irc_message *msg, struct client *c)
{
if (msg->params.len < 1)
{
irc_send_reply (c, IRC_ERR_NEEDMOREPARAMS, msg->command);
return;
}
struct str reply;
str_init (&reply);
for (size_t i = 0; i < 5 && i < msg->params.len; i++)
{
const char *nick = msg->params.vector[i];
struct client *target = str_map_find (&c->ctx->users, nick);
if (!target)
continue;
if (i)
str_append_c (&reply, ' ');
str_append (&reply, nick);
if (target->mode & IRC_USER_MODE_OPERATOR)
str_append_c (&reply, '*');
str_append_printf (&reply, "=%c%s@%s",
target->away_message ? '-' : '+',
target->username, target->hostname);
}
irc_send_reply (c, IRC_RPL_USERHOST, reply.str);
str_free (&reply);
}
static void
irc_handle_lusers (const struct irc_message *msg, struct client *c)
{
@ -981,19 +1014,20 @@ irc_register_handlers (struct server_context *ctx)
// TODO: more commands, see RFC 2812 :!
static const struct irc_command message_handlers[] =
{
{ "PASS", false, irc_handle_pass },
{ "NICK", false, irc_handle_nick },
{ "USER", false, irc_handle_user },
{ "PASS", false, irc_handle_pass },
{ "NICK", false, irc_handle_nick },
{ "USER", false, irc_handle_user },
{ "LUSERS", true, irc_handle_lusers },
{ "MOTD", true, irc_handle_motd },
{ "PING", true, irc_handle_ping },
{ "PONG", false, irc_handle_pong },
{ "QUIT", false, irc_handle_quit },
{ "TIME", true, irc_handle_time },
{ "VERSION", true, irc_handle_version },
{ "USERHOST", true, irc_handle_userhost },
{ "LUSERS", true, irc_handle_lusers },
{ "MOTD", true, irc_handle_motd },
{ "PING", true, irc_handle_ping },
{ "PONG", false, irc_handle_pong },
{ "QUIT", false, irc_handle_quit },
{ "TIME", true, irc_handle_time },
{ "VERSION", true, irc_handle_version },
{ "PRIVMSG", true, irc_handle_privmsg },
{ "PRIVMSG", true, irc_handle_privmsg },
};
for (size_t i = 0; i < N_ELEMENTS (message_handlers); i++)