Esempio n. 1
0
        public async Task GetUserInfo(ChatUserInfoCtx ctx)
        {
            Session s = await _userSession.GetSession(ctx.PeerId);

            if (s == null)
            {
                throw new InvalidOperationException("Error occured when ChatEventHandler try to get a specific user");
            }
            else
            {
                ctx.User = s.User;
            }
        }
Esempio n. 2
0
        // Todo jojo : vérifier avec JN ou JM comment faire pour la gestion des ban et des erreurs lors du get info
        // Pour ne pas ajouter un utilisatuer alors qu'il est déjà connecté
        // Todo jojo : ajouter une métadata pour mettre la/les raisons de l'erreur
        private async Task OnConnected(IScenePeerClient clientPeer)
        {
            ChatUserInfoDto connectingUserInfo = new ChatUserInfoDto {
                PeerId = clientPeer.Id
            };

            ChatUserInfoCtx chatCtx = new ChatUserInfoCtx {
                PeerId = clientPeer.Id
            };

            await _eventUserHandlers?.RunEventHandler(eh => eh.GetUserInfo(chatCtx), ex =>
            {
                _log.Log(LogLevel.Error, _logCategory, "An error occured while running ChatService.GetUserInfo event handlers", ex);
                connectingUserInfo = new ChatUserInfoDto {
                    PeerId = Convert.ToInt64(clientPeer.Id.ToString()), Status = UserStatusDto.Error
                };

                clientPeer.Send("statuschange", (s) => {
                    clientPeer.Serializer().Serialize((int)UserStatusDto.Error, s);
                    clientPeer.Serializer().Serialize(connectingUserInfo, s);
                },
                                PacketPriority.MEDIUM_PRIORITY,
                                PacketReliability.RELIABLE
                                );
            });

            //Send list of connected user
            if (!_connectedUsers.Any(x => x.Value.PeerId == connectingUserInfo.PeerId))
            {
                connectingUserInfo.UserId = chatCtx.User.Id;
                connectingUserInfo.Status = UserStatusDto.Connected;
                connectingUserInfo.Data   = chatCtx.User.UserData.ToString();

                _connectedUsers.TryAdd(clientPeer, connectingUserInfo);
                List <ChatUserInfoDto> usersInChat = _connectedUsers.Values.ToList <ChatUserInfoDto>();

                _scene.Broadcast("statuschange", (s) => {
                    clientPeer.Serializer().Serialize((int)UserStatusDto.Connected, s);
                    clientPeer.Serializer().Serialize(usersInChat, s);
                });
            }
        }