From 5e6def5bb0b2f4f43116d907c764d8e3527fe770 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 2 Aug 2014 17:56:40 +0200 Subject: kike: implement PRIVMSG to user --- src/kike.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/kike.c b/src/kike.c index d9b8291..bc64180 100644 --- a/src/kike.c +++ b/src/kike.c @@ -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++) -- cgit v1.2.3-70-g09d2