6 Replies - 10958 Views - Last Post: 18 March 2013 - 03:09 PM

#1 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Update Users Data While Offline

Posted 18 March 2013 - 08:45 AM

Hey, so i'm sure we've all seen the popular games like "Mobsters Vendetta" on facebook or "iMobsters" for iOS and Droid; but i had a question, how do these games automatically restore the users energy and stuff when the user is offline. I know it's a server side script, but for the life of me, i can't think of any rational way someone would do this.

Does anybody have any ideas?

What we know:
- Would be updated using a server side script on a timer.
- Updates to a database.

This post has been edited by LilGhost: 18 March 2013 - 08:51 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Update Users Data While Offline

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9571
  • View blog
  • Posts: 36,243
  • Joined: 12-June 08

Re: Update Users Data While Offline

Posted 18 March 2013 - 08:55 AM

It's probably part of the log in script. Take the current time minus the time since you last logged in.. and figure out (on scale) how much you energy/etc you get back.
Was This Post Helpful? 1
  • +
  • -

#3 GrooN  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 20
  • Joined: 27-February 13

Re: Update Users Data While Offline

Posted 18 March 2013 - 12:04 PM

As Modi123_1 said, you could make it a part of the login process, which would eliminate having to calculate peoples energy levels over and over again, even for people who has chsoen to quit the game. Another solution could be to use a cron job (or pseudo cron job, like wordpress), and do the calculation from there. I think those are you options, for timing the operation. When it comes to the operation itself, do as modi said, figure out how much energy the user gets per a specific time period, and then see how many of these periods has occurred since last energy calculation.
Was This Post Helpful? 1
  • +
  • -

#4 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Update Users Data While Offline

Posted 18 March 2013 - 01:44 PM

In your opinion (i haven't tested) would this be alright pseudo code for the operation:
Time() - LastUpdateTime / (3 * 60)



Where a user automatically gains 1 energy for ever 2 minutes.

As for the automatic updating while in game, javascript and then a push command to a php file? the php file of course would do some server side checks to prevent hacking.

This post has been edited by LilGhost: 18 March 2013 - 01:45 PM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9571
  • View blog
  • Posts: 36,243
  • Joined: 12-June 08

Re: Update Users Data While Offline

Posted 18 March 2013 - 01:46 PM

Absolutely not. Unless you want odd order of operations.
Was This Post Helpful? 1
  • +
  • -

#6 GrooN  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 20
  • Joined: 27-February 13

Re: Update Users Data While Offline

Posted 18 March 2013 - 02:44 PM

View PostLilGhost, on 18 March 2013 - 01:44 PM, said:

In your opinion (i haven't tested) would this be alright pseudo code for the operation:
Time() - LastUpdateTime / (3 * 60)



Where a user automatically gains 1 energy for ever 2 minutes.

As for the automatic updating while in game, javascript and then a push command to a php file? the php file of course would do some server side checks to prevent hacking.


Yea, you're gonna need a parenthesis in there.
(Time() - LastUpdateTime) / (3 * 60)


Was This Post Helpful? 1
  • +
  • -

#7 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

Re: Update Users Data While Offline

Posted 18 March 2013 - 03:09 PM

View Postmodi123_1, on 18 March 2013 - 01:46 PM, said:

Absolutely not. Unless you want odd order of operations.

Then what would you recommend?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1