/// <summary>
        /// On click, queries the database to check if user exsits, and input is correct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            //Check input isn't empty, else error message is shown
            if (usernameBox.TextLength > 0 && passwordBox.TextLength > 0)
            {
                //Hide existing error label, if any
                errorLabel.Hide();

                //Sends input to login function, if input is good, sends user to main menu
                //Else error message is shown
                if (NetworkClasses.Login(usernameBox.Lines[0], passwordBox.Lines[0], Helpers.GetLocalIpAddress()))
                {
                    Form form = new MainMenuForm();
                    form.Show();
                    Dispose();
                }
                else
                {
                    errorLabel.Text = "Invalid Username/Password";
                    errorLabel.Show();
                }
            }
            else
            {
                errorLabel.Text = "Username/Password cannot be blank.";
                errorLabel.Show();
            }
        }
예제 #2
0
        /// <summary>
        /// On click, takes user back to the main menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainMenu_Click(object sender, EventArgs e)
        {
            var main = new MainMenuForm();

            Client.ClientStop();
            main.Show();
            Dispose();
        }
        /// <summary>
        /// On click, resets character to null, stops NetServer, and takes user back to main menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void leaveGame_Click(object sender, EventArgs e)
        {
            _timer.Stop();
            NetworkClasses.UpdateCharacter(User.PlayerId, null);
            Host.ServerStop();
            var main = new MainMenuForm();

            main.Show();
            Dispose();
        }
예제 #4
0
        /// <summary>
        /// On click, resets character to null, removes player from server, stops NetClient, and takes user back to main menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void leaveGame_Click(object sender, EventArgs e)
        {
            _timer.Stop();
            NetworkClasses.UpdateCharacter(User.PlayerId, null);
            NetworkClasses.FindRemovePlayer(Client.Conn, User.PlayerId);
            Client.ClientStop();
            var form = new MainMenuForm();

            form.Show();
            Dispose();
        }
예제 #5
0
        /// <summary>
        /// Updates the list of players with the current information about the server via the database
        /// </summary>
        private void UpdateList()
        {
            playerList.Items.Clear();
            try
            {
                var ds  = NetworkClasses.GetServer(Client.Conn);
                var row = ds.Tables[0].Rows[0];

                var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

                //Host
                var listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
                //Add the row entry to the listview
                playerList.Items.Add(listItem);

                for (var i = 2; i <= 6; i++)
                {
                    if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                    {
                        continue;
                    }
                    grabber  = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                    listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                    listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
                    playerList.Items.Add(listItem);
                }
            }
            catch (Exception) //Thrown if server no longer exists
            {
                Form form = new MainMenuForm();
                form.Show();
                _timer.Stop();
                Client.ClientStop();
                NetworkClasses.UpdateCharacter(User.PlayerId, null);
                MessageBox.Show("Host left the game", "Server Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Dispose();
            }
        }