Use Header Login
Failure Modes Switch to use proxied wss
This commit is contained in:
parent
176c43d5a6
commit
5af921f4cc
@ -79,6 +79,6 @@
|
||||
// Must be differentiated due to SxS Install
|
||||
#define FSXSE_SUBVERSION 62615
|
||||
|
||||
#define WEBSOCKET_ADDRESS "wss://ws.hofmannnet.myhome-server.de:8000"
|
||||
#define WEBSOCKET_ADDRESS "wss://wsecho.hofmannnet.myhome-server.de/ws"
|
||||
|
||||
#endif
|
||||
@ -56,6 +56,13 @@ namespace gaconnector
|
||||
float trueHeading;
|
||||
};
|
||||
|
||||
enum failures {
|
||||
NONE,
|
||||
AUTH,
|
||||
DUPLICATESIM,
|
||||
OTHER,
|
||||
};
|
||||
|
||||
#pragma pack(pop) /* restore original alignment from stack */
|
||||
} // namespace websocket
|
||||
} // namespace gaconnector
|
||||
|
||||
@ -28,6 +28,7 @@ namespace gaconnector
|
||||
{
|
||||
private:
|
||||
bool isLoggedIn = false;
|
||||
enum failures failureMode = failures::NONE;
|
||||
char lastPath[513] = "";
|
||||
char lastHash[2 * MD5LEN + 1] = "";
|
||||
ix::WebSocket *webSocket = nullptr;
|
||||
|
||||
@ -19,7 +19,9 @@ namespace gaconnector
|
||||
|
||||
this->webSocket = new ix::WebSocket();
|
||||
this->webSocket->setExtraHeaders({
|
||||
{ "Authentication", "Bearer " + this->token }
|
||||
{"origin", "GAClient"},
|
||||
{"authentication", "Bearer " + this->token},
|
||||
{"user", this->user},
|
||||
});
|
||||
this->webSocket->enableAutomaticReconnection();
|
||||
this->webSocket->setUrl(host);
|
||||
@ -51,29 +53,21 @@ namespace gaconnector
|
||||
for (const auto &it : msg->openInfo.headers) {
|
||||
debug_msg << "\t\t" << it.first << ": " << it.second << std::endl;
|
||||
}
|
||||
|
||||
this->toLog(debug_msg.str());
|
||||
|
||||
this->webSocket->send("MASTER:" + user);
|
||||
this->toLog("Connecting as " + user);
|
||||
this->toLog("Connected as " + user);
|
||||
this->isLoggedIn = true;
|
||||
this->failureMode = failures::NONE;
|
||||
} else if (msg->type == ix::WebSocketMessageType::Close) {
|
||||
if (msg->closeInfo.reason.compare("DUPLICATE") == 0) {
|
||||
this->webSocket->disableAutomaticReconnection();
|
||||
std::stringstream debug_msg;
|
||||
|
||||
this->toLog("Disconnected due to beeing a duplicate simualtor");
|
||||
this->isLoggedIn = false;
|
||||
} else {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "Connection closed" << std::endl;
|
||||
debug_msg << "\tCode: " << msg->closeInfo.code << std::endl;
|
||||
debug_msg << "\tReason: " << msg->closeInfo.reason << std::endl;
|
||||
debug_msg << "\tRemote: " << msg->closeInfo.remote << std::endl;
|
||||
|
||||
debug_msg << "Connection closed" << std::endl;
|
||||
debug_msg << "\tCode: " << msg->closeInfo.code << std::endl;
|
||||
debug_msg << "\tReason: " << msg->closeInfo.reason << std::endl;
|
||||
debug_msg << "\tRemote: " << msg->closeInfo.remote << std::endl;
|
||||
|
||||
this->toLog(debug_msg.str());
|
||||
this->isLoggedIn = false;
|
||||
}
|
||||
this->toLog(debug_msg.str());
|
||||
this->isLoggedIn = false;
|
||||
} else if (msg->type == ix::WebSocketMessageType::Error) {
|
||||
std::stringstream debug_msg;
|
||||
|
||||
@ -86,6 +80,22 @@ namespace gaconnector
|
||||
debug_msg << "\tRetries: " << msg->errorInfo.retries << std::endl;
|
||||
debug_msg << "\tWait time: " << msg->errorInfo.wait_time << std::endl;
|
||||
|
||||
if (msg->errorInfo.http_status == 401) {
|
||||
this->webSocket->disableAutomaticReconnection();
|
||||
|
||||
this->toLog("Disabling automatic reconnection due to auth failure");
|
||||
this->failureMode = failures::AUTH;
|
||||
} else if (msg->errorInfo.http_status == 500 &&
|
||||
msg->errorInfo.reason.find("Duplicate") !=
|
||||
std::string::npos) {
|
||||
this->webSocket->disableAutomaticReconnection();
|
||||
|
||||
this->toLog("Disabling automatic reconnection due to duplicate");
|
||||
this->failureMode = failures::DUPLICATESIM;
|
||||
} else {
|
||||
this->failureMode = failures::OTHER;
|
||||
}
|
||||
|
||||
this->toLog(debug_msg.str());
|
||||
this->isLoggedIn = false;
|
||||
} else if (msg->type == ix::WebSocketMessageType::Message) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user