diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 785b0038..7c6605a2 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -220,9 +220,8 @@ RequestResult RequestHandler::ProcessRequest(const Request &request) std::vector RequestHandler::GetRequestList() { std::vector ret; - for (auto const &[key, val] : _handlerMap) { + for (auto const &[key, val] : _handlerMap) ret.push_back(key); - } return ret; } diff --git a/src/websocketserver/WebSocketServer.cpp b/src/websocketserver/WebSocketServer.cpp index 836fca0a..67d5f68c 100644 --- a/src/websocketserver/WebSocketServer.cpp +++ b/src/websocketserver/WebSocketServer.cpp @@ -158,9 +158,8 @@ void WebSocketServer::Stop() _threadPool.waitForDone(); // This can delay the thread that it is running on. Bad but kinda required. - while (_sessions.size() > 0) { + while (_sessions.size() > 0) std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } _serverThread.join(); @@ -257,7 +256,7 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl) json helloMessageData; helloMessageData["obsWebSocketVersion"] = OBS_WEBSOCKET_VERSION; helloMessageData["rpcVersion"] = OBS_WEBSOCKET_RPC_VERSION; - if (conf->AuthRequired) { + if (session->AuthenticationRequired()) { session->SetSecret(_authenticationSecret); std::string sessionChallenge = Utils::Crypto::GenerateSalt(); session->SetChallenge(sessionChallenge); diff --git a/src/websocketserver/WebSocketServer_Protocol.cpp b/src/websocketserver/WebSocketServer_Protocol.cpp index 7772d7bb..8d7d7e71 100644 --- a/src/websocketserver/WebSocketServer_Protocol.cpp +++ b/src/websocketserver/WebSocketServer_Protocol.cpp @@ -82,7 +82,7 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces } // Only `Identify` is allowed when not identified - if (!session->IsIdentified() && opCode != 1) { + if (!session->IsIdentified() && opCode != WebSocketOpCode::Identify) { ret.closeCode = WebSocketCloseCode::NotIdentified; ret.closeReason = "You attempted to send a non-Identify message while not identified."; return; @@ -146,9 +146,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces session->SetRpcVersion(requestedRpcVersion); SetSessionParameters(session, ret, payloadData); - if (ret.closeCode != WebSocketCloseCode::DontClose) { + if (ret.closeCode != WebSocketCloseCode::DontClose) return; - } // Increment refs for event subscriptions auto eventHandler = GetEventHandler(); @@ -178,9 +177,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces eventHandler->ProcessUnsubscription(session->EventSubscriptions()); SetSessionParameters(session, ret, payloadData); - if (ret.closeCode != WebSocketCloseCode::DontClose) { + if (ret.closeCode != WebSocketCloseCode::DontClose) return; - } // Increment refs for new subscriptions eventHandler->ProcessSubscription(session->EventSubscriptions()); @@ -377,19 +375,16 @@ void WebSocketServer::BroadcastEvent(uint64_t requiredIntent, const std::string // Recurse connected sessions and send the event to suitable sessions. std::unique_lock lock(_sessionMutex); for (auto &it : _sessions) { - if (!it.second->IsIdentified()) { + if (!it.second->IsIdentified()) continue; - } - if (rpcVersion && it.second->RpcVersion() != rpcVersion) { + if (rpcVersion && it.second->RpcVersion() != rpcVersion) continue; - } if ((it.second->EventSubscriptions() & requiredIntent) != 0) { websocketpp::lib::error_code errorCode; switch (it.second->Encoding()) { case WebSocketEncoding::Json: - if (messageJson.empty()) { + if (messageJson.empty()) messageJson = eventMessage.dump(); - } _server.send((websocketpp::connection_hdl)it.first, messageJson, websocketpp::frame::opcode::text, errorCode); it.second->IncrementOutgoingMessages();