diff --git a/format.sh b/format.sh index 59aa6ed..d80c918 100755 --- a/format.sh +++ b/format.sh @@ -2,7 +2,7 @@ shopt -s globstar -GLOBIGNORE='**/XPLM/**:XPLM/**:**/XPLM:**/ixwebsocket/**:ixwebsocket/**:**/ixwebsocket:**/nlohmann/**:nlohmann/**:**/nlohmann:**/XPSDK/**:XPSDK/**:**/XPSDK:**/build*/**:build*/**:**/build*' +GLOBIGNORE='**/XPLM/**:XPLM/**:**/XPLM:**/ixwebsocket/**:ixwebsocket/**:**/ixwebsocket:**/nlohmann/**:nlohmann/**:**/nlohmann:**/XPSDK/**:XPSDK/**:**/XPSDK:**/build*/**:build*/**:**/build*:**/openSSL/**:openSSL/**:**/openSSL' clang-format -verbose -i **/*.cpp clang-format -verbose -i **/*.h diff --git a/websocket/include/websocket.h b/websocket/include/websocket.h index 5c95d11..73e0599 100644 --- a/websocket/include/websocket.h +++ b/websocket/include/websocket.h @@ -25,7 +25,6 @@ class Websocket char lastPath[513] = ""; char lastHash[2 * MD5LEN + 1] = ""; ix::WebSocket *webSocket = nullptr; - std::mutex wsLock; std::string host; std::string user; std::function toLog; @@ -36,7 +35,7 @@ class Websocket std::function toLog); ~Websocket(); void onClientMessageCallback(const ix::WebSocketMessagePtr &msg); - void sendData(data d); + void sendData(data &d); }; #endif \ No newline at end of file diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 8d2f9d1..ea9b2a0 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -43,17 +43,23 @@ void Websocket::onClientMessageCallback(const ix::WebSocketMessagePtr &msg) toLog(debug_msg.str()); - webSocket->send("LOGIN:" + user); + webSocket->send("MASTER:" + user); toLog("Connecting as " + user); } else if (msg->type == ix::WebSocketMessageType::Close) { - std::stringstream debug_msg; + if (msg->closeInfo.reason.compare("DUPLICATE")) { + webSocket->disableAutomaticReconnection(); - debug_msg << "Connection closed" << std::endl; - debug_msg << "Code: " << msg->closeInfo.code << std::endl; - debug_msg << "Reason: " << msg->closeInfo.reason << std::endl; - debug_msg << "Remote: " << msg->closeInfo.remote << std::endl; + toLog("Disconnected due to beeing a duplicate simualtor"); + } else { + std::stringstream debug_msg; - toLog(debug_msg.str()); + debug_msg << "Connection closed" << std::endl; + debug_msg << "Code: " << msg->closeInfo.code << std::endl; + debug_msg << "Reason: " << msg->closeInfo.reason << std::endl; + debug_msg << "Remote: " << msg->closeInfo.remote << std::endl; + + toLog(debug_msg.str()); + } } else if (msg->type == ix::WebSocketMessageType::Error) { std::stringstream debug_msg; @@ -73,7 +79,7 @@ void Websocket::onClientMessageCallback(const ix::WebSocketMessagePtr &msg) } } -void Websocket::sendData(data d) +void Websocket::sendData(data &d) { if (strcmp(d.path, lastPath) != 0) { strcpy(lastPath, d.path); @@ -94,11 +100,8 @@ void Websocket::sendData(data d) }; { - std::lock_guard lock(wsLock); if (webSocket != nullptr) { - std::ostringstream msg; - msg << "SEND:" << user << ":" << json.dump(); - webSocket->send(msg.str(), false); + webSocket->send(json.dump(), false); } } } \ No newline at end of file