Ejemplo n.º 1
0
    protected void UserJoinGame(IClient client)
    {
        UserAccountInfo userInfo = null;

        if (LobbyClientAccountMap.ContainsKey(client))
        {
            userInfo = LobbyClientAccountMap[client];
            LobbyClientAccountMap.Remove(client);
        }
        else if (InGameClientAccountMap.ContainsKey(client))
        {
            userInfo = InGameClientAccountMap[client];
        }

        //Record client in game map
        if (InGameClientAccountMap.ContainsKey(client))
        {
            InGameClientAccountMap[client] = userInfo;
        }
        else
        {
            InGameClientAccountMap.Add(client, userInfo);
        }

        Player     player     = ServerGameManager.Instance.PlayerJoined(userInfo.PlayFabId, userInfo.TitleInfo.DisplayName);
        PlayerData playerData = DatabaseManager.GetPlayerData(userInfo.PlayFabId);

        player.maxSquadCost = playerData.MaxSquadCost;

        //Alert other players of the new player
        using (DarkRiftWriter writer = DarkRiftWriter.Create()) {
            writer.Write(player);

            using (Message message = Message.Create(NetworkTags.PlayerJoined, writer)) {
                foreach (IClient otherClient in InGameClientAccountMap.Keys)
                {
                    if (!otherClient.Equals(client))
                    {
                        otherClient.SendMessage(message, SendMode.Reliable);
                    }
                }
            }
        }

        //Send current game state to newly-joined player
        using (DarkRiftWriter writer = DarkRiftWriter.Create()) {
            writer.Write(ServerGameManager.Instance.GameState);
            //whether player already has entities spawned
            writer.Write(ServerEntityManager.Instance.GetUnitsForPlayer(player.id).Count > 0);

            using (Message message = Message.Create(NetworkTags.GameState, writer)) {
                client.SendMessage(message, SendMode.Reliable);
            }
        }

        ServerGameManager.Instance.TryToStartGame();
    }
Ejemplo n.º 2
0
    private void DarkRift_OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
    {
        string playFabId = null;

        if (LobbyClientAccountMap.ContainsKey(e.Client))
        {
            playFabId = LobbyClientAccountMap[e.Client].PlayFabId;
            LobbyClientAccountMap.Remove(e.Client);
        }

        if (InGameClientAccountMap.ContainsKey(e.Client))
        {
            playFabId = InGameClientAccountMap[e.Client].PlayFabId;
            Player player = ServerGameManager.Instance.PlayerLeft(playFabId);

            InGameClientAccountMap.Remove(e.Client);

            if (player != null)
            {
                //Alert other players of the disconnection
                using (DarkRiftWriter writer = DarkRiftWriter.Create()) {
                    writer.Write(player);

                    using (Message message = Message.Create(NetworkTags.PlayerLeft, writer)) {
                        foreach (IClient otherClient in InGameClientAccountMap.Keys)
                        {
                            otherClient.SendMessage(message, SendMode.Reliable);
                        }
                    }
                }
            }
        }

        if (playFabId != null)
        {
            ServerPlayFabManager.Instance.NotifyPlayerLeft(playFabId);
        }
    }