adjust protocoll
This commit is contained in:
parent
ff179ee3a4
commit
0612afb37b
@ -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
|
||||
|
||||
@ -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<void(std::string)> toLog;
|
||||
@ -36,7 +35,7 @@ class Websocket
|
||||
std::function<void(const std::string)> toLog);
|
||||
~Websocket();
|
||||
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);
|
||||
void sendData(data d);
|
||||
void sendData(data &d);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -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<std::mutex> lock(wsLock);
|
||||
if (webSocket != nullptr) {
|
||||
std::ostringstream msg;
|
||||
msg << "SEND:" << user << ":" << json.dump();
|
||||
webSocket->send(msg.str(), false);
|
||||
webSocket->send(json.dump(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user