Esempio n. 1
0
        protected override void OnThreadUnSafeEventFired(object source, GenericSocialEventArgs <GuildMemberInviteEventModel> args)
        {
            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                //TODO: We need a better way to handle guild query.
                //We need to translate the names first.
                var nameQueryResponse = await NameQueryService.RetrieveGuildNameAsync(args.Data.GuildId)
                                        .ConfigureAwait(true);
                string inviterName = await EntityNameQueryable.RetrieveAsync(args.Data.InviterGuid)
                                     .ConfigureAwait(true);

                TextChatPublisher.PublishEvent(this, new TextChatEventArgs($"{inviterName} invited you to join the guild <{nameQueryResponse.Result.EntityName}>.", ChatChannelType.System));
            });
        }
Esempio n. 2
0
        protected override void OnThreadUnSafeEventFired(object source, GenericSocialEventArgs <GuildMemberInviteEventModel> args)
        {
            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                //We need to translate the names first.
                var nameQueryResponse = await NameQueryService.RetrieveGuildNameAsync(args.Data.GuildId)
                                        .ConfigureAwait(true);
                string inviterName = await EntityNameQueryable.RetrieveAsync(args.Data.InviterGuid)
                                     .ConfigureAwait(true);

                if (nameQueryResponse.isSuccessful)
                {
                    GuildInviteWindow.GuildNameText.Text  = $"<{nameQueryResponse.Result.EntityName}>";
                    GuildInviteWindow.InvitationText.Text = $"<color=green><b>{inviterName}</b></color> invites you to join the guild:";

                    //Now it can popup.
                    GuildInviteWindow.SetElementActive(true);
                }
            });
        }
        /// <inheritdoc />
        protected override void OnEventFired(object source, CharacterSelectionEntryDataChangeEventArgs args)
        {
            //At this point, we have a new character. BUT we don't know the name of it yet
            //We must query the name service for it.

            int slot = Interlocked.Increment(ref ButtonIndex);

            UnityExtended.UnityMainThreadContext.PostAsync(async() =>
            {
                //TODO: Handle errors
                //TODO: We should expose NetworkEntityGuid endpoint
                string name = await NameQueryService.RetrieveAsync(args.CharacterEntityGuid.EntityId)
                              .ConfigureAwait(true);

                //Once we have the result, we can assign the name.
                IUILabeledButton button = CharacterButtons.ElementAt(slot);
                button.Text             = name;
                button.IsInteractable   = true;

                //When clicked just broadcast a named event to everything that it has been clicked, and who it was.
                button.AddOnClickListener(() => OnCharacterButtonClicked?.Invoke(this, new CharacterButtonClickedEventArgs(args.CharacterEntityGuid, slot)));
            });
        }
Esempio n. 4
0
        protected override async Task OnMessageRecieved(IHubConnectionMessageContext <IRemoteSocialHubClient> context, GuildMemberInviteRequestModel payload)
        {
            var nameQueryResponseTask = NameQueryService.RetrievePlayerGuidAsync(payload.MemberToInvite);

            //First we need to check if they're in a guild.
            //We don't really need to handle the response for this, since it should never really happen.
            var guildStatus = await SocialService.GetCharacterMembershipGuildStatus(context.CallerGuid.EntityId);

            if (!guildStatus.isSuccessful)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning($"User: {context.CallerGuid} attempted to Invite: {payload.MemberToInvite} to a guild but was not apart of a guild.");
                }

                return;
            }

            //Now we should know what guild the caller is in due to the query.
            //Now we need to do a reverse namequery to get the guid of who they're attempting to invite.
            var nameQueryResponse = await nameQueryResponseTask;

            //If it's not successful, assume the user doesn't exist.
            if (!nameQueryResponse.isSuccessful)
            {
                await SendGuildInviteResponse(context, GuildMemberInviteResponseCode.PlayerNotFound, NetworkEntityGuid.Empty);

                return;
            }

            //Now check if the user is already guilded
            //If they are we should indicate that to the client.
            if (await CheckIfGuilded(nameQueryResponse.Result))
            {
                await SendGuildInviteResponse(context, GuildMemberInviteResponseCode.PlayerAlreadyInGuild, nameQueryResponse.Result);

                return;
            }

            //Ok, the reverse name query was successful. Check if there is a pending invite.
            //TODO: Right now we rely on local state to indicate if there is a pending invite. We need to NOT do that because it won't work when we scale out.
            ProjectVersionStage.AssertBeta();

            //TODO: There is a race condition if multiple invites are sent at the same time, should we care??
            //If they have a pending invite.
            if (PendingInviteData.ContainsKey(nameQueryResponse.Result))
            {
                //If NOT expired then we need to say they're currently pending an invite
                if (!PendingInviteData[nameQueryResponse.Result].isInviteExpired())
                {
                    await SendGuildInviteResponse(context, GuildMemberInviteResponseCode.PlayerAlreadyHasPendingInvite, nameQueryResponse.Result);

                    return;
                }
                else
                {
                    //The invite is EXPIRED so let's added a new one.
                    PendingInviteData.ReplaceObject(nameQueryResponse.Result, GeneratePendingInviteData(context.CallerGuid, guildStatus.Result.GuildId));
                }
            }
            else
            {
                PendingInviteData.AddObject(nameQueryResponse.Result, GeneratePendingInviteData(context.CallerGuid, guildStatus.Result.GuildId));
            }
            //TODO: There is currently no handling to indicate that they are online.

            //Now they have a valid pending invite, so let's address the client
            //that needs to recieve the guild invite.
            IRemoteSocialHubClient playerClient = context.Clients.RetrievePlayerClient(nameQueryResponse.Result);

            //Indicate the player has been invited.
            await SendGuildInviteResponse(context, GuildMemberInviteResponseCode.Success, nameQueryResponse.Result);

            //Now tell the remote/target player they're being invited to a guild.
            await playerClient.ReceiveGuildInviteEventAsync(new GuildMemberInviteEventModel(guildStatus.Result.GuildId, context.CallerGuid));
        }
Esempio n. 5
0
        protected override void OnEventFired(object source, EntityWorldObjectCreatedEventArgs args)
        {
            //Only doing player name queries.
            if (args.EntityGuid.EntityType != EntityType.Player)
            {
                return;
            }

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    ResponseModel <NameQueryResponse, NameQueryResponseCode> responseModel = await NameQueryService.RetrievePlayerNameAsync(args.EntityGuid.RawGuidValue);

                    if (responseModel.isSuccessful)
                    {
                        args.WorldReprensetation.SetName(responseModel.Result.EntityName);
                    }
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Failed to query name for Player: {args.EntityGuid}. Reason: {e}");
                    }

                    throw;
                }
            });
        }