void ReplyChannelMessage(MessageUserToken userToken, ChatMessage cm) { var channelMsg = ConvertHelper.Deserialize <ChannelMessage>(cm.Content); if (channelMsg != null && !string.IsNullOrEmpty(channelMsg.Name)) { channelMsg.Sender = userToken.ID; channelMsg.Sended = DateTimeHelper.ToString(); var channel = _channelList.Get(channelMsg.Name); if (channel != null && channel.Members != null) { lock (_channelList.SyncLocker) { var ccm = new ChatMessage(ChatMessageType.ChannelMessage, ConvertHelper.Serialize(channelMsg)); var data = ConvertHelper.PBSerialize(cm); var sp = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); Parallel.ForEach(channel.Members, (m) => { if (m.ID != userToken.ID) { var r = SessionManager.Get(m.ID); if (r != null) { SendAsync(r, sp); } } }); } } } }
void ReplyBase(IUserToken userToken, ChatMessage cm) { var data = ConvertHelper.PBSerialize(cm); var sp = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); SendAsync(userToken, sp); }
private void SendBase(ChatMessage cm) { var data = ConvertHelper.PBSerialize(cm); var content = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); this.Send(content); Actived = DateTimeHelper.Now; }
void ReplyGroupMessage(MessageUserToken userToken, ChatMessage cm) { ReplyBase(userToken, new ChatMessage(ChatMessageType.GroupMessageAnswer, "")); var groupMsg = cm.GetIMessage <GroupMessage>(); if (groupMsg != null && !string.IsNullOrEmpty(groupMsg.Name)) { groupMsg.Sender = userToken.ID; groupMsg.Sended = DateTimeHelper.ToString(); var group = _groupList.Get(groupMsg.Name); if (group != null && group.Members != null) { lock (_groupList.SyncLocker) { var ccm = new ChatMessage(ChatMessageType.GroupMessage, groupMsg); var data = ConvertHelper.PBSerialize(cm); var sp = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); Parallel.ForEach(group.Members, (m) => { if (m.ID != userToken.ID) { var r = SessionManager.Get(m.ID); if (r != null) { SendAsync(r, sp); } } }); } } } }