Exemplo n.º 1
0
        private void FSD_NetworkDisconnected(object sender, NetworkEventArgs e)
        {
            mPositionUpdateTimer.Stop();
            DisconnectInfo disconnectInfo = new DisconnectInfo
            {
                Type   = (mForcedDisconnect ? DisconnectType.Forcible : (mIntentialDisconnect ? DisconnectType.Intentional : DisconnectType.Other)),
                Reason = (mForcedDisconnect ? mKillReason : string.Empty)
            };

            NetworkDisconnected?.Invoke(this, new NetworkDisconnectedEventArgs(disconnectInfo));
            mIntentialDisconnect = false;
            mForcedDisconnect    = false;
            mIsIdenting          = false;
            mIsIdentPressed      = false;
            if (disconnectInfo.Type == DisconnectType.Forcible)
            {
                if (!string.IsNullOrEmpty(disconnectInfo.Reason))
                {
                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Warning, $"Forcibly disconnected from the network: { disconnectInfo.Reason }"));
                }
                else
                {
                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Warning, "Forcibly disconnected from the network."));
                }
                PlaySoundRequested?.Invoke(this, new PlaySoundEventArgs(SoundEvent.Error));
            }
            else
            {
                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Disconnected from the network."));
            }
        }
Exemplo n.º 2
0
 private void OnNotificationPosted()
 {
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs()
     {
         ShouldCauseWakeUp = true
     });
 }
Exemplo n.º 3
0
 private void FSD_NetworkConnected(object sender, NetworkEventArgs e)
 {
     mForcedDisconnect    = false;
     mIntentialDisconnect = false;
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, mConnectInfo.ObserverMode ? "Connected to network in observer mode" : "Connected to network"));
     NetworkConnected?.Invoke(this, new NetworkConnectedEventArgs(mConnectInfo));
 }
Exemplo n.º 4
0
 private void OnNotificationPosted(bool shouldCauseWakeup, OpenNotification sbn, bool updatesPreviousNotification)
 {
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs()
     {
         ShouldCauseWakeUp           = shouldCauseWakeup,
         OpenNotification            = sbn,
         UpdatesPreviousNotification = updatesPreviousNotification
     });
 }
Exemplo n.º 5
0
 private void FSD_ProtocolErrorReceived(object sender, DataReceivedEventArgs <PDUProtocolError> e)
 {
     if (e.PDU.ErrorType == NetworkError.NoFlightPlan)
     {
         NoFlightPlanReceived?.Invoke(this, EventArgs.Empty);
     }
     else
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Network error: { e.PDU.Message }"));
     }
 }
Exemplo n.º 6
0
 public void OnPlaySelcalRequested(object sender, EventArgs e)
 {
     try
     {
         PlaySelcal(mFsdManager.SelcalCode);
     }
     catch (Exception ex)
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Error playing SELCAL tone: {ex.Message}"));
     }
 }
Exemplo n.º 7
0
        private void XPilotVersionCheck()
        {
            NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Performing version check..."));

            try
            {
                var dto = new VersionCheckDto
                {
                    UserVersion = Application.ProductVersion.ToString(),
                    Channel     = mConfig.UpdateChannel.GetDescription()
                }.ToJSON();

                var client  = new RestClient(ROOT_URL);
                var request = new RestRequest(VERSION_CHECK_ENDPOINT, DataFormat.Json);
                request.Method = Method.POST;
                request.AddParameter("application/json", dto, ParameterType.RequestBody);
                var response = client.Execute(request).Content;

                var data = JsonConvert.DeserializeObject <VersionCheckResponse>(response);

                if (data != null)
                {
                    Version version = new Version(data.Version);
                    if (version > Assembly.GetExecutingAssembly().GetName().Version)
                    {
                        NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "A new version is available for download."));

                        using (var dlg = new UpdateForm())
                        {
                            dlg.NewVersion  = version.ToString();
                            dlg.DownloadUrl = data.VersionUrl;
                            dlg.ShowDialog();
                        }
                    }
                    else
                    {
                        NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Version check complete. You are running the latest version."));
                    }
                }
                else
                {
                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Version check complete. You are running the latest version."));
                }
            }
            catch (Exception ex)
            {
                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Error performing version check: {ex.Message}"));
            }
        }
Exemplo n.º 8
0
 private void AfvUserClient_Disconnected(object sender, DisconnectedEventArgs e)
 {
     if (e.Reason != "Intentional")
     {
         RaiseVoiceServerConnectionLost?.Invoke(this, EventArgs.Empty);
         PlaySoundRequested?.Invoke(this, new PlaySoundEventArgs(SoundEvent.Error));
         if (e.AutoReconnect)
         {
             NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Warning, $"Disconnected from voice server: { e.Reason }. Attempting to auto-reconnect..."));
         }
         else
         {
             NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Warning, $"Disconnected from voice server: { e.Reason }"));
         }
     }
 }
Exemplo n.º 9
0
        public async void OnNetworkDisconnected(object sender, NetworkDisconnectedEventArgs e)
        {
            if (mAfvUserClient.IsConnected)
            {
                try
                {
                    await mAfvUserClient.Disconnect("Intentional");

                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Disconnected from the voice server."));
                }
                catch (Exception ex)
                {
                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Error disconnecting from voice server: { ex.Message }"));
                }
            }
        }
Exemplo n.º 10
0
        public void ForceDisconnect(string reason = "")
        {
            if (IsConnected)
            {
                FSD.SendPDU(new PDUDeletePilot(OurCallsign, mConfig.VatsimId.Trim()));
                FSD.Disconnect();
            }
            DisconnectInfo disconnectInfo = new DisconnectInfo
            {
                Type   = DisconnectType.Quiet,
                Reason = reason
            };

            NetworkDisconnected?.Invoke(this, new NetworkDisconnectedEventArgs(disconnectInfo));
            NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Warning, disconnectInfo.Reason));
        }
Exemplo n.º 11
0
        private void AircraftTypeCodeUpdate()
        {
            try
            {
                var client   = new RestClient(ROOT_URL);
                var request  = new RestRequest(AIRCRAFT_DB_ENDPOINT, DataFormat.Json);
                var response = client.Execute(request).Content;
                var data     = JsonConvert.DeserializeObject <AircraftTypeCodes>(response);

                if (data != null)
                {
                    if (File.Exists(Path.Combine(mConfig.AppPath, "TypeCodes.json")))
                    {
                        var hash = FileChecksum.CalculateCheckSum(Path.Combine(mConfig.AppPath, "TypeCodes.json"));
                        if (hash != data.ChecksumHash)
                        {
                            using (WebClient wc = new WebClient())
                            {
                                var json = wc.DownloadString(data.TypeCodesUrl);
                                if (json != null)
                                {
                                    File.WriteAllText(Path.Combine(mConfig.AppPath, "TypeCodes.json"), json);
                                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Aircraft type code database updated."));
                                }
                            }
                        }
                    }
                    else
                    {
                        using (WebClient wc = new WebClient())
                        {
                            var json = wc.DownloadString(data.TypeCodesUrl);
                            if (json != null)
                            {
                                File.WriteAllText(Path.Combine(mConfig.AppPath, "TypeCodes.json"), json);
                                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Aircraft type code database updated."));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Error downloading aircraft type code database: {ex.Message}"));
            }
        }
Exemplo n.º 12
0
 private void StopClientConnection()
 {
     try
     {
         ComRadioTransmittingChanged?.Invoke(this, new ComRadioTxRxChangedEventArgs(1, false));
         ComRadioReceivingChanged?.Invoke(this, new ComRadioTxRxChangedEventArgs(1, false));
         ComRadioTransmittingChanged?.Invoke(this, new ComRadioTxRxChangedEventArgs(2, false));
         ComRadioReceivingChanged?.Invoke(this, new ComRadioTxRxChangedEventArgs(2, false));
         if (mAfvUserClient.Started)
         {
             mAfvUserClient.Stop();
         }
         mUpdateTransceiverTimer.Stop();
     }
     catch (Exception ex)
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Error stopping voice server client: " + ex.Message));
     }
 }
Exemplo n.º 13
0
 private void ServerListBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Server list download cancelled. Using previously cached server list."));
     }
     else if (e.Error != null)
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, $"Server list download failed. Using previously cached server list. Error: { e.Error.Message }"));
     }
     else
     {
         mConfig.CachedServers.Clear();
         foreach (NetworkServerInfo server in mServerList)
         {
             mConfig.CachedServers.Add(server);
         }
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, $"Server list successfully downloaded. { mServerList.Count } servers found."));
         NetworkServerListUpdated?.Invoke(this, EventArgs.Empty);
         mConfig.SaveConfig();
     }
 }
Exemplo n.º 14
0
 private void StartClientConnection()
 {
     try
     {
         if (!mAfvUserClient.Started)
         {
             if (!ClientAudioUtilities.IsInputDevicePresent())
             {
                 mOutputDeviceName         = mConfig.OutputDeviceName;
                 mAfvUserClient.Com1Volume = mConfig.Com1Volume;
                 mAfvUserClient.Com2Volume = mConfig.Com2Volume;
                 mAfvUserClient.Start(mOutputDeviceName, new List <ushort> {
                     1, 2
                 });
                 NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "No audio input device was detected. xPilot will run in receive only mode."));
             }
             else
             {
                 mInputDeviceName             = mConfig.InputDeviceName;
                 mOutputDeviceName            = mConfig.OutputDeviceName;
                 mAfvUserClient.InputVolumeDb = mConfig.InputVolumeDb / 4;
                 mAfvUserClient.Com1Volume    = mConfig.Com1Volume;
                 mAfvUserClient.Com2Volume    = mConfig.Com2Volume;
                 mAfvUserClient.Start(mInputDeviceName, mOutputDeviceName, new List <ushort> {
                     1, 2
                 });
             }
             mAfvUserClient.BypassEffects = mConfig.DisableAudioEffects;
         }
         mUpdateTransceiverTimer.Start();
         PrepareTransceivers();
     }
     catch (Exception ex)
     {
         NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Error starting voice server client: " + ex.Message));
     }
 }
Exemplo n.º 15
0
        public XplaneConnectionManager(IEventBroker broker, IAppConfig config, IFsdManger fsdManager) : base(broker)
        {
            DealerSocket visualDealerSocket = null;

            mVisualDealerSockets = null;
            mConfig     = config;
            mFsdManager = fsdManager;

            if (mConfig.VisualClientIPs.Count > 0)
            {
                foreach (string mIP in mConfig.VisualClientIPs)
                {
                    visualDealerSocket = new DealerSocket();
                    visualDealerSocket.Options.Identity     = Encoding.UTF8.GetBytes("CLIENT");
                    visualDealerSocket.Options.TcpKeepalive = true;
                    try
                    {
                        visualDealerSocket.Connect("tcp://" + mIP + ":" + mConfig.TcpPort);
                        if (mVisualDealerSockets == null)
                        {
                            mVisualDealerSockets = new List <DealerSocket>();
                        }
                        mVisualDealerSockets.Add(visualDealerSocket);
                    }
                    catch (AddressAlreadyInUseException)
                    {
                        NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Plugin port already in use. Please choose a different TCP port."));
                    }
                }
            }

            if (!string.IsNullOrEmpty(mConfig.SimClientIP))
            {
                mSimulatorIP = mConfig.SimClientIP;
            }

            mMessageQueue = new NetMQQueue <string>();
            mDealerSocket = new DealerSocket();
            mDealerSocket.Options.TcpKeepalive = true;
            mDealerSocket.Options.Identity     = Encoding.UTF8.GetBytes("CLIENT");
            mDealerSocket.ReceiveReady        += DealerSocket_ReceiveReady;
            try
            {
                mDealerSocket.Connect("tcp://" + mSimulatorIP + ":" + mConfig.TcpPort);
            }
            catch (AddressAlreadyInUseException)
            {
                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Plugin port already in use. Please choose a different TCP port."));
            }
            mPoller = new NetMQPoller {
                mDealerSocket, mMessageQueue
            };
            if (!mPoller.IsRunning)
            {
                mPoller.RunAsync();
            }

            mMessageQueue.ReceiveReady += (s, e) =>
            {
                if (mMessageQueue.TryDequeue(out string msg, TimeSpan.FromMilliseconds(100)))
                {
                    if (mDealerSocket != null)
                    {
                        mDealerSocket.SendFrame(msg);
                    }
                    if (mVisualDealerSockets != null && mVisualDealerSockets.Count > 0)
                    {
                        foreach (DealerSocket socket in mVisualDealerSockets)
                        {
                            socket.SendFrame(msg);
                        }
                    }
                }
            };

            mXplaneConnector  = new XPlaneConnector.XPlaneConnector(mSimulatorIP);
            mUserAircraftData = new UserAircraftData();
            mRadioStackState  = new UserAircraftRadioStack();

            mGetXplaneDataTimer = new Timer
            {
                Interval = 10
            };
            mGetXplaneDataTimer.Tick += GetXplaneDataTimer_Tick;
            mGetXplaneDataTimer.Start();

            mConnectionTimer = new Timer
            {
                Interval = 50
            };
            mConnectionTimer.Tick += ConnectionTimer_Tick;
            mConnectionTimer.Start();

            mRetryConnectionTimer = new Timer
            {
                Interval = 1000
            };
            mRetryConnectionTimer.Tick += RetryConnectionTimer_Tick;
            mRetryConnectionTimer.Start();

            mWhosOnlineListRefresh = new Timer
            {
                Interval = 5000
            };
            mWhosOnlineListRefresh.Tick += WhosOnlineListRefresh_Tick;

            SetupSubscribers();

            if (!Directory.Exists(Path.Combine(mConfig.AppPath, "PluginLogs")))
            {
                Directory.CreateDirectory(Path.Combine(mConfig.AppPath, "PluginLogs"));
            }

            var directory = new DirectoryInfo(Path.Combine(mConfig.AppPath, "PluginLogs"));
            var query     = directory.GetFiles("*", SearchOption.AllDirectories);

            foreach (var file in query.OrderByDescending(file => file.CreationTime).Skip(10))
            {
                file.Delete();
            }

            mRawDataStream = new StreamWriter(Path.Combine(mConfig.AppPath, string.Format($"PluginLogs/PluginLog-{DateTime.UtcNow:yyyyMMddHHmmss}.log")), false);
        }
Exemplo n.º 16
0
 private void FSD_NetworkError(object sender, NetworkErrorEventArgs e)
 {
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, e.Error));
 }
Exemplo n.º 17
0
 public void Connect(ConnectInfo info, string address)
 {
     mConnectInfo = info;
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Connecting to network..."));
     FSD.Connect(address, 6809, !mConnectInfo.TowerViewMode);
 }
Exemplo n.º 18
0
 private void InvokeNotificationEvent(INotificationMessage notification)
 {
     NotificationPosted?.Invoke(this, notification);
 }
Exemplo n.º 19
0
 private void AfvUserClient_Connected(object sender, ConnectedEventArgs e)
 {
     NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Info, "Connected to voice server."));
 }
Exemplo n.º 20
0
        private void DealerSocket_ReceiveReady(object sender, NetMQSocketEventArgs e)
        {
            string command = e.Socket.ReceiveFrameString();

            if (!string.IsNullOrEmpty(command))
            {
                try
                {
                    var     json = JsonConvert.DeserializeObject <XplaneConnect>(command);
                    dynamic data = json.Data;
                    switch (json.Type)
                    {
                    case XplaneConnect.MessageType.PluginHash:
                        string hash = data.Hash;
                        if (!string.IsNullOrEmpty(hash))
                        {
                            mFsdManager.ClientProperties.PluginHash = hash;
                        }
                        break;

                    case XplaneConnect.MessageType.RequestAtis:
                        string callsign = data.Callsign;
                        if (!string.IsNullOrEmpty(callsign))
                        {
                            RequestControllerAtisSent?.Invoke(this, new RequestControllerAtisEventArgs(callsign));
                        }
                        break;

                    case XplaneConnect.MessageType.PluginVersion:
                        mReceivedInitialHandshake = true;
                        int pluginVersion = (int)data.Version;
                        if (pluginVersion != MIN_PLUGIN_VERSION)
                        {
                            EnableConnectButton?.Invoke(this, new ClientEventArgs <bool>(false));
                            if (!mInvalidPluginVersionShown)
                            {
                                NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Error: Incorrect xPilot Plugin Version. You are using an out of date xPilot plugin. Please close X-Plane and reinstall xPilot."));
                                PlaySoundRequested?.Invoke(this, new PlaySoundEventArgs(SoundEvent.Error));
                                mInvalidPluginVersionShown = true;
                            }
                        }
                        break;

                    case XplaneConnect.MessageType.SocketMessage:
                    {
                        string msg = data.Message;
                        if (!string.IsNullOrEmpty(msg))
                        {
                            RaiseSocketMessageReceived?.Invoke(this, new ClientEventArgs <string>(msg));
                        }
                    }
                    break;

                    case XplaneConnect.MessageType.PrivateMessageSent:
                    {
                        string msg = data.Message;
                        string to  = data.To;
                        if (mFsdManager.IsConnected)
                        {
                            PrivateMessageSent?.Invoke(this, new PrivateMessageSentEventArgs(mFsdManager.OurCallsign, to, msg));
                        }
                    }
                    break;

                    case XplaneConnect.MessageType.ValidateCslPaths:
                        mValidCsl = (bool)data.Result;
                        if (data.Result == false)
                        {
                            EnableConnectButton?.Invoke(this, new ClientEventArgs <bool>(false));
                            NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Error: No valid CSL paths are configured or enabled, or you have no CSL models installed. Please verify the CSL configuration in X-Plane (Plugins > xPilot > Preferences). If you need assistance configuring your CSL paths, see the \"CSL Model Configuration\" section in the xPilot Documentation (http://docs.xpilot-project.org). Restart X-Plane and xPilot after you have properly configured your CSL models."));
                            PlaySoundRequested?.Invoke(this, new PlaySoundEventArgs(SoundEvent.Error));
                        }
                        break;

                    case XplaneConnect.MessageType.ForceDisconnect:
                        string reason = data.Reason;
                        NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, reason));
                        PlaySoundRequested?.Invoke(this, new PlaySoundEventArgs(SoundEvent.Error));
                        mFsdManager.Disconnect(new DisconnectInfo
                        {
                            Type = DisconnectType.Intentional
                        });
                        break;
                    }
                }
                catch (JsonException ex)
                {
                    NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Error deserializing JSON object: " + ex.Message));
                }
            }
        }