Exemplo n.º 1
0
        protected override void BroadcastPlayerOptions()
        {
            if (!IsHost)
            {
                return;
            }

            var sb = new ExtendedStringBuilder(PLAYER_OPTIONS_BROADCAST_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            foreach (PlayerInfo pInfo in Players.Concat(AIPlayers))
            {
                sb.Append(pInfo.Name);
                sb.Append(pInfo.SideId);
                sb.Append(pInfo.ColorId);
                sb.Append(pInfo.StartingLocation);
                sb.Append(pInfo.TeamId);
                sb.Append(Convert.ToInt32(pInfo.IsAI || pInfo.Ready));
                sb.Append(pInfo.IPAddress);
                if (pInfo.IsAI)
                {
                    sb.Append(pInfo.AILevel);
                }
                else
                {
                    sb.Append("-1");
                }
            }

            BroadcastMessage(sb.ToString());
        }
Exemplo n.º 2
0
        public string Join(string user, string connectionId)
        {
            var existing = Players.Concat(WaitingRoom).FirstOrDefault(t => t.Name == user);

            if (existing != null)
            {
                if (existing.ConnectionId != connectionId)
                {
                    existing.ConnectionId = connectionId;
                    Message(user, $"re-joined the game");
                }
            }
            else if (string.IsNullOrEmpty(Owner))
            {
                Owner = user;
                Players.Add(CreatePlayer(user, connectionId));
            }
            else
            {
                if (Players.Count >= MaxPlayers)
                {
                    return($"Game already has maximum number of players");
                }
                WaitingRoom.Add(CreatePlayer(user, connectionId));
                Message(user, $"requested to join the game");
            }
            return(null);
        }
Exemplo n.º 3
0
        private string CheckGameValidity()
        {
            int totalPlayerCount = Players.Count(p => p.SideId < ddPlayerSides[0].Items.Count - 1)
                                   + AIPlayers.Count;

            if (GameMode.MultiplayerOnly)
            {
                return(GameMode.UIName + " can only be played on CnCNet and LAN.");
            }

            if (GameMode.MinPlayersOverride > -1 && totalPlayerCount < GameMode.MinPlayersOverride)
            {
                return(GameMode.UIName + " cannot be played with less than " + GameMode.MinPlayersOverride + " players.");
            }

            if (Map.MultiplayerOnly)
            {
                return("The selected map can only be played on CnCNet and LAN.");
            }

            if (totalPlayerCount < Map.MinPlayers)
            {
                return("The selected map cannot be played with less than " + Map.MinPlayers + " players.");
            }

            if (Map.EnforceMaxPlayers)
            {
                if (totalPlayerCount > Map.MaxPlayers)
                {
                    return("The selected map cannot be played with more than " + Map.MaxPlayers + " players.");
                }

                IEnumerable <PlayerInfo> concatList = Players.Concat(AIPlayers);

                foreach (PlayerInfo pInfo in concatList)
                {
                    if (pInfo.StartingLocation == 0)
                    {
                        continue;
                    }

                    if (concatList.Count(p => p.StartingLocation == pInfo.StartingLocation) > 1)
                    {
                        return("Multiple players cannot share the same starting location on the selected map.");
                    }
                }
            }

            if (Map.IsCoop && Players[0].SideId == ddPlayerSides[0].Items.Count - 1)
            {
                return("Co-op missions cannot be spectated. You'll have to show a bit more effort to cheat here.");
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the user's click on the "Launch Game" / "I'm Ready" button.
        /// If the local player is the game host, checks if the game can be launched and then
        /// launches the game if it's allowed. If the local player isn't the game host,
        /// sends a ready request.
        /// </summary>
        protected override void BtnLaunchGame_LeftClick(object sender, EventArgs e)
        {
            if (!IsHost)
            {
                RequestReadyStatus();
                return;
            }

            if (!Locked)
            {
                LockGameNotification();
                return;
            }

            List <int> occupiedColorIds = new List <int>();

            foreach (PlayerInfo player in Players)
            {
                if (occupiedColorIds.Contains(player.ColorId) && player.ColorId > 0)
                {
                    SharedColorsNotification();
                    return;
                }

                occupiedColorIds.Add(player.ColorId);
            }

            if (AIPlayers.Count(pInfo => pInfo.SideId == ddPlayerSides[0].Items.Count - 1) > 0)
            {
                AISpectatorsNotification();
                return;
            }

            if (Map.EnforceMaxPlayers)
            {
                foreach (PlayerInfo pInfo in Players)
                {
                    if (pInfo.StartingLocation == 0)
                    {
                        continue;
                    }

                    if (Players.Concat(AIPlayers).ToList().Find(
                            p => p.StartingLocation == pInfo.StartingLocation &&
                            p.Name != pInfo.Name) != null)
                    {
                        SharedStartingLocationNotification();
                        return;
                    }
                }

                for (int aiId = 0; aiId < AIPlayers.Count; aiId++)
                {
                    int startingLocation = AIPlayers[aiId].StartingLocation;

                    if (startingLocation == 0)
                    {
                        continue;
                    }

                    int index = AIPlayers.FindIndex(aip => aip.StartingLocation == startingLocation);

                    if (index > -1 && index != aiId)
                    {
                        SharedStartingLocationNotification();
                        return;
                    }
                }

                int totalPlayerCount = Players.Count(p => p.SideId < ddPlayerSides[0].Items.Count - 1)
                                       + AIPlayers.Count;

                if (totalPlayerCount < Map.MinPlayers)
                {
                    InsufficientPlayersNotification();
                    return;
                }

                if (Map.EnforceMaxPlayers && totalPlayerCount > Map.MaxPlayers)
                {
                    TooManyPlayersNotification();
                    return;
                }
            }

            int iId = 0;

            foreach (PlayerInfo player in Players)
            {
                iId++;

                if (player.Name == ProgramConstants.PLAYERNAME)
                {
                    continue;
                }

                if (!player.Verified)
                {
                    NotVerifiedNotification(iId - 1);
                    return;
                }

                if (!player.Ready)
                {
                    if (player.IsInGame)
                    {
                        StillInGameNotification(iId - 1);
                    }
                    else
                    {
                        GetReadyNotification();
                    }

                    return;
                }
            }

            HostLaunchGame();
        }
Exemplo n.º 5
0
 public virtual IEnumerable <ITargetable> GetTargetables()
 {
     return(Players.Concat(Opponents));
 }