public void PlayGame(Game g) { lock (this.statusLock) { this.game = g; Debug.Assert(this.game == g && this.Status == ConnectionStatus.RespondingToGameProposal); this.Status = ConnectionStatus.PlayingGame; } }
public void EndGame() { lock (this.statusLock) { this.game = null; Debug.Assert(this.Status == ConnectionStatus.PlayingGame); this.Status = ConnectionStatus.Ready; } }
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(); }