Esempio n. 1
0
        void AddMessageToCache(ChatMessageDTO dto)
        {
            _MessagesCache.Enqueue(dto);

            ChatMessageDTO trash;

            while (_MessagesCache.Count > _NbrMessagesToKeep)
            {
                _MessagesCache.TryDequeue(out trash);
            }
        }
Esempio n. 2
0
        Task OnMessageReceived(Packet <IScenePeerClient> packet)
        {
            var          dto = new ChatMessageDTO();
            ChatUserInfo temp;

            if (_UsersInfos.TryGetValue(packet.Connection.Id, out temp) == false)
            {
                temp          = new ChatUserInfo();
                temp.ClientId = packet.Connection.Id;
                temp.User     = "";
            }
            dto.UserInfo  = temp;
            dto.Message   = packet.ReadObject <string>();
            dto.TimeStamp = _env.Clock;

            AddMessageToCache(dto);

            _scene.Broadcast("chat", dto, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE);

            return(Task.FromResult(true));
        }
Esempio n. 3
0
        Task OnDisconnected(DisconnectedArgs args)
        {
            if (_UsersInfos.ContainsKey(args.Peer.Id) == true)
            {
                ChatUserInfo temp;
                _UsersInfos.TryRemove(args.Peer.Id, out temp);

                ChatMessageDTO dto = new ChatMessageDTO();
                dto.UserInfo = temp;
                dto.Message  = args.Reason;
                foreach (IScenePeerClient clt in _scene.RemotePeers)
                {
                    if (clt.Routes.Select(x => x.Name == "DiscardInfo").Any())
                    {
                        clt.Send <ChatMessageDTO>("DiscardInfo", dto, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE);
                    }
                }
                ;
            }
            return(Task.FromResult(true));
        }