Esempio n. 1
0
 public void SendNotification()
 {
     foreach (LobbyPlayerInfo playerInfo in TeamInfo.TeamPlayerInfo)
     {
         if (!playerInfo.IsNPCBot)
         {
             LobbyServerConnection player        = LobbyServer.GetPlayerByAccountId(playerInfo.AccountId);
             LobbyTeamInfo         teamInfoClone = TeamInfo.Clone();
             foreach (LobbyPlayerInfo pi in teamInfoClone.TeamPlayerInfo)
             {
                 if (pi.PlayerId == playerInfo.PlayerId)
                 {
                     pi.ControllingPlayerId = 0;
                 }
             }
             LobbyPlayerInfo playerInfoClone = playerInfo.Clone();
             playerInfoClone.ControllingPlayerId = 0;
             //Log.Print(LogType.Debug, $"Sending notification to {Players[i]}");
             GameInfoNotification gameInfoNotification = new GameInfoNotification()
             {
                 GameInfo   = GameInfo,
                 PlayerInfo = playerInfoClone,
                 TeamInfo   = teamInfoClone
             };
             _ = player.SendMessage(gameInfoNotification);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a GameManager instance which holds each match. Called from the lobby queue
        /// </summary>
        /// <param name="gameInfo">Match configuration</param>
        /// <param name="teamInfo">players information (players + bots)</param>
        public static void CreateGameManager(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo, List <long> PlayerSessionTokens)
        {
            if (string.IsNullOrEmpty(gameInfo.GameConfig.RoomName))
            {
                throw new EmptyRoomNameGameServerException();
            }
            try
            {
                EvosServer server = new EvosServer();
                server.Setup(gameInfo, teamInfo);
                ActiveServers.Add(gameInfo.GameConfig.RoomName, server);
                foreach (long sessionToken in PlayerSessionTokens)
                {
                    ServersByPlayerSessionToken.Add(sessionToken, server);
                }

                server.OnStop += HandleOnServerStop;

                Log.Print(LogType.Debug, "Game Server Launched with name " + gameInfo.GameConfig.RoomName);
            }
            catch (System.Exception e)
            {
                throw new EvosException("Error Creating Game Manager", e);
            }
        }
Esempio n. 3
0
        private void Ws_OnMessage(object sender, MessageEventArgs e)
        {
            MemoryStream      stream = new MemoryStream(e.RawData);
            BridgeMessageType messageType;
            string            data;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
            {
                messageType = (BridgeMessageType)reader.Read();
                data        = reader.ReadToEnd();
            }

            switch (messageType)
            {
            case BridgeMessageType.SetLobbyGameInfo:
                LobbyGameInfo gameInfo = JsonConvert.DeserializeObject <LobbyGameInfo>(data);
                Artemis.ArtemisServer.SetGameInfo(gameInfo);
                break;

            case BridgeMessageType.SetTeamInfo:
                LobbyTeamInfo teamInfo = JsonConvert.DeserializeObject <LobbyTeamInfo>(data);
                Artemis.ArtemisServer.SetTeamInfo(teamInfo);
                break;

            case BridgeMessageType.Start:
                Artemis.ArtemisServer.StartGame();
                break;

            default:
                Log.Error("Received unhandled ws message type: " + messageType.ToString());
                break;
            }
        }
Esempio n. 4
0
        public void Setup(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
        {
            GameInfo = gameInfo;
            TeamInfo = teamInfo;

            foreach (LobbyPlayerInfo playerInfo in teamInfo.TeamPlayerInfo)
            {
                CreateActor(playerInfo);
            }
        }
Esempio n. 5
0
        public void StartGame(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
        {
            GameInfo   = gameInfo;
            TeamInfo   = teamInfo;
            GameStatus = GameStatus.Assembling;

            SendGameInfo();
            SendTeamInfo();
            SendStartNotification();
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a new game and puts all players in the pending games queue
        /// </summary>
        /// <param name="gameInfo"></param>
        /// <param name="teamInfo"></param>
        public static void CreateGame(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
        {
            Log.Print(LogType.Debug, "Creating Game for playes:");
            foreach (var a in teamInfo.TeamPlayerInfo)
            {
                Log.Print(LogType.Debug, $"   player {a.Handle} in team {a.TeamId.ToString()}");
            }


            gameInfo.GameStatus = GameStatus.Assembling;
            LobbyQueueManager.GetInstance().PendingGames.Add(new PendingGame(gameInfo, teamInfo));
        }
Esempio n. 7
0
 public PendingGame(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
 {
     GameInfo            = gameInfo;
     TeamInfo            = teamInfo;
     PlayerSessionTokens = new List <long>();
     foreach (LobbyPlayerInfo playerInfo in TeamInfo.TeamPlayerInfo)
     {
         if (!playerInfo.IsNPCBot)
         {
             LobbyServerConnection player = LobbyServer.GetPlayerByAccountId(playerInfo.AccountId);
             PlayerSessionTokens.Add(player.SessionToken);
         }
     }
 }
Esempio n. 8
0
        public static string GetServer(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
        {
            lock (ServerPool)
            {
                foreach (BridgeServerProtocol server in ServerPool.Values)
                {
                    if (server.IsAvailable())
                    {
                        server.StartGame(gameInfo, teamInfo);

                        return(server.Address + ":" + server.Port);
                    }
                }
            }

            return(null);
        }
Esempio n. 9
0
        private bool FillTeam(Team team, TeamCompositionRules compositionRules, int maxPlayers, int maxBots, ref List <LobbyServerConnection> availablePlayers, ref LobbyTeamInfo teamInfo)
        {
            Log.Print(LogType.Debug, $"Filling Team {team.ToString()}");
            int usedPlayers = 0;
            int usedBots    = 0;

            List <LobbyPlayerInfo> playerInfo = new List <LobbyPlayerInfo>();

            for (int slot = 1; slot <= 5; slot++)
            {
                //Log.Print(LogType.Debug, "fillteam:: slot "+slot);
                FreelancerSet botSet = new FreelancerSet()
                {
                    Roles = new List <CharacterRole>(), Types = new List <CharacterType>()
                };
                bool filled = false;

                if (usedPlayers != maxPlayers)
                {
                    foreach (LobbyServerConnection player in availablePlayers)
                    {
                        bool matchedAny = false;
                        bool matched    = true;

                        //Log.Print(LogType.Debug, "matching rules with " + player.UserName);

                        foreach (TeamCompositionRules.SlotTypes slotType in compositionRules.Rules.Keys)
                        {
                            if (compositionRules.MatchesSlotType(slotType, team, slot))
                            {
                                matchedAny = true;
                                //Log.Print(LogType.Debug, "Matched slotType " + slotType.ToString());

                                /*if (!CharacterUtils.MatchesCharacter(player.PlayerInfo.GetCharacterType(), compositionRules.Rules[slotType]))
                                 * {
                                 *  //Log.Print(LogType.Debug, "not matched rule");
                                 *  matched = false;
                                 *
                                 *  if (usedBots == maxBots)
                                 *  {
                                 *      break;
                                 *  }
                                 *  else
                                 *  {
                                 *      FreelancerSet tempSet = compositionRules.Rules[slotType];
                                 *      if (tempSet.Roles != null)
                                 *          botSet.Roles.AddRange(tempSet.Roles);
                                 *      if (tempSet.Types != null)
                                 *          botSet.Types.AddRange(tempSet.Types);
                                 *  }
                                 * }*/
                            }
                        }

                        if (matchedAny && matched)
                        {
                            //Log.Print(LogType.Debug, "Adding player");
                            LobbyPlayerInfo info = player.GetLobbyPlayerInfo().Clone();
                            info.TeamId = team;
                            playerInfo.Add(info);

                            filled = true;
                            usedPlayers++;
                            availablePlayers.Remove(player);
                            break;
                        }
                    }
                }

                if (!filled)
                {
                    // try fill with bots
                    if (usedBots != maxBots) // Bots remaining to fill
                    {
                        // create bot
                        //Log.Print(LogType.Debug, "creating bot");
                        LobbyPlayerInfo botInfo = CharacterUtils.CreateBotCharacterFromFreelancerSet(botSet);
                        botInfo.TeamId = team;
                        playerInfo.Add(botInfo);
                        usedBots++;
                    }
                }
            }

            //Log.Print(LogType.Debug, "For finished");

            if (usedPlayers != maxPlayers)
            {
                //Log.Print(LogType.Debug, "Bot overflow");
                QueueInfo.QueueStatus = QueueStatus.QueueDoesntHaveEnoughHumans;
                return(false);
            }

            //Log.Print(LogType.Debug, "Filling team info");
            foreach (LobbyPlayerInfo playerinfo in playerInfo)
            {
                teamInfo.TeamPlayerInfo.Add(playerinfo);
            }
            //Log.Print(LogType.Debug, "TeamFilled!");

            return(true);
        }
Esempio n. 10
0
        private void MakeMatchSubType(GameSubType subType)
        {
            TeamCompositionRules         composition      = subType.TeamComposition;
            List <LobbyServerConnection> availablePlayers = new List <LobbyServerConnection>(Players);
            LobbyTeamInfo teamInfo = new LobbyTeamInfo()
            {
                TeamPlayerInfo = new List <LobbyPlayerInfo>()
            };

            if (
                FillTeam(Team.TeamA, composition, subType.TeamAPlayers, subType.TeamABots, ref availablePlayers, ref teamInfo) &&
                FillTeam(Team.TeamB, composition, subType.TeamBPlayers, subType.TeamBBots, ref availablePlayers, ref teamInfo)
                )
            {
                for (int i = 0; i < teamInfo.TeamPlayerInfo.Count; i++)
                {
                    teamInfo.TeamPlayerInfo[i].PlayerId            = i + 1;
                    teamInfo.TeamPlayerInfo[i].ControllingPlayerId = i + 1; // must be non-zero for players because 0 has a special use

                    if (!teamInfo.TeamPlayerInfo[i].IsNPCBot)
                    {
                    }
                }

                LobbyGameConfig gameConfig = QueueInfo.GameConfig.Clone();
                gameConfig.RoomName = GenerateRoomName();
                gameConfig.Map      = subType.GameMapConfigs[new Random().Next(0, subType.GameMapConfigs.Count - 1)].Map;

                LobbyGameInfo gameInfo = new LobbyGameInfo()
                {
                    GameConfig            = gameConfig,
                    AcceptedPlayers       = teamInfo.TotalPlayerCount,
                    ActiveSpectators      = 0,
                    AcceptTimeout         = TimeSpan.FromSeconds(30),
                    CreateTimestamp       = DateTime.Now.Ticks,
                    GameResult            = GameResult.NoResult,
                    GameServerAddress     = "ws://127.0.0.1:6061",
                    GameStatus            = GameStatus.Launched,
                    GameServerHost        = gameConfig.RoomName,
                    GameServerProcessCode = null,
                    LoadoutSelectTimeout  = EvoSGameConfig.LoadoutSelectTimeout,
                    IsActive = true,
                    LoadoutSelectionStartTimestamp = DateTime.Now.Ticks,
                    SelectionStartTimestamp        = DateTime.Now.Ticks,
                    SelectedBotSkillTeamA          = BotDifficulty.Medium,
                    SelectedBotSkillTeamB          = BotDifficulty.Medium,
                    SelectionSubPhase = FreelancerResolutionPhaseSubType.UNDEFINED,
                    SelectionSubPhaseStartTimestamp = DateTime.Now.Ticks,
                    SelectTimeout   = TimeSpan.FromSeconds(20),
                    UpdateTimestamp = DateTime.Now.Ticks
                };

                if (GameType == GameType.Practice)
                {
                    gameInfo.AcceptTimeout = TimeSpan.Zero;
                }

                Log.Print(LogType.Debug, "Removing players from queue...");
                foreach (LobbyPlayerInfo player in teamInfo.TeamPlayerInfo)
                {
                    if (!player.IsNPCBot)
                    {
                        //Log.Print(LogType.Debug, $"found player {player.Handle}");
                        for (int i = 0; i < Players.Count; i++)
                        {
                            /*if (Players[i].PlayerInfo.GetAccountId() == player.AccountId)
                             * {
                             *  RemovePlayer(Players[i]);
                             *  break;
                             * }*/
                        }
                    }
                }
                try
                {
                    LobbyQueueManager.CreateGame(gameInfo, teamInfo);
                }
                catch (Exception)
                {
                    throw new EvosException("Error on LobbyQueueManager.CreateGame");
                }
            }
        }
Esempio n. 11
0
 public void SetTeamInfo(LobbyTeamInfo teamInfo)
 {
     TeamInfo = teamInfo; SetTeamPlayerInfo(teamInfo.TeamPlayerInfo);
 }
Esempio n. 12
0
        public static void StartPractice(LobbyServerProtocolBase client)
        {
            LobbyGameInfo practiceGameInfo = new LobbyGameInfo
            {
                AcceptedPlayers    = 1,
                AcceptTimeout      = new TimeSpan(0, 0, 0),
                ActiveHumanPlayers = 1,
                ActivePlayers      = 1,
                CreateTimestamp    = DateTime.Now.Ticks,
                GameConfig         = new LobbyGameConfig
                {
                    GameOptionFlags        = GameOptionFlag.NoInputIdleDisconnect & GameOptionFlag.NoInputIdleDisconnect,
                    GameServerShutdownTime = -1,
                    GameType           = GameType.Practice,
                    InstanceSubTypeBit = 1,
                    IsActive           = true,
                    Map = Maps.VR_Practice,
                    ResolveTimeoutLimit = 1600, // TODO ?
                    RoomName            = "",
                    Spectators          = 0,
                    SubTypes            = GameModeManager.GetGameTypeAvailabilities()[GameType.Practice].SubTypes,
                    TeamABots           = 0,
                    TeamAPlayers        = 1,
                    TeamBBots           = 2,
                    TeamBPlayers        = 0
                }
            };

            LobbyTeamInfo teamInfo = new LobbyTeamInfo();

            teamInfo.TeamPlayerInfo = new List <LobbyPlayerInfo>
            {
                SessionManager.GetPlayerInfo(client.AccountId),
                CharacterManager.GetPunchingDummyPlayerInfo(),
                CharacterManager.GetPunchingDummyPlayerInfo()
            };
            teamInfo.TeamPlayerInfo[0].TeamId   = Team.TeamA;
            teamInfo.TeamPlayerInfo[0].PlayerId = 1;
            teamInfo.TeamPlayerInfo[1].PlayerId = 2;
            teamInfo.TeamPlayerInfo[2].PlayerId = 3;

            string serverAddress = ServerManager.GetServer(practiceGameInfo, teamInfo);

            if (serverAddress == null)
            {
                Log.Print(LogType.Error, "No available server for practice gamemode");
            }
            else
            {
                practiceGameInfo.GameServerAddress = "ws://" + serverAddress;
                practiceGameInfo.GameStatus        = GameStatus.Launching;

                GameAssignmentNotification notification1 = new GameAssignmentNotification
                {
                    GameInfo          = practiceGameInfo,
                    GameResult        = GameResult.NoResult,
                    Observer          = false,
                    PlayerInfo        = teamInfo.TeamPlayerInfo[0],
                    Reconnection      = false,
                    GameplayOverrides = client.GetGameplayOverrides()
                };

                client.Send(notification1);

                practiceGameInfo.GameStatus = GameStatus.Launched;
                GameInfoNotification notification2 = new GameInfoNotification()
                {
                    TeamInfo   = teamInfo,
                    GameInfo   = practiceGameInfo,
                    PlayerInfo = teamInfo.TeamPlayerInfo[0]
                };

                client.Send(notification2);
            }
        }
Esempio n. 13
0
 public static void SetTeamInfo(LobbyTeamInfo teamInfo)
 {
     instance.TeamInfo = teamInfo;
     Log.Info("Setting Team Info");
 }