Ver código fonte

Split 'loginSuccess' into server and client-specific versions

Ivan Savenko 1 ano atrás
pai
commit
be641d1710

+ 3 - 3
client/globalLobby/GlobalLobbyClient.cpp

@@ -51,8 +51,8 @@ void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<INetworkConnectio
 	if(json["type"].String() == "operationFailed")
 		return receiveOperationFailed(json);
 
-	if(json["type"].String() == "loginSuccess")
-		return receiveLoginSuccess(json);
+	if(json["type"].String() == "clientLoginSuccess")
+		return receiveClientLoginSuccess(json);
 
 	if(json["type"].String() == "chatHistory")
 		return receiveChatHistory(json);
@@ -106,7 +106,7 @@ void GlobalLobbyClient::receiveOperationFailed(const JsonNode & json)
 	// TODO: handle errors in lobby menu
 }
 
-void GlobalLobbyClient::receiveLoginSuccess(const JsonNode & json)
+void GlobalLobbyClient::receiveClientLoginSuccess(const JsonNode & json)
 {
 	{
 		Settings configCookie = settings.write["lobby"]["accountCookie"];

+ 1 - 1
client/globalLobby/GlobalLobbyClient.h

@@ -37,7 +37,7 @@ class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyabl
 
 	void receiveAccountCreated(const JsonNode & json);
 	void receiveOperationFailed(const JsonNode & json);
-	void receiveLoginSuccess(const JsonNode & json);
+	void receiveClientLoginSuccess(const JsonNode & json);
 	void receiveChatHistory(const JsonNode & json);
 	void receiveChatMessage(const JsonNode & json);
 	void receiveActiveAccounts(const JsonNode & json);

+ 2 - 2
config/schemas/lobbyProtocol/loginSuccess.json → config/schemas/lobbyProtocol/clientLoginSuccess.json

@@ -1,7 +1,7 @@
 {
 	"type" : "object",
 	"$schema" : "http://json-schema.org/draft-06/schema",
-	"title" : "Lobby protocol: loginSuccess",
+	"title" : "Lobby protocol: clientLoginSuccess",
 	"description" : "Sent by server once player sucesfully logs into the lobby",
 	"required" : [ "type", "accountCookie", "displayName" ],
 	"additionalProperties" : false,
@@ -10,7 +10,7 @@
 		"type" :
 		{
 			"type" : "string",
-			"const" : "loginSuccess"
+			"const" : "clientLoginSuccess"
 		},
 		"accountCookie" :
 		{

+ 21 - 0
config/schemas/lobbyProtocol/serverLoginSuccess.json

@@ -0,0 +1,21 @@
+{
+	"type" : "object",
+	"$schema" : "http://json-schema.org/draft-06/schema",
+	"title" : "Lobby protocol: serverLoginSuccess",
+	"description" : "Sent by server once server sucesfully logs into the lobby",
+	"required" : [ "type", "accountCookie" ],
+	"additionalProperties" : false,
+
+	"properties" : {
+		"type" :
+		{
+			"type" : "string",
+			"const" : "serverLoginSuccess"
+		},
+		"accountCookie" :
+		{
+			"type" : "string",
+			"description" : "Security cookie that should be stored by server and used for future operations"
+		}
+	}
+}

+ 13 - 6
lobby/LobbyServer.cpp

@@ -90,13 +90,20 @@ void LobbyServer::sendOperationFailed(const NetworkConnectionPtr & target, const
 	sendMessage(target, reply);
 }
 
-void LobbyServer::sendLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie, const std::string & displayName)
+void LobbyServer::sendClientLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie, const std::string & displayName)
 {
 	JsonNode reply;
-	reply["type"].String() = "loginSuccess";
+	reply["type"].String() = "clientLoginSuccess";
+	reply["accountCookie"].String() = accountCookie;
+	reply["displayName"].String() = displayName;
+	sendMessage(target, reply);
+}
+
+void LobbyServer::sendServerLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie)
+{
+	JsonNode reply;
+	reply["type"].String() = "serverLoginSuccess";
 	reply["accountCookie"].String() = accountCookie;
-	if(!displayName.empty())
-		reply["displayName"].String() = displayName;
 	sendMessage(target, reply);
 }
 
@@ -409,7 +416,7 @@ void LobbyServer::receiveClientLogin(const NetworkConnectionPtr & connection, co
 
 	activeAccounts[connection] = accountID;
 
-	sendLoginSuccess(connection, accountCookie, displayName);
+	sendClientLoginSuccess(connection, accountCookie, displayName);
 	sendChatHistory(connection, database->getRecentMessageHistory());
 
 	// send active game rooms list to new account
@@ -435,7 +442,7 @@ void LobbyServer::receiveServerLogin(const NetworkConnectionPtr & connection, co
 	{
 		database->insertGameRoom(gameRoomID, accountID);
 		activeGameRooms[connection] = gameRoomID;
-		sendLoginSuccess(connection, accountCookie, {});
+		sendServerLoginSuccess(connection, accountCookie);
 		broadcastActiveGameRooms();
 	}
 }

+ 2 - 1
lobby/LobbyServer.h

@@ -68,7 +68,8 @@ class LobbyServer final : public INetworkServerListener
 	void sendChatMessage(const NetworkConnectionPtr & target, const std::string & roomMode, const std::string & roomName, const std::string & accountID, const std::string & displayName, const std::string & messageText);
 	void sendAccountCreated(const NetworkConnectionPtr & target, const std::string & accountID, const std::string & accountCookie);
 	void sendOperationFailed(const NetworkConnectionPtr & target, const std::string & reason);
-	void sendLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie, const std::string & displayName);
+	void sendServerLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie);
+	void sendClientLoginSuccess(const NetworkConnectionPtr & target, const std::string & accountCookie, const std::string & displayName);
 	void sendChatHistory(const NetworkConnectionPtr & target, const std::vector<LobbyChatMessage> &);
 	void sendAccountJoinsRoom(const NetworkConnectionPtr & target, const std::string & accountID);
 	void sendJoinRoomSuccess(const NetworkConnectionPtr & target, const std::string & gameRoomID, bool proxyMode);

+ 3 - 3
server/GlobalLobbyProcessor.cpp

@@ -68,8 +68,8 @@ void GlobalLobbyProcessor::onPacketReceived(const std::shared_ptr<INetworkConnec
 		if(json["type"].String() == "operationFailed")
 			return receiveOperationFailed(json);
 
-		if(json["type"].String() == "loginSuccess")
-			return receiveLoginSuccess(json);
+		if(json["type"].String() == "serverLoginSuccess")
+			return receiveServerLoginSuccess(json);
 
 		if(json["type"].String() == "accountJoinsRoom")
 			return receiveAccountJoinsRoom(json);
@@ -90,7 +90,7 @@ void GlobalLobbyProcessor::receiveOperationFailed(const JsonNode & json)
 	owner.setState(EServerState::SHUTDOWN);
 }
 
-void GlobalLobbyProcessor::receiveLoginSuccess(const JsonNode & json)
+void GlobalLobbyProcessor::receiveServerLoginSuccess(const JsonNode & json)
 {
 	// no-op, wait just for any new commands from lobby
 	logGlobal->info("Lobby: Succesfully connected to lobby server");

+ 1 - 1
server/GlobalLobbyProcessor.h

@@ -30,7 +30,7 @@ class GlobalLobbyProcessor : public INetworkClientListener
 	void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
 
 	void receiveOperationFailed(const JsonNode & json);
-	void receiveLoginSuccess(const JsonNode & json);
+	void receiveServerLoginSuccess(const JsonNode & json);
 	void receiveAccountJoinsRoom(const JsonNode & json);
 
 	void establishNewConnection();