Loading relayserver/RelayServer.cpp +22 −4 Original line number Diff line number Diff line #include "RelayServer.h" #include <iostream> #include <string> #include <TcpServer/EPoll.h> #include <nlohmann/json.hpp> using nlohmann::json; RelayServer::RelayServer() { Loading Loading @@ -35,11 +38,11 @@ int RelayServer::Run() con->FrameComplete(frame_id, _tcpProtocol); auto key = con->getViewerKey(); //if (key!=0) TODO implement if (key!=0) { for (auto& item: logMessages) { //if (item->viewer_key == key) // TODO implement if (item.viewer_key == key) { con->LogMessage(frame_id, item.message); } Loading Loading @@ -69,7 +72,22 @@ int RelayServer::Run() h.onMessage([](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) { //ws->send(message, length, opCode); auto *con = static_cast<WebsocketConnection*>(ws->getUserData()); if (length>MAX_CLIENT_MESSAGE_SIZE) { return; } std::string s(message, length); json data = json::parse(s, nullptr, false); if (!data.is_object()) { return; } if (data["viewer_key"].is_string()) { std::string key = data["viewer_key"]; con->setViewerKey(static_cast<uint64_t>(std::stol(key))); } }); std::string response = "Hello!"; Loading relayserver/RelayServer.h +1 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ class RelayServer static constexpr const char* ENV_GAMESERVER_PORT_DEFAULT = "9010"; static constexpr const char* ENV_WEBSOCKET_PORT = "WEBSOCKET_PORT"; static constexpr const char* ENV_WEBSOCKET_PORT_DEFAULT = "9009"; static constexpr const size_t MAX_CLIENT_MESSAGE_SIZE = 10*1024; static int connectTcpSocket(const char* hostname, const char* port); static const char* getEnvOrDefault(const char* envVar, const char* defaultValue); }; relayserver/WebsocketConnection.h +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ class WebsocketConnection void LogMessage(uint64_t frame_id, const std::string& message); void sendString(std::string data); uint64_t getViewerKey() { return _viewerKey; } void setViewerKey(uint64_t key) { _viewerKey = key; } private: uWS::WebSocket<uWS::SERVER> *_websocket; Loading Loading
relayserver/RelayServer.cpp +22 −4 Original line number Diff line number Diff line #include "RelayServer.h" #include <iostream> #include <string> #include <TcpServer/EPoll.h> #include <nlohmann/json.hpp> using nlohmann::json; RelayServer::RelayServer() { Loading Loading @@ -35,11 +38,11 @@ int RelayServer::Run() con->FrameComplete(frame_id, _tcpProtocol); auto key = con->getViewerKey(); //if (key!=0) TODO implement if (key!=0) { for (auto& item: logMessages) { //if (item->viewer_key == key) // TODO implement if (item.viewer_key == key) { con->LogMessage(frame_id, item.message); } Loading Loading @@ -69,7 +72,22 @@ int RelayServer::Run() h.onMessage([](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) { //ws->send(message, length, opCode); auto *con = static_cast<WebsocketConnection*>(ws->getUserData()); if (length>MAX_CLIENT_MESSAGE_SIZE) { return; } std::string s(message, length); json data = json::parse(s, nullptr, false); if (!data.is_object()) { return; } if (data["viewer_key"].is_string()) { std::string key = data["viewer_key"]; con->setViewerKey(static_cast<uint64_t>(std::stol(key))); } }); std::string response = "Hello!"; Loading
relayserver/RelayServer.h +1 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ class RelayServer static constexpr const char* ENV_GAMESERVER_PORT_DEFAULT = "9010"; static constexpr const char* ENV_WEBSOCKET_PORT = "WEBSOCKET_PORT"; static constexpr const char* ENV_WEBSOCKET_PORT_DEFAULT = "9009"; static constexpr const size_t MAX_CLIENT_MESSAGE_SIZE = 10*1024; static int connectTcpSocket(const char* hostname, const char* port); static const char* getEnvOrDefault(const char* envVar, const char* defaultValue); };
relayserver/WebsocketConnection.h +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ class WebsocketConnection void LogMessage(uint64_t frame_id, const std::string& message); void sendString(std::string data); uint64_t getViewerKey() { return _viewerKey; } void setViewerKey(uint64_t key) { _viewerKey = key; } private: uWS::WebSocket<uWS::SERVER> *_websocket; Loading