Beispiel #1
0
 public bool ChangeNickName(RemotingInterface.UserInfo userInfo)
 {
     if (!IsExistUser(userInfo.PlayId, userInfo.UserPassPortId))
     {
         Loger.Debug("ChangeNickName user [" + userInfo.UserPassPortId + "] dose not in the buffer !");
         return false;
     }
     bool bRet = Common.DBSync.ChangeNickName(userInfo);
     return bRet;
 }
Beispiel #2
0
        /// <summary>
        /// 从数据库中移除用户
        /// </summary>
        /// <param name="userId"></param>
        private void RemoveDBFailUser(RemotingInterface.UserInfo userInfo)
        {
            SqlConnection DelConn = new SqlConnection(BaseConfig.ConnStr);
            try
            {
                if (DelConn.State == ConnectionState.Closed)
                    DelConn.Open();

                SqlCommand sqlCmdDel = new SqlCommand("DELETE FROM  [UserList" + BaseConfig.PlayId + "] WHERE UserId = @UserId", sqlConn);
                sqlCmdDel.Parameters.Add("@UserId", SqlDbType.Int);
                sqlCmdDel.Parameters["@UserId"].Value = userInfo.UserId;
                sqlCmdDel.ExecuteNonQuery();
                Loger.Debug(" Remove userId = :" + userInfo.UserId);
                Common.userBuffer.RemoveUserInfo(userInfo);
            }
            catch (Exception err)
            {
                Loger.Debug("RemoveDBFailUser :userId =" + userInfo.UserId + "\t" + err.ToString());
            }
            finally
            {
                if (DelConn.State != ConnectionState.Closed)
                    DelConn.Close();
            }
        }
Beispiel #3
0
        public bool ChangeNickName(RemotingInterface.UserInfo User)
        {
            try
            {
                if (BaseConfig.bAllowReg == false)
                    return false;

                if (User.UserPassPortId == "" || User.PlayId <= 0 || User.AreaId <= 0)
                    return false;

                if (sqlConn.State == ConnectionState.Closed)
                    sqlConn.Open();

                //先在数据库中查找指定的用户信息
                sqlCmd = new SqlCommand("SELECT AreaId,UserName,UserDataBase FROM [UserList" + BaseConfig.PlayId + "] WHERE AreaId = @AreaId AND UserName = @UserName AND Validity = 1 ", sqlConn);
                sqlCmd.Parameters.Add("@AreaId", SqlDbType.Int); sqlCmd.Parameters["@AreaId"].Value = User.AreaId;
                sqlCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@UserName"].Value = User.UserPassPortId;
                sqlReader = sqlCmd.ExecuteReader();
                if (sqlReader.Read())
                {
                    sqlReader.Close();

                    //加入数据库
                    sqlCmd = new SqlCommand("UPDATE [UserList" + BaseConfig.PlayId + "] SET NickName = @NickName WHERE AreaId = @AreaId AND UserName = @UserName AND Validity = 1 ", sqlConn);
                    sqlCmd.Parameters.Add("@AreaID", SqlDbType.Int); sqlCmd.Parameters["@AreaID"].Value = User.AreaId;
                    sqlCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@UserName"].Value = User.UserPassPortId;
                    sqlCmd.Parameters.Add("@NickName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@NickName"].Value = User.UserNickName;
                    sqlCmd.ExecuteNonQuery();

                    RemotingInterface.UserInfo urkUser = new RemotingInterface.UserInfo();
                    urkUser.Clear();
                    urkUser.PlayId = User.PlayId;
                    urkUser.GameId = User.GameId;
                    urkUser.AreaId = User.AreaId;
                    urkUser.UserPassPortId = User.UserPassPortId;
                    urkUser.UserNickName = User.UserNickName;
                    urkUser.UserDataBase = BaseConfig.mapNotifySrv[urkUser.PlayId][BaseConfig.CurrentRmtServerKey].DataBaseChar;

                    #region 注册通知
                    try
                    {
                        //加入用户缓存
                        if (Common.userBuffer != null)
                        {
                            Common.userBuffer.ChangeNickName(urkUser);
                            Loger.Debug("NickName Changed. userId " + "\t userName = "******"注册失败 userName = " + User.UserPassPortId);
                Loger.Debug(err.ToString());
                if (!sqlReader.IsClosed)
                    sqlReader.Close();
                return false;
            }
            finally
            {
                if (sqlConn.State != ConnectionState.Closed)
                    sqlConn.Close();
            }
        }
Beispiel #4
0
        /// <summary>
        /// 将用户信息加入用户内存,并将新用户加入新用户队列
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        public bool AddNewUser(RemotingInterface.UserInfo User)
        {
            try
            {
                if (BaseConfig.bAllowReg == false)
                    return false;

                if (User.UserPassPortId == "" || User.PlayId <= 0 || User.AreaId <= 0)
                    return false;

                if (sqlConn.State == ConnectionState.Closed)
                    sqlConn.Open();

                //先在数据库中查找指定的用户信息
                sqlCmd = new SqlCommand("SELECT AreaId,UserName,UserDataBase FROM [UserList" + BaseConfig.PlayId + "] WHERE AreaId = @AreaId AND UserName = @UserName AND Validity = 1 ", sqlConn);
                sqlCmd.Parameters.Add("@AreaId", SqlDbType.Int); sqlCmd.Parameters["@AreaId"].Value = User.AreaId;
                sqlCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@UserName"].Value = User.UserPassPortId;
                sqlReader = sqlCmd.ExecuteReader();
                if (sqlReader.Read())
                {
                    sqlReader.Close();
                    return false;
                }
                else  //未找到则添加
                {
                    sqlReader.Close();

                    //为用户分配撮合交易服务器
#if DEBUG
                    #region 轮循
                    if (!Regex.IsMatch(BaseConfig.CurrentRmtServerKey, "[A-K]"))
                    {
                        BaseConfig.CurrentRmtServerKey = "K";
                    }
                    char chrBaseChar = char.Parse(BaseConfig.CurrentRmtServerKey);
                    int nBaseChar = (int)'A';
                    int nOffSet = (int)chrBaseChar - nBaseChar;
                    int nNextOffSet = (nOffSet + 1) % BaseConfig.RmtNumber;
                    char chrCurr = (char)(nBaseChar + nNextOffSet);

                    BaseConfig.CurrentRmtServerKey = chrCurr.ToString();
                    #endregion
#else
                    #region 随机 
                    Random rd = new Random();
                    int nDataBaseChar = rd.Next(0, BaseConfig.RmtNumber);

                    int nBaseChar = (int)'A';
                    BaseConfig.CurrentRmtServerKey = ((char)(nDataBaseChar + nBaseChar)).ToString();
                    #endregion
#endif
                    //加入数据库
                    sqlCmd = new SqlCommand("INSERT INTO [UserList" + BaseConfig.PlayId + "] (AreaID, UserName, NickName, UserDataBase,Rtime,RIP) VALUES (@AreaID, @UserName, @NickName, @UserDataBase,@Rtime,@RIP) SELECT @@IDENTITY", sqlConn);
                    sqlCmd.Parameters.Add("@AreaID", SqlDbType.Int); sqlCmd.Parameters["@AreaID"].Value = User.AreaId;
                    sqlCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@UserName"].Value = User.UserPassPortId;
                    sqlCmd.Parameters.Add("@NickName", SqlDbType.VarChar, 32); sqlCmd.Parameters["@NickName"].Value = User.UserNickName;
                    sqlCmd.Parameters.Add("@UserDataBase", SqlDbType.VarChar, 16); sqlCmd.Parameters["@UserDataBase"].Value = BaseConfig.mapNotifySrv[User.PlayId][BaseConfig.CurrentRmtServerKey].DataBaseChar;
                    sqlCmd.Parameters.Add("@Rtime", SqlDbType.DateTime); sqlCmd.Parameters["@Rtime"].Value = User.Rtime;
                    sqlCmd.Parameters.Add("@RIP", SqlDbType.VarChar, 16); sqlCmd.Parameters["@RIP"].Value = User.RIP;
                    int cRet = Convert.ToInt32(sqlCmd.ExecuteScalar());

                    RemotingInterface.UserInfo urkUser = new RemotingInterface.UserInfo();
                    urkUser.Clear();
                    urkUser.UserId = cRet;
                    urkUser.PlayId = User.PlayId;
                    urkUser.GameId = User.GameId;
                    urkUser.AreaId = User.AreaId;
                    urkUser.UserPassPortId = User.UserPassPortId;
                    urkUser.UserNickName = User.UserNickName;
                    urkUser.UserDataBase = BaseConfig.mapNotifySrv[urkUser.PlayId][BaseConfig.CurrentRmtServerKey].DataBaseChar;

                    #region 注册通知
                    try
                    {
                        //撮合系统接口
                        zns.Result flag = Common.znRmtIobj[User.PlayId][BaseConfig.CurrentRmtServerKey].PostUserData(cRet);
                        if (flag ==zns.Result.Existent_User)
                        {
                            Loger.Debug("撮合系统中存在该用户 userId = " + User.UserPassPortId + " status = " + flag);
                        }
                        else  if (flag!=zns.Result.Success)
                        {
                            Loger.Debug("用户加入撮合系统失败 userId = " + User.UserId + " status = " + flag);
                            RemoveDBFailUser(urkUser);
                            return false;
                        }

                        //加入用户缓存
                        if (Common.userBuffer != null)
                        {
                            Common.userBuffer.SetUserInfo(urkUser);
                            Loger.Debug("完成注册 userId = " + cRet.ToString() + "\t userName = "******"\t DataBase =" + urkUser.UserDataBase);
                        }
                    }
                    catch (Exception ex)
                    {
                        Loger.Debug("通知失败");
                        RemoveDBFailUser(urkUser);
                        Loger.Debug(ex.ToString());
                    }



                    #endregion

                }
                return true;
            }
            catch (Exception err)
            {
                Loger.Debug("注册失败 userName = " + User.UserPassPortId);
                Loger.Debug(err.ToString());
                if (!sqlReader.IsClosed)
                    sqlReader.Close();
                return false;
            }
            finally
            {
                if (sqlConn.State != ConnectionState.Closed)
                    sqlConn.Close();
            }
        }
Beispiel #5
0
 public bool RemoveUserInfo(RemotingInterface.UserInfo userInfo)
 {
     try
     {
         if (userInfo.AreaId <= 0)
         {
             return false;
         }
         if (string.IsNullOrEmpty(userInfo.UserPassPortId))
         {
             return false;
         }
         lock (mapUser)
         {
             if (mapUser.ContainsKey(userInfo.AreaId))
             {
                 if (mapUser[userInfo.AreaId].ContainsKey(userInfo.UserPassPortId))
                 {
                     mapUser[userInfo.AreaId].Remove(userInfo.UserPassPortId);
                     Loger.Debug(" remove cache success , userName = "******"remove user error : userName = "******" error : " + err.ToString());
         return false;
     }
 }
Beispiel #6
0
        public bool ChangeNickName(RemotingInterface.UserInfo userInfo)
        {
            try
            {
                if (userInfo.AreaId <= 0)
                {
                    return false;
                }
                if (string.IsNullOrEmpty(userInfo.UserPassPortId))
                {
                    return false;
                }
                lock (mapUser)
                {
                    if (!mapUser.ContainsKey(userInfo.AreaId))
                    {
                        return false;
                    }

                    if (!mapUser[userInfo.AreaId].ContainsKey(userInfo.UserPassPortId))
                    {
                        return false;
                    }

                    mapUser[userInfo.AreaId][userInfo.UserPassPortId] = userInfo;
                    return true;
                }
            }
            catch (Exception err)
            {
                Loger.Debug("NickName change error : " + err.ToString());
                return false;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 用户信息加入用户缓存表
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool SetUserInfo(RemotingInterface.UserInfo userInfo)
        {
            try
            {
                if (userInfo.AreaId <= 0)
                {
                    return false;
                }
                if (string.IsNullOrEmpty(userInfo.UserPassPortId))
                {
                    return false;
                }
                lock (mapUser)
                {

                    if (!mapUser.ContainsKey(userInfo.AreaId))
                    {
                        Dictionary<string, RemotingInterface.UserInfo> mapTempUser = new Dictionary<string, RemotingInterface.UserInfo>();
                        mapTempUser[userInfo.UserPassPortId] = userInfo;
                        mapUser.Add(userInfo.AreaId, mapTempUser);
                    }
                    else
                    {
                        if (!mapUser[userInfo.AreaId].ContainsKey(userInfo.UserPassPortId))
                        {
                            mapUser[userInfo.AreaId].Add(userInfo.UserPassPortId, userInfo);
                        }
                    }
                    return true;
                }
            }
            catch (Exception err)
            {
                Loger.Debug("SetUserInfo error : " + err.ToString());
                return false;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 检测用户是否存在,如果存在则返回该用户信息
        /// </summary>
        /// <param name="playId">活动ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="userInfo">用户信息</param>
        /// <returns></returns>
        public bool IsExistUser(int playId, string userName, out RemotingInterface.UserInfo userInfo)
        {
            userInfo = new RemotingInterface.UserInfo();
            userInfo.Clear();
            try
            {
                Dictionary<int, Dictionary<string, RemotingInterface.UserInfo>> mapTempUser = null;
                mapTempUser = new Dictionary<int, Dictionary<string, RemotingInterface.UserInfo>>(mapUser);
                if (mapTempUser == null)
                    return false;

                foreach (KeyValuePair<int, Dictionary<string, RemotingInterface.UserInfo>> amap in mapTempUser)
                {
                    foreach (KeyValuePair<string, RemotingInterface.UserInfo> umap in amap.Value)
                    {
                        if (playId == umap.Value.PlayId && userName == umap.Value.UserPassPortId)
                        {
                            userInfo = umap.Value;
                            return true;
                        }
                    }
                }

                return false;
            }
            catch (Exception err)
            {
                Loger.Debug("IsExistUser(int playId, string userName,out RemotingInterface.UserInfo userInfo) error :" + err.ToString());
                return false;
            }
        }
Beispiel #9
0
        public bool RequestNewUser(string strRemoteKey,RemotingInterface.UserInfo userInfo)
        {
            try
            {
                if (BaseConfig.bAllowReg == false)
                    return false;

                if (userInfo.AreaId<=0 || userInfo.UserPassPortId.Length<=0)
                {
                    Loger.Debug("userInfo areaId or UserPassPortId error ");
                    return false;
                }

                if (IsExistUser(userInfo.PlayId, userInfo.UserPassPortId))
                {
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": 用户 [ " + userInfo.UserPassPortId + " ] 已经存在");
                    return false;
                }

                bool bRet = Common.DBSync.AddNewUser(userInfo);
                return bRet;
            }
            catch
            {
                return false;
            }
        }
Beispiel #10
0
 static BaseConfig()
 {
     RegUserRemotingUrl = ConfigurationManager.AppSettings["RegUserRemotingUrl"];
     remoteUserRegObj = Activator.GetObject(typeof(RemotingInterface), RegUserRemotingUrl) as RemotingInterface;
     strRegUserRemoteKey = "testRemoteKey";
 }