Esempio n. 1
0
        internal void RequestChanneListMessage(MessageEventArgs <RequestChannelListMessage> e)
        {
            if (!e.Connection.IsConnected)
            {
                return;
            }

            if (!context.GetPermission(PermissionName.RequestChannelList, e.Connection))
            {
                e.Connection.SendAsync(new ChannelListMessage(GenericResult.FailedPermissions));
            }
            else
            {
                IEnumerable <IChannelInfo> channels = this.context.ChannelsProvider.GetChannels();
                e.Connection.SendAsync(new ChannelListMessage(channels, context.ChannelsProvider.DefaultChannel));
            }
        }
Esempio n. 2
0
        internal void OnRequestUserListMessage(MessageEventArgs <RequestUserListMessage> e)
        {
            var msg = e.Message;

            if (msg.Mode == UserListMode.Current)
            {
                if (!context.GetPermission(PermissionName.RequestChannelList))
                {
                    e.Connection.SendAsync(new PermissionDeniedMessage(GablarskiMessageType.RequestUserList));
                    return;
                }

                e.Connection.SendAsync(new UserInfoListMessage(this));
            }
            else
            {
                if (!context.GetPermission(PermissionName.RequestFullUserList))
                {
                    e.Connection.SendAsync(new PermissionDeniedMessage(GablarskiMessageType.RequestUserList));
                    return;
                }

                e.Connection.SendAsync(new UserListMessage(context.UserProvider.GetUsers()));
            }
        }
Esempio n. 3
0
        public static bool GetPermission(this IGablarskiServerContext self, PermissionName name, IConnection connection)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }
            if (connection == null)
            {
                return(self.GetPermission(name));
            }

            IUserInfo user = self.Users[connection];

            if (user == null)
            {
                return(self.GetPermission(name));
            }

            return(self.GetPermission(name, user.CurrentChannelId, user.UserId));
        }
Esempio n. 4
0
        private void ClientQueryServer(ConnectionlessMessageEventArgs e)
        {
            var msg = (QueryServerMessage)e.Message;

            if (!msg.ServerInfoOnly && !context.GetPermission(PermissionName.RequestChannelList))
            {
                var denied = new PermissionDeniedMessage(GablarskiMessageType.QueryServer);
                e.Messenger.SendConnectionlessMessageAsync(denied, e.From);

                return;
            }

            var result = new QueryServerResultMessage();

            if (!msg.ServerInfoOnly)
            {
                result.Channels = this.context.ChannelsProvider.GetChannels();
                result.Users    = this.users.ToList();
            }

            result.ServerInfo = GetServerInfo();
            e.Messenger.SendConnectionlessMessageAsync(result, e.From);
        }
Esempio n. 5
0
        internal void RequestSourceMessage(MessageEventArgs <RequestSourceMessage> e)
        {
            var request = (RequestSourceMessage)e.Message;

            SourceResult result = SourceResult.FailedUnknown;

            IUserInfo requestingUser = context.Users[e.Connection];

            if (requestingUser == null)
            {
                return;
            }

            if (!context.GetPermission(PermissionName.RequestSource, requestingUser))
            {
                result = SourceResult.FailedPermissions;
            }

            if (String.IsNullOrEmpty(request.Name) ||
                AudioCodecArgs.IsInvalidBitrate(request.AudioSettings.Bitrate) ||
                AudioCodecArgs.IsInvalidComplexity(request.AudioSettings.Complexity) ||
                AudioCodecArgs.IsInvalidFrequency(request.AudioSettings.SampleRate) ||
                AudioCodecArgs.IsInvalidFrameSize(request.AudioSettings.SampleRate, request.AudioSettings.Channels, request.AudioSettings.FrameSize))
            {
                result = SourceResult.FailedInvalidArguments;
            }

            AudioSource source = null;

            try
            {
                if (result == SourceResult.FailedUnknown)
                {
                    int bitrate = context.Settings.DefaultAudioBitrate;
                    if (request.AudioSettings.Bitrate != 0)
                    {
                        bitrate = request.AudioSettings.Bitrate.Trim(context.Settings.MinimumAudioBitrate, context.Settings.MaximumAudioBitrate);
                    }

                    if (manager.IsSourceNameTaken(requestingUser, request.Name))
                    {
                        result = SourceResult.FailedDuplicateSourceName;
                    }
                    else
                    {
                        source = manager.Create(request.Name, requestingUser,
                                                new AudioCodecArgs(request.AudioSettings)
                        {
                            Bitrate = bitrate
                        });
                        result = SourceResult.Succeeded;
                    }
                }
            }
            catch (OverflowException)
            {
                result = SourceResult.FailedLimit;
            }
            finally
            {
                e.Connection.SendAsync(new SourceResultMessage(request.Name, result, source));
                if (result == SourceResult.Succeeded)
                {
                    foreach (IConnection connection in context.Connections)
                    {
                        if (connection == e.Connection)
                        {
                            continue;
                        }

                        connection.SendAsync(new SourceResultMessage(request.Name, SourceResult.NewSource, source));
                    }
                }
            }
        }