question

contact-3 avatar image
contact-3 asked

Best way to port unity - supersocket (ws) - c# server to Playfab [SPECIFIC]

Hi,

I'd like to get into playfab to manage my users credentials, user data, monetization, matchmaking and server load balancing.

Right now we have a functional game that works with a c# custom server https://github.com/kerryjiang/SuperSocket, Unity connects to it through a custom WebSocket logic.

For now we're using a custom Mongo instance to persist players data.

We've seen Photon plugins, it seems we could easily plug our current logic into it (we solely need to matchmake players with others or IA and to send asynchronous messages), we already have a serializable gameState too.

What would be the best way to address our changes and to integrate with playfab/photon ? Is even photon necessary or could we use your own server system directly for room creation/matchmaking/load balancing ? What's the most mature in your own opinion ?

Concerning Load-balancing, is there a way to manage it without creating rooms ? I'd like to keep a list of available player looking for a match and create a room only if two of them "match". Is this a normal behaviour?

Can we create a room with only 1 player for when the player connects to deal with custom account logic without having to implement JS code or to host our own account server logic ?

Anyway it seems we at least need to add Playfab SDK to our unity project.

Lot's of questions :)

Cheers

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.

brendan avatar image
brendan answered

Certainly - it's possible to manage your custom logic in our service a variety of ways:

1. For lightweight logic (the kind that doesn't need a dedicated server, for low-latency response), you can use Cloud Script: https://api.playfab.com/docs/using-cloud-script

2. We provide for custom game server hosting in our scalable infrastructure: https://api.playfab.com/docs/custom-game-servers

3. You can also host servers in your own datacenter, or any game server provider's: https://api.playfab.com/docs/external-server-hosting

For credentials, user data, and monetization, we have built-in systems to support those concepts:

https://playfab.com/first-impressions-count-best-practices-friction-free-player-authentication/

https://api.playfab.com/docs/using-player-data

https://playfab.com/show-me-money-receipt-validation-ios-and-android/

https://api.playfab.com/docs/non-receipt-purchasing

And please feel free to let us know if you have any other questions on how to port your title. We're happy to help.

10 |1200

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

contact-3 avatar image
contact-3 answered

Thanks for the answer, now if we go more in the detail. It does not seem that playfab SDK manages client/server protocole (sockets/messaging) and client connection like photon does for the game itself. Am I right ? When I tried to include your SDK it was a bit blurry to me.

Hypothesis 1 : Custom server

- It looks like we'll have to keep supersocket for the client connection as there is no messaging/connection protocol included.

- Whenever a client connect, disconnect through supersocket or any playfab relevant event happens we notify you via the SDK.

- In this case I was not able to connect with websockets through my uploaded server, just a simple test without implementing anything for the playfab side. putting the IP in a browser I'm having a "ok"

- If I'm wrong and that playfab does manage clients connections and messaging that might be the preferred solution as it will simplify the process. After looking at your c# sdk I didn't find anything to implement as a plugin or to inherit from.

Hypothesis 2 : Photon plugin

- We use a photon plugin and implement some of the given callback (login/connection/event)

- We can get rid of supersocket as photon does events messaging.

- It seems we'll have to host it as external server hosting, your integration of photon does not appear to include plugin hosting.

- So in the end what is the most convenient way to interface with photon and c# plugins ?

Other questions :

- Are user data regularly backup ?

- Can we easily export user data ?

- Are user/company data kept secret or playfab access them for commercial purposes (analytics, etc ...) ?

- So you do manage user accounts ?

Thanks again

10 |1200

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

brendan avatar image
brendan answered

Correct - we partnered with Photon specifically because our services are very complementary. They provide for realtime multiplayer sessions in a pre-built cloud service, while we provide all the backend authentication, data, etc., components you need. Our service is Web API based, and so does not use persistent connections to the client. You simply make the calls using SSL, regardless of whether it's a Client or Server API call (or Admin, for your own toolset). Our integration with Photon is in two parts:

1. Authentication - Once signed into PlayFab,you can get a token for signing into your Photon App ID (the one provided in the Add-ons marketplace Photon tab).

2. Webhooks - All Photon Realtime App IDs provided by PlayFab are pre-configured to make the standard Photon webhook calls, with the endpoint being in the Cloud Script you have uploaded for your title.

For your other questions:

Yes, all data is regularly backed up.

We provide you with the ability to pipe all events to your own S3 bucket, so that you can see everything every user does. We will be providing a bulk action service soon which will allow you to retrieve data for segments of users (and "all users" could be a segment).

All data specific to your title and players is yours. By our terms of service, we do have the right to use anonymized user data from titles, but this would be stripped of any PII, so that no private data is exposed.

Could you clarify what you mean by managing user accounts? We provide a user account service that integrates with many authentication providers. In the Players tab in the Game Manager, we provide all the relevant information about your users, so that your team can make any changes needed, or take care of any customer service issues which arise. If the question is, do we provide customer service to players of your games, then the answer would be no - we provide the service and all the tools needed for titles to work with their customers, but customer support within your games is something you will need to own.

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.

Clark Richard Smiley avatar image Clark Richard Smiley commented ·

I’m sorry this is an old post but just making sure I understand. So playfab only provides the back end and I would need to use MLAPI, Mirror or Photon to update the players real-time and use playfab for data storage, login and leaderboards and for hosting the servers?

0 Likes 0 ·
contact-3 avatar image
contact-3 answered

By user account management I was asking for persistent user account that encapsulate publisher specific data and on which user can act on, changing his linked accounts, username, etc... Indeed I was not asking for customer service. It seems okay then.

- The real question about user data was the ability to export all user accounts in a JSON format for example like for importation in mailchimp or anything that resemble.

Concerning implementation : (Sorry I'd rather ask all the technical questions now to be sure on what to do)

Can a custom server and client listen to playstream events (didn't find any listener class) or can they only send events to playfab ? Can those events+customs be used as player commands in a turn based game, is there any latency induced ? That would be a way to use it at messaging protocole without having to use photon and external server hosting.

The thing is our master server code, let's say "Room code", is already quite grown up and very specific, we don't want to alter it. We could then host it on your platform. We'll have from 2 to 4 player game rooms and also 1 vs AI. I guess it's no hurdle having 1 player rooms ?

Now we'll have to split the master server impl, such as user connection, user data retrieval and modifications (inventories), and matchmaking (we have a server authoritative one). It seems either we'll have to host it on a separate provider as your hosting service is only for "room code", or we'll have to implement it in JS through cloud scripts.

The good thing with cloud script is : hosted by your services, scalable (I guess). But we'll need to do some code duplication we tried to avoid.

So in the end if we'd like to keep up with C# the best thing would be to :

- Split our server in "Master Code" and "Room Code"

- Plug our Room and Master server with photon and playfab server SDK.

- Plug our client with playfab (for inventories, persistency, account mngt, ...) and photon sdk (for matchmaking and room).

- Host both on let's say Azure for robustness and scalability.

Is there a better way of doing it in your team opinion?

10 |1200

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

brendan avatar image
brendan answered

Ah, in that case, yes - we have you covered for account management. You can create player accounts via the Login... calls in PlayFab (as well as RegisterPlayFabUser), and you can use the Link... API calls to connect additional authentication methods to that account, so that regardless of how the players sign in, they always get back to their correct account.

For export, you'll be able to get an export like that of all user emails for a MailChimp campaign as of our release of the bulk actions system.

Other implementation questions:

Listing for events: You can subscribe a server to events - have a look at our example server for an implementation sample: https://github.com/PlayFab/PlayFabGameServer/blob/bd07a13bf6c72e0b7e3a388c1f94f1d2da14c06e/README.md. You cannot subscribe clients directly to events, as it requires the Secret Key, which must never be made available to the client. However, you could use the server to pass events on to connected clients, and you can use Push Notifications for mobile clients to notify them of completed moves, etc.

Rooms: If you've been using Photon all along, and you don't want to change your code, it seems like you'll want to continue using Photon. For our server hosting, you can write any custom game logic you like, but I will say that if a game instance in our definition only supports one player, that wouldn't be very efficient. Better to have a game instance manage many players, and just treat them within that instance as being in separate "rooms". But no, we do not have a concept of "rooms" in PlayFab, as we do not provide the same service as Exit Games does with Photon Cloud.

External servers: Not a problem - the tutorial I mentioned above shows how to do that.

As for your plan, I don't think I have a clear enough picture of your architecture to say whether separating the "room" and "master" concepts is necessary. It does sound like you have a need for a realtime connection between players, which would imply using either a custom game server or Photon, as Cloud Script isn't designed for realtime data exchange between players. But yes, our Server API would be the one to use on your game server, while our Client API would be the one to use on the client (along with Photon, if you're using their service). If you're using custom game servers for all the multiplayer, that would remove Photon from the equation, and you could use either our matchmaker or your own (using the Matchamer API, if you want us to host your game servers). If you're hosting your own custom game servers, you can do that in any game server provider you like - Azure isn't a problem at all. Our core services are running in AWS, but there's nothing preventing it from communicating with servers in Azure.

10 |1200

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

contact-3 avatar image
contact-3 answered

Okay thanks for the enlightenment, now I think I understand a bit more.

- I try to grasp a picture of the whole painting It would be feasible to keep a server code that manage players connection/ matchmaking and games. And host it on playfab.

- How is replication and load balancing managed in your realm ?

The only issue with this would be that a client that started its WS connection on one instance and is match with a player on one other instance would have to close its WS connection and switch to an other instance, but nothing that bad.

- How to expose a port in my custom server, is there any configuration needed ? Last time I tried I couldn't connect websocket with my client.

Connection to the IP directly prints a "ok", it's not my side so I guess you have a wrapper somewhere. ( 52.212.85.143 ), our ws port is 2012, tried https://www.websocket.org/echo.html but no connection

Thanks

10 |1200

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

brendan avatar image
brendan answered

It sounds like you're talking about hosting different kinds of servers for different purposes, but just in case, I wanted to make sure one point is very clear:

The Web API methods that comprise PlayFab - all the calls you see in our documentation - are running on our servers, and can scale to any number of users. What most titles that have custom game servers do is use our matchmaker to determine which custom game server instance to join. If you have a need to do your own custom matchmaking of course, that's always an option. I just want to be sure to avoid any confusion.

When you set up custom game server hosting in PlayFab, you specify the number of instances of the game server that can run on the server host machine you've chosen (from the EC2 list). You also configure the minimum number of free slots you want to have available at all times. Since it can take EC2 upwards of 10-12 minutes to get us a new server, it's important to have that set high enough to manage your peak number of users who'd be looking to start a new session in that time (aim for 15 minutes, to be safe). Whenever a game instance starts, we spin up a new server host if the number of available slots is below the minimum you specified. And when a server instance ends, we check if we can shut down the server host (without going below the minimum you've specified).

For the port, that's set by our Game Wrangler - it generates all the command line parameter values (the ones in angle brackets in the tutorial). Since many instances of the game can run on one server host machine, it makes sure they each get a distinct port for talking to clients.

10 |1200

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

contact-3 avatar image
contact-3 answered

No confusion for the API scaling :)

----

One thing we want to avoid is splitting our playerbase, hence we want a globalized matchmaking system that takes into account all the players LFG.

Each time a player A ask for a game we check in the LFG player list if one player is matchable with A regarding flexible criteria. If not A is added to the LFG list. Then regularly the list is checked up to lower the matching expectations for people that are LFG for a long time. One player shouldn't wait more than 15 to 30 sec to find a game.

It seemed to me the base matchmaking API was not able to do so and we'll probably have to roll our own system.

----

For now, whenever a player connects to our system we open a webSocket connection with the server. And only then the matchmaking happens, but all the protocole passes through it.

It does not seems like Game Server Instances are made for this purpose. As I understand it we should do the matchmaking first and only then create a websocket connection for both the players.

The only option I see here would be to have a dummy "1player_game_mode", that opens a ws connection and manages everything a player have to do on his own and even vs AI games. So we take advantages of server scaling/management even here and let the matchmaker decide where to connect players.

Then each time the player joins a PvP game if both the players are not in the same instance we close one connection and make them both rejoin the same server.

Does this looks correct, what is the preferred way to manage the non-multiplayer part ?

10 |1200

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

brendan avatar image
brendan answered

The PlayFab matchmaker finds the first available slot matching the parameters specified, and returns that server's info, reserving a slot in it. While we do want to provide a queue-type matchmaker in a future update, one thing we've very clearly seen is that there's a wide range of ways titles want to control matchmaking - that's why we have the Matchmaker API, so that you can build your own matchmaker and have it control server spin up and what specific instances players are added to (while still hosting servers in PlayFab). So yes, you could easily build the type of matchmaker you're talking about.

In either case - and specifically for your non-multiplayer component - your game play server would indeed be distinct from the matchmaker server (yours or ours). It sounds like you have a number of things you want to do with server-side authority which are outside the scope of the gameplay server, so that functionality could live on your matchmaker.

10 |1200

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

contact-3 avatar image
contact-3 answered

Thank you very much for your patience, we're getting closer,

We can have :

- A matchmaker/authority server build that works with the "matchmaker_game_mode"

- A gameplay server build that works with a "1v1_game_mode" or "coop_mode"

- Any other specific build and associated game modes

For the matchmaking queue :

- We can have a queue of all LFG players stored in a shared Server Title Data or even using cloud script to deal with concurrency. Cloud script will behave as the "master server" concerning the queue management.

We'll simply have to open/close WS connections to specific servers when joining and leaving by requesting a "game" with the specific mode.

So we're assured that matchmakers and gameplay servers will lift heavy loads being able to replicate and that concurrency will be safe.

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.