Browse Source

Distinguish "connected but not logged in" from "not connected" state

Possible in case of login failure
Ivan Savenko 1 year ago
parent
commit
dd91a99e36
2 changed files with 13 additions and 6 deletions
  1. 11 6
      client/globalLobby/GlobalLobbyClient.cpp
  2. 2 0
      client/globalLobby/GlobalLobbyClient.h

+ 11 - 6
client/globalLobby/GlobalLobbyClient.cpp

@@ -106,10 +106,9 @@ void GlobalLobbyClient::receiveOperationFailed(const JsonNode & json)
 
 void GlobalLobbyClient::receiveClientLoginSuccess(const JsonNode & json)
 {
-	{
-		setAccountDisplayName(json["displayName"].String());
-		setAccountCookie(json["accountCookie"].String());
-	}
+	accountLoggedIn = true;
+	setAccountDisplayName(json["displayName"].String());
+	setAccountCookie(json["accountCookie"].String());
 
 	auto loginWindowPtr = loginWindow.lock();
 
@@ -343,6 +342,7 @@ void GlobalLobbyClient::onDisconnected(const std::shared_ptr<INetworkConnection>
 
 	assert(connection == networkConnection);
 	networkConnection.reset();
+	accountLoggedIn = false;
 
 	while (!GH.windows().findWindows<GlobalLobbyWindow>().empty())
 	{
@@ -376,6 +376,11 @@ void GlobalLobbyClient::connect()
 	CSH->getNetworkHandler().connectToRemote(*this, hostname, port);
 }
 
+bool GlobalLobbyClient::isLoggedIn() const
+{
+	return networkConnection != nullptr && accountLoggedIn;
+}
+
 bool GlobalLobbyClient::isConnected() const
 {
 	return networkConnection != nullptr;
@@ -461,7 +466,7 @@ void GlobalLobbyClient::activateInterface()
 	if (!GH.windows().findWindows<GlobalLobbyLoginWindow>().empty())
 		return;
 
-	if (isConnected())
+	if (isLoggedIn())
 		GH.windows().pushWindow(createLobbyWindow());
 	else
 		GH.windows().pushWindow(createLoginWindow());
@@ -534,7 +539,7 @@ void GlobalLobbyClient::resetMatchState()
 
 void GlobalLobbyClient::sendMatchChatMessage(const std::string & messageText)
 {
-	if (!isConnected())
+	if (!isLoggedIn())
 		return; // we are not playing with lobby
 
 	if (currentGameRoomUUID.empty())

+ 2 - 0
client/globalLobby/GlobalLobbyClient.h

@@ -34,6 +34,7 @@ class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyabl
 
 	std::shared_ptr<INetworkConnection> networkConnection;
 	std::string currentGameRoomUUID;
+	bool accountLoggedIn = false;
 
 	std::weak_ptr<GlobalLobbyLoginWindow> loginWindow;
 	std::weak_ptr<GlobalLobbyWindow> lobbyWindow;
@@ -93,5 +94,6 @@ public:
 
 	void connect();
 	bool isConnected() const;
+	bool isLoggedIn() const;
 	bool isInvitedToRoom(const std::string & gameRoomID);
 };