kike: implement PRIVMSG to user

This commit is contained in:
Přemysl Eric Janouch 2014-08-02 17:56:40 +02:00
parent facd810548
commit 5e6def5bb0
1 changed files with 32 additions and 0 deletions

View File

@ -629,8 +629,11 @@ enum
IRC_RPL_ENDOFMOTD = 376,
IRC_RPL_TIME = 391,
IRC_ERR_NOSUCHNICK = 401,
IRC_ERR_NOSUCHSERVER = 402,
IRC_ERR_NOORIGIN = 409,
IRC_ERR_NORECIPIENT = 411,
IRC_ERR_NOTEXTTOSEND = 412,
IRC_ERR_UNKNOWNCOMMAND = 421,
IRC_ERR_NOMOTD = 422,
IRC_ERR_NONICKNAMEGIVEN = 431,
@ -660,8 +663,11 @@ static const char *g_default_replies[] =
[IRC_RPL_ENDOFMOTD] = ":End of MOTD command",
[IRC_RPL_TIME] = "%s :%s",
[IRC_ERR_NOSUCHNICK] = "%s :No such nick/channel",
[IRC_ERR_NOSUCHSERVER] = "%s :No such server",
[IRC_ERR_NOORIGIN] = ":No origin specified",
[IRC_ERR_NORECIPIENT] = ":No recipient given (%s)",
[IRC_ERR_NOTEXTTOSEND] = ":No text to send",
[IRC_ERR_UNKNOWNCOMMAND] = "%s: Unknown command",
[IRC_ERR_NOMOTD] = ":MOTD File is missing",
[IRC_ERR_NONICKNAMEGIVEN] = ":No nickname given",
@ -932,6 +938,30 @@ irc_handle_version (const struct irc_message *msg, struct client *c)
c->ctx->server_name, PROGRAM_NAME " " PROGRAM_VERSION);
}
static void
irc_handle_privmsg (const struct irc_message *msg, struct client *c)
{
if (msg->params.len < 1)
irc_send_reply (c, IRC_ERR_NORECIPIENT, msg->command);
else if (msg->params.len < 2 || !*msg->params.vector[1])
irc_send_reply (c, IRC_ERR_NOTEXTTOSEND);
else
{
const char *target = msg->params.vector[0];
const char *text = msg->params.vector[1];
struct client *target_c = str_map_find (&c->ctx->users, target);
if (!target_c)
{
irc_send_reply (c, IRC_ERR_NOSUCHNICK, target);
return;
}
// TODO: channels
irc_send (target_c, ":%s!%s@%s PRIVMSG %s :%s",
c->nickname, c->username, c->hostname, target, text);
}
}
// -----------------------------------------------------------------------------
struct irc_command
@ -959,6 +989,8 @@ irc_register_handlers (struct server_context *ctx)
{ "QUIT", false, irc_handle_quit },
{ "TIME", true, irc_handle_time },
{ "VERSION", true, irc_handle_version },
{ "PRIVMSG", true, irc_handle_privmsg },
};
for (size_t i = 0; i < N_ELEMENTS (message_handlers); i++)