question

natepac avatar image
natepac asked

Connecting to a Multiplayer Server hosted on PlayFab

Right now the examples just have you work with a local container and through local host. What I want to know is how to actually connect to a remote PlayFab server. I have figured out how to get it built, sent up to PlayFab and have it ready to listen. But how do I connect to it? How do I start a game? I believe you have to use PlayFabMultiplayerAPI.RequestMultiplayerServer() but then what? You the information back from that method sure, but do you connect with PlayFabMultiplayerAPI.GetBuild()...? No idea. Listening on a localhost connection is easy. How do we connect with a remote server?

And don't point me to: https://community.playfab.com/questions/26677/playfab-multiplayer-servers-20-thunderhead-game-se.html?childToView=26785#answer-26785 This doesn't have the answer.

I am happy to put together a test project and share it with the community cause this would be an awesome feature if this question / tutorial was better answered.

1 comment
10 |1200

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

natepac avatar image natepac commented ·

Oh and this using Unity and Mirror for networking.

0 Likes 0 ·
natepac avatar image
natepac answered

1.) You need to enable your game to "Allow client to start games" this is found under the Settings gear for your game. Click the gear, in the drop down go to Title settings, then click the API Features tab. The check box is on that page.

2.) You need to login a player so that player can connect to the server.

3.) You need to call PlayFabMultiplayerAPI.RequestMultiplayerServer to get a server list based on the params you pass into that method.

4.) From the response of that method, you will get the necessary data to connect to a PlayFab hosted server a bit on that here: https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/using-qos-beacons-to-measure-player-latency-to-azure

RequestMultiplayerServer API here: https://docs.microsoft.com/en-us/rest/api/playfab/multiplayer/multiplayerserver/requestmultiplayerserver?view=playfab-rest

You can check out example code here: https://pastebin.com/1fbw0FAd

Note: I haven't figured out how or what GUID SessionId is looking for yet so I just stole one from someone else. I have tried generating my own GUIDs but PlayFab doesn't like them yet. I also don't know if they are being generated on PlayFab or if they are ones I make.

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

natepac avatar image natepac commented ·

By the way @SethDu whats the deal with SessionId in RequestMultiplayerServerRequest? Why is PlayFab so exact with the format of the GUID on this? Do you have a suggestion on how to generate one? Or does it come from somewhere else?

1 Like 1 ·
Seth Du avatar image Seth Du ♦ natepac commented ·

You may generate your customized session ID, and in the server instance, session ID defined in RequestMultiplayerServerRequest will be passed through to the GSDK, which can be used for verification.

Session ID equals to Match ID from matchmaking ticket. Meanwhile, if you directly request a server instance, it can be customized.

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray Seth Du ♦ commented ·

@SethDu

Assuming I created a server in cloudscript via Request Multiplayer Server and I receive the response object, how would I communicate to the server? This would be in cloudscript only. Amd the games ever is in Unity.

0 Likes 0 ·
Show more comments
Seth Du avatar image Seth Du ♦ commented ·

Thanks your the feedback. This will be good example for developers in the community. I will follow the instructions to double check it.

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray Seth Du ♦ commented ·

@SethDu

@Natepac

May I have a cloudscript example of :

RequestMultiplayerServer API here: https://docs.microsoft.com/en-us/rest/api/playfab/multiplayer/multiplayerserver/requestmultiplayerserver?view=playfab-rest

Using the FQDN, wouldI be able to communicate to the specific server?

0 Likes 0 ·
natepac avatar image natepac commented ·

The PasteBin link isn't totally accurate with some custom code, but it's pretty close. I will edit more details here as I keep on a real implementation, beyond an example server.

0 Likes 0 ·
natepac avatar image
natepac answered

Ok, I got it connected. Here is what you need to do in case anyone else wants to connect Unity and Mirror to a hosted server on PlayFab.

You can use the example that PlayFab has here, but you will have to adapt it: https://github.com/PlayFab/gsdkSamples/tree/master/UnityMirror

The server should work out of the box per their configuration values and instructions, just don't host it locally. Use the instructions here as a guide along with the parameters described in the previous link: https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/quickstart-for-multiplayer-servers-game-manager Build the server in Unity and deploy. Remember to zip up just the files into a zip and put those on PlayFab, don't just zip up the containing folder.

Once you have the server setup, you need to get your client to connect to it. Use the example in the first link to get your client going. Open it in Unity and make sure it just builds. If you want to work locally, follow the instructions in the first link, but if you want to put this remote, check out my next comment, I am running out of character limit...

10 |1200

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

Denzie Gray avatar image
Denzie Gray answered

@SethDu

"The response of RequestMultiplayerServer will contain the IP and port number of initialized server instance, which will be returned to client. Then it is client-server thing."

Yes but what if I wanted to use the IP and Port number in CloudScript?

What do I use to communicate to the GameServer in CloudScript? I do not want to have the client talk to the server at all.

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.

Seth Du avatar image Seth Du ♦ commented ·

No, you cannot do that in the common scenario. CloudScript is based on Google V8 Engine and uses headless server, which is not designed for this purpose. There is runtime limit while usually the TCP/UDP connection may last long.

Why do you want to forbid clients communicating with server instance? The server instance is fully controlled by yourself, where any verification steps can be done easily. I guess you want to have an agent server to handle all requests from the client, but usually it is not necessary. What is the detailed scenario and your concerns?

0 Likes 0 ·
Denzie Gray avatar image Denzie Gray Seth Du ♦ commented ·

@SethDu

I want the to send a single long to the GameServer via CloudScript.

I don't expect or intend to stay connected past the posting of the input. This is a turn based game. Here is what I want:

My plan is to have a Webhook that the clients call which will,

Request the server and then pass an action to it. Here is a breakdown.

1. Make call to CloudScript with action

2. Request server.

3. Pass action to server (this is a Unity.exe).

4. Potentially return response to player

5. CloudScript function ends;

This is a turn-based game so I don't expect latency to be an issue.
I would expect the response in the game to take 100 MS tops to finish the calculations. This could all happen under the 10 second limit.
If I could 'post' to the server and get back a response, I would have everything needed to finish this migration to PlayFab atm.

Thanks in advance. And thanks for the previous response.

Assuming I used C# TCPListener on the client, would I just use the IP4 and Port to send data to the specific Game Server, Thats all I need? Do I need the PortName too?And What does the FQDN let me do?

0 Likes 0 ·
brendan avatar image brendan Denzie Gray commented ·

Since you also posted a new thread for this, let's keep the discussion there, if you have follow-up questions: https://community.playfab.com/questions/47116/multiplayer-game-server-questions.html

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.