"Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

"Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Zenith » 23 Jun 2018, 20:44

Hi,
This is to understand what are your views regarding how can we implement scoring and virtual game currency integration between SFS and Unity now that game is actually ran on Unity instances and user accounts etc are on SFS.
We don't intend to make clients submit their scores and currency changes.
So what sort of architecture do you suggest where we can have communication between unity instance and SFS Room .

Regards.
Sorry if it is too noobish!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 25 Jun 2018, 08:58

There is nothing noobish about this :)
With the SFS2X + Unity approach each player is running two connections, so each client can talk to both your Extension and the Unity game code.

I would usually recommend to use Unity exclusively for the in-game logic, movement updates, positions, collisions etc... and SFS2X to the rest of the work such as managing in-game chat, buddy lists, database operations, etc.

With this said if the user wants to run a transaction with virtual currency the request should be sent to SFS2X which can validate the operation and update the user's profile via the DB.

Similarly the score should be managed by SFS2X. In this case it can be a little more complex because the score is probably calculated by the Unity server which in turn needs to store it somewhere at the end of the game.
What I would suggest here is that the Unity server sends the game scores via an HTTP call to a servlet running in SFS2X.

Makes sense?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Zenith » 25 Jun 2018, 15:34

Lapo wrote:
Similarly the score should be managed by SFS2X. In this case it can be a little more complex because the score is probably calculated by the Unity server which in turn needs to store it somewhere at the end of the game.
What I would suggest here is that the Unity server sends the game scores via an HTTP call to a servlet running in SFS2X.

Makes sense?


I get this but how does unity server know which player is which.
I mean to say there should be some API by which server can confirm that player who is sending his username to server as "Zenith" is actually "Zenith" and not the case that "Lapo" is logged in in SFS but is sending his username as "Zenith" to Unity server. :-P

So we need a way to verify the player in Unity Game Server is a valid logged in SmartFoxServer Player.
Maybe here also a ticket system can be made -->

Players logs in SFS.---> Gets Back a Ticket
Player sends the Ticket to Unity Server (instead of username) --> Unity Server sends Ticket to SFS.
SFS verified Ticket and sends back player Unique Id or Name to Unity Server.
Unity server sends score to SFS with that player Unique Id.

Is this appropriate approach?
Can you suggest some things to create Tickets or if they should be stored in db . Also tickets should Timeout.
Can this whole thing be made into SFS as API. Because this much system becomes as a must for communicating securely the scores from Unity Server to SFS Server.

Playfab Guys are doing it like this for external server support .
https://api.playfab.com/docs/tutorials/ ... me-servers

I think such or some alternate system for this would be great help to devs going to use Unity and SFS together in Best of Both World Scenario.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 25 Jun 2018, 16:09

So we need a way to verify the player in Unity Game Server is a valid logged in SmartFoxServer Player.
Maybe here also a ticket system can be made -->

Players logs in SFS.---> Gets Back a Ticket
Player sends the Ticket to Unity Server (instead of username) --> Unity Server sends Ticket to SFS.
SFS verified Ticket and sends back player Unique Id or Name to Unity Server.
Unity server sends score to SFS with that player Unique Id.

Yes, this is a good way to verify the user.
The "ticket" already exists, because each user is auto-assigned a session token (not the userId) which is 32 character random string.
You can use that as an identification.

Playfab Guys are doing it like this for external server support .

I didn't know about this one. We're working on a similar concept, for integrating Unity servers with SFS2X.
The project is currently on hold as we're waiting for the Unity team to improve the performance of the Unity server itself as we've found it currently uses too many resources even when idle, thus requiring quite a lot of extra power for running in this kind of distributed approach.

We've found this issue only very recently and submitted a bug report. Unity has gotten back to us confirming the bug, and promising to look into it, though they haven't provided a possible release schedule.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
mubashar
Posts: 14
Joined: 21 Dec 2019, 05:00

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby mubashar » 28 Dec 2019, 10:43

Lapo wrote:There is nothing noobish about this :)
With the SFS2X + Unity approach each player is running two connections, so each client can talk to both your Extension and the Unity game code.

I would usually recommend to use Unity exclusively for the in-game logic, movement updates, positions, collisions etc... and SFS2X to the rest of the work such as managing in-game chat, buddy lists, database operations, etc.

With this said if the user wants to run a transaction with virtual currency the request should be sent to SFS2X which can validate the operation and update the user's profile via the DB.

Similarly the score should be managed by SFS2X. In this case it can be a little more complex because the score is probably calculated by the Unity server which in turn needs to store it somewhere at the end of the game.
What I would suggest here is that the Unity server sends the game scores via an HTTP call to a servlet running in SFS2X.

Makes sense?


As u said here we can call the servlet for communication between unity instance and SmartFoxServer but as stated in the blog http call is very slow so can we make a socket connection among two like we do with client side and make unity instance a special user for confirming players, saving scores etc?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 28 Dec 2019, 15:05

HTTP calls are slow when they run across the internet but in a local network they are fast enough, unless your use case require continuous traffic. If it' just for the occasional score update and things like that HTTP will work fine in a local network.

Establishing socket connections is also a choice but I would recommend when your Unity game server is constantly sending updates or when there's a more complex interaction between the main SFS2X service and the Unity servers (i.e. SFS2X triggers events in the Unity game servers)

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games
mubashar
Posts: 14
Joined: 21 Dec 2019, 05:00

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby mubashar » 28 Dec 2019, 16:12

Yeah that makes sense.
I am planning to use smartfox with unity instance for each room(two players per room) and want to use jelastic paas for this. What are your suggestions regarding this setup? Will it be scaleable for thousands of concurrent users? And is jelastic suitable for this purpose, if so then which is the most appropriate service provider on jelastic like massice grid, eApps etc?
Also tell me if there are any better options
Thanks.
mubashar
Posts: 14
Joined: 21 Dec 2019, 05:00

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby mubashar » 31 Dec 2019, 07:34

Yeah that makes sense.
I am planning to use smartfox with unity instance for each room(two players per room) and want to use jelastic paas for this. What are your suggestions regarding this setup? Will it be scaleable for thousands of concurrent users? And is jelastic suitable for this purpose, if so then which is the most appropriate service provider on jelastic like massice grid, eApps etc?
Also tell me if there are any better options
Thanks.
User avatar
holyfiregames
Posts: 19
Joined: 16 Jul 2019, 19:11

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby holyfiregames » 31 Dec 2019, 16:26

Couldn't the Unity server just connect to the SFS server and communicate through SFS api like a trusted client connection or something like that? It could send over all of the player scores on set intervals or something like that with a normal SFS message.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 02 Jan 2020, 08:26

holyfiregames wrote:Couldn't the Unity server just connect to the SFS server and communicate through SFS api like a trusted client connection or something like that? It could send over all of the player scores on set intervals or something like that with a normal SFS message.

Yes and no, it depends how it's implemented.
With this approach every Unity server is logging into SFS2X as a client, which add to the list of actual players in the same Zone.
If you're relying on Rooms to keep your players organized I think you should be fine, as the Unity clients will not join any Room and therefore remain "invisible" in the system.

If, however, you are also relying heavily on Zone user lists then you will need a way to filter out those clients representing the connected Unity game servers.

A third way is to connect the Unity servers to a different Zone, so that they are entirely isolated.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Pirisok
Posts: 16
Joined: 06 Jan 2018, 10:11

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Pirisok » 28 Jan 2020, 09:05

hi
each user is auto-assigned a session token (not the userId) which is 32 characters random string


Is this session token unique for players?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 28 Jan 2020, 09:08

Hi,
Pirisok wrote:Is this session token unique for players?

Yes, it is.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
holyfiregames
Posts: 19
Joined: 16 Jul 2019, 19:11

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby holyfiregames » 06 May 2020, 21:43

Hi, has there been any updates to the API for leveraging Unity servers with SFS? I know this is an old post, but we're looking into this as an option right now and we're a little confused on the best approach for leveraging Unity as a server through SFS.

Could you please explain or give any tips on how the Unity server can control the game login in a MMO room for example where it would need to know and control everything in the room not just what's around it, or how it would control all of the units in the room for the AI for example. Any further explanation on how this works would be greatly appreciated. I've read through the two blog posts about combining Unity servers with SFS but I'm still confused on how the Unity server actually controls everything in the room if it doesn't have access to the server API only the client API through the c# SDK, or am I missing something there?

Could you also explain how the unity server sends it's info back to the clients, is this through the normal SFS messaging API so it would be a client API sending to client API, or is there somehow a way to send commands from Unity Server using the SFS Server API? In the articles it mentions that the client has 2 connections. One to SFS server and one to the Unity server. Is this two SFS connections, or does the Unity server chat with the clients through another networking engine like UNET? I'm having a hard time wrapping my head around how this all works with the Unity server.

Thanks!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby Lapo » 07 May 2020, 09:56

holyfiregames wrote:Could you please explain or give any tips on how the Unity server can control the game login in a MMO room for example where it would need to know and control everything in the room not just what's around it, or how it would control all of the units in the room for the AI for example. Any further explanation on how this works would be greatly appreciated. I've read through the two blog posts about combining Unity servers with SFS but I'm still confused on how the Unity server actually controls everything in the room if it doesn't have access to the server API only the client API through the c# SDK, or am I missing something there?

The idea proposed in the article is to use SFS2X as an orchestrator for multiple Unity servers (one per game), with different responsibilities.
SFS2X takes care of login, match making, launching games, chatting etc.
Unity takes control of the game itself. So essentially all of the game logic is taken care of by Unity server side code, not the SFS2X server API.

If you wanted to mix server side MMO API with Unity logic, it's going to be more complicated as you would need to split the game logic between two sides and make them communicate via local connection. It can be done but it makes things more complicated in terms of debugging, deployment etc...
I'd rather re-implement the basic MMO Room logic in Unity so that all game code stays in one place.

Could you also explain how the unity server sends it's info back to the clients, is this through the normal SFS messaging API so it would be a client API sending to client API, or is there somehow a way to send commands from Unity Server using the SFS Server API?

The idea is to use native Unity networking, be it the old UNet or any of the more recent replacements such as Mirror, for instance.
So each client would use one SFS2X connection and one Unity connection.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
holyfiregames
Posts: 19
Joined: 16 Jul 2019, 19:11

Re: "Unity and Smartfox Best Of Both Worlds" How to integrate scores and currency?

Postby holyfiregames » 07 May 2020, 15:44

Thanks, this cleared it up for us!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 55 guests