Ejemplo n.º 1
0
        public void Activate()
        {
            if (Dependencies.RemoteGameServer != null && Dependencies.RemoteGameServer.IsConnected)
            {
                return;
            }

            if (m_gState == null)
            {
                m_gState = Dependencies.State;
            }
            if (m_job == null)
            {
                m_job = Dependencies.Job;
            }
            //m_persistentDataPath = Application.persistentDataPath;
            m_persistentDataPath = Application.streamingAssetsPath;

            m_loggedInPlayers = m_gState.GetValue <HashSet <Guid> >("LocalGameServer.m_loggedInPlayers");
            if (m_loggedInPlayers == null)
            {
                m_loggedInPlayers = new HashSet <Guid>();
            }

            m_room = m_gState.GetValue <Room>("LocalGameServer.m_room");
            if (m_room == null)
            {
                m_room         = new Room();
                m_room.Players = new List <Guid>();
                m_room.MapInfo = new MapInfo
                {
                    Name           = "Default",
                    MaxPlayers     = GameConstants.MaxPlayers,
                    SupportedModes = GameMode.All
                };
            }

            m_players = m_gState.GetValue <Dictionary <Guid, Player> >("LocalGameServer.m_players");
            if (m_players == null)
            {
                m_players = new Dictionary <Guid, Player>();
            }

            if (!m_players.ContainsKey(m_neutralPlayer.Id))
            {
                m_players.Add(m_neutralPlayer.Id, m_neutralPlayer);
            }

            if (!m_room.Players.Contains(m_neutralPlayer.Id))
            {
                m_room.Players.Insert(0, m_neutralPlayer.Id);
            }

            m_abilities = new Dictionary <Guid, VoxelAbilities[]>();
            m_tasks     = new Dictionary <Guid, SerializedTask[]>();
            m_serializedTaskTemplates = new Dictionary <Guid, SerializedNamedTaskLaunchInfo[]>();
            for (int i = 0; i < m_room.Players.Count; ++i)
            {
                m_abilities.Add(m_room.Players[i], CreateDefaultAbilities());
                m_tasks.Add(m_room.Players[i], CreateDefaultTaskTemplates());
                m_serializedTaskTemplates.Add(m_room.Players[i], CreateDefaultTaskTemplateData());
            }

            Guid[] clientIds = new[] { Guid.Empty };
            m_pingTimer = new PingTimer(clientIds, 3);

            ReplayData replay = m_gState.GetValue <ReplayData>("LocalGameServer.m_replay");

            if (replay != null)
            {
                m_replay = MatchFactory.CreateReplayPlayer();
                m_replay.Load(replay);
            }
            Connect();
        }
Ejemplo n.º 2
0
        public MatchServerImpl(ITimeService timeService, string persistentDataPath, Guid creatorClientId, Room room, Guid[] clientIds, Player[] players, ReplayData replay)
        {
            m_serializer = new ProtobufSerializer();

            m_time = timeService;
            m_persistentDataPath = persistentDataPath;
            m_room = room;
            m_room.CreatorClientId = creatorClientId;

            m_registeredClients            = new HashSet <Guid>();
            m_readyToPlayClients           = new HashSet <Guid>();
            m_readyToBeUnregisteredClients = new List <DisconnectedClient>();
            m_clientIdToPlayers            = new Dictionary <Guid, Dictionary <Guid, Player> >();
            m_playerToClientId             = new Dictionary <Guid, Guid>();
            m_clientIds = clientIds.ToList();
            for (int i = 0; i < m_clientIds.Count; ++i)
            {
                Guid clientId = m_clientIds[i];
                if (clientId != Guid.Empty)
                {
                    Dictionary <Guid, Player> idToPlayer;
                    if (!m_clientIdToPlayers.TryGetValue(clientId, out idToPlayer))
                    {
                        idToPlayer = new Dictionary <Guid, Player>();
                        m_clientIdToPlayers.Add(clientId, idToPlayer);
                    }
                    Player player = players[i];
                    idToPlayer.Add(player.Id, player);
                    m_playerToClientId.Add(player.Id, clientId);
                }
            }

            m_players = players.ToDictionary(p => p.Id);

            //Adding neutral player to room
            m_neutralPlayer         = new Player();
            m_neutralPlayer.BotType = BotType.Neutral;
            m_neutralPlayer.Name    = "Neutral";
            m_neutralPlayer.Id      = Guid.NewGuid();

            //Dictionary<Guid, Player> idToPlayer = new Dictionary<Guid, Player>();
            //idToPlayer.Add(m_neutralPlayer.Id, m_neutralPlayer);
            m_players.Add(m_neutralPlayer.Id, m_neutralPlayer);

            if (!m_room.Players.Contains(m_neutralPlayer.Id))
            {
                m_room.Players.Insert(0, m_neutralPlayer.Id);
                m_clientIds.Insert(0, Guid.Empty);
            }

            m_abilities         = new Dictionary <Guid, VoxelAbilities[]>();
            m_taskTemplates     = new Dictionary <Guid, SerializedTask[]>();
            m_taskTemplatesInfo = new Dictionary <Guid, SerializedNamedTaskLaunchInfo[]>();
            for (int i = 0; i < m_room.Players.Count; ++i)
            {
                m_abilities.Add(m_room.Players[i], CreateDefaultAbilities());
                m_taskTemplates.Add(m_room.Players[i], CreateDefaultTaskTemplates());
                m_taskTemplatesInfo.Add(m_room.Players[i], CreateDefaultTaskTemplateInfo());
            }

            m_pingTimer = new PingTimer(m_clientIdToPlayers.Keys.ToArray(), 3);

            if (replay != null)
            {
                m_replay = MatchFactory.CreateReplayPlayer();
                m_replay.Load(replay);
            }
        }