Beispiel #1
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;
            }
        }
Beispiel #2
0
        public static void CreateMatch(LobbyGameInfo gameInfo, LobbyServerTeamInfo teamInfo)
        {
            var game = new GameManager();

            // TODO setup GameManager instance
            game.SetTeamInfo(teamInfo);
            game.SetGameInfo(new LobbyGameInfo
            {
                GameConfig = new LobbyGameConfig
                {
                    Map = "VR_Practice"
                          // Map = "CargoShip_Deathmatch"
                          // Map = "Casino01_Deathmatch"
                          // Map = "EvosLab_Deathmatch"
                          // Map = "Oblivion_Deathmatch"
                          // Map = "Reactor_Deathmatch"
                          // Map = "RobotFactory_Deathmatch"
                          // Map = "Skyway_Deathmatch"
                }
            });
            game.LaunchGame();

            foreach (var playerInfo in teamInfo.TeamAPlayerInfo.Union(teamInfo.TeamPlayerInfo))
            {
                _gameManagers.Add(playerInfo.AccountId.ToString(), game);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void Setup(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo)
        {
            GameInfo = gameInfo;
            TeamInfo = teamInfo;

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

            SendGameInfo();
            SendTeamInfo();
            SendStartNotification();
        }
Beispiel #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));
        }
Beispiel #7
0
        public void Reset()
        {
            GameInfo              = new LobbyGameInfo();
            TeamInfo              = new LobbyServerTeamInfo();
            m_gameplayOverrides   = new LobbyGameplayOverrides();
            m_gameStatus          = GameStatus.Stopped;
            QueueInfo             = null;
            ForbiddenDevKnowledge = null;
//            if (!((UnityEngine.Object) GameWideData.Get() != (UnityEngine.Object) null))
//                return;
//            this.GameplayOverrides.SetBaseCharacterConfigs(GameWideData.Get());
        }
Beispiel #8
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);
         }
     }
 }
Beispiel #9
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);
        }
Beispiel #10
0
        public LobbyGameInfo CreateGameInfo()
        {
            GameTypeAvailability gameAvailability = Gamemode.GameModeManager.GetGameTypeAvailabilities()[GameType];

            LobbyGameInfo gameInfo = new LobbyGameInfo
            {
                AcceptedPlayers    = gameAvailability.TeamAPlayers + gameAvailability.TeamBPlayers,
                AcceptTimeout      = GameType == GameType.Practice ? TimeSpan.FromSeconds(0) : TimeSpan.FromSeconds(5),
                ActiveHumanPlayers = 0,
                ActivePlayers      = 0,
                ActiveSpectators   = 0,
                CreateTimestamp    = DateTime.Now.Ticks,
                GameConfig         = new LobbyGameConfig
                {
                    GameOptionFlags     = GameOptionFlag.AllowDuplicateCharacters & GameOptionFlag.EnableTeamAIOutput & GameOptionFlag.NoInputIdleDisconnect,
                    GameType            = GameType,
                    IsActive            = true,
                    RoomName            = $"Evos-{GameType.ToString()}-{GameID++}",
                    SubTypes            = gameAvailability.SubTypes,
                    TeamAPlayers        = gameAvailability.TeamAPlayers,
                    TeamABots           = gameAvailability.TeamABots,
                    TeamBPlayers        = gameAvailability.TeamBPlayers,
                    TeamBBots           = gameAvailability.TeamBBots,
                    Map                 = SelectMap(gameAvailability),
                    ResolveTimeoutLimit = 1600,
                    Spectators          = 0
                },
                GameResult           = GameResult.NoResult,
                GameServerAddress    = "",
                GameStatus           = GameStatus.Assembling,
                GameServerHost       = "",
                IsActive             = true,
                LoadoutSelectTimeout = GameType == GameType.Practice ? TimeSpan.FromSeconds(0) : TimeSpan.FromSeconds(5),
                SelectTimeout        = GameType == GameType.Practice ? TimeSpan.FromSeconds(0) : TimeSpan.FromSeconds(5),
                // TODO: there are more options that may be usefull
            };

            return(gameInfo);
        }
Beispiel #11
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");
                }
            }
        }
Beispiel #12
0
 public void SetGameInfo(LobbyGameInfo gameInfo)
 {
     GameInfo = gameInfo;
 }
Beispiel #13
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);
            }
        }
Beispiel #14
0
 public static void SetGameInfo(LobbyGameInfo gameInfo)
 {
     instance.GameInfo = gameInfo;
     Log.Info("Setting Game Info");
 }