diff options
author | Treeki <treeki@gmail.com> | 2014-01-25 01:47:04 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2014-01-25 01:47:04 +0100 |
commit | d67fdae167bf5118b17d3bfaeb5f91929dfa812d (patch) | |
tree | c064c5b235e1ffbf0e28d8b075e8ae70919aca01 /bouncer | |
parent | bdbdb57fc3ae81c0dbb46c4e6ffdd6c0205a81c0 (diff) | |
download | bounce4-d67fdae167bf5118b17d3bfaeb5f91929dfa812d.tar.gz bounce4-d67fdae167bf5118b17d3bfaeb5f91929dfa812d.zip |
add processing for the KICK irc message
Diffstat (limited to 'bouncer')
-rw-r--r-- | bouncer/core.h | 1 | ||||
-rw-r--r-- | bouncer/ircserver.cpp | 20 | ||||
-rw-r--r-- | bouncer/window.cpp | 40 |
3 files changed, 60 insertions, 1 deletions
diff --git a/bouncer/core.h b/bouncer/core.h index 1d6b9db..6b73067 100644 --- a/bouncer/core.h +++ b/bouncer/core.h @@ -99,6 +99,7 @@ public: void handleJoin(const UserRef &user); void handlePart(const UserRef &user, const char *message); void handleQuit(const UserRef &user, const char *message); + void handleKick(const UserRef &user, const char *target, const char *message); void handleNick(const UserRef &user, const char *newNick); void handleMode(const UserRef &user, const char *str); void handlePrivmsg(const UserRef &user, const char *str); diff --git a/bouncer/ircserver.cpp b/bouncer/ircserver.cpp index 3b09d49..19bea9d 100644 --- a/bouncer/ircserver.cpp +++ b/bouncer/ircserver.cpp @@ -203,7 +203,7 @@ void IRCServer::lineReceivedEvent(char *line, int size) { } else if (strcmp(cmdBuf, "PART") == 0) { Channel *c = findChannel(targetBuf, false); if (c) { - c->handlePart(user, paramsAfterFirst);; + c->handlePart(user, paramsAfterFirst); return; } @@ -212,6 +212,24 @@ void IRCServer::lineReceivedEvent(char *line, int size) { i.second->handleQuit(user, allParams); return; + } else if (strcmp(cmdBuf, "KICK") == 0) { + char *space = strchr(paramsAfterFirst, ' '); + const char *kickMsg = ""; + + if (space) { + *space = 0; + kickMsg = space + 1; + + if (*kickMsg == ':') + ++kickMsg; + } + + Channel *c = findChannel(targetBuf, false); + if (c) { + c->handleKick(user, paramsAfterFirst, kickMsg); + return; + } + } else if (strcmp(cmdBuf, "NICK") == 0) { if (user.isSelf) { strncpy(currentNick, allParams, sizeof(currentNick)); diff --git a/bouncer/window.cpp b/bouncer/window.cpp index 5371176..01849e2 100644 --- a/bouncer/window.cpp +++ b/bouncer/window.cpp @@ -317,6 +317,46 @@ void Channel::handleQuit(const UserRef &user, const char *message) { pushMessage(buf); } +void Channel::handleKick(const UserRef &user, const char *target, const char *message) { + auto i = users.find(target); + if (i != users.end()) { + users.erase(i); + + Buffer packet; + packet.writeU32(id); + packet.writeU32(1); + packet.writeStr(target); + + server->bouncer->sendToClients( + Packet::B2C_CHANNEL_USER_REMOVE, packet); + } + + char buf[1024]; + + if (strcmp(target, server->currentNick) == 0) { + inChannel = false; + + snprintf(buf, sizeof(buf), + "You have been kicked by %s (%s)", + user.nick.c_str(), + message); + + } else if (user.isSelf) { + snprintf(buf, sizeof(buf), + "You have kicked %s (%s)", + target, + message); + } else { + snprintf(buf, sizeof(buf), + "%s has kicked %s (%s)", + user.nick.c_str(), + target, + message); + } + + pushMessage(buf); +} + void Channel::handleNick(const UserRef &user, const char *newNick) { auto i = users.find(user.nick); if (i == users.end()) |