コード例 #1
0
        public MemberData MemberLogin(string account, string password)
        {
            MemberData memberData = new MemberData();

            memberData.ReturnCode    = "S200";
            memberData.ReturnMessage = "";
            try
            {
                TextUtility textUtility = new TextUtility();

                // 檢查會員帳號
                if (textUtility.SaveTextChk(account) != 1)
                {
                    memberData.ReturnCode    = "S202";
                    memberData.ReturnMessage = "會員帳號內含不合法字元!!";
                    return(memberData);
                }

                // 檢查密碼
                if (textUtility.SaveTextChk(password, new char[] { '#', '$', '%', '^', '&', '*', '(', ')' }) != 1)
                {
                    memberData.ReturnCode    = "S203";
                    memberData.ReturnMessage = "會員密碼內含不合法字元!!";
                    return(memberData);
                }

                //如果檢查成功 進行會員資料比對
                MemberIO memberIO = new MemberIO();
                memberData = memberIO.MemberLogin(account, password);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(memberData);
        }
コード例 #2
0
ファイル: MemberIO.cs プロジェクト: Chita16/MPServer
        public MemberData JoinMember(string account, string password, string nickname, byte age, byte sex, string IP, string email, string joinTime, string memberType)
        {
            MemberData memberData = default(MemberData);

            memberData.ReturnCode    = "(IO)S100";
            memberData.ReturnMessage = "";
            DataSet DS = new DataSet();

            try
            {
                using (SqlConnection sqlConn = new SqlConnection(this.connectionString))
                {
                    SqlCommand sqlCmd = new SqlCommand();
                    sqlCmd.Connection = sqlConn;
                    sqlConn.Open();

                    SqlDataAdapter adapter = new SqlDataAdapter();

                    adapter.SelectCommand = new SqlCommand(string.Format("SELECT * FROM GansolMember WHERE (Account='{0}') ", account), sqlConn);
                    adapter.Fill(DS);
                    Log.Debug("Tables Count: " + DS.Tables[0].Rows.Count);


                    //假如資料表中找不到資料 尚未加入會員
                    if (DS.Tables[0].Rows.Count == 0)
                    {
                        //插入 會員資料
                        string     query   = "INSERT INTO GansolMember (Account,Password,Nickname,Age,Sex,IP,Email,JoinTime,MemberType) VALUES(@account, @password, @nickname, @age, @sex, @IP, @email, @joinTime, @memberType)";
                        SqlCommand command = new SqlCommand(query, sqlCmd.Connection);
                        command.Parameters.AddWithValue("@account", account);
                        command.Parameters.AddWithValue("@password", password);
                        command.Parameters.AddWithValue("@nickname", nickname);
                        command.Parameters.AddWithValue("@age", age);
                        command.Parameters.AddWithValue("@sex", sex);
                        command.Parameters.AddWithValue("@IP", IP);
                        command.Parameters.AddWithValue("@email", email);
                        command.Parameters.AddWithValue("@joinTime", joinTime);
                        command.Parameters.AddWithValue("@memberType", memberType);
                        int ExecuteNonQuery = command.ExecuteNonQuery();

                        memberData.ReturnCode    = "S101";
                        memberData.ReturnMessage = "加入會員成功!";
                    }
                    else if (DS.Tables[0].Rows.Count > 0)
                    {
                        memberData.ReturnCode    = "S108";
                        memberData.ReturnMessage = "已有相同的會員帳號!";
                    }

                    adapter.SelectCommand = new SqlCommand(string.Format("SELECT * FROM Player_PlayerData WHERE (Account='{0}') ", account), sqlConn);
                    adapter.Fill(DS);

                    //假如玩家資料中沒有資料 建立一份新玩家資料
                    if (DS.Tables[0].Rows.Count == 0)
                    {
                        string     query   = "INSERT INTO PlayerData (Account) VALUES (@account) ";
                        SqlCommand command = new SqlCommand(query, sqlCmd.Connection);
                        command.Parameters.AddWithValue("@account", account);
                        int ExecuteNonQuery = command.ExecuteNonQuery();
                    }


                    adapter.SelectCommand = new SqlCommand(string.Format("SELECT * FROM Player_GameCurrency WHERE (Account='{0}') ", account), sqlConn);
                    adapter.Fill(DS);

                    //假如玩家貨幣資料中沒有資料 建立一份新玩家貨幣資料
                    if (DS.Tables[0].Rows.Count == 0)
                    {
                        string     query   = "INSERT INTO GameCurrency (Account) VALUES (@account) ";
                        SqlCommand command = new SqlCommand(query, sqlCmd.Connection);
                        command.Parameters.AddWithValue("@account", account);
                        int ExecuteNonQuery = command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                memberData.ReturnCode    = "S199";
                memberData.ReturnMessage = "加入會員失敗,未知例外情況!";
                Log.Debug("(IO)JoinMember failed!" + e.Message + " Track: " + e.StackTrace);
                throw e;
            }
            return(memberData);
        }
コード例 #3
0
        public MemberData JoinMember(string account, string password, string nickname, byte age, byte sex, string IP, string email, string joinTime)
        {
            MemberData memberData = new MemberData();

            memberData.ReturnCode    = "(Logic)S100";
            memberData.ReturnMessage = "";

            try
            {
                TextUtility textUtility = new TextUtility();

                // 檢查會員帳號
                if (textUtility.SaveTextChk(account) != 1)
                {
                    memberData.ReturnCode    = "S102";
                    memberData.ReturnMessage = "會員帳號內含不合法字元!!";
                    return(memberData);
                }
                else if (account.Length < 8 || account.Length > 16)
                {
                    memberData.ReturnCode    = "S102";
                    memberData.ReturnMessage = "會員帳號長度不正確(8~16字元)!!";
                    return(memberData);
                }

                // 檢查密碼
                if (textUtility.SaveTextChk(password, new char[] { '#', '$', '%', '^', '&', '*', '(', ')' }) != 1)
                {
                    memberData.ReturnCode    = "S103";
                    memberData.ReturnMessage = "會員密碼內含不合法字元!!";
                    return(memberData);
                }
                else if (password.Length < 8 || password.Length > 16)
                {
                    memberData.ReturnCode    = "S103";
                    memberData.ReturnMessage = "會員密碼長度不正確(8~16字元)!!";
                    return(memberData);
                }

                // 檢查暱稱
                if (textUtility.SaveTextChk(nickname, new char[] { '#', '$', '%', '^', '&', '*', '(', ')' }) != 1)
                {
                    memberData.ReturnCode    = "S104";
                    memberData.ReturnMessage = "會員暱稱內含不合法字元!!";
                    return(memberData);
                }
                else if (nickname == "" || nickname.Length <= 0 || nickname.Length > 12)
                {
                    memberData.ReturnCode    = "S104";
                    memberData.ReturnMessage = "會員暱稱長度不正確(1~12字元)!!";
                    return(memberData);
                }

                // 檢查年齡
                if ((textUtility.NumTextChk(age.ToString()) != 1) || age <= 0 || age >= 100)
                {
                    memberData.ReturnCode    = "S105";
                    memberData.ReturnMessage = "請選擇正確年齡!!";
                    return(memberData);
                }

                // 檢查性別
                if (sex < 0 || sex > 1)
                {
                    memberData.ReturnCode    = "S106";
                    memberData.ReturnMessage = "請選擇正確性別!!";
                    return(memberData);
                }

                // 檢查Email
                if (textUtility.EMailChk(email) != 1)
                {
                    memberData.ReturnCode    = "S107";
                    memberData.ReturnMessage = "請輸入正確Email !!";
                    return(memberData);
                }
                else if (email.Length <= 5 || email.Length > 48)
                {
                    memberData.ReturnCode    = "S107";
                    memberData.ReturnMessage = "Email長度不正確(6~48字元)!!";
                    return(memberData);
                }

                // 驗證成功後再進行IO寫入 寫入後存入 memberData
                MemberIO memberIO = new MemberIO();
                memberData = memberIO.JoinMember(account, password, nickname, age, sex, IP, email, joinTime, "Gansol");
            }
            catch (Exception e)
            {
                throw e;
            }

            return(memberData); //回傳資料
        }