private void SendUnreadMessage(AccountSession session) { DateTime lastAccessTime; AccountState state; AccountState state2; lock ((state2 = state = this)) { lastAccessTime = (DateTime)this.GetConfig("MESSAGE.CONF")["LastReceivedTime"]; if (lastAccessTime > this.m_LastAccessTime) { lastAccessTime = this.m_LastAccessTime; } } List <Message> list = MessageImpl.Instance.Find(this.m_User, "*", new DateTime?(lastAccessTime)); string data = string.Empty; if (list.Count > 0) { data = Utility.RenderHashJson(new object[] { "Peer", "*", "Messages", list }); Hashtable config = this.GetConfig("MESSAGE.CONF"); lock (config) { foreach (Message message in list) { DateTime time2 = (DateTime)config["LastReceivedTime"]; if (time2 < message.CreatedTime) { config["LastReceivedTime"] = message.CreatedTime; } } } lock ((state2 = state = this)) { this.SaveConfig(); } } else { data = Utility.RenderHashJson(new object[] { "Peer", "*", "Messages", JsonText.EmptyArray }); } session.Send("GLOBAL:IM_MESSAGE_NOTIFY", data); }
private void SendUnreadMessage(AccountSession session) { try { if (m_UserID == AccountImpl.AdminID) { return; } DateTime from; lock (this) { from = m_LastAccessTime; } List <Message> msgs = MessageImpl.Instance.Find(m_UserID, 0, from); string data = String.Empty; if (msgs.Count > 0) { data = Utility.RenderHashJson( "Peer", 0, "Messages", msgs, "Users", Utility.GetRelUsers(msgs) ); AccountInfo userInfo = AccountImpl.Instance.GetUserInfo(m_UserID); } else { data = Utility.RenderHashJson( "Peer", 0, "Messages", JsonText.EmptyArray, "Users", JsonText.EmptyObject ); } session.Send("GLOBAL:IM_MESSAGE_NOTIFY", data); } catch { } }
public void NewSession(string sessionId) { AccountSession session = null; lock (this) { if (!this.m_Sessions.ContainsKey(sessionId)) { this.m_Sessions[sessionId] = session = new AccountSession(this.m_User, sessionId); } session = this.m_Sessions[sessionId] as AccountSession; ServerImpl.Instance.WriteLog(string.Format("New Session:SessionID = \"{0}\", UserName='******'", sessionId, this.m_User)); } if (session != null) { this.SendUnreadMessage(session); SessionManagement.Instance.Insert(session); } AccountInfo userInfo = AccountImpl.Instance.GetUserInfo(this.UserName); SessionManagement.Instance.Send("UserStateChanged", Utility.RenderHashJson(new object[] { "User", userInfo.Name.ToUpper(), "State", "Online", "Details", userInfo.DetailsJson })); }
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); } }
public AccountSession NewSession(string sessionId) { Status = "Online"; AccountSession session = null; lock (this) { string remove_session = null; foreach (KeyValuePair<String, AccountSession> ent in m_Sessions) { if ((ent.Value as AccountSession).SessionID != sessionId) { (ent.Value as AccountSession).Send("GLOBAL:OFFLINE", null); remove_session = (ent.Value as AccountSession).SessionID; } } if (!String.IsNullOrEmpty(remove_session)) { m_Sessions.Remove(remove_session); } if (!m_Sessions.ContainsKey(sessionId)) { m_Sessions[sessionId] = (session = new AccountSession(m_UserID, sessionId)); } session = m_Sessions[sessionId] as AccountSession; # if TRACE ServerImpl.Instance.WriteLog(String.Format("New Session:SessionID = \"{0}\", UserID=\'{1}\'", sessionId, m_UserID)); # endif } if (session != null) { SendUnreadMessage(session); SessionManagement.Instance.Insert(session); } lock (this) { m_LastAccessTime = DateTime.Now; UpdateLastAccessTime(); } AccountInfo info = AccountImpl.Instance.GetUserInfo(UserID); SessionManagement.Instance.Send("UserStateChanged", Utility.RenderHashJson("User", info.ID, "State", "Online", "Details", info.DetailsJson)); return session; }
public ClearSessionNode(string username, string sessionid, AccountSession session) { this._userName = username; this._sessionID = sessionid; this._session = session; }