diff options
-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 | ||||
-rw-r--r-- | python_client.py | 21 |
5 files changed, 55 insertions, 2 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]; diff --git a/python_client.py b/python_client.py index 5a82031..22c31da 100644 --- a/python_client.py +++ b/python_client.py @@ -358,6 +358,20 @@ class MainWindow(QtWidgets.QMainWindow): self.tabs.addTab(tab, wtitle) self.tabLookup[wid] = tab tab.pushMessage('\n'.join(msgs)) + elif ptype == 0x101: + # WINDOW CLOSE + wndCount = u32.unpack_from(pdata, 0)[0] + pos = 4 + + for i in range(wndCount): + wid = u32.unpack_from(pdata, pos)[0] + pos += 4 + + if wid in self.tabLookup: + tab = self.tabLookup[wid] + self.tabs.removeTab(self.tabs.indexOf(tab)) + del self.tabLookup[wid] + elif ptype == 0x102: # WINDOW MESSAGES wndID, msglen = struct.unpack_from('<II', pdata, 0) @@ -427,8 +441,11 @@ class MainWindow(QtWidgets.QMainWindow): def handleWindowInput(self, text): wid = self.sender().winID with packetLock: - data = str(text).encode('utf-8') - writePacket(0x102, struct.pack('<II', wid, len(data)) + data) + if text == '/close': + writePacket(0x101, u32.pack(wid)) + else: + data = str(text).encode('utf-8') + writePacket(0x102, struct.pack('<II', wid, len(data)) + data) app = QtWidgets.QApplication(sys.argv) |