2
\$\begingroup\$

Can we let a time counter working even if an app is closed? I would like to add a timer so that we have to wait XX seconds/minutes before a building is created in a game.

I don't want to use an internet connection, and if the user closes the app and just changes the time on his mobile, I cannot compare the 2 time values - before and after.

Would you know how to do this?

Thanks

\$\endgroup\$
1

3 Answers 3

0
\$\begingroup\$

Timestamp modification is a type of memory-modification cheating, as asked here. The solution is the same:

Is your game multi-player?

If yes, keep an authoritative timestamp on the game server that you already have.
If no, where's the problem? Your players are only cheating themselves.

\$\endgroup\$
6
  • \$\begingroup\$ it is not multi-player, I am trying to avoid having some players beating the leaderboards by 1000% in some hours, when other could take a week to get the same result :) \$\endgroup\$
    – Paul
    Jul 18, 2013 at 14:51
  • \$\begingroup\$ Ah, the terminology gets my way! :D It's the same idea: Multiple players are interacting by competing on a leaderboard. As long as some such interaction exists, players might cheat others. Your options are security by obscurity (but here's why not) or keeping a copy you know is correct. \$\endgroup\$
    – Anko
    Jul 18, 2013 at 15:53
  • \$\begingroup\$ I'm not sure the player would be modifying any timestamps in this situation. It's the actual device clock that's changing, nothing in-memory with the game. (Which is why I also don't think this is a duplicate of the memory editor question, not only because that one has to do with desktop games). \$\endgroup\$
    – House
    Jul 19, 2013 at 13:45
  • \$\begingroup\$ @Byte Whether or not intentionally changed, the device clock is not a global authority on current time. The clock value is loaded into memory by any application that wants to inspect it, where it's then susceptible to memory editing. This is a layer of abstraction up, but they're fundamentally the same problem. \$\endgroup\$
    – Anko
    Jul 19, 2013 at 15:02
  • 1
    \$\begingroup\$ For example, one strategy for preventing memory editing would be multiple copies of the value, or multiple data types representing the same data. This wouldn't work in this situation because there's nowhere to get an accurate value to begin with. This question is essentially "How do I trust the client, when the client is the only source for this value?". Of course the answer is, you can't. \$\endgroup\$
    – House
    Jul 19, 2013 at 15:29
4
\$\begingroup\$

If you're wanting to ensure the time is accurate, you should get the time from the internet or from the GPS on the device.

If the user closes the app, there is nothing left to run a timer with. Even services are paired with a process and will get cleaned up if not being used.

You can detect time changes when your app is running, but your app won't know what happened while it wasn't running.

Here's a strategy that may work. It does involve using the internet, but it limits the usage to times when the user should likely have a connection. This avoids the player not being able to play when there's no connection.

  1. When the game is installed, connect to the internet and get the time you want to use, along with the device time.
  2. Every time a building is built, record a timestamp to the file system. (If a connection is available, get the time from the internet to verify).
  3. When/if the player submits their score the leaderboard, connect to the internet again and get the time you want to use. Ensure that all the buildings were built between the current time and the last valid time you have recorded. If it's impossible for the player to have built that many buildings in that time frame, invalidate the score.

It doesn't detect every case, but it should help a little.

\$\endgroup\$
3
  • \$\begingroup\$ Ah, the silent downvote, what could be less useful? \$\endgroup\$
    – House
    Jul 19, 2013 at 13:05
  • \$\begingroup\$ Hi Byte56, sorry it was me, it's because that I read that solution with internet and the file in the other answers, and I would prefer not to use internet, and avoid the issue with changing the clock as I said in my post. But nothing personal, I put the +1 back for your answer. (edit: as soon as I can ;) it's locked now) \$\endgroup\$
    – Paul
    Jul 19, 2013 at 13:14
  • \$\begingroup\$ I know it's nothing personal Paul. It's just nice to have a reason so I can make it a better answer! I've tried to do just that. \$\endgroup\$
    – House
    Jul 19, 2013 at 13:21
1
\$\begingroup\$

can you not just log something in a file or something that says "pending event at time X". Then when the game is next loaded do the required "add building" if the time is passed?

Failing that, if the game is server based surely all that happens is when the game is next loaded the change is picked up because the server already did it.

It's more a case of ... Is the game running or not? If it is, then it likely has a UI, if it isn't then me as a user, i don't want that game doing stuff i'm not expecting. Seems suspicious when devs try to this sort of stuff.

\$\endgroup\$
2
  • \$\begingroup\$ "if the time is passed" If I check the time when he comes back, the user could just change his own clock on his mobile I guess? \$\endgroup\$
    – Paul
    Jul 18, 2013 at 14:47
  • \$\begingroup\$ i guess it depends if this "time based event" is critical / likely to result in some sort of exploit ... most people code their games in such a way that they effectively pause when unloaded. \$\endgroup\$
    – War
    Jul 19, 2013 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .