diff options
author | Treeki <treeki@gmail.com> | 2014-01-27 05:01:34 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2014-01-27 05:01:34 +0100 |
commit | 1417c14821024bde33552573665973165613fa2a (patch) | |
tree | d4ccf63d1f2812813a6fe9119be5230470f5fc9b /bouncer | |
parent | 6248214f5aa6c6f73c248f4239c66fef01cbbbfa (diff) | |
download | bounce4-1417c14821024bde33552573665973165613fa2a.tar.gz bounce4-1417c14821024bde33552573665973165613fa2a.zip |
add window closing for queries
Diffstat (limited to 'bouncer')
-rw-r--r-- | bouncer/core.h | 7 | ||||
-rw-r--r-- | bouncer/ircserver.cpp | 10 | ||||
-rw-r--r-- | bouncer/mobileclient.cpp | 10 | ||||
-rw-r--r-- | bouncer/window.cpp | 9 |
4 files changed, 36 insertions, 0 deletions
diff --git a/bouncer/core.h b/bouncer/core.h index a0b9cfe..d7d54f3 100644 --- a/bouncer/core.h +++ b/bouncer/core.h @@ -64,6 +64,7 @@ public: virtual int getType() const = 0; virtual void syncStateForClient(Buffer &output); virtual void handleUserInput(const char *str) { } + virtual void handleUserClosed(); void pushMessage(const char *str); }; @@ -122,6 +123,7 @@ public: virtual const char *getTitle() const; virtual int getType() const; virtual void handleUserInput(const char *str); + virtual void handleUserClosed(); void handleQuit(const char *message); void handlePrivmsg(const char *str); @@ -190,6 +192,7 @@ struct Packet { B2C_WINDOW_MESSAGE = 0x102, B2C_WINDOW_RENAME = 0x103, + C2B_WINDOW_CLOSE = 0x101, C2B_WINDOW_INPUT = 0x102, B2C_CHANNEL_USER_ADD = 0x120, @@ -348,6 +351,10 @@ private: Channel *findChannel(const char *name, bool createIfNeeded); Query *findQuery(const char *name, bool createIfNeeded); + +public: + // This probably *shouldn't* be public... >< + void deleteQuery(Query *query); }; diff --git a/bouncer/ircserver.cpp b/bouncer/ircserver.cpp index 818478f..63d5c90 100644 --- a/bouncer/ircserver.cpp +++ b/bouncer/ircserver.cpp @@ -72,6 +72,16 @@ Query *IRCServer::findQuery(const char *name, bool createIfNeeded) { } } +void IRCServer::deleteQuery(Query *query) { + auto i = queries.find(query->partner); + if (i != queries.end()) { + bouncer->deregisterWindow(query); + + queries.erase(i); + delete query; + } +} + void IRCServer::connectedEvent() { diff --git a/bouncer/mobileclient.cpp b/bouncer/mobileclient.cpp index fb8b3c1..65ddefe 100644 --- a/bouncer/mobileclient.cpp +++ b/bouncer/mobileclient.cpp @@ -41,6 +41,16 @@ void MobileClient::packetReceivedEvent(Packet::Type type, Buffer &pkt) { window->handleUserInput(text); + } else if (type == Packet::C2B_WINDOW_CLOSE) { + int winID = pkt.readU32(); + Window *window = bouncer->findWindow(winID); + if (!window) { + printf("[MobileClient:%p] Close request for unknown window %d\n", this, winID); + return; + } + + window->handleUserClosed(); + } else { printf("[MobileClient:%p] Unrecognised packet for MobileClient: type %d, size %d\n", this, type, pkt.size()); diff --git a/bouncer/window.cpp b/bouncer/window.cpp index dbfe3b5..98f0418 100644 --- a/bouncer/window.cpp +++ b/bouncer/window.cpp @@ -39,6 +39,10 @@ void Window::pushMessage(const char *str) { } } +void Window::handleUserClosed() { + // Do nothing. (For now?) +} + @@ -591,6 +595,11 @@ int Query::getType() const { return 3; } + +void Query::handleUserClosed() { + server->deleteQuery(this); +} + void Query::handleUserInput(const char *str) { char msgBuf[16384]; |