private void JoinGame(JoinGameAction joinGameAction) { lock (threadSync) { ServerGame game = (from g in _Games where g.Game.ID == joinGameAction.GameID select g).Single(); game.Game.Spectators.Add(_CurrentPerson); } GameJoinedAction gameJoined = new GameJoinedAction() { DateTime = DateTime.Now, GameID = joinGameAction.GameID, Sender = joinGameAction.Sender }; BroadcastMessage(gameJoined, null); }
private void TryJoinGame(JoinGameAction action) { ServerGame gameToFind = null; foreach (ServerGame game in _Games) { if (game.ID == action.GameID) { gameToFind = game; break; } } // whoops, user send a wrong ID or game is removed // notify the user the game is lost into oblivion if (gameToFind == null) { string message = "The game you where trying to join was not found on the server"; MessageFromServerAction messageBack = new MessageFromServerAction(); messageBack.Message = message; messageBack.Sender = _ServerUser; Whisper(action.Sender.Name, messageBack); return; } //game full, notify user if (gameToFind != null) { if (gameToFind.Users.Count == gameToFind.Settings.MaxPlayers) { string message = "The game you where trying to join is already full"; MessageFromServerAction messageBack = new MessageFromServerAction(); messageBack.Message = message; messageBack.Sender = _ServerUser; Whisper(action.Sender.Name, messageBack); return; } if (gameToFind.Users.Count < gameToFind.Settings.MaxPlayers) { gameToFind.Users.Add(action.Sender); GameJoinedAction gameJoinedAction = new GameJoinedAction(); gameJoinedAction.GameID = action.GameID; gameJoinedAction.Player = action.Sender; gameJoinedAction.Sender = _ServerUser; BroadcastMessage(gameJoinedAction, null); } } }