Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="receiveParam"></param>
        /// <param name="periodTime"></param>
        /// <param name="isReplace"></param>
        /// <returns></returns>
        protected bool TryLoadRankCache(string key, TransReceiveParam receiveParam, int periodTime, bool isReplace)
        {
            //todo: trace
            var watch = RunTimeWatch.StartNew(string.Format("Try load rank cache:{0}-{1}", receiveParam.Schema.EntityType.FullName, key));

            try
            {
                List <T> dataList;
                if (DataContainer.TryReceiveData(receiveParam, out dataList))
                {
                    CacheItemSet itemSet;
                    DataContainer.TryGetOrAddRank(key, out itemSet, periodTime);
                    watch.Check("received count:" + dataList.Count);
                    InitCache(dataList, periodTime, isReplace);
                    watch.Check("Init cache:");
                    itemSet.OnLoadSuccess();
                    return(true);
                }
            }
            finally
            {
                watch.Flush(true, 20);
            }
            TraceLog.WriteError("Try load cache data:{0} error.", typeof(T).FullName);
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 加载Enity数据
        /// </summary>
        /// <param name="receiveParam"></param>
        /// <param name="periodTime"></param>
        /// <param name="isReplace"></param>
        /// <returns></returns>
        protected bool TryLoadCache(TransReceiveParam receiveParam, int periodTime, bool isReplace)
        {
            //todo: trace TryLoadCache
            var watch = RunTimeWatch.StartNew(string.Format("Try load cache data:{0}", receiveParam.Schema.EntityType.FullName));

            try
            {
                List <T> dataList;
                if (DataContainer.TryReceiveData(receiveParam, out dataList))
                {
                    watch.Check("received count:" + dataList.Count, 20);
                    if (dataList.Count == 0)
                    {
                        return(true);
                    }
                    return(InitCache(dataList, periodTime, isReplace));
                }
            }
            catch (Exception ex)
            {
                string name = receiveParam.Schema != null ? receiveParam.Schema.EntityName : typeof(T).FullName;
                TraceLog.WriteError("Try load cache \"{0}\" data error:{1}", name, ex);
            }
            finally
            {
                watch.Flush(false, 500);
            }
            return(false);
        }
Exemple #3
0
 public void ProcessPackage(RequestPackage package, GameSession session)
 {
     if (package == null)
     {
         return;
     }
     try
     {
         var          watch = RunTimeWatch.StartNew(string.Format("当前线程{0},{1}协议执行时间", Thread.CurrentThread.ManagedThreadId, package.ActionId));
         ActionGetter actionGetter;
         byte[]       data = new byte[0];
         if (!string.IsNullOrEmpty(package.RouteName))
         {
             actionGetter = ActionDispatcher.GetActionGetter(package, session);
             if (CheckRemote(package.RouteName, actionGetter))
             {
                 MessageStructure response = new MessageStructure();
                 OnCallRemote(package.RouteName, actionGetter, response);
                 data = response.PopBuffer();
             }
             else
             {
                 return;
             }
         }
         else
         {
             SocketGameResponse response = new SocketGameResponse();
             response.WriteErrorCallback += ActionDispatcher.ResponseError;
             actionGetter = ActionDispatcher.GetActionGetter(package, session);
             DoAction(actionGetter, response);
             data = response.ReadByte();
         }
         try
         {
             if (session != null && data.Length > 0)
             {
                 session.SendAsync(actionGetter.OpCode, data, 0, data.Length, OnSendCompleted);
             }
         }
         catch (Exception ex)
         {
             TraceLog.WriteError("PostSend error:{0}", ex);
         }
         watch.Flush(true);
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Task error:{0}", ex);
     }
     finally
     {
         if (session != null)
         {
             session.ExitSession();
         }
     }
 }
        /// <summary>
        /// 子类实现Action处理
        /// </summary>
        /// <returns></returns>
        public override bool TakeAction()
        {
            ILogin login = CreateLogin();

            login.Password = DecodePassword(login.Password);
            //todo: login test
            var watch = RunTimeWatch.StartNew("Request login server");

            try
            {
                Sid = string.Empty;
                if (login.CheckLogin())
                {
                    watch.Check("GetResponse");

                    ////Current.SetExpired();    // modify by xiejin
                    ////Current = GameSession.CreateNew(Guid.NewGuid());
                    Sid        = Current.SessionId;//create new
                    PassportId = login.PassportID;
                    UserType   = login.UserType;
                    SetParameter(login);
                    int   userId = login.UserID.ToInt();
                    IUser user;
                    if (!GetError() && DoSuccess(userId, out user))
                    {
                        watch.Check("DoSuccess");
                        var session = GameSession.Get(Sid);
                        if (session != null)
                        {
                            //user is null in create role.
                            session.Bind(user ?? new SessionUser()
                            {
                                PassportId = PassportId, UserId = userId
                            });
                            return(true);
                        }
                    }
                }
                else
                {
                    DoLoginFail(login);
                }
            }
            catch (HandlerException error)
            {
                ErrorCode = (int)error.StateCode;
                ErrorInfo = error.Message;
            }
            finally
            {
                watch.Flush(true, 100);
            }
            return(false);
        }
Exemple #5
0
        public ResponseData Excute(LoginInfo data)
        {
            int    userId;
            int    userType;
            string passportId;

            if (!string.IsNullOrEmpty(data.RetailUser) && !string.IsNullOrEmpty(data.RetailToken))
            {
                ILogin login = LoginProxy.GetLogin(data.RetailID, data);
                login.Password = DecodePassword(login.Password);
                var watch = RunTimeWatch.StartNew("Request login server");
                try
                {
                    if (login.CheckLogin())
                    {
                        watch.Check("GetResponse");
                        userId     = int.Parse(login.UserID);
                        passportId = login.PassportID;
                        userType   = login.UserType;
                    }
                    else
                    {
                        //DoLoginFail();
                        throw new HandlerException(StateCode.Error, StateDescription.PassworkError);
                    }
                }
                finally
                {
                    watch.Flush(true, 100);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(data.Pwd) || data.Pwd.Length < 5)
                {
                    throw new HandlerException(StateCode.Error, StateDescription.PassworkLengthError);
                }
                data.Pwd = DecodePassword(data.Pwd);
                //快速登录
                RegType regType;
                userId = SnsManager.LoginByDevice(data.Pid, data.Pwd, data.DeviceID, out regType, data.IsCustom);
                if (userId <= 0)
                {
                    throw new HandlerException(StateCode.PassworkError, StateDescription.PassworkError);
                }
                passportId = data.Pid;
                userType   = (int)regType;
            }

            return(AuthorizeLogin(userId, passportId, userType));
        }
Exemple #6
0
        /// <summary>
        /// 子类实现Action处理
        /// </summary>
        /// <returns></returns>
        public override bool TakeAction()
        {
            ILogin login = CreateLogin();

            login.Password = DecodePassword(login.Password);
            //todo: login test
            var watch = RunTimeWatch.StartNew("Request login server");

            try
            {
                Sid = string.Empty;
                if (login.CheckLogin())
                {
                    watch.Check("GetResponse");

                    //Current.SetExpired();
                    //Current = GameSession.CreateNew(Guid.NewGuid());
                    Sid        = Current.SessionId;//create new
                    PassportId = login.PassportID;
                    UserType   = login.UserType;
                    SetParameter(login);
                    var   accountId = login.UserID.ToLong();
                    IUser user;
                    if (!GetError() && DoSuccess(accountId, out user))
                    {
                        watch.Check("DoSuccess");
                        OnAuthorized(Sid, user);
                        return(true);
                    }
                }
                else
                {
                    DoLoginFail(login);
                }
            }
            catch (HandlerException error)
            {
                ErrorCode = (int)error.StateCode;
                ErrorInfo = error.Message;
            }
            finally
            {
                watch.Flush(true, 100);
            }
            return(false);
        }