Example #1
0
        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);
                                }
                            }
                        });
                    }
                }
            }
        }
Example #2
0
        void ReplyBase(IUserToken userToken, ChatMessage cm)
        {
            var data = ConvertHelper.PBSerialize(cm);

            var sp = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes();

            SendAsync(userToken, sp);
        }
Example #3
0
        private void SendBase(ChatMessage cm)
        {
            var data = ConvertHelper.PBSerialize(cm);

            var content = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes();

            this.Send(content);

            Actived = DateTimeHelper.Now;
        }
Example #4
0
        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);
                                }
                            }
                        });
                    }
                }
            }
        }