• Hello
Search Results for

    Show / Hide Table of Contents

    Universal - Device Time - Detector (Pro)

    Many games use the device clock for trials, daily rewards, or timers. The player can change that clock in the system settings. This detector notices the change and gives you a safer time.

    This detector needs the Pro version.

    Walkthrough: Protecting against device clock cheating.

    What it does

    DeviceTimeCheatingDetector (namespace GUPS.AntiCheat.Detector) does two things:

    • It detects. It listens to the two device time monitors. They compare the device clock with clocks the player cannot edit. The detector decides if the clock was moved.
    • It keeps a safer time. ProtectedTime.UtcNow returns the time in UTC, the world time without time zones. It comes from the internet when that works. Otherwise it starts from the device clock and then counts on with a clock the player cannot edit.

    Do you need to add it?

    No, if you use the predefined Anti-Cheat-Monitor prefab. It already includes this detector and both monitors.

    If you use your own monitor prefab, drag the Device Time Cheating Detector prefab onto the monitor so it becomes a child. The prefab holds the detector and both monitors together.

    The detector prefabs in Assets/GUPS/AntiCheat/Resources/Prefabs/Detectors.

    Note

    DeviceTimeContinuousMonitor and DeviceTimeEventMonitor must be on the same GameObject as the detector. If both are missing, the detector logs a warning and does nothing.

    Settings

    The DeviceTimeCheatingDetector settings.

    • Is Active (isActive, bool, default true): Turns the detector on or off.
    • Possibility Of False Positive (possibilityOfFalsePositive, 0 to 1, default 0.25): How likely a find is a false alarm. A drifting clock or a long sleep can look like a moved clock.
    • Threat Rating (threatRating, default 400): How much one find adds to the threat score.
    • Tolerance (tolerance, seconds, default 25, minimum 1): How far the device clock may be off before it is reported. A range of 10 to 60 is a good start.
    • On Cheating Detection Event (OnCheatingDetectionEvent): Methods to call on every find.

    The internet time settings (Use Internet Time, Server Address, Server Certificate Hash) are on the DeviceTimeEventMonitor, on the same GameObject. See the monitor page.

    Use ProtectedTime.UtcNow

    Replace DateTime.UtcNow with ProtectedTime.UtcNow (namespace GUPS.AntiCheat.Protected.Time).

    // Before
    bool canRefill = DateTime.UtcNow >= nextRefillUtc;
    
    // After
    bool canRefill = ProtectedTime.UtcNow >= nextRefillUtc;
    

    The first read from the server takes a moment after the game starts. Until it works, the protected time uses the device clock. For a reward that must only use the server time, wait for IsServerTimeResolved:

    var detector = AntiCheatMonitor.Instance.GetDetector<DeviceTimeCheatingDetector>();
    
    if (detector != null && detector.IsServerTimeResolved)
    {
        // ProtectedTime.UtcNow now comes from the server.
    }
    

    What it reports

    On a find, the detector sends a DeviceTimeDetectionStatus:

    public struct DeviceTimeDetectionStatus : ICheatingDetectionStatus
    {
        // The kind of cheat. Always ECheatType.DeviceTime.
        public ECheatType CheatType { get; }
    
        // How likely this find is a false alarm, from 0 to 1.
        public float PossibilityOfFalsePositive { get; }
    
        // How much this find adds to the threat score.
        public uint ThreatRating { get; }
    
        // Which check found it: Clock, Internet, or Local.
        public EDeviceTimeCheck Check { get; }
    
        // Stopped, Backward, Forward, or Untrusted.
        public EDeviceTimeDeviation Deviation { get; }
    }
    
    • Clock: the device clock jumped while the game was running.
    • Internet: the device clock disagrees with the time from the server.
    • Local: the device clock disagrees with the time saved in the last session.

    You can also read these properties on the detector:

    • PossibleCheatingDetected: true while a moved clock is found.
    • IsServerTimeResolved: true once the protected time comes from the server.
    • CurrentUtcTime: the protected time. ProtectedTime.UtcNow returns the same value.

    Good to know

    • The flag clears. PossibleCheatingDetected turns false again once all three checks agree with the device clock. Most other detectors keep it true.
    • Each check reports on its own. One moved clock can cause up to three finds. That is why one find reaches the soft punishers and a second one can reach a hard one.
    • A failed server read is not a cheat. The last trusted time is kept.
    • Offline players. Without internet, IsServerTimeResolved stays false. The clock is still watched while the game runs.
    • The time is remembered. The trusted time is saved between sessions, so a clock that was moved back while the game was closed can be noticed.

    Platforms and requirements

    Every platform.

    The detector needs at least one of the two device time monitors on the same GameObject. The prefab includes both. Internet time needs a connection to the server you set.

    React to a find

    Every find is added to the threat score of the Anti-Cheat Monitor. The predefined monitor prefab has no punisher. So nothing more happens to the player until you react yourself or add a punisher.

    In the Inspector. Add a method to On Cheating Detection Event. It runs on every find.

    Inspector callbacks on a detector.

    In code. Ask the detector:

    var detector = AntiCheatMonitor.Instance.GetDetector<DeviceTimeCheatingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // The device clock was moved.
    }
    

    Or listen, so your code runs at the moment of the find. Subscribe returns an IDisposable. Dispose it when you want to stop.

    using System;
    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Core.Detector;
    using GUPS.AntiCheat.Detector;
    using UnityEngine;
    
    public class DeviceTimeDetectionLogger : MonoBehaviour, IObserver<IDetectorStatus>
    {
        private void Start()
        {
            var detector = AntiCheatMonitor.Instance.GetDetector<DeviceTimeCheatingDetector>();
            detector.Subscribe(this);
        }
    
        public void OnNext(IDetectorStatus status)
        {
            if (status is DeviceTimeDetectionStatus time)
            {
                Debug.LogWarning($"Device clock moved. Check: {time.Check}, change: {time.Deviation}");
            }
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    Back to the Detector overview.

    In This Article
    Back to top GuardingPearSoftware documentation