SFS Server Side Extension for Pong

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

JarrodParkes
Posts: 6
Joined: 27 Jun 2010, 23:23
Location: Madison
Contact:

SFS Server Side Extension for Pong

Postby JarrodParkes » 06 Jul 2010, 17:54

i have had a new train of thought for a multiplayer pong game that uses SFS server and its server side extensions.

this will help to control the possibility of cheating (which in the case of pong is not really that much, but i figured that experimenting with this "server-side protection" would be a good idea at the most simple level)

Here are the steps taken:

(1) the server initializes the players' starting paddle positions
(2) the server generates the ball and its starting direction or force
(3) the server receives inputs from both players for their requested paddle positions

...

(4) if the requested positions and the ball position (or maybe you give it collision bounds) collide, then the server will calculate a new direction for the ball
(5) if the ball's position falls outside a certain bounds then one of the players has scored a point

...

(6) give the correct player a point and re-initialize the ball

...

(7) if one of the player's scores reaches maybe 5 points, then the game is over

...

my main question is how can i update that ball's position every "Update" so that i can send that information to the clients? is that even possible? i do not want the clients to control the ball at all, then ball should just react on the server's calculations for collision, scoring, ect. is it possible to create a "game-loop" on the server that updates as the clients attempt to receive/interpolate/extrapolation/update as quick as possible?
Xbox360 Gamertag - TBRM 2
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 17 Jul 2010, 12:24

You will really need to have a server side simulation of the ball yes. This is not unlike FPS or other real time simulations where you have an autoritative server and the clients only rendering the results they get from the server.

What you need is to have time sync, interpolation (between recieving updates from server) and extrapolation (moving the ball in anticipation of where its going to be at this exact moment).

Remember, that the clients will always be behind the server time wise. So extrapolation is needed. Remember the important time sync and to add time stamp to each server update + the current "lag time" between server and client

/Thomas
JarrodParkes
Posts: 6
Joined: 27 Jun 2010, 23:23
Location: Madison
Contact:

Postby JarrodParkes » 18 Jul 2010, 18:06

Thomas,

Since the server does not have a "Update" function, are you saying that I would need to send a request from the client every update from inside Unity? And with the requests I would also send a time stamp so that the server can see how long it is taking messages to get to/from? Also, if the server has no "Update" function (or maybe does, this is the part I'm confused about) then how do I run the simulation of the ball movement in the server-side script?

Thank you for your help!
Xbox360 Gamertag - TBRM 2
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 18 Jul 2010, 21:30

Hi,

SFS has a scheduler class for coarse grained timed callbacks. For more fine grained control, simply make a thread on the server that runs all the time and periodically send out updates to the clients.

Thats at least how I'd do it. As usual there is not a single "right way". So your mileage may vary.

Best bet is to poke your head into the server extension forums and ask them what they usually do for an "update" loop.

/Thomas
JarrodParkes
Posts: 6
Joined: 27 Jun 2010, 23:23
Location: Madison
Contact:

Postby JarrodParkes » 19 Jul 2010, 14:33

i did not even realize there was a server extension forum. i will definitely check that and the scheduler class out, but what your saying sounds like a good solution for what I had in mind.

thanks again!
Xbox360 Gamertag - TBRM 2

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 25 guests