question

muhammet avatar image
muhammet asked

İnvite to lobby notification

Hello, I am trying to set up a structure where I can receive lobby invitations in the game, but I cannot do this because I cannot find a source. https://learn.microsoft.com/en-us/gaming/playfab/features/multiplayer/lobby/lobby-invites, unfortunately this source is not very descriptive. My code is stuck like this, can you help me?


 #include "PFLobbyFunctions.h"
    
    
    
 PFLobbyFunctions::PFLobbyFunctions()
 {
     AllowInvitations2();
 }
    
 PFLobbyFunctions::~PFLobbyFunctions()
 {
     free(entity);
 }
    
 void PFLobbyFunctions::Init()
 {
     IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
     if (OnlineSub)
     {
         IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
         if (Sessions.IsValid())
         {
             UE_LOG(LogTemp, Log, TEXT("BAŞLATILDI"));
             Sessions->AddOnSessionInviteReceivedDelegate_Handle(FOnSessionInviteReceivedDelegate::CreateRaw(this, &PFLobbyFunctions::OnSessionInviteReceived));
         }
         else
         {
             UE_LOG(LogTemp, Log, TEXT("Başlatılmadı 11"));
         }
     }
     else
     {
         UE_LOG(LogTemp, Log, TEXT("Başlatılmadı 22"));
     }
 }
    
 void PFLobbyFunctions::OnSessionInviteReceived(const FUniqueNetId& UserId, const FUniqueNetId& FriendId, const FString& InviteText, const FOnlineSessionSearchResult& FriendSearchResult)
 {
     // Davet alındığında yapılacak işlemler
 //    FString SessionId = FriendSearchResult.GetSessionIdStr();
     UE_LOG(LogTemp, Log, TEXT("Davet alındı. Session ID"));
 }
 void PFLobbyFunctions::AllowInvitations2() {
     entity = (PFEntityKey*)malloc(sizeof(PFEntityKey));
     entity->id = "9435B3270D470754";
     entity->type = "title_player_account";
     HRESULT hr = PFMultiplayerStartListeningForLobbyInvites(Lobbyhandle, entity);
    if (FAILED(hr)) {
         UE_LOG(LogTemp, Error, TEXT("HATAA %s"), ANSI_TO_TCHAR(PFMultiplayerGetErrorMessage(hr)));
    }
    else {
        UE_LOG(LogTemp, Error, TEXT("HATA YOK"));
    }
    
    
 }
multiplayer
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Infer Wang avatar image
Infer Wang answered

As doc shows, after you call PFMultiplayerStartListeningForLobbyInvites, you can call PFMultiplayerGetLobbyInvitationListenerStatus to get the status and switch it. Also, you can call SendInvite and HandleInvitationNotification for sending invitation.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

muhammet avatar image muhammet commented ·

i am getting error invalid handle. And

 void HandleInvitationNotification(const PFLobbyInviteReceivedStateChange& invite)
 {
     Log("%s invited to lobby by %s", invite.listeningEntity.id, invite.invitingEntity.id);
     // pass invite.connectionString to PFMultiplayerJoinLobby
 }

How does this function become a callback? Dear Sir, do not answer by referring to the documentation. We are already reading these

0 Likes 0 ·
muhammet avatar image muhammet commented ·

I am getting an invalid handle error, what can I do about this? Does the handle need to be initialized? what should I do

0 Likes 0 ·
Infer Wang avatar image Infer Wang muhammet commented ·

You can define PlayFabMultiplayer.OnLobbyInviteReceivedHandler - PlayFab | Microsoft Learn to handle for when the client has received an invite to a lobby.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.