Jump to content
  • Advertisement
Sign in to follow this  

Dealing with latency in Farmville-type game

This topic is 2086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would you deal with latency in a Farmville-type game? Specifically -> if you have farm land that produces items like grapes (every 60 seconds), and you have a visual timer on the client that starts at 60 seconds and counts down to 0 seconds... how do you make it so the client and server match up? I'm thinking the client can probably get to -1 or -2 seconds or so before the server tells the client the grapes are ready. Even if you keep displaying "0 seconds" on the client, people will know that it took an extra 1 or 2 seconds for the grapes to be ready.


My thoughts:
1. Trust the client (if the client is collecting grapes, they are ready even if the server doesn't think they are). I don't think this is a good idea. A hacked client could collect grapes whenever they wanted to.
2. The server sends the "grapes are available" message a few seconds ahead, but the client still waits for the full countdown to allow grape collection. This is better than #1, but a hacked client could still collect faster than a normal client.
3. Focus on reducing latency
I'm thinking a combination of #2 and #3 is the way to go, but please provide your insights.

Share this post

Link to post
Share on other sites

I'd say don't worry about matching it up. Just do something like this

1) Player "plants" grapes and sends message about planting to server.

2) Server sets timestamp for when grapes should be ready and sends that timestamp back to client

3) Client calculates time left till ready based on time stamp.

4) Player "collects" grapes by clicking grapes initiating a message from client to server to collect grapes.

5) Server compares message received time to grapes ready timestamp.

6) If time past time stamp send "OK- Qnty picked" message to client else send "Too early" timestamp to client.


Using this method, the lag will occur on the front end, between when a player chooses to plant to grapes and when they actually start growing... yet the count down will still 

be displayed correctly on the client. Then, there may be a bit of lag between Collect grapes, got grapes... but a savy user, recognizing they have lag could click a second early and still collect properly... 

Basically, the client only sends Plz plant, and Plz collect... let the server decide  if it is ready or not.. and since you are sending the pre defined ending time rather than the time left you don't have to worry about them being out of sync b/c it isn't a time sensitive value any more.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!