Esempio n. 1
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="password"></param>
        /// <param name="paramNames"></param>
        /// <param name="paramValues"></param>
        /// <returns>pid</returns>
        public static string RegisterPassport(string password, string[] paramNames = null, string[] paramValues = null)
        {
            string pid = new SnsPassport().GetRegPassport();

            DoRegisterPassport(pid, password, paramNames, paramValues);
            return(pid);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines whether this instance is exist retail.
        /// </summary>
        /// <returns><c>true</c> if this instance is exist retail; otherwise, <c>false</c>.</returns>
        public bool IsExistRetail()
        {
            var command = ConnectManager.Provider.CreateCommandStruct("SnsUserInfo", CommandMode.Inquiry);

            command.Columns          = "userid";
            command.OrderBy          = "USERID ASC";
            command.Filter           = ConnectManager.Provider.CreateCommandFilter();
            command.Filter.Condition = string.Format("{0} AND {1}",
                                                     command.Filter.FormatExpression("RetailID"),
                                                     command.Filter.FormatExpression("RetailUser")
                                                     );
            command.Filter.AddParam("RetailID", RetailID);
            command.Filter.AddParam("RetailUser", RetailUser);
            command.Parser();

            using (var aReader = ConnectManager.Provider.ExecuteReader(CommandType.Text, command.Sql, command.Parameters))
            {
                if (aReader.Read())
                {
                    return(true);
                }
            }

            //自动获取通行证
            SnsPassport passport = new SnsPassport();

            this._PassportId  = passport.GetRegPassport();
            this._PassportPwd = passport.GetRandomPwd();
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// 通道商验证登录
        /// </summary>
        /// <param name="retailId"></param>
        /// <param name="retailUser"></param>
        /// <returns></returns>
        public static string[] LoginByRetail(string retailId, string retailUser)
        {
            string[]      result        = new string[2];
            SnsCenterUser snsCenterUser = new SnsCenterUser();
            var           snsuser       = snsCenterUser.GetUserInfo(retailId, retailUser);

            if (snsuser.UserId <= 0)
            {
                //自动获取通行证
                SnsPassport passport = new SnsPassport();
                string      pid      = passport.GetRegPassport();
                string      pwd      = passport.GetRandomPwd();
                //modify login of retail bug.
                snsCenterUser = new SnsCenterUser(pid, pwd, string.Empty)
                {
                    RetailID = retailId, RetailUser = retailUser
                };
                result[0] = snsCenterUser.InsertSnsUser().ToString();
                result[1] = pid;
                return(result);
            }
            result[0] = snsuser.UserId.ToString();
            result[1] = snsuser.PassportId;
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="password"></param>
        /// <param name="imei"></param>
        /// <param name="paramNames"></param>
        /// <param name="paramValues"></param>
        /// <returns>pid</returns>
        public static string RegisterPassport(string password, string imei, string[] paramNames = null, string[] paramValues = null)
        {
            int    userType;
            string pid = new SnsPassport().GetRegPassport();

            DoRegisterPassport(pid, password, imei, paramNames, paramValues, out userType, false);
            return(pid);
        }
Esempio n. 5
0
        public int InsertSnsUser(string[] paramNames, string[] paramValues)
        {
            SnsPassport oSnsPassportLog = new SnsPassport();

            if (!oSnsPassportLog.VerifyRegPassportId(_PassportId))
            {
                return(0);
            }
            //md5加密
            string password = CryptoHelper.DES_Decrypt(_PassportPwd, GameEnvironment.ProductDesEnKey);

            password = PasswordEncryptMd5(password);
            string sInsertSql = string.Empty;

            string extColumns = string.Join(",", paramNames);

            extColumns = extColumns.TrimEnd().Length > 0 ? "," + extColumns : string.Empty;
            string paramColumns = string.Join(",@", paramNames);

            paramColumns = paramColumns.TrimEnd().Length > 0 ? ",@" + paramColumns : string.Empty;

            List <SqlParameter> paramsInsert = new List <SqlParameter>();

            sInsertSql  = string.Format("insert into SnsUserInfo(passportid, passportpwd, DeviceID, RegType, RegTime,RetailID,RetailUser,PwdType{0})", extColumns);
            sInsertSql += string.Format("values(@aPassportId, @aPassportPwd, @DeviceID, @RegType, @RegTime, @RetailID, @RetailUser,@PwdType{0}) select @@IDENTITY", paramColumns);
            paramsInsert.Add(SqlParamHelper.MakeInParam("@aPassportId", SqlDbType.VarChar, 0, _PassportId));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@aPassportPwd", SqlDbType.VarChar, 0, password));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@deviceID", SqlDbType.VarChar, 0, _deviceID));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RegType", SqlDbType.Int, 0, (int)RegType));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RegTime", SqlDbType.DateTime, 0, DateTime.Now));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RetailID", SqlDbType.VarChar, 0, RetailID));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RetailUser", SqlDbType.VarChar, 0, RetailUser));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@PwdType", SqlDbType.Int, 0, (int)PwdType.MD5));
            for (int i = 0; i < paramNames.Length; i++)
            {
                paramsInsert.Add(SqlParamHelper.MakeInParam("@" + paramNames[i], SqlDbType.VarChar, 0, paramValues[i]));
            }
            try
            {
                if (!oSnsPassportLog.SetPassportReg(_PassportId))
                {
                    throw new Exception("SetPassportReg Error");
                }
                using (SqlDataReader aReader = SqlHelper.ExecuteReader(config.connectionString, CommandType.Text, sInsertSql, paramsInsert.ToArray()))
                {
                    if (aReader.Read())
                    {
                        _userid = Convert.ToInt32(aReader[0]);
                    }
                }
                return(_userid);
            }
            catch (Exception ex)
            {
                _Logger.SaveLog(ex);
                return(0);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts the sns user.
        /// </summary>
        /// <returns>The sns user.</returns>
        /// <param name="paramNames">Parameter names.</param>
        /// <param name="paramValues">Parameter values.</param>
        public int InsertSnsUser(string[] paramNames, string[] paramValues)
        {
            SnsPassport oSnsPassportLog = new SnsPassport();

            if (!oSnsPassportLog.VerifyRegPassportId(_PassportId))
            {
                return(0);
            }
            //md5加密
            string password = PasswordEncryptMd5(_PassportPwd);

            var command = ConnectManager.Provider.CreateCommandStruct("SnsUserInfo", CommandMode.Insert);

            command.ReturnIdentity = true;
            command.AddParameter("passportid", _PassportId);
            command.AddParameter("passportpwd", password);
            command.AddParameter("DeviceID", _imei);
            command.AddParameter("RegType", (int)RegType);
            command.AddParameter("RegTime", DateTime.Now);
            command.AddParameter("RetailID", RetailID);
            command.AddParameter("RetailUser", RetailUser);
            command.AddParameter("PwdType", (int)PwdType.MD5);

            if (paramNames != null && paramValues != null)
            {
                for (int i = 0; i < paramNames.Length; i++)
                {
                    command.AddParameter(paramNames[i], paramValues.Length > i ? paramValues[i] : "");
                }
            }
            command.Parser();

            try
            {
                if (!oSnsPassportLog.SetPassportReg(_PassportId))
                {
                    throw new Exception("Set passport  State.Reg fail.");
                }
                using (var aReader = ConnectManager.Provider.ExecuteReader(CommandType.Text, command.Sql, command.Parameters))
                {
                    if (aReader.Read())
                    {
                        _userid = Convert.ToInt32(aReader[0]);
                    }
                }
                return(_userid);
            }
            catch (Exception ex)
            {
                _Logger.SaveLog(ex);
                return(0);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei)
        {
            if (!SnsCenterUser.CheckDevice(imei))
            {
                throw (new Exception("禁止登入"));
            }
            var           list       = new List <string>();
            SnsCenterUser user       = SnsCenterUser.GetUserByDeviceId(imei);
            string        passportId = string.Empty;

            if (user != null)
            {
                passportId = user.PassportId;
                list.Add(passportId);
                list.Add(user.Password);
            }
            else
            {
                SnsPassport     passport = new SnsPassport();
                PassportExpired passportExpired;
                if (!imeiMap.TryGetValue(imei, out passportExpired))
                {
                    passportId    = passport.GetRegPassport();
                    imeiMap[imei] = new PassportExpired(passportId);
                }
                else
                {
                    passportId = passportExpired.Pid;
                    if (passportExpired.ExpiredTime < DateTime.Now)
                    {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List <string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10))
                    {
                        foreach (var expired in expiredMap)
                        {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }

                string password = passport.GetRandomPwd();
                list.Add(passportId);
                list.Add(password);
            }

            return(list.ToArray());
        }
Esempio n. 8
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="password"></param>
        /// <param name="paramNames"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        public static string RegisterPassport(string password, string[] paramNames, string[] paramValues)
        {
            string        pid           = new SnsPassport().GetRegPassport();
            SnsCenterUser snsCenterUser = new SnsCenterUser(pid, password, string.Empty);

            if (snsCenterUser.InsertSnsUser(paramNames, paramValues) > 0)
            {
                return(pid);
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei)
        {
            if (!SnsCenterUser.CheckDevice(imei))
                throw (new Exception("禁止登入"));
            var list = new List<string>();
            SnsCenterUser user = SnsCenterUser.GetUserByDeviceId(imei);
            string passportId = string.Empty;

            if (user != null)
            {
                passportId = user.PassportId;
                list.Add(passportId);
                list.Add(user.Password);
            }
            else
            {
                SnsPassport passport = new SnsPassport();
                PassportExpired passportExpired;
                if (!imeiMap.TryGetValue(imei, out passportExpired))
                {
                    passportId = passport.GetRegPassport();
                    imeiMap[imei] = new PassportExpired(passportId);
                }
                else
                {
                    passportId = passportExpired.Pid;
                    if (passportExpired.ExpiredTime < DateTime.Now)
                    {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List<string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10))
                    {
                        foreach (var expired in expiredMap)
                        {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }

                string password = passport.GetRandomPwd();
                list.Add(passportId);
                list.Add(password);
            }

            return list.ToArray();
        }
Esempio n. 10
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <param name="isNew"></param>
        /// <param name="encodeFunc"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei, bool isNew = false, Func<string, string> encodeFunc = null) {
            if (!SnsCenterUser.CheckDevice(imei))
                throw (new Exception("禁止登入"));
            var list = new List<string>();
            SnsUser user = new SnsCenterUser().GetUserByDeviceId(imei);
            string passportId = string.Empty;

            if (!isNew && user.UserId > 0) {
                passportId = user.PassportId;
                if (user.RegType == RegType.Guest) {
                    //客户端换包重新获取游客账号,密码需要重置 
                    string password = GetRandomPassword();
                    user.Password = encodeFunc != null ? encodeFunc(password) : password;
                    var sns = new SnsCenterUser(user.PassportId, password, imei);
                    sns.ChangePassword(user.UserId.ToString(), true);
                } else {
                    if (encodeFunc != null) user.Password = encodeFunc(user.Password);
                }
                list.Add(passportId);
                list.Add(user.Password);
            } else {
                PassportExpired passportExpired;
                if (isNew || !imeiMap.TryGetValue(imei, out passportExpired)) {
                    passportId = new SnsPassport().GetRegPassport();
                    if (!string.IsNullOrEmpty(imei))
                        imeiMap[imei] = new PassportExpired(passportId);
                } else {
                    passportId = passportExpired.PassportId;
                    if (passportExpired.ExpiredTime < DateTime.Now) {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List<string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10)) {
                        foreach (var expired in expiredMap) {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }
                string password = GetRandomPassword();
                if (encodeFunc != null) password = encodeFunc(password);
                list.Add(passportId);
                list.Add(password);
            }
            return list.ToArray();
        }
Esempio n. 11
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="deviceID"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string deviceID)
        {
            if (!SnsCenterUser.CheckDevice(deviceID))
                throw (new Exception("禁止登入"));
            List<string> list = new List<string>();
            SnsCenterUser user = SnsCenterUser.GetUserByDeviceID(deviceID);

            if (user != null)
            {
                list.Add(user.PassportId);
                list.Add(user.Password);
            }
            else
            {
                SnsPassport passport = new SnsPassport();
                string password = passport.GetRandomPwd();
                list.Add(passport.GetRegPassport());
                list.Add(CryptoHelper.DES_Encrypt(password, GameEnvironment.Setting.ProductDesEnKey));
            }

            return list.ToArray();
        }
Esempio n. 12
0
        public bool IsExistRetail()
        {
            string sGetSql = "select top 1 userid from SnsUserInfo where RetailID=@RetailID and RetailUser=@RetailUser";
            List <SqlParameter> listTmp = new List <SqlParameter>();

            listTmp.Add(SqlParamHelper.MakeInParam("@RetailID", SqlDbType.VarChar, 0, RetailID));
            listTmp.Add(SqlParamHelper.MakeInParam("@RetailUser", SqlDbType.VarChar, 0, RetailUser));
            SqlParameter[] paramsGet = listTmp.ToArray();
            using (SqlDataReader aReader = SqlHelper.ExecuteReader(config.connectionString, CommandType.Text, sGetSql, paramsGet))
            {
                if (aReader.Read())
                {
                    return(true);
                }
            }

            //自动获取通行证
            SnsPassport passport = new SnsPassport();

            this._PassportId  = passport.GetRegPassport();
            this._PassportPwd = CryptoHelper.DES_Encrypt(passport.GetRandomPwd(), GameEnvironment.ProductDesEnKey);
            return(false);
        }
Esempio n. 13
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei)
        {
            if (!SnsCenterUser.CheckDevice(imei))
            {
                throw (new Exception("禁止登入"));
            }
            var           list = new List <string>();
            SnsCenterUser user = SnsCenterUser.GetUserByDeviceId(imei);

            if (user != null)
            {
                list.Add(user.PassportId);
                list.Add(user.Password);
            }
            else
            {
                SnsPassport passport = new SnsPassport();
                string      password = passport.GetRandomPwd();
                list.Add(passport.GetRegPassport());
                list.Add(password);
            }

            return(list.ToArray());
        }
Esempio n. 14
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="deviceID"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string deviceID)
        {
            if (!SnsCenterUser.CheckDevice(deviceID))
            {
                throw (new Exception("禁止登入"));
            }
            List <string> list = new List <string>();
            SnsCenterUser user = SnsCenterUser.GetUserByDeviceID(deviceID);

            if (user != null)
            {
                list.Add(user.PassportId);
                list.Add(user.Password);
            }
            else
            {
                SnsPassport passport = new SnsPassport();
                string      password = passport.GetRandomPwd();
                list.Add(passport.GetRegPassport());
                list.Add(CryptoHelper.DES_Encrypt(password, GameEnvironment.ProductDesEnKey));
            }

            return(list.ToArray());
        }
Esempio n. 15
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <param name="password"></param>
 /// <param name="imei"></param>
 /// <param name="paramNames"></param>
 /// <param name="paramValues"></param>
 /// <returns>pid</returns>
 public static string RegisterPassport(string password, string imei, string[] paramNames = null, string[] paramValues = null) {
     int userType;
     string pid = new SnsPassport().GetRegPassport();
     DoRegisterPassport(pid, password, imei, paramNames, paramValues, out userType, false);
     return pid;
 }
Esempio n. 16
0
 /// <summary>
 /// 通行证检查
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public static bool CheckPassport(string user)
 {
     SnsPassport passport = new SnsPassport();
     return passport.VerifyRegPassportId(user);
 }
Esempio n. 17
0
 /// <summary>
 /// 通道商验证登录
 /// </summary>
 /// <param name="retailId"></param>
 /// <param name="retailUser"></param>
 /// <returns></returns>
 public static string[] LoginByRetail(string retailId, string retailUser)
 {
     string[] result = new string[2];
     SnsCenterUser snsCenterUser = new SnsCenterUser();
     var snsuser = snsCenterUser.GetUserInfo(retailId, retailUser);
     if (snsuser.UserId <= 0)
     {
         //自动获取通行证
         SnsPassport passport = new SnsPassport();
         string pid = passport.GetRegPassport();
         string pwd = passport.GetRandomPwd();
         //modify login of retail bug.
         snsCenterUser = new SnsCenterUser(pid, pwd, string.Empty) { RetailID = retailId, RetailUser = retailUser };
         result[0] = snsCenterUser.InsertSnsUser().ToString();
         result[1] = pid;
         return result;
     }
     result[0] = snsuser.UserId.ToString();
     result[1] = snsuser.PassportId;
     return result;
 }
Esempio n. 18
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <param name="password"></param>
 /// <param name="paramNames"></param>
 /// <param name="paramValues"></param>
 /// <returns>pid</returns>
 public static string RegisterPassport(string password, string[] paramNames = null, string[] paramValues = null)
 {
     string pid = new SnsPassport().GetRegPassport();
     DoRegisterPassport(pid, password, paramNames, paramValues);
     return pid;
 }
Esempio n. 19
0
        /// <summary>
        /// Determines whether this instance is exist retail.
        /// </summary>
        /// <returns><c>true</c> if this instance is exist retail; otherwise, <c>false</c>.</returns>
        public bool IsExistRetail()
        {
            var command = ConnectManager.Provider.CreateCommandStruct("SnsUserInfo", CommandMode.Inquiry);
            command.Columns = "userid";
            command.OrderBy = "USERID ASC";
            command.Filter = ConnectManager.Provider.CreateCommandFilter();
            command.Filter.Condition = string.Format("{0} AND {1}",
                    command.Filter.FormatExpression("RetailID"),
                    command.Filter.FormatExpression("RetailUser")
                );
            command.Filter.AddParam("RetailID", RetailID);
            command.Filter.AddParam("RetailUser", RetailUser);
            command.Parser();

            using (var aReader = ConnectManager.Provider.ExecuteReader(CommandType.Text, command.Sql, command.Parameters))
            {
                if (aReader.Read())
                {
                    return true;
                }
            }

            //自动获取通行证
            SnsPassport passport = new SnsPassport();
            this._PassportId = passport.GetRegPassport();
            this._PassportPwd = CryptoHelper.DES_Encrypt(passport.GetRandomPwd(), GameEnvironment.ProductDesEnKey);
            return false;
        }
Esempio n. 20
0
        /// <summary>
        /// 通行证检查
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool CheckPassport(string user)
        {
            SnsPassport passport = new SnsPassport();

            return(passport.VerifyRegPassportId(user));
        }
Esempio n. 21
0
        /// <summary>
        /// Inserts the sns user.
        /// </summary>
        /// <returns>The sns user.</returns>
        /// <param name="paramNames">Parameter names.</param>
        /// <param name="paramValues">Parameter values.</param>
        public int InsertSnsUser(string[] paramNames, string[] paramValues)
        {
            SnsPassport oSnsPassportLog = new SnsPassport();
            if (!oSnsPassportLog.VerifyRegPassportId(_PassportId))
            {
                return 0;
            }
            //md5加密
            string password = PasswordEncryptMd5(_PassportPwd);

            var command = ConnectManager.Provider.CreateCommandStruct("SnsUserInfo", CommandMode.Insert);
            command.ReturnIdentity = true;
            command.AddParameter("passportid", _PassportId);
            command.AddParameter("passportpwd", password);
            command.AddParameter("DeviceID", _imei);
            command.AddParameter("RegType", (int)RegType);
            command.AddParameter("RegTime", DateTime.Now);
            command.AddParameter("RetailID", RetailID);
            command.AddParameter("RetailUser", RetailUser);
            command.AddParameter("PwdType", (int)PwdType.MD5);

            if (paramNames != null && paramValues != null)
            {
                for (int i = 0; i < paramNames.Length; i++)
                {
                    command.AddParameter(paramNames[i], paramValues.Length > i ? paramValues[i] : "");
                }
            }
            command.Parser();

            try
            {
                if (!oSnsPassportLog.SetPassportReg(_PassportId))
                {
                    throw new Exception("Set passport  State.Reg fail.");
                }
                using (var aReader = ConnectManager.Provider.ExecuteReader(CommandType.Text, command.Sql, command.Parameters))
                {
                    if (aReader.Read())
                    {
                        _userid = Convert.ToInt32(aReader[0]);
                    }
                }
                return _userid;
            }
            catch (Exception ex)
            {
                _Logger.SaveLog(ex);
                return 0;
            }
        }
Esempio n. 22
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <param name="password"></param>
 /// <param name="paramNames"></param>
 /// <param name="paramValues"></param>
 /// <returns></returns>
 public static string RegisterPassport(string password, string[] paramNames, string[] paramValues)
 {
     string pid = new SnsPassport().GetRegPassport();
     SnsCenterUser snsCenterUser = new SnsCenterUser(pid, password, string.Empty);
     if (snsCenterUser.InsertSnsUser(paramNames, paramValues) > 0)
     {
         return pid;
     }
     else
     {
         return string.Empty;
     }
 }
Esempio n. 23
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <param name="isNew"></param>
        /// <param name="encodeFunc"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei, bool isNew = false, Func <string, string> encodeFunc = null)
        {
            if (!SnsCenterUser.CheckDevice(imei))
            {
                throw (new Exception("禁止登入"));
            }
            var     list       = new List <string>();
            SnsUser user       = new SnsCenterUser().GetUserByDeviceId(imei);
            string  passportId = string.Empty;

            if (!isNew && user.UserId > 0)
            {
                passportId = user.PassportId;
                if (user.RegType == RegType.Guest)
                {
                    //客户端换包重新获取游客账号,密码需要重置
                    string password = GetRandomPwd();
                    user.Password = encodeFunc != null?encodeFunc(password) : password;

                    var sns = new SnsCenterUser(user.PassportId, password, imei);
                    sns.ChangePass(user.UserId.ToString(), true);
                }
                else
                {
                    if (encodeFunc != null)
                    {
                        user.Password = encodeFunc(user.Password);
                    }
                }
                list.Add(passportId);
                list.Add(user.Password);
            }
            else
            {
                PassportExpired passportExpired;
                if (isNew || !imeiMap.TryGetValue(imei, out passportExpired))
                {
                    passportId = new SnsPassport().GetRegPassport();
                    if (!string.IsNullOrEmpty(imei))
                    {
                        imeiMap[imei] = new PassportExpired(passportId);
                    }
                }
                else
                {
                    passportId = passportExpired.Pid;
                    if (passportExpired.ExpiredTime < DateTime.Now)
                    {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List <string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10))
                    {
                        foreach (var expired in expiredMap)
                        {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }

                string password = GetRandomPwd();
                if (encodeFunc != null)
                {
                    password = encodeFunc(password);
                }
                list.Add(passportId);
                list.Add(password);
            }
            return(list.ToArray());
        }
Esempio n. 24
0
        public bool IsExistRetail()
        {
            string sGetSql = "select top 1 userid from SnsUserInfo where RetailID=@RetailID and RetailUser=@RetailUser";
            List<SqlParameter> listTmp = new List<SqlParameter>();
            listTmp.Add(SqlParamHelper.MakeInParam("@RetailID", SqlDbType.VarChar, 0, RetailID));
            listTmp.Add(SqlParamHelper.MakeInParam("@RetailUser", SqlDbType.VarChar, 0, RetailUser));
            SqlParameter[] paramsGet = listTmp.ToArray();
            using (SqlDataReader aReader = SqlHelper.ExecuteReader(config.connectionString, CommandType.Text, sGetSql, paramsGet))
            {
                if (aReader.Read())
                {
                    return true;
                }
            }

            //自动获取通行证
            SnsPassport passport = new SnsPassport();
            this._PassportId = passport.GetRegPassport();
            this._PassportPwd = CryptoHelper.DES_Encrypt(passport.GetRandomPwd(), GameEnvironment.ProductDesEnKey);
            return false;
        }
Esempio n. 25
0
        public int InsertSnsUser(string[] paramNames, string[] paramValues)
        {
            SnsPassport oSnsPassportLog = new SnsPassport();
            if (!oSnsPassportLog.VerifyRegPassportId(_PassportId))
            {
                return 0;
            }
            //md5加密
            string password = CryptoHelper.DES_Decrypt(_PassportPwd, GameEnvironment.ProductDesEnKey);
            password = PasswordEncryptMd5(password);
            string sInsertSql = string.Empty;

            string extColumns = string.Join(",", paramNames);
            extColumns = extColumns.TrimEnd().Length > 0 ? "," + extColumns : string.Empty;
            string paramColumns = string.Join(",@", paramNames);
            paramColumns = paramColumns.TrimEnd().Length > 0 ? ",@" + paramColumns : string.Empty;

            List<SqlParameter> paramsInsert = new List<SqlParameter>();
            sInsertSql = string.Format("insert into SnsUserInfo(passportid, passportpwd, DeviceID, RegType, RegTime,RetailID,RetailUser,PwdType{0})", extColumns);
            sInsertSql += string.Format("values(@aPassportId, @aPassportPwd, @DeviceID, @RegType, @RegTime, @RetailID, @RetailUser,@PwdType{0}) select @@IDENTITY", paramColumns);
            paramsInsert.Add(SqlParamHelper.MakeInParam("@aPassportId", SqlDbType.VarChar, 0, _PassportId));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@aPassportPwd", SqlDbType.VarChar, 0, password));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@deviceID", SqlDbType.VarChar, 0, _deviceID));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RegType", SqlDbType.Int, 0, (int)RegType));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RegTime", SqlDbType.DateTime, 0, DateTime.Now));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RetailID", SqlDbType.VarChar, 0, RetailID));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@RetailUser", SqlDbType.VarChar, 0, RetailUser));
            paramsInsert.Add(SqlParamHelper.MakeInParam("@PwdType", SqlDbType.Int, 0, (int)PwdType.MD5));
            for (int i = 0; i < paramNames.Length; i++)
            {
                paramsInsert.Add(SqlParamHelper.MakeInParam("@" + paramNames[i], SqlDbType.VarChar, 0, paramValues[i]));
            }
            try
            {

                if (!oSnsPassportLog.SetPassportReg(_PassportId))
                {
                    throw new Exception("SetPassportReg Error");
                }
                using (SqlDataReader aReader = SqlHelper.ExecuteReader(config.connectionString, CommandType.Text, sInsertSql, paramsInsert.ToArray()))
                {
                    if (aReader.Read())
                    {
                        _userid = Convert.ToInt32(aReader[0]);
                    }
                }
                return _userid;
            }
            catch (Exception ex)
            {
                _Logger.SaveLog(ex);
                return 0;
            }
        }