diff --git a/PROTOCOL.md b/PROTOCOL.md index 812ab79..56c74ee 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -275,11 +275,6 @@ Communication between the master server and clients will be done over a WebSocke Password String - - 3 - Server Id - Packed Unsigned Short - diff --git a/src/server/hosts/master.hpp b/src/server/hosts/master.hpp index 29a6acf..b5b7a98 100644 --- a/src/server/hosts/master.hpp +++ b/src/server/hosts/master.hpp @@ -17,11 +17,14 @@ namespace sosc { class MasterClient { public: + MasterClient() = delete; explicit MasterClient(const ScapeConnection& client); bool Process(const db::Queries* queries); bool Close(); bool Close(const Packet& message); + + ~MasterClient(); private: enum MasterToClientId { kLoginResponse = 0, @@ -47,11 +50,11 @@ class MasterClientPool : public Pool { protected: void SetupQueries(db::Queries* queries) override; bool ProcessClient( - MasterClient& client, + MasterClient* client, ctx::MasterClientContext* context, const db::Queries* queries) override { - return client.Process(queries); + return client->Process(queries); } }; @@ -59,11 +62,14 @@ protected: class MasterIntra { public: + MasterIntra() = delete; explicit MasterIntra(const IntraClient& client); bool Process(const db::Queries* queries); bool Close(); bool Close(const Packet& message); + + ~MasterIntra(); private: bool Authentication(Packet& pck); bool StatusUpdate(Packet& pck); @@ -99,11 +105,11 @@ class MasterIntraPool : public Pool { protected: void SetupQueries(db::Queries* queries) override; bool ProcessClient - (MasterIntra& client, + (MasterIntra* client, ctx::MasterIntraContext* context, const db::Queries* queries) override { - return client.Process(queries); + return client->Process(queries); } }; } diff --git a/src/server/main.cpp b/src/server/main.cpp index 694aac1..fee8db2 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -41,7 +41,7 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) { using namespace sosc; IntraServer server; - IntraClient client; + IntraClient* client; if(!server.Listen(port)) return false; @@ -49,7 +49,7 @@ bool master_intra(uint16_t port, const sosc::poolinfo_t& info) { pool.Configure(info); pool.Start(); - while(server.Accept(&client)) + while(server.Accept(client = new IntraClient())) pool.AddClient(MasterIntra(client)); pool.Stop(); @@ -60,7 +60,7 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) { using namespace sosc; ScapeServer server; - ScapeConnection client; + ScapeConnection* client; if(!server.Listen(port, true)) return false; @@ -68,7 +68,7 @@ bool master_client(uint16_t port, const sosc::poolinfo_t& info) { pool.Configure(info); pool.Start(); - while(server.Accept(&client)) + while(server.Accept(client = new ScapeConnection())) pool.AddClient(MasterClient(client)); pool.Stop(); @@ -79,7 +79,7 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) { using namespace sosc; ScapeServer server; - ScapeConnection client; + ScapeConnection* client; if(!server.Listen(port)) return false; @@ -87,7 +87,7 @@ bool slave(uint16_t port, const sosc::poolinfo_t& info) { pool.Configure(info); pool.Start(); - while(server.Accept(&client)) + while(server.Accept(client = new ScapeConnection())) pool.AddClient(SlaveClient(client)); pool.Stop(); diff --git a/src/server/sock/frame.hpp b/src/server/sock/frame.hpp index f498302..f7da2a0 100644 --- a/src/server/sock/frame.hpp +++ b/src/server/sock/frame.hpp @@ -72,7 +72,7 @@ private: std::string body; inline static bool IsValidOpCode(int op) { - return !(op == 0x0 || op == 0x1 || op == 0x2 + return (op == 0x0 || op == 0x1 || op == 0x2 || op == 0x8 || op == 0x9 || op == 0xA); } }; diff --git a/src/server/sock/pool.hpp b/src/server/sock/pool.hpp index f30519d..80bb4fa 100644 --- a/src/server/sock/pool.hpp +++ b/src/server/sock/pool.hpp @@ -36,7 +36,7 @@ public: void Configure(const poolinfo_t& info); void Start(); - bool AddClient(T client); + bool AddClient(T* client); int ClientCount(); inline bool IsOpen() const { return this->is_open; @@ -46,7 +46,7 @@ public: protected: virtual void SetupQueries(db::Queries* queries) {}; virtual bool ProcessClient - (T& client, U* context, const db::Queries* queries) = 0; + (T* client, U* context, const db::Queries* queries) = 0; private: bool IsStackFull(int stackCount) const; bool CanAddStack() const; @@ -58,7 +58,7 @@ private: void Start(); - void AddClient(T client); + void AddClient(T* client); int ClientCount(); inline bool IsOpen() const { return this->is_open; @@ -74,7 +74,7 @@ private: bool is_open; bool is_running; - std::list clients; + std::list clients; std::mutex clients_mtx; }; @@ -132,7 +132,7 @@ bool Pool::CanAddStack() const { } template -bool Pool::AddClient(T client) { +bool Pool::AddClient(T* client) { if(!this->is_open) return false; @@ -214,7 +214,7 @@ void Pool::Stack::Start() { } template -void Pool::Stack::AddClient(T client) { +void Pool::Stack::AddClient(T* client) { if(!this->is_open || !this->is_running) return; @@ -248,9 +248,10 @@ void Pool::Stack::StackThread() { this->clients_mtx.lock(); if(!this->pool->ProcessClient - (*client, &this->pool->context, &this->queries)) + (client, &this->pool->context, &this->queries)) { this->clients.erase(client); + delete client; } this->clients_mtx.unlock(); } @@ -269,8 +270,11 @@ void Pool::Stack::Stop() { this->is_running = false; this->thread->join(); - delete this->thread; + + for(auto client : this->clients) + delete client; + this->is_open = false; } } diff --git a/src/web/index.html b/src/web/index.html index 3edcf21..6e08ffe 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -12,9 +12,7 @@