Beispiel #1
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            var user = ConnectedUsers.GetByConnectionId(Context.ConnectionId);

            ConnectedUsers.GameUsers.Remove(user);
            await Clients.Group(user.GroupId).SendAsync(GameEvents.UserLeft, ConnectedUsers.GetByGroup(user.GroupId));

            await Groups.RemoveFromGroupAsync(Context.ConnectionId, user.GroupId);

            await base.OnDisconnectedAsync(exception);
        }
Beispiel #2
0
        public async void JoinGroup(JoinGameRequestDto request)
        {
            var user = new GameUser
            {
                Name         = request.Name,
                GroupId      = request.GroupId,
                ConnectionId = Context.ConnectionId
            };

            ConnectedUsers.GameUsers.Add(user);

            await Groups.AddToGroupAsync(Context.ConnectionId, user.GroupId);

            await Clients.Client(Context.ConnectionId).SendAsync(GameEvents.GameJoined, user);

            await Clients.Group(user.GroupId).SendAsync(GameEvents.UserJoined, ConnectedUsers.GetByGroup(user.GroupId));
        }