Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Jay_Santos · Feb 21, 2012 at 01:14 AM · timedatetimetimestamp

System.DateTime.now and how to avoid time cheats

Hi,

I want to reward my player if he comes back to my game every day.

The obvious solution for this would be something like:

     DateTime currentTime = DateTime.Now;
     TimeSpan ts = currentTime - Convert.ToDateTime (GameParameters.lastPlayDate);
     if (ts.TotalHours > 24)
     {
         Debug.Log ("Welcome back, here's a prize for you!");
     }

But, this approach can be exploited by changing the time and date on my device. I'd like to avoid that, I've look for an answer here, in Unity forums and in game dev in general and I couldn't find any answer...

Is there any way to avoid this cheat at all? Either locally or, say, getting time and date from a server via Unity?

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by reddragonpradeep · Jun 16, 2017 at 10:29 AM

For Local use in Android use this method to get system elapsed Time , independent of System Date And Time

C#

public static long ElapsedTime(){ if (Application.platform != RuntimePlatform.Android) return 0; AndroidJavaClass systemClock = new AndroidJavaClass("android.os.SystemClock"); return systemClock.CallStatic<long>("elapsedRealtime"); }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by Vavius · Aug 01, 2014 at 06:25 AM

I've published an asset to solve this task locally on mobile platforms. With the help of native system code it tracks down device date and time changes and calculates unbiased time.

Works only on real Android and iOS devices. It is useful even if you use server timestamps, since user can turn off connection and cheat.

http://forum.unity3d.com/threads/system-datetime-now-and-how-to-avoid-time-cheats.124282/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image furic · Apr 22, 2016 at 10:54 AM 0
Share

I was surprised while testing this function with Crossy Road and it just works as you said in the plugin. Not sure if the developer uses this plugin too...

I force quit the game, switch on flight mode, set time become 1 hour later, back to the game and the free gift time still the same!

Will definitely take a look for the plugin if it working like Crossy Road!

avatar image
2

Answer by MorleyInsane · Mar 01, 2012 at 04:28 AM

Have your game ping a server to get the time. So if you are serving content (like news and such)to the game, use the server for that service to get the time. If they can't connect to the server (no connection, or site is down) they don't receive the reward(possibly build in a recheck on next launch?)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LilGames · Jan 28, 2020 at 03:38 PM 0
Share

That works, but then you have to consider server load if your game gets popular. (A nice problem to have I suppose! :) )

avatar image
1

Answer by jnc1 · Feb 25, 2014 at 01:18 PM

Hello,

You can work with a database containing a last_logged for your players and create a php server, here is an example : http://wiki.unity3d.com/index.php?title=Server_Side_Highscores#Step_3:_The_Unity_HSController_Script

With php you can get the server time so like this even if the player change is time locally this will not have any impact.

Of course you need to check if he can get his reward in the php file :

 if [time] > 0 and [time] <= [lastlogged] {
     // send reward
 } else {
     // no reward for you
 }

Like this, if the player connects after 00:00 server time you can send him a notification of reward

Sorry for this "code" because that is no code but working progress. Actually I plan to do a system reward in my project, it is not already implemented but I know how it will process.

I hope for you that you already found a way, cause it is a 2 years old post, but I was passing by ^^

edit : WWW can get the content of the url specified, so printing the response with 'echo' is sufficient

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Leaton · Nov 18, 2017 at 10:27 PM

I use the internet time to keep my time and date the same across all devices. http://leatonm.net/unity3d-internet-time-date-setup-guide-stop-time-cheat/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why in game time is correct in dev env. but not in browser 1 Answer

How to make a date/time system with a fast forward feature? 2 Answers

Save current time on quit, then on relaunch compare to new current time and get difference? 3 Answers

How can I track how much time has passed since a game was turned off? 2 Answers

Check System Time and execute function 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges