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) { foreach (var m in channel.Members) { try { if (m.ID != userToken.ID) { var r = SessionManager.Get(m.ID); if (r != null) { ReplyBase(r, new ChatMessage(ChatMessageType.ChannelMessage, ConvertHelper.Serialize(channelMsg))); } } } catch { } } } } } }
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 = SerializeHelper.PBSerialize(cm); var sp = BaseSocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); Parallel.ForEach(group.Members, (m) => { if (m.ID != userToken.ID) { _server.SendAsync(m.ID, sp); } }); } } } }
void ReplyChannelMessage(MessageUserToken userToken, ChatMessage cm) { var channelMsg = SerializeHelper.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) { var members = channel.Members.ToArray(); var ccm = new ChatMessage(ChatMessageType.ChannelMessage, SerializeHelper.Serialize(channelMsg)); var data = SerializeHelper.PBSerialize(ccm); var sp = BaseSocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes(); Parallel.ForEach(members, (m) => { if (m.ID != userToken.ID) { _server.SendAsync(m.ID, sp); } }); } } }
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 ReplyRemoveMember(MessageUserToken userToken, ChatMessage cm) { string result = "0"; if (_groupList.Leave(cm.Content, userToken.ID)) { result = "1"; } ReplyBase(userToken, new ChatMessage(ChatMessageType.RemoveMemberAnswer, result)); }
void ReplyRemoveGroup(MessageUserToken userToken, ChatMessage cm) { string result = "0"; if (_groupList.Remove(cm.Content)) { result = "1"; } ReplyBase(userToken, new ChatMessage(ChatMessageType.RemoveGroupAnswer, result)); }
void ReplyCreateGroup(MessageUserToken userToken, ChatMessage cm) { string result = "0"; if (_groupList.Create(cm.Content, userToken.ID)) { result = "1"; } ReplyBase(userToken, new ChatMessage(ChatMessageType.CreateGroupAnswer, result)); }
void ReplyUnsubscribe(MessageUserToken userToken, ChatMessage cm) { string result = "0"; if (_channelList.Unsubscribe(cm.Content, userToken.ID)) { result = "1"; } ReplyBase(userToken, new ChatMessage(ChatMessageType.UnSubscribeAnswer, result)); }
void ReplyPrivateMessage(MessageUserToken userToken, ChatMessage cm) { ReplyBase(userToken, new ChatMessage(ChatMessageType.PrivateMessageAnswer, "")); var privateMessage = ConvertHelper.Deserialize <PrivateMessage>(cm.Content); if (privateMessage != null && !string.IsNullOrEmpty(privateMessage.Receiver)) { privateMessage.Sender = userToken.ID; privateMessage.Sended = DateTimeHelper.ToString(); var r = SessionManager.Get(privateMessage.Receiver); if (r != null) { ReplyBase(r, new ChatMessage(ChatMessageType.PrivateMessage, ConvertHelper.Serialize(privateMessage))); } } }
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) { foreach (var m in group.Members) { try { if (m.ID != userToken.ID) { var r = SessionManager.Get(m.ID); if (r != null) { ReplyBase(r, new ChatMessage(ChatMessageType.GroupMessage, groupMsg)); } } } catch { } } } } } }
void ReplyLogin(MessageUserToken userToken, ChatMessage cm) { userToken.Logined = DateTimeHelper.Now; ReplyBase(userToken, new ChatMessage(ChatMessageType.LoginAnswer, "")); }