summaryrefslogtreecommitdiff
path: root/window.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-01-22 09:31:30 +0100
committerTreeki <treeki@gmail.com>2014-01-22 09:31:30 +0100
commite3e6a3f2c422a6b82b234f575a6b3bad459e5e0b (patch)
tree411f501c1e5ee85228607d1440df341be0b66c4c /window.cpp
parentf458a0b65de5db40ecb57d5831117305fc4dd876 (diff)
downloadbounce4-e3e6a3f2c422a6b82b234f575a6b3bad459e5e0b.tar.gz
bounce4-e3e6a3f2c422a6b82b234f575a6b3bad459e5e0b.zip
add window management, move hacky Python client over to PyQt5
Diffstat (limited to '')
-rw-r--r--window.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/window.cpp b/window.cpp
new file mode 100644
index 0000000..5fc094a
--- /dev/null
+++ b/window.cpp
@@ -0,0 +1,79 @@
+#include "core.h"
+
+Window::Window(NetCore *_core) {
+ core = _core;
+}
+
+void Window::syncStateForClient(Buffer &output) {
+ output.writeU32(getType());
+ output.writeU32(id);
+ output.writeStr(getTitle());
+
+ output.writeU32(messages.size());
+
+ std::list<std::string>::iterator
+ i = messages.begin(),
+ e = messages.end();
+
+ for (; i != e; ++i) {
+ output.writeStr(i->c_str());
+ }
+}
+
+void Window::pushMessage(const char *str) {
+ messages.push_back(str);
+
+ bool createdPacket = false;
+ Buffer packet;
+
+ for (int i = 0; i < core->clientCount; i++) {
+ if (core->clients[i]->isAuthed()) {
+ if (!createdPacket) {
+ packet.writeU32(id);
+ packet.writeStr(str);
+ createdPacket = true;
+ }
+
+ core->clients[i]->sendPacket(Packet::B2C_WINDOW_MESSAGE, packet);
+ }
+ }
+}
+
+
+
+
+StatusWindow::StatusWindow(IRCServer *_server) :
+ Window(_server->bouncer)
+{
+ server = _server;
+}
+
+const char *StatusWindow::getTitle() const {
+ return server->config.hostname;
+}
+
+int StatusWindow::getType() const {
+ return 1;
+}
+
+void StatusWindow::handleUserInput(const char *str) {
+ if (str[0] == '/') {
+ // moof
+ if (strcmp(str, "/connect") == 0) {
+ server->connect();
+ } else if (strcmp(str, "/disconnect") == 0) {
+ server->close();
+ } else if (strncmp(str, "/password ", 10) == 0) {
+ pushMessage("Password set.");
+
+ // This is ugly, ugh
+ strncpy(
+ server->config.password,
+ &str[10],
+ sizeof(server->config.password));
+ server->config.password[sizeof(server->config.password) - 1] = 0;
+ }
+ } else {
+ server->sendLine(str);
+ }
+}