Beispiel #1
0
        private void OnLobbyUpdated(ClientDataEventArgs <ILobbyData> args)
        {
            var lobbyData = args.Value;

            if (lobbyData == null)
            {
                OptionsPanel.IsEnabled = false;
                StartButton.IsEnabled  = false;
                return;
            }

            StartButton.IsEnabled  = AppContext.IsGameHost;
            OptionsPanel.IsEnabled = AppContext.IsGameHost && !lobbyData.GameOptions.IsFrozen;
            OptionsPanel.Options   = lobbyData.GameOptions;

            if (PlayerInfoPanel.Children.Count == 0)
            {
                CreateSlots(lobbyData);
            }

            //GameLog.Print("GameContext.Current.IsMultiplayerGame={0}", GameContext.Current.IsMultiplayerGame    IffffsMultiplayerGame.ToString());
            if (AppContext.IsSinglePlayerGame)
            {
                return;
            }

            UpdateSlots(lobbyData);
        }
Beispiel #2
0
 private void OnClientDisconnected(ClientDataEventArgs <ClientDisconnectReason> obj)
 {
     if (_isClosing)
     {
         _exitInProgress = true;
     }
 }
Beispiel #3
0
        private void OnPlayerExited(ClientDataEventArgs <IPlayer> args)
        {
            var player = args.Value;

            if (!_appContext.IsGameInPlay)
            {
                return;
            }

            if (Equals(player, _appContext.LocalPlayer))
            {
                return;
            }

            var remainingPlayers = _appContext.RemotePlayers.Where(o => !Equals(o, player));

            if (!remainingPlayers.Any())
            {
                var result = MessageDialog.Show(
                    _resourceManager.GetString("PLAYER_EXITED_MESSAGE_HEADER"),
                    _resourceManager.GetStringFormat("LAST_PLAYER_EXITED_MESSAGE_CONTENT", player.Name),
                    MessageDialogButtons.YesNo);
                if (result == MessageDialogResult.No)
                {
                    EndGame(false);
                }
            }
            else
            {
                MessageDialog.Show(
                    _resourceManager.GetString("PLAYER_EXITED_MESSAGE_HEADER"),
                    _resourceManager.GetStringFormat("PLAYER_EXITED_MESSAGE_CONTENT", player.Name),
                    MessageDialogButtons.Ok);
            }
        }
Beispiel #4
0
 public static void Route(ClientDataEventArgs e)
 {
     var stream = CodedInputStream.CreateInstance(e.Data.ToArray());
     while (!stream.IsAtEnd)
     {
         Identify(e.Client, stream);
     }
 }
Beispiel #5
0
 private void OnGameUpdateDataReceived(ClientDataEventArgs <GameUpdateData> args)
 {
     _accessLock.EnterWriteLock();
     try
     {
         args.Value.UpdateLocalGame((GameContext)_currentGame);
     }
     finally
     {
         _accessLock.ExitWriteLock();
     }
     OnPropertyChanged("LocalPlayerEmpire");
 }
Beispiel #6
0
        private void OnChatMessageReceived(ClientDataEventArgs <ChatMessage> e)
        {
            if (e.Value == null || !_appContext.IsGameInPlay)
            {
                return;
            }

            if (ReferenceEquals(e.Value.Sender, _appContext.LocalPlayer))
            {
                return;
            }

            _soundPlayer.PlayFile("Resources/SoundFX/ChatMessage.ogg");
        }
Beispiel #7
0
        public static void Route(ClientDataEventArgs e)
        {            
            var buffer = e.Data.ToArray();
            // handle data as a stream -- a single packet can contain multiple messages
            while (buffer.Length > 0)
            {
                var bytesConsumed = Identify(e.Client, buffer);
                if (bytesConsumed <= 0)
                    return;

                var bytesLeft=buffer.Length - bytesConsumed;
                var tmp = new byte[bytesLeft];
                Array.Copy(buffer, bytesConsumed, tmp, 0, bytesLeft);
                buffer = tmp;
            }
        }
Beispiel #8
0
        public static void Route(ClientDataEventArgs e)
        {
            var buffer = e.Data.ToArray();

            // handle data as a stream -- a single packet can contain multiple messages
            while (buffer.Length > 0)
            {
                var bytesConsumed = Identify(e.Client, buffer);
                if (bytesConsumed <= 0)
                {
                    return;
                }

                var bytesLeft = buffer.Length - bytesConsumed;
                var tmp       = new byte[bytesLeft];
                Array.Copy(buffer, bytesConsumed, tmp, 0, bytesLeft);
                buffer = tmp;
            }
        }
Beispiel #9
0
 private void OnGameStarted(ClientDataEventArgs <GameStartData> args)
 {
     _accessLock.EnterWriteLock();
     try
     {
         _currentGame = args.Value.CreateLocalGame();
         _dispatcher.Invoke(
             (Action <GameContext>)GameContext.PushThreadContext,
             DispatcherPriority.Send,
             _currentGame);
         _isGameInPlay = true;
     }
     finally
     {
         _accessLock.ExitWriteLock();
     }
     OnPropertyChanged("CurrentGame");
     OnPropertyChanged("IsGameInPlay");
     OnPropertyChanged("LocalPlayerEmpire");
 }
Beispiel #10
0
        private void OnGameStarted(ClientDataEventArgs <GameStartData> obj)
        {
            UpdateCommands();

            if (_appContext.IsGameInPlay)
            {
                if (_appContext.LocalPlayer.Empire.Key == "FEDERATION")
                {
                    LoadTheme("Federation");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "ROMULANS")
                {
                    LoadTheme("Romulans");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "KLINGONS")
                {
                    LoadTheme("Klingons");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "CARDASSIANS")
                {
                    LoadTheme("Cardassians");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "DOMINION")
                {
                    LoadTheme("Dominion");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "BORG")
                {
                    LoadTheme("Borg");
                }
                else if (_appContext.LocalPlayer.Empire.Key == "TERRANEMPIRE")
                {
                    LoadTheme("TerranEmpire");
                }
                else
                {
                    LoadDefaultTheme();
                }
            }
        }
Beispiel #11
0
 /// <summary>Метод вызова события "при передаче данных"</summary>
 protected virtual void InvokeDataSendEvent(ClientDataEventArgs e) => DataSent?.Invoke(this, e);
Beispiel #12
0
 /// <summary>Метод вызова события "при получении данных"</summary>
 protected virtual void OnDataReceived(ClientDataEventArgs e) => DataReceived?.Invoke(this, e);
Beispiel #13
0
 private void OnChatMessageReceived(ClientDataEventArgs <ChatMessage> arg)
 {
     PushChatMessage(arg.Value);
 }
Beispiel #14
0
 private void OnGameStarted(ClientDataEventArgs <GameStartData> obj)
 {
     ContextMenu = new GameContextMenu {
         CustomPopupPlacementCallback = ContextMenuPlacementCallback
     };
 }