How to Stop Users from chaging time from client side (Use firebase server time in Unity)

If you are using an application which heavily depend on time for example you are releasing a cool feautre that is going to launch on a specific date and you are using something like :

DateTime.Now 

The problem with this is, this is dependent on the users device timestamp, users can easily change the system timestamp and go forward in time. 

One of the solutions is to use the firebase server time. Considering you have already added the firebase sdk to the project, if not please follow the guide:

https://firebase.google.com/docs/unity/setup#add-sdks


PS: Do not forget to add the FirebaseFirestore package, which will look like this: 






Once you have done this, use the following code to get the server time: 

Firebase.Firestore.Timestamp.GetCurrentTimestamp().ToDateTime();



Please comment if your are facing any problems making this work. Also please let me know in comments if there is an easier way to get the server timestamp. 

Comments