diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2014-08-02 17:56:40 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-08-02 21:33:55 +0200 |
commit | 5e6def5bb0b2f4f43116d907c764d8e3527fe770 (patch) | |
tree | e891da1c46d9580342a67874995fcf705e1bf856 | |
parent | facd8105481b2af1f8c519905c8150e6da5347ea (diff) | |
download | xK-5e6def5bb0b2f4f43116d907c764d8e3527fe770.tar.gz xK-5e6def5bb0b2f4f43116d907c764d8e3527fe770.tar.xz xK-5e6def5bb0b2f4f43116d907c764d8e3527fe770.zip |
kike: implement PRIVMSG to user
-rw-r--r-- | src/kike.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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++) |