Esempio n. 1
0
        IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
        {
            m_Context = context;
            string sessionId = context.Request.Params["SessionID"];
            string clientVersion = context.Request.Params["ClientVersion"];
            string serverVersion = context.Request.Params["ServerVersion"];

            ResponsesListener asyncResult = new ResponsesListener(sessionId, cb, extraData);

            try
            {
                if (serverVersion != ServerImpl.Instance.Version) throw new IncompatibleException();
                if (!String.IsNullOrEmpty(clientVersion) && clientVersion != Custom.ApplicationInfo.ReleaseVersion) throw new IncompatibleException();

                int userid = ServerImpl.Instance.GetUserID(context);
                if (userid == 0) throw new UnauthorizedException();

                try
                {
                    if (context.Request.Params["State"] != null)
                    {
                        Hashtable hash_state = Utility.ParseJson(context.Request.Params["State"]) as Hashtable;
                        if (hash_state != null && hash_state.ContainsKey("Status"))
                        {
                            SessionManagement.Instance.MarkStatus(userid, hash_state["Status"].ToString());
                        }
                    }
                }
                catch
                {
                }

                if (SessionManagement.Instance.Receive(userid, sessionId, asyncResult))
                {
                    ThreadPool.QueueUserWorkItem(asyncResult.Complete);
                }
            }
            catch (Exception ex)
            {
                asyncResult.Cache(Utility.RenderHashJson("IsSucceed", false, "Exception", ex));
                ThreadPool.QueueUserWorkItem(asyncResult.Complete);
            }
            return asyncResult;
        }
Esempio n. 2
0
        public bool Receive(ResponsesListener listener)
        {
            lock (_lock)
            {
                _createdTime = DateTime.Now;

                if (_cache.Count > 0)
                {
                    String json = Utility.RenderHashJson("IsSucceed", true, "Responses", _cache);
                    listener.Cache(json);
                    _cache.Clear();
                    return true;
                }
                else
                {
                    _listener = listener;
                    return false;
                }
            }
        }
Esempio n. 3
0
 public void SendCache()
 {
     lock (_lock)
     {
         if (_listener != null)
         {
             try
             {
                 String json = Utility.RenderHashJson("IsSucceed", true, "Responses", _cache);
                 _listener.Cache(json);
                 _cache.Clear();
             }
             finally
             {
                 ThreadPool.QueueUserWorkItem(_listener.Complete);
                 _listener = null;
             }
         }
     }
 }
Esempio n. 4
0
 public bool Receive(int user, string sessionId, ResponsesListener listener)
 {
     return GetAccountState(user).Receive(sessionId, listener);
 }
Esempio n. 5
0
        public bool Receive(string sessionId, ResponsesListener listener)
        {
            bool sendOnline = (m_Sessions.Count == 0);

            AccountSession session = null;
            bool reset = false;

            lock (this)
            {
                if (!m_Sessions.ContainsKey(sessionId))
                {
                    m_Sessions[sessionId] = new AccountSession(m_UserID, sessionId);
                    reset = true;
                }

                session = m_Sessions[sessionId] as AccountSession;
            }

            if (session != null)
            {
                SessionManagement.Instance.Insert(session);
            }

            if (reset)
            {
            #				if TRACE
                ServerImpl.Instance.WriteLog(String.Format("Reset Session:SessionID = \"{0}\", UserID=\'{1}\'", sessionId, m_UserID));
            #				endif

                if (session != null)
                {
                    session.Send("GLOBAL:SessionReset", "null");
                    SendUnreadMessage(session);
                }
            }