示例#1
0
        /// <summary>
        /// Handles when the status of the <see cref="IClientSocketManager"/> changes.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ClientSocketManagerStatusChangedEventArgs"/> instance containing the event data.</param>
        void _sockets_StatusChanged(IClientSocketManager sender, ClientSocketManagerStatusChangedEventArgs e)
        {
            // Make sure we are the active screen
            if (ScreenManager.ActiveNonConsoleScreen != this)
            {
                return;
            }

            switch (e.NewStatus)
            {
            case NetConnectionStatus.Connected:
                SetMessage("Connected to server. Sending new account request...");

                // When the status has changed to Connected, send the account info
                var name  = _cNameText.Text;
                var pass  = _cPasswordText.Text;
                var email = _cEmailText.Text;
                using (var pw = ClientPacket.CreateNewAccount(name, pass, email))
                {
                    _sockets.Send(pw, ClientMessageType.System);
                }
                break;

            case NetConnectionStatus.Disconnected:

                // If we were the ones to disconnect, do not change the display text
                if (sender.ClientDisconnected)
                {
                    break;
                }

                // If no reason specified, use generic one
                var reason = e.Reason;
                if (string.IsNullOrEmpty(reason))
                {
                    reason = GameMessageCollection.CurrentLanguage.GetMessage(GameMessage.DisconnectNoReasonSpecified);
                }

                SetError(reason);

                break;
            }
        }