private Task Client_VoiceStateUpdate(VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return(Task.Delay(0));
            }

            if (e.User == null)
            {
                return(Task.Delay(0));
            }

            if (e.User.Id == Client.CurrentUser.Id && ActiveConnections.TryGetValue(e.Guild.Id, out var vnc))
            {
                vnc.Channel = e.Channel;
            }

            if (!string.IsNullOrWhiteSpace(e.SessionId) && e.User.Id == Client.CurrentUser.Id && e.Channel != null && VoiceStateUpdates.ContainsKey(gld.Id))
            {
                VoiceStateUpdates.TryRemove(gld.Id, out var xe);
                xe.SetResult(e);
            }

            return(Task.Delay(0));
        }
Example #2
0
        private void StoreConnection(int?boardId = null)
        {
            var user = _userResolver.GetUser(Context.User);

            if (user == null)
            {
                return;
            }

            var connectionId = Context.ConnectionId;

            if (boardId.HasValue && !_accessService.HasAccess(user.ID, boardId.Value))
            {
                return;
            }

            if (ActiveConnections.TryGetValue(connectionId, out var syncPoint))
            {
                syncPoint.BoardId = boardId;
            }
            else
            {
                _activeConnections.TryAdd(Context.ConnectionId,
                                          new BoardSynchronizationPoint
                {
                    UserId  = user.ID,
                    BoardId = boardId
                });
            }
        }
        private async Task Client_VoiceServerUpdate(VoiceServerUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return;
            }

            if (ActiveConnections.TryGetValue(e.Guild.Id, out var vnc))
            {
                vnc.ServerData = new VoiceServerUpdatePayload
                {
                    Endpoint = e.Endpoint,
                    GuildId  = e.Guild.Id,
                    Token    = e.VoiceToken
                };

                var eps = e.Endpoint;
                var epi = eps.LastIndexOf(':');
                var eph = string.Empty;
                var epp = 80;
                if (epi != -1)
                {
                    eph = eps.Substring(0, epi);
                    epp = int.Parse(eps.Substring(epi + 1));
                }
                else
                {
                    eph = eps;
                }
                vnc.ConnectionEndpoint = new ConnectionEndpoint {
                    Hostname = eph, Port = epp
                };

                vnc.Resume = false;
                await vnc.ReconnectAsync().ConfigureAwait(false);
            }

            if (VoiceServerUpdates.ContainsKey(gld.Id))
            {
                VoiceServerUpdates.TryRemove(gld.Id, out var xe);
                xe.SetResult(e);
            }
        }