ソースを参照

Some progress on private rooms support

Ivan Savenko 1 年間 前
コミット
1a144fc516

+ 10 - 0
client/CServerHandler.cpp

@@ -997,3 +997,13 @@ void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const
 	if(getState() != EClientState::STARTING)
 		c->sendPack(&pack);
 }
+
+bool CServerHandler::inLobbyRoom() const
+{
+	return CSH->serverMode == EServerMode::LOBBY_HOST || CSH->serverMode == EServerMode::LOBBY_GUEST;
+}
+
+bool CServerHandler::inGame() const
+{
+	return c != nullptr;
+}

+ 2 - 0
client/CServerHandler.h

@@ -165,6 +165,8 @@ public:
 
 	bool isHost() const;
 	bool isGuest() const;
+	bool inLobbyRoom() const;
+	bool inGame() const;
 
 	const std::string & getCurrentHostname() const;
 	const std::string & getLocalHostname() const;

+ 9 - 1
client/globalLobby/GlobalLobbyClient.cpp

@@ -66,6 +66,9 @@ void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<INetworkConnectio
 	if(json["type"].String() == "joinRoomSuccess")
 		return receiveJoinRoomSuccess(json);
 
+	if(json["type"].String() == "inviteReceived")
+		return receiveInviteReceived(json);
+
 	logGlobal->error("Received unexpected message from lobby server: %s", json["type"].String());
 }
 
@@ -188,6 +191,11 @@ void GlobalLobbyClient::receiveActiveGameRooms(const JsonNode & json)
 		lobbyWindowPtr->onActiveRooms(activeRooms);
 }
 
+void GlobalLobbyClient::receiveInviteReceived(const JsonNode & json)
+{
+	assert(0); //TODO
+}
+
 void GlobalLobbyClient::receiveJoinRoomSuccess(const JsonNode & json)
 {
 	Settings configRoom = settings.write["lobby"]["roomID"];
@@ -293,7 +301,7 @@ void GlobalLobbyClient::connect()
 	CSH->getNetworkHandler().connectToRemote(*this, hostname, port);
 }
 
-bool GlobalLobbyClient::isConnected()
+bool GlobalLobbyClient::isConnected() const
 {
 	return networkConnection != nullptr;
 }

+ 2 - 1
client/globalLobby/GlobalLobbyClient.h

@@ -43,6 +43,7 @@ class GlobalLobbyClient final : public INetworkClientListener, boost::noncopyabl
 	void receiveActiveAccounts(const JsonNode & json);
 	void receiveActiveGameRooms(const JsonNode & json);
 	void receiveJoinRoomSuccess(const JsonNode & json);
+	void receiveInviteReceived(const JsonNode & json);
 
 	std::shared_ptr<GlobalLobbyLoginWindow> createLoginWindow();
 	std::shared_ptr<GlobalLobbyWindow> createLobbyWindow();
@@ -65,5 +66,5 @@ public:
 	void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);
 
 	void connect();
-	bool isConnected();
+	bool isConnected() const;
 };

+ 6 - 2
client/globalLobby/GlobalLobbyWidget.cpp

@@ -123,7 +123,9 @@ GlobalLobbyAccountCard::GlobalLobbyAccountCard(GlobalLobbyWindow * window, const
 	backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
 	labelName = std::make_shared<CLabel>( 5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, accountDescription.displayName);
 	labelStatus = std::make_shared<CLabel>( 5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, accountDescription.status);
-	buttonInvite = std::make_shared<CButton>(Point(95, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onInviteClicked);
+
+	if (CSH->inLobbyRoom())
+		buttonInvite = std::make_shared<CButton>(Point(95, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onInviteClicked);
 }
 
 GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription)
@@ -146,5 +148,7 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
 	labelName = std::make_shared<CLabel>( 5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, roomDescription.hostAccountDisplayName);
 	labelStatus = std::make_shared<CLabel>( 5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomDescription.description);
 	labelRoomSize = std::make_shared<CLabel>( 160, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomSizeText.toString());
-	buttonJoin = std::make_shared<CButton>(Point(195, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onJoinClicked);
+
+	if (!CSH->inGame())
+		buttonJoin = std::make_shared<CButton>(Point(195, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onJoinClicked);
 }

+ 0 - 4
client/globalLobby/GlobalLobbyWidget.h

@@ -38,8 +38,6 @@ class GlobalLobbyAccountCard : public CIntObject
 public:
 	GlobalLobbyAccountCard(GlobalLobbyWindow * window, const GlobalLobbyAccount & accountDescription);
 
-	GlobalLobbyWindow * window;
-
 	std::shared_ptr<TransparentFilledRectangle> backgroundOverlay;
 	std::shared_ptr<CLabel> labelName;
 	std::shared_ptr<CLabel> labelStatus;
@@ -51,8 +49,6 @@ class GlobalLobbyRoomCard : public CIntObject
 public:
 	GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription);
 
-	GlobalLobbyWindow * window;
-
 	std::shared_ptr<TransparentFilledRectangle> backgroundOverlay;
 	std::shared_ptr<CLabel> labelName;
 	std::shared_ptr<CLabel> labelRoomSize;

+ 15 - 1
client/globalLobby/GlobalLobbyWindow.cpp

@@ -55,7 +55,11 @@ void GlobalLobbyWindow::doCreateGameRoom()
 
 void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
 {
-	assert(0); // TODO
+	JsonNode toSend;
+	toSend["type"].String() = "sendInvite";
+	toSend["accountID"].String() = accountID;
+
+	CSH->getGlobalLobby().sendMessage(toSend);
 }
 
 void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
@@ -89,3 +93,13 @@ void GlobalLobbyWindow::onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms
 {
 	widget->getRoomList()->reset();
 }
+
+void GlobalLobbyWindow::onJoinedRoom()
+{
+	widget->getAccountList()->reset();
+}
+
+void GlobalLobbyWindow::onLeftRoom()
+{
+	widget->getAccountList()->reset();
+}

+ 2 - 0
client/globalLobby/GlobalLobbyWindow.h

@@ -33,4 +33,6 @@ public:
 	void onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when);
 	void onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts);
 	void onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms);
+	void onJoinedRoom();
+	void onLeftRoom();
 };

+ 5 - 3
lobby/LobbyServer.cpp

@@ -526,12 +526,14 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
 
 void LobbyServer::receiveLeaveGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json)
 {
-	std::string gameRoomID = json["gameRoomID"].String();
-	std::string senderName = activeAccounts[connection];
+	std::string accountID = json["accountID"].String();
+	std::string gameRoomID = activeGameRooms[connection];
 
-	if(!database->isPlayerInGameRoom(senderName, gameRoomID))
+	if(!database->isPlayerInGameRoom(accountID, gameRoomID))
 		return sendOperationFailed(connection, "You are not in the room!");
 
+	database->deletePlayerFromGameRoom(accountID, gameRoomID);
+
 	broadcastActiveGameRooms();
 }
 

+ 17 - 7
server/GlobalLobbyProcessor.cpp

@@ -36,6 +36,21 @@ void GlobalLobbyProcessor::onDisconnected(const std::shared_ptr<INetworkConnecti
 	}
 	else
 	{
+		if (owner.getState() == EServerState::LOBBY)
+		{
+			for (auto const & proxy : proxyConnections)
+			{
+				if (proxy.second == connection)
+				{
+					JsonNode message;
+					message["type"].String() = "leaveGameRoom";
+					message["accountID"].String() = proxy.first;
+					controlConnection->sendPacket(message.toBytes(true));
+					break;
+				}
+			}
+		}
+
 		// player disconnected
 		owner.onDisconnected(connection, errorMessage);
 	}
@@ -107,7 +122,7 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
 		toSend["gameRoomID"].String() = owner.uuid;
 		toSend["accountID"] = settings["lobby"]["accountID"];
 		toSend["accountCookie"] = settings["lobby"]["accountCookie"];
-		sendMessage(connection, toSend);
+		connection->sendPacket(toSend.toBytes(true));
 	}
 	else
 	{
@@ -122,14 +137,9 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
 		toSend["gameRoomID"].String() = owner.uuid;
 		toSend["guestAccountID"].String() = guestAccountID;
 		toSend["accountCookie"] = settings["lobby"]["accountCookie"];
-		sendMessage(connection, toSend);
+		connection->sendPacket(toSend.toBytes(true));
 
 		proxyConnections[guestAccountID] = connection;
 		owner.onNewConnection(connection);
 	}
 }
-
-void GlobalLobbyProcessor::sendMessage(const NetworkConnectionPtr & target, const JsonNode & data)
-{
-	target->sendPacket(data.toBytes(true));
-}

+ 0 - 2
server/GlobalLobbyProcessor.h

@@ -29,8 +29,6 @@ class GlobalLobbyProcessor : public INetworkClientListener
 	void onConnectionFailed(const std::string & errorMessage) override;
 	void onConnectionEstablished(const std::shared_ptr<INetworkConnection> &) override;
 
-	void sendMessage(const NetworkConnectionPtr & target, const JsonNode & data);
-
 	void receiveOperationFailed(const JsonNode & json);
 	void receiveLoginSuccess(const JsonNode & json);
 	void receiveAccountJoinsRoom(const JsonNode & json);