Exemplo n.º 1
0
 public void Save(PirateSession session)
 {
     if (_sessionDic.ContainsKey(session.Id))
     {
         _sessionDic[session.Id] = session;
     }
 }
Exemplo n.º 2
0
        public void Save(PirateSession session)
        {
            var urn = GetUrnOnlineRole(session.Id);
            var db  = _connectionMultiplexer.GetDatabase();

            db.StringSet(urn, Serializer.Serilazer(session), Expiry);
        }
Exemplo n.º 3
0
        public virtual PirateSession ToSession(ActorContext context, IToken token)
        {
            var session = new PirateSession
            {
                SessionId       = context.SessionId,
                Id              = token.Rid,
                Did             = token.Did,
                Token           = context.Request.Token,
                Uid             = token.Uid,
                StartTimestamp  = DateTime.UtcNow.GetTimestampAsSecond(),
                ResponseConvert = context.ResponseCovnert,
                ServerName      = context.ServerName,
                FrontendID      = context.FrontendID,
            };

            return(session);
        }
Exemplo n.º 4
0
        public void Login(PirateSession pirateSession)
        {
            if (pirateSession == null)
            {
                return;
            }

            if (pirateSession.Id <= 0)
            {
                return;
            }

            var urn = GetUrnOnlineRole(pirateSession.Id);

            var db = _connectionMultiplexer.GetDatabase();

            db.StringSet(urn, Serializer.Serilazer(pirateSession), Expiry);
            db.StringSet(GetUrnOnlineRole(pirateSession.SessionId), urn, Expiry);
            db.HashSet(GetDidUrn(pirateSession.Did), Convert.ToString(pirateSession.Id), urn);
        }
Exemplo n.º 5
0
        public void PushMessage <T>(PirateSession session, T t)
        {
            var headers = new NameValueCollection
            {
                { "c", typeof(T).Name },
                { "i", MessageType.Boradcast },
                { "format", DefaultResponseCovnert } // TODO 默认解析器
            };

            if (Equals(DefaultResponseCovnert, "protobuf"))
            {
                headers["responsetype"] = typeof(T).Name;
            }


            if (Logger.IsDebugEnabled && t != null)
            {
                Logger.Debug($"S2C PUSH #{session.Id}# {string.Join("&", headers.AllKeys.Select(a => a + "=" + headers[a]))} {JsonConvert.SerializeObject(t)}");
            }

            ActorNetService.PushMessage(session.FrontendID, headers, DistrictContainer.ServerIoc.ResolveKeyed <IResponseConvert>(DefaultResponseCovnert).SerializeObject(t));
        }
Exemplo n.º 6
0
 public void Login(PirateSession pirateSession)
 {
     _sessionDic.AddOrUpdate(pirateSession.Id, pirateSession, (l, session) => pirateSession);
     _sessionidDic.AddOrUpdate(pirateSession.SessionId, pirateSession.Id, (s, l) => pirateSession.Id);
 }
Exemplo n.º 7
0
 public virtual void OnSessionConnected(PirateSession session)
 {
     OnlineCount++;
 }
Exemplo n.º 8
0
        ///// <summary>
        ///// 多线程处理请求
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected override void ProcessTaskPullSocket(object sender, NetMQSocketEventArgs e)
        //{
        //    var msg = e.Socket.ReceiveMultipartMessage();
        //    if(Logger.IsDebugEnabled)
        //        Logger.Debug($"Pull,ActorService[{_id}],ThreadID:{Thread.CurrentThread.ManagedThreadId}");

        //    Task.Factory.StartNew(() => ProcessReceive(msg)).ContinueWith(t =>
        //    {
        //        //发生内部错误
        //        if (Logger.IsErrorEnabled)
        //            Logger.Error(t.Exception);

        //        //发生异常需要处理
        //        //t.Exception
        //    }, TaskContinuationOptions.OnlyOnFaulted);
        //}

        //处理接收

        public virtual void OnSessionClosed(PirateSession session)
        {
            OnlineCount--;
        }