Beispiel #1
0
        /// <summary>
        /// Starts establishing a connection with the given host on the given port.
        /// </summary>
        /// <param name="address">The address of the host to connect to.</param>
        /// <param name="port">The port of the host to connect to.</param>
        /// <param name="username">The username of the client.</param>
        /// <param name="authKey">The auth key of the client.</param>
        /// <param name="addonData">A list of addon data that the client has.</param>
        public void Connect(
            string address,
            int port,
            string username,
            string authKey,
            List <AddonData> addonData
            )
        {
            try {
                _udpNetClient.Connect(address, port);
            } catch (SocketException e) {
                Logger.Get().Warn(this, $"Failed to connect due to SocketException, message: {e.Message}");

                OnConnectFailed(new ConnectFailedResult {
                    Type = ConnectFailedResult.FailType.SocketException
                });
                return;
            }

            UpdateManager = new ClientUpdateManager(_udpNetClient);
            UpdateManager.StartUdpUpdates();
            // During the connection process we register the connection failed callback if we time out
            UpdateManager.OnTimeout += OnConnectTimedOut;

            UpdateManager.SetLoginRequestData(username, authKey, addonData);
            Logger.Get().Info(this, "Sending login request");
        }
Beispiel #2
0
        private void OnConnect()
        {
            // Only when the TCP connection is successful, we connect the UDP
            _udpNetClient.Connect(_lastHost, _lastPort, _tcpNetClient.GetConnectedPort());

            UpdateManager = new ClientUpdateManager(_udpNetClient);
            UpdateManager.StartUdpUpdates();

            IsConnected = true;

            // Invoke callback if it exists
            OnConnectEvent?.Invoke();
        }