/// <summary> /// Handles the corresponding event. /// </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) { switch (e.NewStatus) { case NetConnectionStatus.Connected: // When the status has changed to Connected, and this screen is active, send the login info if (ScreenManager.ActiveNonConsoleScreen == this) { var name = _cNameText.Text; var pass = _cPasswordText.Text; using (var pw = ClientPacket.Login(name, pass)) { _sockets.Send(pw, ClientMessageType.System); } } break; case NetConnectionStatus.Disconnected: // If any screen other than this screen or the new account screen is the active screen when we // receive a disconnect, set this screen as active if ( !(ScreenManager.ActiveNonConsoleScreen is LoginScreen || ScreenManager.ActiveNonConsoleScreen is NewAccountScreen)) ScreenManager.ActiveScreen = this; // If this screen is the active screen, set the error text if (ScreenManager.ActiveNonConsoleScreen == this) { // If we were the ones to disconnect, clear the error if (sender.ClientDisconnected) { SetError(null); 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; } }
/// <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; } }