Exemplo n.º 1
0
        public async Task <ActionResult> JoinChannel([FromBody] JoinChannelRequest joinChannelRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Errors = ModelState.ConvertErrorsToDictionary() }));
            }

            var channel = await _applicationDbContext.Channels.FindAsync(joinChannelRequest.ChannelId.ToUpper());

            if (channel == null)
            {
                return(NotFound(new
                                { Errors = new { ChannelId = new[] { "The remote ID is incorrect or the session has ended." } } }));
            }

            var user = new User
            {
                Id        = Guid.NewGuid(),
                ChannelId = joinChannelRequest.ChannelId,
                Name      = joinChannelRequest.UserName
            };

            await _applicationDbContext.Users.AddAsync(user);

            await _applicationDbContext.SaveChangesAsync();

            return(Ok(new { AccessToken = CreateUserAccessToken(joinChannelRequest.ChannelId, user.Id.ToString()) }));
        }
Exemplo n.º 2
0
        private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
        {
            if (channel == null)
            {
                return(null);
            }

            channel = getChannel(channel, addToJoined: true);

            // ensure we are joined to the channel
            if (!channel.Joined.Value)
            {
                channel.Joined.Value = true;

                switch (channel.Type)
                {
                case ChannelType.Multiplayer:
                    // join is implicit. happens when you join a multiplayer game.
                    // this will probably change in the future.
                    joinChannel(channel, fetchInitialMessages);
                    return(channel);

                case ChannelType.PM:
                    var createRequest = new CreateChannelRequest(channel);
                    createRequest.Success += resChannel =>
                    {
                        if (resChannel.ChannelID.HasValue)
                        {
                            channel.Id = resChannel.ChannelID.Value;

                            handleChannelMessages(resChannel.RecentMessages);
                            channel.MessagesLoaded = true;     // this will mark the channel as having received messages even if there were none.
                        }
                    };

                    api.Queue(createRequest);
                    break;

                default:
                    var req = new JoinChannelRequest(channel);
                    req.Success += () => joinChannel(channel, fetchInitialMessages);
                    req.Failure += ex => LeaveChannel(channel);
                    api.Queue(req);
                    return(channel);
                }
            }
            else
            {
                if (fetchInitialMessages)
                {
                    fetchInitalMessages(channel);
                }
            }

            CurrentChannel.Value ??= channel;

            return(channel);
        }
Exemplo n.º 3
0
        public void JoinChannel(EntityId channelId, ChannelAPI.ChannelType channelType)
        {
            JoinChannelRequest joinChannelRequest = new JoinChannelRequest();

            joinChannelRequest.SetChannelId(channelId);
            joinChannelRequest.SetObjectId(ChannelAPI.GetNextObjectId());
            ChannelAPI.ChannelData channelData = new ChannelAPI.ChannelData(this, channelId, 0uL, channelType);
            channelData.SetSubscriberObjectId(joinChannelRequest.ObjectId);
            this.m_rpcConnection.QueueRequest(this.m_channelOwnerService.Id, 3u, joinChannelRequest, new RPCContextDelegate(channelData.JoinChannelCallback), (uint)channelType);
        }
Exemplo n.º 4
0
        public void JoinChannel(Channel channel)
        {
            if (channel == null)
            {
                return;
            }

            // ReSharper disable once AccessToModifiedClosure
            var existing = JoinedChannels.FirstOrDefault(c => c.Id == channel.Id);

            if (existing != null)
            {
                // if we already have this channel loaded, we don't want to make a second one.
                channel = existing;
            }
            else
            {
                var foundSelf = channel.Users.FirstOrDefault(u => u.Id == api.LocalUser.Value.Id);
                if (foundSelf != null)
                {
                    channel.Users.Remove(foundSelf);
                }

                JoinedChannels.Add(channel);

                if (channel.Type == ChannelType.Public && !channel.Joined)
                {
                    var req = new JoinChannelRequest(channel, api.LocalUser);
                    req.Success += () =>
                    {
                        channel.Joined.Value = true;
                        JoinChannel(channel);
                    };
                    req.Failure += ex => LeaveChannel(channel);
                    api.Queue(req);
                    return;
                }
            }

            if (CurrentChannel.Value == null)
            {
                CurrentChannel.Value = channel;
            }

            if (!channel.MessagesLoaded)
            {
                // let's fetch a small number of messages to bring us up-to-date with the backlog.
                fetchInitalMessages(channel);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Joins a channel if it has not already been joined.
        /// </summary>
        /// <param name="channel">The channel to join.</param>
        /// <param name="alreadyJoined">Whether the channel has already been joined server-side. Will skip a join request.</param>
        /// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
        public Channel JoinChannel(Channel channel, bool alreadyJoined = false)
        {
            if (channel == null)
            {
                return(null);
            }

            channel = getChannel(channel, addToJoined: true);

            // ensure we are joined to the channel
            if (!channel.Joined.Value)
            {
                if (alreadyJoined)
                {
                    channel.Joined.Value = true;
                }
                else
                {
                    switch (channel.Type)
                    {
                    case ChannelType.Public:
                        var req = new JoinChannelRequest(channel, api.LocalUser);
                        req.Success += () => JoinChannel(channel, true);
                        req.Failure += ex => LeaveChannel(channel);
                        api.Queue(req);
                        return(channel);
                    }
                }
            }

            if (CurrentChannel.Value == null)
            {
                CurrentChannel.Value = channel;
            }

            if (!channel.MessagesLoaded)
            {
                // let's fetch a small number of messages to bring us up-to-date with the backlog.
                fetchInitalMessages(channel);
            }

            return(channel);
        }
Exemplo n.º 6
0
        private void addChannel(Channel channel)
        {
            if (channel == null)
            {
                return;
            }

            // ReSharper disable once AccessToModifiedClosure
            var existing = careChannels.Find(c => c.Id == channel.Id);

            if (existing != null)
            {
                // if we already have this channel loaded, we don't want to make a second one.
                channel = existing;
            }
            else
            {
                careChannels.Add(channel);
                channelTabs.AddItem(channel);

                if (channel.Type == ChannelType.Public && !channel.Joined)
                {
                    var req = new JoinChannelRequest(channel, api.LocalUser);
                    req.Success += () => addChannel(channel);
                    req.Failure += ex => removeChannel(channel);
                    api.Queue(req);
                    return;
                }
            }

            // let's fetch a small number of messages to bring us up-to-date with the backlog.
            fetchInitialMessages(channel);

            if (CurrentChannel == null)
            {
                CurrentChannel = channel;
            }

            channel.Joined.Value = true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Joins a channel if it has not already been joined.
        /// </summary>
        /// <param name="channel">The channel to join.</param>
        /// <param name="alreadyJoined">Whether the channel has already been joined server-side. Will skip a join request.</param>
        /// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
        public Channel JoinChannel(Channel channel, bool alreadyJoined = false)
        {
            if (channel == null)
            {
                return(null);
            }

            channel = getChannel(channel, addToJoined: true);

            // ensure we are joined to the channel
            if (!channel.Joined.Value)
            {
                if (alreadyJoined)
                {
                    channel.Joined.Value = true;
                }
                else
                {
                    switch (channel.Type)
                    {
                    case ChannelType.Public:
                        var req = new JoinChannelRequest(channel, api.LocalUser.Value);
                        req.Success += () => JoinChannel(channel, true);
                        req.Failure += ex => LeaveChannel(channel);
                        api.Queue(req);
                        return(channel);
                    }
                }
            }

            if (CurrentChannel.Value == null)
            {
                CurrentChannel.Value = channel;
            }

            return(channel);
        }
Exemplo n.º 8
0
 public override void JoinChannel(IRpcController controller, JoinChannelRequest request, Action<JoinChannelResponse> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
Exemplo n.º 9
0
		public override void JoinChannel(Google.ProtocolBuffers.IRpcController controller, JoinChannelRequest request, Action<JoinChannelResponse> done) {
			throw new NotImplementedException();
		}
Exemplo n.º 10
0
 public override void JoinChannel(IRpcController controller, JoinChannelRequest request, Action <JoinChannelResponse> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
        public override async Task <Empty> JoinChannel(JoinChannelRequest request, ServerCallContext context)
        {
            await OrchestrationHub.AddChannel(hub.Clients, request.Channelname, logger);

            return(new Empty());
        }
Exemplo n.º 12
0
 public override void JoinChannel(IRpcController controller, JoinChannelRequest request, Action <JoinChannelResponse> done)
 {
     done(new JoinChannelResponse.Builder().Build());
 }
Exemplo n.º 13
0
 public override void JoinChannel(IRpcController controller, JoinChannelRequest request, Action <JoinChannelResponse> done)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 public override void JoinChannel(IRpcController controller, JoinChannelRequest request, Action<JoinChannelResponse> done)
 {
     done(new JoinChannelResponse.Builder().Build());
 }
Exemplo n.º 15
0
 public override Task <JoinChannelResponse> JoinChannel(JoinChannelRequest request, ServerCallContext context)
 {
     return(base.JoinChannel(request, context));
 }