Universal - Device Time - Detector (Pro)
Using the current date and time is essential for many applications. However, relying on the clock of the user's device creates trust issues as users can manipulate it for various purposes, such as extending trial periods or gaining advantages in games. AntiCheat has introduced a way to step up against such time manipulation.
Detector
The 'DeviceTimeCheatingDetector' is used to detect device or system time manipulation. It observes the 'DeviceTimeMonitor' and subscribes to time deviations, based on this it calculates the possibility of cheating and notifies observers of the detected cheating. It also provides a trustworthy DateTime.UtcNow either calculated based on the internet time or device time, provided in the ProtectedTime class.
Observed Subject
The detector observes the 'DeviceTimeStatus' sent by the 'DeviceTimeMonitor'.
Detector Status
The detector receives device time deviations and decides wether the device time was paused, speed up, slowed down or runs as planned. If a deviation and so cheating was detected, the detector notifies its observers with a 'CheatingDetectionStatus'. The status contains the following properties:
- PossibilityOfFalsePositive: A value indicating the possibility of a false positive when assessing threats for the implementing subject from 0.0 to 1.0.
- ThreatRating: The threat rating associated with the detected cheating, indicating the assessed level of a potential threat.
Supported Platforms
The detector is available on all platforms.
Requirements
There are no requirements.
How To Use
The usage is quite simple, attach a 'DeviceTimeMonitor' (if not already done) and the 'DeviceTimeCheatingDetector' to a child GameObject of the 'AntiCheat-Monitor' and define a reaction on cheating detection.
Add Monitor Component
To detect any kind of device time manipulation, an origin of device time deviation data is required. To do so use the 'DeviceTimeMonitor' and attach it to the same GameObject you will attach the 'DeviceTimeCheatingDetector' to. The detector will subscribe to the 'DeviceTimeStatus', containing the device time deviation, send by the monitor.
Add Detector Component
Manual
Add the 'DeviceTimeCheatingDetector' MonoBehavior from the 'GUPS.AntiCheat.Detector' namespace to your 'AntiCheat-Monitor' GameObject or better to a child GameObject, next to your 'DeviceTimeMonitor' MonoBehavior.
Add the 'DeviceTimeCheatingDetector' as Component.
Prefab
There is also a prefab, including the detector and the monitors, which you can directly attach as a GameObject to the 'AntiCheat-Monitor'.
Add the 'Device Time Cheating Detector' prefab to the 'AntiCheat-Monitor'.
Settings
After attaching the 'DeviceTimeCheatingDetector' MonoBehavior to a GameObject, you will see the following in the inspector:
The settings of the 'DeviceTimeCheatingDetector' Component.
- General Settings: Define here if the detector should be active.
- Threat Rating Settings: Define here the severity of the detected cheating.
- Observable Settings: Add here callbacks invoken when a cheating got detected.
- Device Time Settings: Apply here settings used to provide a trustworthy DateTime.UtcNow.
Runtime
On the Awake callback the detector observes the 'DeviceTimeMonitor' and subscribes to time deviations, based on this it calculates the possibility of cheating and notifies observers of the detected cheating. It also provides a trustworthy DateTime.UtcNow either calculated based on the internet time or device time, provided in the ProtectedTime class.
An abstract of the ProtectedTime class:
// Instead of using DateTime.UtcNow, use the UtcNow from GUPS.AntiCheat.Protected.Time.ProtectedTime.
public static class ProtectedTime
{
// The protected Coordinated Universal Time (UTC) DateTime (Read Only). The calculated utc time, which may differs from the original DateTime.UtcNow
// because it is calculated to be secure and trustable as possible.
public static DateTime UtcNow { get; }
}
React On Cheating
When the monitor (data provider) and detector (data validator) are set up, you sure want to react on detected cheating.
Punisher
In general, any cheat detected is forwarded to the 'AntiCheat-Monitor', which calculates an overall threat level. Based on the threat level, you can apply punishments by using Punisher components added to a child GameObject of the 'AntiCheat-Monitor'. There are some built-in punishers that you can find here as prefabs:
The location of the built-in Punisher prefabs.
Inspector
You can set a callback in the Unity Inspector view of the detector. This callback is invoken as soon as the specific cheating is detected.
A list of callbacks invoken when cheating got detected from the detector.
Code
If you would like to write a custom listener to the detector, you can attach an observer:
// Get the detector.
var detector = AntiCheatMonitor.Instance
.GetDetector<DeviceTimeCheatingDetector>();
// Subscribe as observer and get notified on inconsistency.
detector.Subscribe(myObserver);
Also the detector has an inherited property 'PossibleCheatingDetected' which is set to true once a cheating got detected.