Exemplo n.º 1
0
        public async Task Join(GroupChangeEvent evt)
        {
            //todo add all user connections to group(s)
            var userId = await _userStore.GetUserIdForConnectionAsync(Context.ConnectionId);

            var connections = await _userStore.GetUserConnectionsAsync(userId);

            var tasks = evt.Groups
                        .Select(group => Groups.AddToGroupAsync(Context.ConnectionId, group));

            await Task.WhenAll(tasks);

            await _userStore.AddUserToGroupsAsync(userId, evt.Groups);

            // send presence event
            var presenceEvents = evt.Groups.Select(g => new PresenceEvent
            {
                Action = PresenceAction.Join,
                Group  = g,
                Uuid   = userId
            });

            var presenceTasks = presenceEvents.Select(e => Clients.GroupExcept(e.Group, connections).Presence(e));

            await Task.WhenAll(presenceTasks);
        }
Exemplo n.º 2
0
        public async Task Leave(GroupChangeEvent evt)
        {
            var tasks = evt.Groups
                        .Select(group => Groups.RemoveFromGroupAsync(Context.ConnectionId, group));

            await Task.WhenAll(tasks);

            var userId = await _userStore.GetUserIdForConnectionAsync(Context.ConnectionId);

            await _userStore.RemoveUserFromGroupsAsync(userId, evt.Groups);

            //todo send presence event
        }
        private static void OnChangingGroup(GroupChangeEvent ev)
        {
            if (ev.Player != player)
            {
                return;
            }

            Timing.CallDelayed(0.2f, () =>
            {
                if (ev.NewGroup == ev.Player.Group)
                {
                    originalColor = player.ReferenceHub.serverRoles.NetworkMyColor;
                    Timing.KillCoroutines(coroutineHandle);
                    coroutineHandle = Timing.RunCoroutine(UpdateColor());
                }
            });
        }