question

martinliu1993 avatar image
martinliu1993 asked

How to create a custom UE4 Game Server using PlayFab?,How to create a custom UE4 Server using PlayFab?

I've looked through tutorials but haven't found anything that allows me to create dedicated game server in UE4. Basically, I just want an empty third person shooter project with PlayFabs plugin installed, and dedicated server hosted using PlayFab.

This link here had some hints as to how to create a UE4 game server, but doesn't delve into the details. I also see that there is a test server project for Unity here. Is there something for UE4? If not, are there good tutorials as to how to setup one?

Thanks

,
Custom Game Servers
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

·
brendan avatar image
brendan answered

There's actually nothing PlayFab-specific about creating a game server in UE4 - any executable that can run on Windows 2K12R2 will work in our hosting. I take it you're starting from the UE4 Shooter Game example (https://docs.unrealengine.com/latest/INT/Resources/SampleGames/ShooterGame/index.html)?

While we don't have a sample project showing this, there are really only a few things that would be required:

First, you'll need to make sure you use the https://api.playfab.com/Documentation/Server/method/RedeemMatchmakerTicket call to confirm that the player is supposed to be joining the server as a result of a call to Matchmake (assuming you're using our matchmaker - otherwise, you'll want to have a way to validate, such as an encrypted signature), and https://api.playfab.com/Documentation/Server/method/NotifyMatchmakerPlayerLeft to let us know when the player leaves the session. The Game Mode is the best place for that - do the ticket redemption in PreLogin, so that in case the player has to download a lot of content from the server for the level his ticket doesn't time out, and the player left call can then go in the Game Mode Logout call.

Other than that, you'll want to add some logic to report the results of the match to the player statistics and possibly User (Read-Only or Internal) Data. That could be called from a number of places, but one approach would be to put it in HandleMatchHasEnded (or trigger it separately from WaitingPostMatch).

8 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.

martinliu1993 avatar image martinliu1993 commented ·

Hey @Brendan

So I've successfully setup a server running on USCentral using the tutorial here.I followed the tutorial and called MatchMake as you wrote above. Basically, this is the code I have in my test UE4 Project:

clientAPI = IPlayFabModuleInterface::Get().GetClientAPI();
clientAPI->SetTitleId(TEXT("144"));


PlayFab::ClientModels::FLoginWithCustomIDRequest request;
request.CustomId = TEXT("GettingStartedGuide");
request.CreateAccount = true;


clientAPI->LoginWithCustomID(request,
		PlayFab::UPlayFabClientAPI::FLoginWithCustomIDDelegate::CreateUObject(this, &AMyProject2Character::OnSuccess),
		PlayFab::FPlayFabErrorDelegate::CreateUObject(this, &AMyProject2Character::OnError)
	);


PlayFab::ClientModels::FMatchmakeRequest MatchMakeRequest;
MatchMakeRequest.GameMode = "123";
MatchMakeRequest.BuildVersion = "123";


clientAPI->Matchmake(MatchMakeRequest,
		PlayFab::UPlayFabClientAPI::FMatchmakeDelegate::CreateUObject(this, &AMyProject2Character::OnMatchMakeSuccess),
		PlayFab::FPlayFabErrorDelegate::CreateUObject(this, &AMyProject2Character::OnMatchMakeError)
	);



The MatchMake call is returning an error:

"Missing or invalid X-Authentication HTTP header", any ideas?

0 Likes 0 ·
brendan avatar image brendan martinliu1993 commented ·

It looks like you're not waiting on the Login call to complete before attempting to call Matchmake. The Login call returns a Session Ticket, which is subsequently used as the authentication header for calls to the Client API. You'll also want to make sure that as part of your overall code flow, you are checking for the invalid ticket error for when it has expired, so that you can sign the player back in again. The ticket is good for 24 hours currently, but there are some crazy-dedicated players out there. :)

0 Likes 0 ·
martinliu1993 avatar image martinliu1993 brendan commented ·

Hey @Brendan, So I successfully made MatchMake work but I'm still getting "Game mode not found". This is how my server is setup:

And this is my new code for calling MatchMake

void AMyProject2Character::OnSuccess(const PlayFab::ClientModels::FLoginResult& Result) const
{
	UE_LOG(LogTemp, Log, TEXT("Congratulations, you made your first successful API call!"));


PlayFab::ClientModels::FMatchmakeRequest MatchMakeRequest;
MatchMakeRequest.GameMode = "test";
MatchMakeRequest.BuildVersion = "123";
MatchMakeRequest.pfRegion = PlayFab::ClientModels::Region::RegionUSCentral;


	clientAPI->Matchmake(MatchMakeRequest,
		PlayFab::UPlayFabClientAPI::FMatchmakeDelegate::CreateUObject(this, &AMyProject2Character::OnMatchMakeSuccess),
		PlayFab::FPlayFabErrorDelegate::CreateUObject(this, &AMyProject2Character::OnMatchMakeError)
	);
}

As you can see, the GameMode is set to "test", and in my code I'm also setting GameMode to "test". Why would it say "Game mode not found"?

1 Like 1 ·
capture.png (13.7 KiB)
capture.png (41.4 KiB)
Show more comments
Show more comments
meshedwell avatar image meshedwell martinliu1993 commented ·

Hello.martinliu1993 & brendan. how can i solve "Game mode not found" error message?

0 Likes 0 ·
1.jpg (54.5 KiB)
2.jpg (169.7 KiB)
brendan avatar image brendan meshedwell commented ·

Just so you know, that's a very different question from the one above, which was about using the Matchmake call. What you are doing is running a game server which you want to connect to the service via the RegisterGame API call, so that it can be discovered by our matchmaker. To do so, you do need to have a build uploaded with the Build ID you want to use, and the Game Mode you want to use configured for it in the Game Manager. But since your screenshot above seems to imply that you have set that up for a title, I would have to assume that the call is failing because it's being made on another Title ID. Can you verify your Title ID settings in your project and let us know what that Title ID is?

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.