/// <summary> /// 插入新的消息,插入消息后将查询m_Listeners中是否有符合条件的监听器,如存在,同时将消息发送出去 /// </summary> public Message NewMessage(int receiver, int sender, String content, Hashtable data, bool isTemp) { AccountInfo senderInfo = AccountImpl.Instance.GetUserInfo(sender); AccountInfo receiverInfo = AccountImpl.Instance.GetUserInfo(receiver); if (senderInfo.ID == AccountImpl.AdminID || receiverInfo.ID == AccountImpl.AdminID) throw new Exception("系统管理员(admin) 不能发送或接受即时消息!"); if (senderInfo == null || receiverInfo == null) throw new Exception("无效的消息接收者,该用户可能已被删除!"); int key = 0; lock (m_Lock) { key = ++m_MaxKey; } if ((senderInfo.IsTemp || receiverInfo.IsTemp) || Custom.ApplicationInfo.FilterHtml) content = HtmlUtil.ReplaceHtml(content); MsgAccessoryEval eval = new MsgAccessoryEval(key, receiverInfo.ID, senderInfo.ID, data); Regex reg = new Regex("{Accessory [^\f\n\r\t\v<>]+}"); content = reg.Replace(content, eval.Replace); lock (m_Lock) { Message message = new Message( senderInfo, receiverInfo, content, new DateTime((DateTime.Now.Ticks / 10000) * 10000), key ); List<Message> messages = new List<Message>(); messages.Add(message); if (isTemp) { message.IsTemp = isTemp; } if (receiverInfo.Type == 1 && receiverInfo.SubType == 3) { string cmdData = Utility.RenderHashJson( "Peer", senderInfo.ID, "Message", message, "Users", Utility.GetRelUsers(message) ); AccountInfo[] users = GetChatRoomUsers(receiverInfo.ID); if (senderInfo.ID != receiverInfo.Creator) { AccountInfo creatorInfo = AccountImpl.Instance.GetUserInfo(receiverInfo.Creator); SessionManagement.Instance.Send(creatorInfo.ID, "GLOBAL:IM_MESSAGE_NOTIFY", cmdData); } foreach (AccountInfo acc in users) { if (acc.ID != senderInfo.ID) SessionManagement.Instance.Send(acc.ID, "GLOBAL:IM_MESSAGE_NOTIFY", cmdData); } } else { if (receiverInfo.Type == 0) { if (SessionManagement.Instance.IsOnline(receiverInfo.ID)) { try { string cmdData = Utility.RenderHashJson( "Peer", senderInfo.ID, "Message", message, "Users", Utility.GetRelUsers(message) ); SessionManagement.Instance.Send(receiverInfo.ID, "GLOBAL:IM_MESSAGE_NOTIFY", cmdData); } catch { } } } else { AccountInfo groupInfo = receiverInfo; foreach (int member in groupInfo.Friends) { try { AccountInfo memberInfo = AccountImpl.Instance.GetUserInfo(member); if (senderInfo.ID != AccountImpl.AdminstratorID && memberInfo.ID == senderInfo.ID) continue; if (memberInfo.ID != 3) { if (SessionManagement.Instance.IsOnline(memberInfo.ID)) { string cmdData = Utility.RenderHashJson( "Peer", groupInfo.ID, "Message", message, "Users", Utility.GetRelUsers(message) ); SessionManagement.Instance.Send(memberInfo.ID, "GLOBAL:IM_MESSAGE_NOTIFY", cmdData); } } } catch { } } } if (!isTemp) { MessageCacheManagement.Instance.Insert(receiver, message); if (MessageCacheManagement.Instance.Count >= MAX_CACHE_COUNT) { WriteCache(); } } } return message; } }
public Message NewMessage(string receiver, string sender, string content, Hashtable data) { lock (this.m_Lock) { Hashtable config; DateTime time; string str; Hashtable hashtable2; Hashtable hashtable3; long key = this.m_MaxKey += 1L; content = HtmlUtil.ReplaceHtml(content); MsgAccessoryEval eval = new MsgAccessoryEval(key, receiver, sender, data); content = new Regex("{Accessory [^\f\n\r\t\v<>]+}").Replace(content, new MatchEvaluator(eval.Replace)); Message item = new Message(AccountImpl.Instance.GetUserInfo(sender), AccountImpl.Instance.GetUserInfo(receiver), content, new DateTime((DateTime.Now.Ticks / 0x2710L) * 0x2710L), key); new List <Message>().Add(item); if (AccountImpl.Instance.GetUserInfo(receiver).Type == 0L) { if (SessionManagement.Instance.IsOnline(receiver)) { try { config = SessionManagement.Instance.GetAccountState(receiver).GetConfig("message.conf"); lock ((hashtable3 = hashtable2 = config)) { time = (DateTime)config["LastReceivedTime"]; config["LastReceivedTime"] = item.CreatedTime; } str = Utility.RenderHashJson(new object[] { "Peer", sender, "Message", item }); SessionManagement.Instance.Send(receiver, "GLOBAL:IM_MESSAGE_NOTIFY", str); } catch { } } } else { AccountInfo userInfo = AccountImpl.Instance.GetUserInfo(receiver); AccountInfo info2 = AccountImpl.Instance.GetUserInfo(sender); foreach (string str2 in userInfo.Friends) { try { AccountInfo info3 = AccountImpl.Instance.GetUserInfo(str2); if (((info2.Name.ToLower() == "administrator") || (info3.ID != info2.ID)) && SessionManagement.Instance.IsOnline(str2)) { config = SessionManagement.Instance.GetAccountState(info3.Name).GetConfig("message.conf"); lock ((hashtable3 = hashtable2 = config)) { time = (DateTime)config["LastReceivedTime"]; config["LastReceivedTime"] = item.CreatedTime; } str = Utility.RenderHashJson(new object[] { "Peer", userInfo.Name, "Message", item }); SessionManagement.Instance.Send(str2, "GLOBAL:IM_MESSAGE_NOTIFY", str); } } catch { } } } MessageCacheManagement.Instance.Insert(receiver, item); if (MessageCacheManagement.Instance.Count >= 4) { this.WriteCache(); } return(item); } }