]> git.sesse.net Git - ultimatescore/blobdiff - client/ws_server.h
Change to communicating over WebSockets instead of over ACMP.
[ultimatescore] / client / ws_server.h
diff --git a/client/ws_server.h b/client/ws_server.h
new file mode 100644 (file)
index 0000000..17d1309
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _WS_SERVER_H
+#define _WS_SERVER_H 1
+
+#include <functional>
+#include <mutex>
+#include <string>
+#include <thread>
+#include <unordered_set>
+#include <vector>
+
+#include <QObject>
+
+class QWebSocket;
+class QWebSocketServer;
+
+class WSServer : public QObject {
+       Q_OBJECT
+
+public:
+       WSServer(const std::string &host, int port);
+
+       void add_init_command(const std::string &cmd);
+       void set_connection_callback(const std::function<void(bool)> &callback);
+       void send_command(const std::string &cmd);
+       void change_port(int port);
+
+private slots:
+       void on_new_connection();
+       void disconnected();
+
+private:
+       void thread_func();
+
+       std::vector<std::string> init_commands;
+       std::function<void(bool)> connection_callback;
+
+       QWebSocketServer *ws_server;
+       std::unordered_set<QWebSocket *> clients;
+};
+
+#endif  // !defined(_WS_SERVER_H)