Stand-alone game timer anti-cheat solution

Original link: http://www.cnblogs.com/lifesteven/p/4633799.html



A cheating method described
    some of the game will allow players to wait for some time, in some cases, such as candy crush game in failure will consume a little less physical, physical dissatisfaction when, every 30 minutes will rise a little. You can not play games when physical exhaustion, then the player can modify the system time, transferred the next time, and then return to the game, the strength will swell. This control of the game becomes ineffective.

    Principle: When consumed a little less physical, the game will record a time t1, wait until the current time is t1 + 30 minutes, it will add a little strength. If the system time to adjust after half an hour, there is no need to wait for a direct recuperate.


Second, Solutions
1. Calculate the boot time by running boot time
    ios and android provides a method of: obtaining from boot time to run now. This method is the use of time to do the check. By acquiring the current time (may be modified) and run the boot time, boot time can be calculated (the former minus the latter), if kept switched on, then the boot time should be the same. If a power-on time and the last calculated calculated different, then an error based on a timer.

2, the recording start time
    will be recorded when the start time running the game for the first time, for later comparison calculation.

3, network time correction
    when a user abnormal time, such as backwards in 1 hour, the calculated power different from the last time, this time the correction time networking needs. The correct current time acquired from the network, users comparison time (may be modified), calculate the time difference between the one hour, records this time difference. After each user obtain the current time minus the time difference at all times, as a result may be able to correct system time, boot time and then calculated according to the method is more accurate. Time correction will be reset after the last boot time as a new reference value.


Third, the sample
    enters the game, to obtain the current system time 8:00, 3 hours to obtain operating power is calculated start time 5:00.
    The game at 9 o'clock triggered a 30-minute timer, should be completed in the 9:30 time. At this time, the user switches to modify the system time set to 10 points.
    Back to the game, a timer will be checked, the system time is 10:00, the boot 4 hours of running time is calculated from the boot 6:00, and 5:00 before the recording is not the same, an error is judged that the timer. If you do not networking correction, it can not continue.
    After the user network, the network real time taken 9:00, the time difference to calculate the user 1 hour (10-9), resets the last boot time, 5 o'clock or not changed (is turned off and on if this value becomes).
    After the timer continues to make a correction, will take the user time minus the time difference, that can get real time, the timer can be a normal operation.
    If the user stay connected state, then the timer error will be corrected instantly.

 

 

Find a circle did not find time to get boot information, and thus whim, get a solution.

My thinking is: are registered program broadcast receiver for receiving a broadcast boot, after receiving the broadcast program, write to the file SharedPreferences, when we need to use the program start time, and then read the information from SharedPreferences.

Ado, the source below.

AndroidManifest.xml

Receiver files, boot record time.

public class BootUpReceiver extends BroadcastReceiver {
	private SharedPreferences sharedPreferences;// 配置文件
	private Editor editor;// 更改配置文件的类实例

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

			sharedPreferences = context.getSharedPreferences("这是存储文件的名字",
					Context.MODE_PRIVATE);
			editor = sharedPreferences.edit();

			editor.putLong("存储时间的key", new Date().getTime());

			editor.commit();// 别忘了提交哦
		}

	}
}

Read boot time

/**
 * Description : 获取开机的时间
 *
 * @return String 秒数
 *
 */  
public static long getUpTime(Activity context) {
    SharedPreferences sharedPreferences=context.getSharedPreferences("这是存储文件的名字", Context.MODE_PRIVATE);
    long seconds= sharedPreferences.getLong("存储时间的key", new Date().getTime());
    return seconds;
}

Reproduced in: https: //www.cnblogs.com/lifesteven/p/4633799.html

Guess you like

Origin blog.csdn.net/weixin_30470643/article/details/94925801