示例#1
0
        public void ProposeGameWithUsers(Connection source, List<string> players, GameSpecificationInfo gameSpecification, Lobby lobby)
        {
            List<Connection> gameConnections = new List<Connection>();
            lock (this.serverLock)
            {
                foreach (string target in players)
                {
                    User user = lobby.Users.FirstOrDefault(u => u.Name == target);
                    if (user == null)
                    {
                        NetworkMessage message = new NetworkMessage();
                        message.MessageCategory = SystemMessages.SystemPrefix;
                        message.MessageType = SystemMessages.DeclineGame;
                        source.SendMessage(message);
                        return;
                    }
                    else
                    {
                        gameConnections.Add(user.Connection);
                    }
                }

                for (int i = 0; i < gameConnections.Count; i++)
                {
                    bool ok = gameConnections[i].TryProposeGame();
                    if (!ok)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            gameConnections[j].CancelGame();
                        }
                        return;
                    }
                }
            }
            Game game = new Game(gameConnections, this, lobby, gameSpecification);
            Thread thread = new Thread(new ThreadStart(game.NegotiateGame));
            thread.Start();
        }