Example #1
0
        /// <summary>
        /// Initialize InSim.
        /// </summary>
        /// <param name="settings">The InSim settings.</param>
        public void Initialize(InSimSettings settings)
        {
            PreInitialize(settings);

            try {
                if (Settings.IsRelayHost)
                {
                    TcpSocket.Connect(RelayHost, RelayPort);
                }
                else
                {
                    TcpSocket.Connect(Settings.Host, Settings.Port);

                    // Initialize InSim.
                    Send(GetInSimInitPacket());

                    PostInitialize();
                }

                OnInitialized(new InitializeEventArgs(Settings));
            }
            catch (SocketException ex) {
                if (ex.SocketErrorCode == SocketError.ConnectionRefused)
                {
                    throw new InSimException(StringResources.InSimCouldNotConnectMessage, ex);
                }
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Initializes the connection with LFS.
        /// </summary>
        /// <param name="settings">A <see cref="InSimSettings"/> object containing information to initialize the connection with.</param>
        public void Initialize(InSimSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            ThrowIfDisposed();
            ThrowIfConnected();

            Settings = new ReadOnlyInSimSettings(settings);

            try {
                if (Settings.IsRelayHost)
                {
                    TcpSocket.Connect(RelayHost, RelayPort);
                }
                else
                {
                    TcpSocket.Connect(Settings.Host, Settings.Port);

                    Send(new IS_ISI {
                        Admin    = Settings.Admin,
                        Flags    = Settings.Flags,
                        IName    = Settings.IName,
                        Interval = Settings.Interval,
                        Prefix   = Settings.Prefix,
                        ReqI     = 1, // Request version.
                        UDPPort  = Settings.UdpPort,
                    });

                    if (Settings.UdpPort > 0)
                    {
                        UdpSocket.Bind(Settings.Host, Settings.UdpPort);
                    }
                }

                OnInitialized(new InitializeEventArgs(Settings));
            }
            catch (SocketException ex) {
                if (ex.SocketErrorCode == SocketError.ConnectionRefused)
                {
                    throw new InSimException(StringResources.InSimCouldNotConnectMessage, ex);
                }
                throw;
            }
        }