Esempio n. 1
0
        private bool RepairTeams()
        {
            if (_players.Count < 2)
            {
                return(false);
            }
            ServerPlayerInfo firstSpi = null;

            foreach (IPlayerID pid in _players.Values)
            {
                firstSpi = (ServerPlayerInfo)pid;
                break;
            }
            int  id     = firstSpi.TeamID;
            bool change = true;

            foreach (ServerPlayerInfo spi in _players.Values)
            {
                if (spi.TeamID != id)
                {
                    change = false;
                    break;
                }
            }
            if (change)
            {
                ((ServerPlayerInfo)_players.Values.GetEnumerator().Current).TeamID = GetTeamForPlayer();
            }
            return(change);
        }
Esempio n. 2
0
        private PlayersMessage CreatePlayerMessage(MessageOperation operation, IPlayerID playerID)
        {
            List <PlayerInfo> list = new List <PlayerInfo>();
            PlayersMessage    msg  = (PlayersMessage)MessageFactory.Create(MessageType.Players);

            msg.Operation = (byte)operation;
            switch (operation)
            {
            case MessageOperation.List:
                foreach (IPlayerID pid in _players.Values)
                {
                    if (pid.GetID() != playerID.GetID())
                    {
                        ServerPlayerInfo spi = pid as ServerPlayerInfo;
                        list.Add(spi.GePlayerInfo());
                    }
                }
                break;

            case MessageOperation.Add:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;

            case MessageOperation.Remove:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;

            case MessageOperation.Modify:
                list.Add(((ServerPlayerInfo)playerID).GePlayerInfo());
                break;
            }
            msg.PlayerList = list;
            return(msg);
        }
Esempio n. 3
0
        protected override IPlayerID TransformInitialy(IPlayerID player)
        {
            Player           p         = player as Player;
            ServerPlayerInfo svp       = new ServerPlayerInfo(p);
            short            teamId    = 1;
            Color            baseColor = ServerPlayerInfo.StartColors[0];

            if (_players.Count > 0)
            {
                lock (((ICollection)_players).SyncRoot) {
                    teamId    = GetTeamForPlayer();
                    baseColor = GetColorForPlayer();
                }
            }
            svp.TeamID = teamId;
            svp.Color  = baseColor;
            return(svp);
        }
Esempio n. 4
0
        public void ModifyPlayer(short id, PlayerInfo pi)
        {
            PlayersMessage pmsg;

            lock (((ICollection)_players).SyncRoot) {
                CancelGameStart();
                ServerPlayerInfo spi = _players[id] as ServerPlayerInfo;
                spi.House = pi.House;
                if (IsTeamModificationValid(pi.TeamID, id))
                {
                    spi.TeamID = pi.TeamID;
                }
                if (IsColorModificationValid(pi.Color, id))
                {
                    spi.Color = pi.Color;
                }
                pmsg = CreatePlayerMessage(MessageOperation.Modify, spi);
            }
            BroadcastExcl(pmsg, -1);
        }