question

Rafael Benavent avatar image
Rafael Benavent asked

Yet another "how to connect to a Multiplayer Server"...

I'm trying to get the IP & port # of a multiplayer server from the client to establish a connection with the server.

I've read quite a few questions on this topic including the one below:

1. https://community.playfab.com/questions/38925/connecting-to-a-multiplayer-server-hosted-on-playf.html

From the answer:

- Need to check "Allow player to start game" <- I don't want a player to start a game, only join games.

- Need to check "Allow player to start game" <- I can't do that because when I try to save my changes I get an error saying Policy JSON is required.

- Devs on slack saying it's not necessary to do this either.

- Checking "Allow player to start game" should enable the Multiplayer API from what I understand, including RequestMultiplayerServer, but I don't want to enable everything. Just the functions that will allow me to retrieve a server's IP & Port.

So, how do I accomplish this?

Custom Game Serversmultiplayer
10 |1200

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

Rick Chen avatar image
Rick Chen answered

It is not necessary to check "Allow player to start game". You could use the Matchmaking process to allocate a server for players. You could create and configure the matchmaking queues and check “Enable server allocation”, then choose a build for multiplayer server. After that, once there is a match, the matchmaking process will allocate a server for players and the players can retrieve the server’s IP & Port through GetMatch API.

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

Rafael Benavent avatar image Rafael Benavent commented ·

Do you know if players can join a match in progress?

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Rafael Benavent commented ·

Players can join a match that is in progress. There are server backfill tickets that allow a game server to search for additional players which will fit into the game currently being played. The backfill process begins similarly to creating a regular matchmaking ticket, but with the CreateServerBackfillTicket call. When the backfill ticket is matched, its ServerDetails structure will be returned to any players who call GetMatch on the resulting match. Please refer to:

Using server backfill tickets

0 Likes 0 ·
Rafael Benavent avatar image Rafael Benavent Rick Chen ♦ commented ·

Thanks I looked into it a bit more but it seems at least 2 players are required for a match. I would like to have players play by themselves.

0 Likes 0 ·
Show more comments
John Wallace avatar image
John Wallace answered

We didn't want our users to directly talk to PlayFab. Instead we wrote CloudScripts to provide the functionality we wanted. To request a multiplayer server, your CloudScript would look something like this:

const BuildId = "[put your build id here]"

// requestGame - requests a game server with the provided sessionId. 
//     If no game server exists then it starts a new one. If a game serve 
//     already exists, then it returns its info. 
// args.sessionId - guid representing the game (ie. could be a 
//     stable-hash of a lobby name).
// returns - buildId, sessionId, serverId, ip, port
handlers.requestGame = function(args, context) {
    var request = {
        "BuildId": BuildId,
        "SessionId": args.sessionId,
        "SessionCookie": "",
        "InitialPlayers": [
        ],
        "PreferredRegions": [
            "EastUs"
        ]
    };
    var result = multiplayer.RequestMultiplayerServer(request);
    return {
	"buildId": buildId, 
	"sessionId": sessionId, 
	"serverId": result.ServerId, 
	"ip": result.IPV4Address, 
	"port": result.Ports[0].Num
    }
}
10 |1200

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

caobagames avatar image
caobagames answered

how can i use the cloudscrid. do i need any command?

10 |1200

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

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.