コード例 #1
0
        /// <summary>
        /// Updates the <see cref="Control"/>. This is called for every <see cref="Control"/>, even if it is disabled or
        /// not visible.
        /// </summary>
        /// <param name="currentTime">The current time in milliseconds.</param>
        ///
        protected override void UpdateControl(TickCount currentTime)
        {
            base.UpdateControl(currentTime);

            if (currentTime >= _nextUpdateTime)
            {
                if (_sockets == null)
                {
                    _sockets = ClientSockets.Instance;
                }

                using (var pw = ClientPacket.GetFriends())
                {
                    _sockets.Send(pw, ClientMessageType.General);
                }

                _nextUpdateTime = (TickCount)(currentTime + _updateTimeOut);
            }
        }
コード例 #2
0
ファイル: LoginScreen.cs プロジェクト: thepirateclub/netgore
        /// <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;
            }
        }
コード例 #3
0
        void ClickButton_CreateCharacter(object sender, MouseButtonEventArgs e)
        {
            var name = _txtName.Text;

            if (!GameData.UserName.IsValid(name))
            {
                SetError("Invalid character name.");
                return;
            }

            _btnCreateCharacter.IsEnabled = false;

            using (var pw = ClientPacket.CreateNewAccountCharacter(name))
            {
                _sockets.Send(pw, ClientMessageType.System);
            }
        }
コード例 #4
0
        private void OnlineUsersForm_VisibleChanged(Control sender, EventArgs e)
        {
            if (Sockets == null || !Sockets.IsConnected)
            {
                return;
            }

            using (var pw = ClientPacket.GetOnlineUsers())
            {
                _sockets.Send(pw, ClientMessageType.GUI);
            }

            if (this.IsVisible)
            {
                Text = (_lbOnlineUsers == null ? "Users Online" : "Users Online: " + _lbOnlineUsers.Items.Count);
                UpdateUsersList();
            }
        }
コード例 #5
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;
            }
        }
コード例 #6
0
        void ClickButton_CreateCharacter(object sender, MouseButtonEventArgs e)
        {
            var name = _txtName.Text;

            // Validate the name client-side before talking to the server
            if (!GameData.UserName.IsValid(name))
            {
                SetError(_invalidCharacterNameMessage);
                return;
            }

            // Disable the button while we wait for a response
            _btnCreateCharacter.IsEnabled = false;

            // Send request to server
            using (var pw = ClientPacket.CreateNewAccountCharacter(name))
            {
                _sockets.Send(pw, ClientMessageType.System);
            }
        }