Single-player game timer anti-cheat solution

Source: Internet
Author: User



I. Description of cheating method
Some games will allow players to wait for a period of time in some cases, such as a Candy Crush in which the game loses a bit of physical strength, and when physically dissatisfied, it will rise a little every 30 minutes. When you are exhausted, you can no longer play the game, at which point the player may modify the system time, adjust to the future time, and then return to the game, the physical strength will be full. This control of the game fails.

Principle: When a bit of physical exertion, the game will record a moment T1, until the current moment of t1+30 minutes, will add a little energy. If the system time is adjusted for half an hour, then there is no need to wait for a direct response to physical strength.


Second, the solution of ideas
1. Calculate Start-up time by power-on operation
Both iOS and Android provide a way to get the uptime from boot to current. is to use this method to do time calibration. By getting the current time (possibly modified) and running time, you can calculate the power-on time (the former minus the latter), if you keep the boot state, then this boot time should be unchanged. If the start time calculation is different from the last time, then you can determine the timer error.

2. Record boot time
The first time you run the game, the boot time is recorded and used for the comparison of subsequent calculations.

3. Network Time correction
When the user time is abnormal, such as 1 hours back, calculate the boot time and the last different, this time need to network remediation. Get the correct current time from the network, compare the user time (which may be modified), calculate the difference of 1 hours, and record the difference. After each time to obtain the user's current time to subtract this difference, the results can be used as the correct system time, and then according to the 1 method to calculate the boot time is more accurate. Time correction will reset the last boot time as a new reference value.


Iii. Examples
Enter the game, obtain the current system time of 8 o'clock, get the boot run 3 hours, calculate the boot time is 5 points.
The game triggers a 30-minute timer at 9 o'clock, which should be done at 9:30. At this point the user cuts to the settings and modifies the system time to 10 points.
Back to the game, will be a timer check, the system time is 10 points, the boot run 4 hours, calculate the boot time is 6 points, and the previous recorded 5 points not the same, to determine the timer error. If the user does not perform a network correction, the operation cannot continue.
After the user is networked, take out the network real Time 9 o'clock, calculate the user difference 1 hours (10-9), reset the last boot time, or 5 o'clock did not change (if it is shutdown and then boot this value will change).
After the correction to let the timer continue, take the user time will be subtracted from the difference, that is, the real time can be obtained, then the timer will be able to run normally.
If the user stays connected, the timer error will be corrected instantly.

Find a lap did not find the boot time data can be started, so the whim, got a solution.

My train of Thought is: The program registers a broadcast receiver, receives the start-up broadcast, when the program receives the broadcast, writes the file sharedpreferences, when our program needs to use the boot time, then reads the information from the sharedpreferences.

Nonsense not much to say, below the source code.

Androidmanifest.xml

Receiver file to record the boot time.

public class Bootupreceiver extends Broadcastreceiver {private Sharedpreferences sharedpreferences;//config file private Editor editor;//Change the class instance of the configuration file @overridepublic void OnReceive (context context, Intent Intent) {if (Intent.getaction (). Equals (intent.action_boot_completed)) {sharedpreferences = Context.getsharedpreferences ("This is the name of the stored file", Context.mode_ PRIVATE); editor = Sharedpreferences.edit (); Editor.putlong ("Key for storage Time", new Date (). GetTime ()); Editor.commit ();// Don't forget to submit Oh}}}

Read boot time

/** * Description: Get boot time * * @return String seconds * */public  static Long Getuptime (Activity context) {    Sharedpref Erences sharedpreferences=context.getsharedpreferences ("This is the name of the stored file", context.mode_private);    Long seconds= Sharedpreferences.getlong ("Key for storage Time", new Date (). GetTime ());    return seconds;}

Single-player game timer anti-cheat solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.