- Home /
How do I implement an 'Expire after 30 days' system to a game developed in Unity?
Hi all,
I am making an educational game in Unity for a client, the client wishes the file to be password protected and then lock after 30 days, so anyone leaving the company cannot continue to use it if they have it on their machine (it is a training tool for internal use only).
Password protecting the file is not really a problem, I can use either a password protect on the file itself or implement one in-game (with the UI tools) when you start it.
The problem is getting it to 'expire' and then lock the user out.
So my question is, how do I get the game to know when 30 days have passed since the user first opened the file? I'm guessing it would need to read the system time to determine what the date was, or something similar? Or maybe have some kind of timer going, that will essentially count down to the expiry time.
Essentially I just need to be able to trigger a UI popup that tells the user they cannot use the application any more (and at the same time just deactivate the play button or something similar).
I am more of an artist than a programmer, so this sort of thing is a little above me, so I would really appreciate some pointers.
Is there a quick and easy way to do this or is it something that is going to be really complicated to set up?
If it is not possible, if anyone has any ideas of alternatives it would be much appreciated!
Thanks in advance
Answer by AlwaysSunny · Apr 27, 2015 at 10:23 PM
A rudimentary solution involves measuring changes in the System.DateTime.
Store the Date the application first ran, and check against this value each time it's run.
This may lead to issues with users who change time zones.
Also, this measure can be foiled by purging the registry values created by the program, or by manipulating the system's date and time settings.
The "right" way to overcome this is by linking access to a user account, and handling all login / access requests through your company server. The application waits for your web service to verify the login and passage of time, then allows or rejects the access attempt based on whatever criteria e.g. bad password or 30 days expired.
Assuming nobody hacks into your server and messes with these values, average users will have much greater difficulty circumventing the lockout.
As an additional protective measure, (to discourage desperate parties from using various "hacking" tools to "spoof" a login) your application and server might exchange some kind of key, on which mathematical operations are performed and verified, to allow or disallow access.
There's a whole industry built around creating these security measures. I expect you may get better, more cost-effective results by purchasing some kind of turnkey solution. In any case, UA is not the place to continue such a line of questioning.
Best,
As i said in my answer, in Unity you can't really implement security due to .NET / mono. You would have to use native code dlls for the most important things and have the security inside that dll to make it half way safe. Server communication is often said to be the best solution, but if the client can that easily be cracked it's not worth the server development / hosting ^^.
Hi AlwaysSunny,
Thank you very much for your detailed response. I only need something very basic, the client doesn't need anything too sophisticated, just a simple time check and popup when a specific time is reached.
Therefore I'm not worried about how easily it can be hacked or anything like that, the target audience is highly unlikely to be bothered doing that, nor would they be likely to know how to do it.
The first option you suggest sounds ideal, do you know of any example scripts I could look at for this action? I'm quite new to the program$$anonymous$$g side of things, so any pointers to write such a script would be much appreciated.
Thanks once again.
Answer by Bunny83 · Apr 27, 2015 at 10:43 PM
You could also use a simple self-checked serial key which you hand out to a user. Something like this:
http://answers.unity3d.com/questions/813827/looking-for-a-way-to-limit-software-use-to-weeks-t.html
However you might want to additionally keep track of the time "already passed" or use a web-time source in case the user tries to spoof the system time.
Keep in mind that all those security things are pointless if your users are intermediate / professional programmers. Unity compiles the scripts to .NET / mono assemblies which can easily be decompiled / manipulated. It also doesn't matter which platform your tool runs on. Even a webbuild or android app can be cracked without much efford.
If your users are "just users" any kind of time check (that doesn't store the timestamp as plain text next to the application or in the registry) will do.
Hi Bunny83,
Thank you very much for your response. $$anonymous$$y users are very much "just users" and are unlikely to have the knowledge or the interest the try and hack it. As I mentioned to AlwaysSunny, if you know of any examples of a script to do a simple time check it would be much appreciated, or even just some pointers to write one. I have until Thursday to do it, so am running out of time a little!
Thanks again.
Here I just setup a simple class with a "two time stamp" system. This script just has to be attached to a gameobject somewhere in your scene.
When you start the application the first time it will remember the current timestamp. Every 30 sec while the application is running it updates the "last" timestamp (which is used to detect if the system time got set back to a previous time) and checks if we are still within the set trial period (hardcoded to 30days (the value is given in seconds so it's 3600*24*30)).
If the trial period has expired it simply shows a GUI Label at the top of the screen and ter$$anonymous$$ates the application after 10 seconds. If it detects time spoofing it quits after 2 sec.
You might want to tweak the times or replace the OnGUI stuff with something made with the new UI, however that's up to you.
Hi Bunny83! Your code is working perfectly, the only problem is when the trial period is over, and we copy the .exe file on another device you can say PC or laptop then it does not recognize the date. it starts counting time when the application copied in that PC. How we can do this. Like if Trail period is over on PC 1 then the same file must show the trial period is over on PC 2.
Waiting for your response Thanks in advance.
Thank you very much, that script works perfectly and exactly what I needed! I really appreciate the help.
One quick question - in this line -
long epochTicks = new System.DateTime(2015, 04, 23).Ticks;
Does it matter what date I put in the brackets? Does it have to be the date I make the build?
Thanks again :D
@Bunny83 Can you please help me also. I am also trying to implement the same thing and i also got the idea how to do it but not able to compare date. Please help me. Thank you
How am i supposed to help you? You posted a question as comment to somebody else's question that contains no information. If you have a question, ask a question and do not bump old questions like this one. I gave two code examples. Note that examples are not meant as "solutions" but as inspiration to create your own solution that fits your needs.
If you ask a question, be more specific. Show what you have done already and where you're stuck
Ey, @Bunny83 , thanks for your code. It was a perfect solution for me.
Cheers,
Your answer
Follow this Question
Related Questions
Can non-admin users change their own password using the Unity Asset server system? 0 Answers
Publishing Settings (keystore password) not saving 1 Answer
Is it feasible to hide the password and serial key when activating a license from the command line 1 Answer
error keeps looping (smartfox connection) even after I stop testing my game 1 Answer
Help connection to SQL via Json file 1 Answer