예제 #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)
                    {
                        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 { }
                        }
                    }
                }
            }
        }
예제 #2
0
파일: MessageServer.cs 프로젝트: ywscr/SAEA
        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);
                            }
                        });
                    }
                }
            }
        }
예제 #3
0
파일: MessageServer.cs 프로젝트: ywscr/SAEA
        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);
                        }
                    });
                }
            }
        }
예제 #4
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);
                                }
                            }
                        });
                    }
                }
            }
        }
예제 #5
0
        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));
        }
예제 #6
0
        void ReplyRemoveGroup(MessageUserToken userToken, ChatMessage cm)
        {
            string result = "0";

            if (_groupList.Remove(cm.Content))
            {
                result = "1";
            }

            ReplyBase(userToken, new ChatMessage(ChatMessageType.RemoveGroupAnswer, result));
        }
예제 #7
0
        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));
        }
예제 #8
0
        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));
        }
예제 #9
0
        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)));
                }
            }
        }
예제 #10
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)
                    {
                        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 { }
                        }
                    }
                }
            }
        }
예제 #11
0
        void ReplyLogin(MessageUserToken userToken, ChatMessage cm)
        {
            userToken.Logined = DateTimeHelper.Now;

            ReplyBase(userToken, new ChatMessage(ChatMessageType.LoginAnswer, ""));
        }