예제 #1
0
 public SpawnOccupant(GameInformation.Player player)
 {
     Color      = player.Color;
     PlayerName = player.Name;
     Team       = player.Team;
     Faction    = player.FactionId;
     SpawnPoint = player.SpawnPoint;
 }
예제 #2
0
 public SpawnOccupant(GameInformation.Player player)
 {
     Color       = player.Color;
     ClientIndex = player.ClientIndex;
     PlayerName  = player.Name;
     Team        = player.Team;
     Country     = player.FactionId;
     SpawnPoint  = player.SpawnPoint;
 }
예제 #3
0
        /// <summary>
        /// Returns a list of GameInformation.Players that matches the indexing of ICreatePlayers.CreatePlayers.
        /// Non-playable players appear as null in the list.
        /// </summary>
        void ICreatePlayersInfo.CreateServerPlayers(MapPreview map, Session lobbyInfo, List <GameInformation.Player> players, MersenneTwister playerRandom)
        {
            var worldInfo            = map.Rules.Actors[SystemActors.World];
            var factions             = worldInfo.TraitInfos <FactionInfo>().ToArray();
            var assignSpawnLocations = worldInfo.TraitInfoOrDefault <IAssignSpawnPointsInfo>();
            var spawnState           = assignSpawnLocations?.InitializeState(map, lobbyInfo);

            // Create the unplayable map players -- neutral, shellmap, scripted, etc.
            foreach (var p in map.Players.Players.Where(p => !p.Value.Playable))
            {
                // We need to resolve the faction, even though we don't use it, to match the RNG state with clients
                Player.ResolveFaction(p.Value.Faction, factions, playerRandom, false);
                players.Add(null);
            }

            // Create the regular playable players.
            var bots = map.Rules.Actors[SystemActors.Player].TraitInfos <IBotInfo>().ToArray();

            foreach (var kv in lobbyInfo.Slots)
            {
                var client = lobbyInfo.ClientInSlot(kv.Key);
                if (client == null)
                {
                    continue;
                }

                var clientFaction      = factions.First(f => client.Faction == f.InternalName);
                var resolvedFaction    = Player.ResolveFaction(client.Faction, factions, playerRandom, !kv.Value.LockFaction);
                var resolvedSpawnPoint = assignSpawnLocations?.AssignSpawnPoint(spawnState, lobbyInfo, client, playerRandom) ?? 0;
                var player             = new GameInformation.Player
                {
                    ClientIndex        = client.Index,
                    Name               = Player.ResolvePlayerName(client, lobbyInfo.Clients, bots),
                    IsHuman            = client.Bot == null,
                    IsBot              = client.Bot != null,
                    FactionName        = resolvedFaction.Name,
                    FactionId          = resolvedFaction.InternalName,
                    DisplayFactionName = clientFaction.Name,
                    DisplayFactionId   = clientFaction.InternalName,
                    Color              = client.Color,
                    Team               = client.Team,
                    Handicap           = client.Handicap,
                    SpawnPoint         = resolvedSpawnPoint,
                    IsRandomFaction    = clientFaction.RandomFactionMembers.Any(),
                    IsRandomSpawnPoint = client.SpawnPoint == 0,
                    Fingerprint        = client.Fingerprint,
                };

                players.Add(player);
            }

            // Create a player that is allied with everyone for shared observer shroud.
            // We need to resolve the faction, even though we don't use it, to match the RNG state with clients
            Player.ResolveFaction("Random", factions, playerRandom, false);
            players.Add(null);
        }
예제 #4
0
        /// <summary>
        /// Returns a list of GameInformation.Players that matches the indexing of ICreatePlayers.CreatePlayers.
        /// Non-playable players appear as null in the list.
        /// </summary>
        void ICreatePlayersInfo.CreateServerPlayers(MapPreview map, Session lobbyInfo, List <GameInformation.Player> players)
        {
            // Create the unplayable map players -- neutral, shellmap, scripted, etc.
            foreach (var p in map.Players.Players.Where(p => !p.Value.Playable))
            {
                players.Add(null);
            }

            // Create the regular playable players.
            var factions = map.Rules.Actors["world"].TraitInfos <FactionInfo>().ToArray();
            var bots     = map.Rules.Actors["player"].TraitInfos <IBotInfo>().ToArray();

            foreach (var kv in lobbyInfo.Slots)
            {
                var client = lobbyInfo.ClientInSlot(kv.Key);
                if (client == null)
                {
                    continue;
                }

                var clientFaction = factions.First(f => client.Faction == f.InternalName);

                // TODO: Resolve random SpawnPoint and Faction to real values
                var player = new GameInformation.Player
                {
                    ClientIndex        = client.Index,
                    Name               = Player.ResolvePlayerName(client, lobbyInfo.Clients, bots),
                    IsHuman            = client.Bot == null,
                    IsBot              = client.Bot != null,
                    FactionName        = clientFaction.Name,
                    FactionId          = clientFaction.InternalName,
                    Color              = client.Color,
                    Team               = client.Team,
                    SpawnPoint         = client.SpawnPoint,
                    IsRandomFaction    = clientFaction.RandomFactionMembers.Any(),
                    IsRandomSpawnPoint = client.SpawnPoint == 0,
                    Fingerprint        = client.Fingerprint,
                };

                players.Add(player);
            }

            // Create a player that is allied with everyone for shared observer shroud.
            players.Add(null);
        }
예제 #5
0
        public void StartGame()
        {
            listener.Stop();

            Console.WriteLine("[{0}] Game started", DateTime.Now.ToString(Settings.TimestampFormat));

            // Drop any unvalidated clients
            foreach (var c in PreConns.ToArray())
            {
                DropClient(c);
            }

            // Drop any players who are not ready
            foreach (var c in Conns.Where(c => GetClient(c).IsInvalid).ToArray())
            {
                SendOrderTo(c, "ServerError", "You have been kicked from the server!");
                DropClient(c);
            }

            // HACK: Turn down the latency if there is only one real player
            if (LobbyInfo.NonBotClients.Count() == 1)
            {
                LobbyInfo.GlobalSettings.OrderLatency = 1;
            }

            SyncLobbyInfo();
            State = ServerState.GameStarted;

            // TODO Add to GameInformation
            List <GameInformation.Player> players = new List <GameInformation.Player>();

            foreach (var c in LobbyInfo.Clients)
            {
                var p = new GameInformation.Player();
                p.ClientIndex = c.Index;
                p.Name        = c.Name;
                p.IsHuman     = c.Bot == null;
                p.IsBot       = c.Bot != null;
                p.FactionName = c.Faction;
                // p.FactionId = -1;
                p.Color      = c.Color;
                p.Team       = c.Team;
                p.SpawnPoint = c.SpawnPoint;
                // p.IsRandomFaction = c.;
                // p.IsRandomSpawnPoint = c.;
                // p.WinState Outcome;
                // p.DateTime OutcomeTimestampUtc;
                players.Add(p);
            }
            GameInfo.Players      = players;
            GameInfo.StartTimeUtc = DateTime.UtcNow;
            GameInfo.Mod          = ModData.Manifest.Id;
            GameInfo.Version      = ModData.Manifest.Metadata.Version;
            GameInfo.MapUid       = Map.Uid;
            GameInfo.MapTitle     = Map.Title;
            Recorder.Metadata     = new OpenRA.FileFormats.ReplayMetadata(GameInfo);

            foreach (var c in Conns)
            {
                foreach (var d in Conns)
                {
                    DispatchOrdersToClient(c, d.PlayerIndex, 0x7FFFFFFF, new byte[] { 0xBF });
                }
            }

            DispatchOrders(null, 0,
                           new ServerOrder("StartGame", "").Serialize());

            foreach (var t in serverTraits.WithInterface <IStartGame>())
            {
                t.GameStarted(this);
            }
        }