Beispiel #1
0
        private void TryJoinGame(JoinGameAction joinGame)
        {
            // check if the game ID is a game which is not started yet

            // player canot be already in another game
            IEnumerable<ServerGame> games = from g in _Games
                                            where (from s in g.Spectators
                                                   where s.ID == joinGame.Sender
                                                   select s).Count() > 0
                                            select g;
            if (games.Count() > 0)
            {
                SayError(joinGame.Sender, "You are already in another game");
                return;
            }

            JoinGame(joinGame);
        }
Beispiel #2
0
 private void btnJoinGame_Click(object sender, RoutedEventArgs e)
 {
     JoinGameAction action = new JoinGameAction();
     action.Sender = Core.Instance.CurrentPlayer.ID;
     action.GameID = _SelectedGame.ID;
     Server.Instance.Proxy.Say(action);
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
                }
            }
        }