Esempio n. 1
0
    /// <summary>
    /// Queries the user identifier and code matched.
    /// </summary>
    /// <returns><c>true</c>, if user identifier and code matched was queryed, <c>false</c> otherwise.</returns>
    /// <param name="db">Db.</param>
    /// <param name="id">Identifier.</param>
    /// <param name="code">Code.</param>
    public static bool QueryUserIdAndCodeMatched(JMySqlAccess db, string id, string code)
    {
        if (db == null)
        {
            throw new Exception("db is null.");
        }

        string[] items      = new string[] { _str_field_user_id, _str_field_user_code };
        string[] where_cols = new string[] { _str_field_user_id, _str_field_user_code };
        string[] operation  = new string[] { _str_operation_equal, _str_operation_equal };
        string[] values     = new string[] { id, code };

        DataSet result = db.Select(_str_table_name, items, where_cols, operation, values);

        if (result == null || result.Tables.Count < 0)
        {
            return(false);
        }
        if (result.Tables[0].Rows.Count == 1)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 2
0
 private bool CreateRole(JMySqlAccess mysql, string account, string roleName, int roleType, ref string roleId, ref int ErrorType)
 {
     try
     {
         string resultMssage = "";
         bool   inserResult  = mysql.DoSql(
             string.Format("INSERT into  {0}  ( role_name, user_account, role_type, scene_id)  VALUES( '{1}' , '{2}' , {3} ,  {4} );",
                           JDBUtil.TableName_Server_RoleInfo,
                           roleName,
                           account,
                           roleType,
                           JDBUtil.TableValue_SenceID_Default), ref resultMssage);
         JLog.Info("resultMssage");
         if (inserResult)
         {
             ErrorType = (int)JCreateRoleRetObject.CreateRoleResultType.successed;
             JLog.Debug("Create role success, account: " + account + " roleName:" + roleName + " roleType:" + roleType);
             return(true);
         }
         else
         {
             ErrorType = (int)JCreateRoleRetObject.CreateRoleResultType.failed;
             JLog.Debug("Create role falied, account: " + account + " roleName:" + roleName + " roleType:" + roleType);
             return(false);
         }
     }
     catch (Exception e) {
         JLog.Error(e.Message);
         ErrorType = (int)JCreateRoleRetObject.CreateRoleResultType.failed;
         return(false);
     }
 }
Esempio n. 3
0
        private bool CheckRoleNameIsValud(JMySqlAccess mysql, string account, string roleName, ref int ErrorType)
        {
            string strSql =
                string.Format("select * from {0} where user_account = '{1}' and role_name = '{2}'",
                              JDBUtil.TableName_Server_RoleInfo,
                              account,
                              roleName);

            try
            {
                DataSet dataset = mysql.Select(strSql);
                if (null == dataset || null == dataset.Tables)
                {
                    ErrorType = (int)JCreateRoleRetObject.CreateRoleResultType.failed;
                    return(false);
                }
                if (dataset.Tables.Count > 0 && dataset.Tables[0].Rows.Count > 0)
                {
                    ErrorType = (int)JCreateRoleRetObject.CreateRoleResultType.RoleNameRepeated;
                    return(false);
                }
            }
            catch (Exception e) {
                JLog.Error("CheckRoleNameIsValud." + e.Message);
                return(false);
            }

            return(true);
        }
            public void run(IDataSet dataSet)
            {
                IStreamObj             obj = dataSet.getData(JObjectType.account_register);
                JObjAccountRegisterReq accountRegisterObj = obj as JObjAccountRegisterReq;

                if (accountRegisterObj == null)
                {
                    return;
                }

                JMySqlAccess mysql = new JMySqlAccess(JDBUtil.ServerDatabaseName, JDBUtil.ServerDatasource, JDBUtil.ServerUser, JDBUtil.ServerUserCode);

                if (!mysql.Open())
                {
                    return;
                }
                if (!mysql.Connected)
                {
                    return;
                }

                DataSet data = mysql.Select(string.Format(
                                                @"Select count(1) from {0} t where t.user_account = '{1}' or t.user_email = '{2}'",
                                                JDBUtil.TableName_Server_UserInfo,
                                                accountRegisterObj._strAccount,
                                                accountRegisterObj._strEmailAddress));

                bool bAreadyExisted = false;

                do
                {
                    if (null == data || null == data.Tables)
                    {
                        break;
                    }
                    if (data.Tables.Count <= 0)
                    {
                        break;
                    }
                    if (null == data.Tables[0].Rows || data.Tables[0].Rows.Count <= 0)
                    {
                        break;
                    }
                    if (int.Parse(data.Tables[0].Rows[0][0].ToString()) == 1)
                    {
                        bAreadyExisted = true;
                    }
                }while(false);

                JObjAccountRegisterRet retObj = new JObjAccountRegisterRet();

                try
                {
                    if (!bAreadyExisted)
                    {
                        string resultMssage = "";
                        bool   inserResult  = mysql.DoSql(
                            string.Format("INSERT into  {0}  ( user_account, user_code, user_email)  VALUES( '{1}' , '{2}' , '{3}' );",
                                          JDBUtil.TableName_Server_UserInfo,
                                          accountRegisterObj._strAccount,
                                          accountRegisterObj._strCode,
                                          accountRegisterObj._strEmailAddress), ref resultMssage);
                        JLog.Info("resultMssage");
                        if (inserResult)
                        {
                            retObj.Result = JObjAccountRegisterRet.AccountRegisterResultType.successed;
                            JLog.Debug("Create account success, account: " + accountRegisterObj._strAccount);
                        }
                        else
                        {
                            retObj.Result = JObjAccountRegisterRet.AccountRegisterResultType.failed;
                            JLog.Debug("Create account falied, account: " + accountRegisterObj._strAccount);
                        }
                    }
                    else
                    {
                        retObj.Result = JObjAccountRegisterRet.AccountRegisterResultType.accountRepeated;
                    }
                }
                catch (Exception e) {
                    JLog.Error(e.Message);
                }
                finally {
                    mysql.Close();
                }

                try {
                    JNetworkDataOperator.SendData(JPacketType.npt_accountRegister_ret, retObj, dataSet.EndPoint);
                    JLog.Info("send npt_accountRegister_ret packet to client", JGame.Log.JLogCategory.Network);
                    return;
                } catch (Exception e) {
                    JLog.Debug("发送数据失败");
                    JLog.Error(e.Message);
                    return;
                }
            }
Esempio n. 5
0
            public void run(IDataSet dataSet)
            {
                IStreamObj  obj       = dataSet.getData(JObjectType.sign_in);
                JObj_SignIn signInObj = obj as JObj_SignIn;

                if (signInObj == null)
                {
                    return;
                }

                string account = signInObj._strAccount;
                string code    = signInObj._strCode;

                JLog.Info("JProcesserSignInServer.run receive npt_signin_req packet from client: account:" + account + "  code:" + code, JGame.Log.JLogCategory.Network);

                JObj_SignRet resultObj = new JObj_SignRet();
                JMySqlAccess sqlite    = new JMySqlAccess("mysql", "127.0.0.1", "root", "684268");

                if (!sqlite.Open())
                {
                    return;
                }
                if (!sqlite.Connected)
                {
                    return;
                }

                DataSet data = sqlite.Select(string.Format(
                                                 @"Select * from user_info t where t.user_account = '{0}' and t.user_code = '{1}'",
                                                 signInObj._strAccount,
                                                 signInObj._strCode));

                bool bSuccess = false;

                do
                {
                    if (null == data || null == data.Tables)
                    {
                        break;
                    }
                    if (data.Tables.Count <= 0)
                    {
                        break;
                    }
                    if (null == data.Tables[0].Rows || data.Tables[0].Rows.Count <= 0)
                    {
                        break;
                    }
                    if (data.Tables[0].Rows.Count > 0)
                    {
                        bSuccess = true;
                    }
                }while(false);
                resultObj.Result = bSuccess;

                string[] items      = new string[] { "role_name", "role_type", "role_level", "x", "y", "z", "x_rotation", "y_rotation", "z_rotation", "user_account" };
                string[] where_cols = new string[] { "user_account" };
                string[] operation  = new string[] { "=" };
                string[] values     = new string[] { signInObj._strAccount };

                string  strAccount = null;
                DataSet roleInfo   = sqlite.Select("role_info", items, where_cols, operation, values);

                do
                {
                    if (null == roleInfo || null == roleInfo.Tables)
                    {
                        break;
                    }
                    if (roleInfo.Tables.Count <= 0)
                    {
                        break;
                    }
                    if (null == roleInfo.Tables[0].Rows || roleInfo.Tables[0].Rows.Count <= 0)
                    {
                        break;
                    }

                    try
                    {
                        if (roleInfo.Tables [0].Rows.Count > 0)
                        {
                            resultObj.RolesInfo = new System.Collections.Generic.List <JObjRoleInfo> ();
                            foreach (DataRow dataRow in roleInfo.Tables[0].Rows)
                            {
                                JObjRoleInfo role = new JObjRoleInfo();
                                role.roleName  = dataRow [0].ToString();
                                role.roleType  = int.Parse(dataRow [1].ToString());
                                role.roleLevel = int.Parse(dataRow [2].ToString());
                                double coord;
                                if (double.TryParse(dataRow [3].ToString(), out coord))
                                {
                                    role.x = coord;
                                }
                                if (double.TryParse(dataRow [4].ToString(), out coord))
                                {
                                    role.y = coord;
                                }
                                if (double.TryParse(dataRow [5].ToString(), out coord))
                                {
                                    role.z = coord;
                                }
                                if (double.TryParse(dataRow [6].ToString(), out coord))
                                {
                                    role.rotatex = coord;
                                }
                                if (double.TryParse(dataRow [7].ToString(), out coord))
                                {
                                    role.rotatey = coord;
                                }
                                if (double.TryParse(dataRow [8].ToString(), out coord))
                                {
                                    role.rotatez = coord;
                                }
                                resultObj.RolesInfo.Add(role);
                                strAccount = dataRow[9].ToString();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        JLog.Error("JProcesserSignInServer.run " + e.Message);
                    }
                }while(false);

                if (null != strAccount)
                {
                    //记录当前新增的登录信息到对应的dataSet
                    IStreamObj clientobj = dataSet.getData(JObjectType.sign_in_info);
                    if (null != clientobj)
                    {
                        JSignInClientInfoObject clientInfo = clientobj as JSignInClientInfoObject;
                        clientInfo.Info.Account = strAccount;
                    }
                    else
                    {
                        JSignInClientInfoObject clientInfo = new JSignInClientInfoObject();
                        clientInfo.Info.Account = strAccount;
                        clientobj = clientInfo;
                    }
                    JLog.Info("JProcesserSignInServer.run add connected client info dataset, account:" + strAccount, JGame.Log.JLogCategory.Network);
                    dataSet.setData(clientobj);
                }

                try {
                    JNetworkDataOperator.SendData(JPacketType.npt_signin_ret, resultObj, dataSet.EndPoint);
                    JLog.Info("JProcesserSignInServer.run send npt_signin_ret packet to client", JGame.Log.JLogCategory.Network);
                    return;
                } catch (Exception e) {
                    JLog.Debug("发送数据失败");
                    JLog.Error(e.Message);
                    return;
                }
            }
Esempio n. 6
0
        public void run(IDataSet dataSet)
        {
            JCreateRoleRetObject createRoleRetObj = new JCreateRoleRetObject();

            createRoleRetObj.Result = JCreateRoleRetObject.CreateRoleResultType.failed;
            do
            {
                //check role info existed
                IStreamObj signinObj = dataSet.getData(JObjectType.sign_in_info);
                if (null == signinObj)
                {
                    createRoleRetObj.Result = JCreateRoleRetObject.CreateRoleResultType.failed;
                    JLog.Error("JProcessorCreateRole.run can not find sign in account info");
                    break;
                }
                JSignInClientInfoObject clientInfo = signinObj as JSignInClientInfoObject;
                string account = clientInfo.Info.Account;

                //process create role request
                IStreamObj           obj = dataSet.getData(JObjectType.create_role);
                JCreateRoleReqObject createRoleReqObj = obj as JCreateRoleReqObject;
                if (createRoleReqObj == null)
                {
                    createRoleRetObj.Result = JCreateRoleRetObject.CreateRoleResultType.failed;
                    break;
                }

                string roleName = createRoleReqObj.RoleName;
                int    roleType = createRoleReqObj.RoleType;

                //open data base
                JMySqlAccess mysql = new JMySqlAccess(JDBUtil.ServerDatabaseName, JDBUtil.ServerDatasource, JDBUtil.ServerUser, JDBUtil.ServerUserCode);
                try
                {
                    if (!mysql.Open())
                    {
                        break;
                    }
                    if (!mysql.Connected)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    JLog.Error("CheckRoleNameIsValud." + e.Message);
                }

                if (!mysql.Connected)
                {
                    mysql.Close();
                    JLog.Error("JProcessorCreateRole.run open database fialied");
                    break;
                }

                //check name is valid or not
                int nErrorType = 0;
                if (!CheckRoleNameIsValud(mysql, account, roleName, ref nErrorType))
                {
                    createRoleRetObj.Result = (JCreateRoleRetObject.CreateRoleResultType)nErrorType;
                    JLog.Info("JProcessorCreateRole.run Create role request not valid, error type:" + createRoleRetObj.Result.GetDescription());
                    mysql.Close();
                    break;
                }
                if (!CheckRoleTypeIsValud(roleType, ref nErrorType))
                {
                    createRoleRetObj.Result = (JCreateRoleRetObject.CreateRoleResultType)nErrorType;
                    JLog.Info("Create role request not valid, error type:" + createRoleRetObj.Result.GetDescription());
                    mysql.Close();
                    break;
                }

                //insert new role record to role_info table
                string roleID = "";
                if (!CreateRole(mysql, account, roleName, roleType, ref roleID, ref nErrorType))
                {
                    createRoleRetObj.Result = (JCreateRoleRetObject.CreateRoleResultType)nErrorType;
                    JLog.Info("JProcessorCreateRole.run CreateRole falied, error type:" + createRoleRetObj.Result.GetDescription());
                }
                createRoleRetObj.Result = JCreateRoleRetObject.CreateRoleResultType.successed;
                mysql.Close();
            } while (false);

            try {
                JNetworkDataOperator.SendData(JPacketType.pt_createRole_ret, createRoleRetObj, dataSet.EndPoint);
            } catch (Exception e) {
                JLog.Debug("JProcessorCreateRole 发送数据失败");
                JLog.Error("JProcessorCreateRole 发送数据失败 " + e.Message);
            }
        }
Esempio n. 7
0
 void Start()
 {
     _db = new JMySqlAccess("mysql", "127.0.0.1", "root", "684268");
 }