Making a lazy server for an MMO

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

Moderators: Lapo, Bax

andrew2110
Posts: 90
Joined: 28 May 2008, 13:36

Making a lazy server for an MMO

Postby andrew2110 » 25 Apr 2017, 14:37

I'm now trying to write an MMO, obviously trying to minimize the CPU power used by the server whilst supporting the most number of users. I've been trying to think of the best way to go about this for a while now and hopefully with an MMORoom I might have a potential, fairly lightweight solution. If someone has a minute to look over this design and just tell me: Yes that looks ok, or No, that's terrible - it would be much appreciated.

- Server has a variable: currentFrame of type Long. This is updated 10 times a second, each time adding 3 frames to currentFrame. This is done via:

SmartFoxServer.getInstance().getTaskScheduler().scheduleAtFixedRate(...);

. The client updates at 30 frames per second. This number is sent to the client when the client joins the room and periodically the client gets an update on this number to make sure it's not gotten too far ahead / behind.


- When a user changes their input, all these are set as UserVariables (the thought being that user variables only update to users in the AoI in an MMO room)
  1. their current position is set using: new SetUserPositionRequest();
  2. their current rotation is set using single float value (it's 3D, but they can only really turn around in circles)
  3. their current speeds are set using a float array (forward speed, rotation speed)
  4. the frame on which this update started is set as "Update set at" variable

With this, the clients would be able to interpolate accurately with very little overhead on the server side?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Making a lazy server for an MMO

Postby Lapo » 26 Apr 2017, 09:02

It makes sense.
With a 30fps update you will need to use UDP for your updates and UserVariables only work with TCP, so I'd recommend switching to custom Extension calls. Unless you're doing this for mobile... in which case TCP would be better and 30fps is likely to be too much in any case.

Other than that I think you're on the right track.

On a related note we managed to make real-time games with TCP using a less frequent update rate (see our SpaceWar tutorial), but of course this depends on the type of game. In our case TCP was more than enough.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
andrew2110
Posts: 90
Joined: 28 May 2008, 13:36

Re: Making a lazy server for an MMO

Postby andrew2110 » 26 Apr 2017, 11:20

Oh sorry, I didn't mean that the server would send out packets 30 times a second, the server wouldn't actually have to send updates out other than the OnUserVariableChange events. All the server will be doing really is ticking its frame counter upwards which all the clients use to keep in sync, and bouncing the user variable updates to one another - the idea being that there's minimal data transfer and processing overheads on the server.

A thought I did have though was that I'll have to make the user do a SetUserPositionRequest every change of input AND after every X change of distance otherwise they could be moving with constant input for 5 minutes and the AoI would never update.


Thanks for letting me write out my ideas here, it's good to get my thoughts written out somewhere and hopefully if someone does see me being an idiot they can come tell me so!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Making a lazy server for an MMO

Postby Lapo » 26 Apr 2017, 12:15

Sorry I misunderstood. You just meant the FPS that the client is running at ... Not a network update rate :D
Ok... force of habit. :mrgreen:

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
meanvel
Posts: 129
Joined: 19 Jan 2017, 14:06

Re: Making a lazy server for an MMO

Postby meanvel » 28 Apr 2017, 07:22

andrew2110 wrote:A thought I did have though was that I'll have to make the user do a SetUserPositionRequest every change of input AND after every X change of distance otherwise they could be moving with constant input for 5 minutes and the AoI would never update.

Thanks for letting me write out my ideas here, it's good to get my thoughts written out somewhere and hopefully if someone does see me being an idiot they can come tell me so!


I don't even do that... I just set the destination cell X/Y and all the clients in AOI calculate the pathfinding by themselves. Stays plenty in sync for a normal RPG type MMO. Very cheap to do it this way, could run 100k players on one server.

AOI is updated every 4 cells moved. One screen is twenty cells wide.
andrew2110
Posts: 90
Joined: 28 May 2008, 13:36

Re: Making a lazy server for an MMO

Postby andrew2110 » 11 May 2017, 15:50

Thanks meanvel! I'll keep this in mind! I've got this coded up now so it seems to work pretty well although it was a lot more complicated than I had first thought!

Basically the way it's working now the remote player has two "bodies" the one that the client sees and one that is 100% accurate and invisible. The one that the user sees just calculates whether the 100% accurate version is infront or behind where it is right now and accelerate / brake to try and keep itself in sync with the accurate version as best it can.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 57 guests