Esempio n. 1
0
        private bool CheckSpecialPackge(RequestPackage package, GameSession session)
        {
            //处理特殊包
            if (package.ActionId == ((int)ActionEnum.Interrupt))
            {
                //Proxy server notifly interrupt connect ops
                OnDisconnected(session);
                if (session != null && (session.ProxySid == Guid.Empty || GameSession.Count > 1))
                {
                    //保留代理服连接
                    session.Close();
                    session.ProxySid = Guid.Empty;
                }
                return(true);
            }

            if (package.ActionId == ((int)ActionEnum.Heartbeat))
            {
                if (session != null)
                {
                    // 客户端tcp心跳包
                    session.Refresh();
                    OnHeartbeat(session);
                    session.ExitSession();
                }
                return(true);
            }
            return(false);
        }
Esempio n. 2
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();
         }
     }
 }
Esempio n. 3
0
        private void ProcessPackage(RequestPackage package, GameSession session)
        {
            if (package == null)
            {
                return;
            }

            try
            {
                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);
                    }
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("PostSend error:{0}", ex);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Task error:{0}", ex);
            }
            finally
            {
                if (session != null)
                {
                    session.ExitSession();
                }
            }
        }
Esempio n. 4
0
        private bool CheckSpecialPackge(RequestPackage package, GameSession session)
        {
            //处理特殊包
            if (package.ActionId == ((int)ActionEnum.Interrupt))
            {
                //Proxy server notifly interrupt connect ops
                OnDisconnected(session);
                if (session != null && (session.ProxySid == Guid.Empty || GameSession.Count > 1))
                {
                    //保留代理服连接
                    session.Close();
                    session.ProxySid = Guid.Empty;
                }
                return true;
            }

            if (package.ActionId == ((int)ActionEnum.Heartbeat))
            {
                // 客户端tcp心跳包
                session.Refresh();
                OnHeartbeat(session);
                session.ExitSession();
                Interlocked.Decrement(ref runningNum);
                return true;
            }
            return false;
        }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="package"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        protected virtual bool CheckSpecialPackge(RequestPackage package, GameSession session)
        {
            //处理特殊包
            if (package.ActionId == ((int)ActionEnum.Interrupt))
            {
                //Proxy server notifly interrupt connect ops
                OnDisconnected(session);
                if (session != null && (session.ProxySid == Guid.Empty || GameSession.Count > 1))
                {
                    //保留代理服连接
                    session.Close();
                    session.ProxySid = Guid.Empty;
                }
                return true;
            }

            if (package.ActionId == ((int)ActionEnum.Heartbeat))
            {
                if (session != null)
                {
                    // 客户端tcp心跳包
                    session.Refresh();
                    OnHeartbeat(session);
                    BuildHearbeatPackage(package, session);
                    session.ExitSession();
                }
                return true;
            }
            return false;
        }
Esempio n. 6
0
        private async System.Threading.Tasks.Task ProcessPackage(RequestPackage package, GameSession session)
        {
            if (package == null) return;

            try
            {
                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)
                    {
                        await session.SendAsync(actionGetter.OpCode, data, 0, data.Length, OnSendCompleted);
                    }
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("PostSend error:{0}", ex);
                }

            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Task error:{0}", ex);
            }
            finally
            {
                if (session != null) session.ExitSession();
            }
        }