Reputation: 10571
I am developing unity build (exe) and trying to implement such an algorithm that expire my player after certain time (e.g., after one week or one month). Here is the complete tested code with one little (actually big) problem:
public class LocalLimitedDaysLicense : MonoBehaviour
{
float numberOfDays = 3;
public string currentDate;
bool isShowExpiryMessage;
void Awake()
{
string playerPrefKeyName = "PlayerStartDateKey";
currentDate = DateTime.Now.ToString();
string playerStartDate = PlayerPrefs.GetString(playerPrefKeyName, "");
if (!PlayerPrefs.HasKey(playerPrefKeyName))
{
Debug.Log("Player Start Date Setting");
PlayerPrefs.SetString(playerPrefKeyName, currentDate);
}
else
{
Debug.Log("Player Start Date already Set");
}
string playerPrefsSaveDate = PlayerPrefs.GetString(playerPrefKeyName);
DateTime today = DateTime.Now;
DateTime playerFirstActiveDate = Convert.ToDateTime(PlayerPrefs.GetString(playerPrefKeyName));
DateTime playerLimitDate = playerFirstActiveDate.AddDays(numberOfDays);
if (DateTime.Compare(today, playerLimitDate) > 0)//confirm that
{
Time.timeScale = 0;
isShowExpiryMessage = true;
}
if (DateTime.Compare(today, playerFirstActiveDate) < 0)//Confirm that user didn't change the date of system
{
Time.timeScale = 0;
isShowExpiryMessage = true;
}
}
void OnGUI()
{
if (isShowExpiryMessage)
{
GUI.Label(new Rect((Screen.width / 2) - 100, Screen.height / 2, 300, 100), "Sorry the exe has expired.!");
}
}
}
It truly halt the program if certain days passed in the build but the problem is, if the user removed the old build and installed the build again then it will allow three days again.
Upvotes: 1
Views: 785
Reputation: 23174
It's not possible to control that from the client only.
By the way, there is another more simple flaw in your checking logic : user can simply change the date on its machine.
Do not try to enforce security features by trusting information from client only. Especially things that can be simply checked serverside.
As suggested by Reezoo Bose, you should implement some server-side checking.
(And if you want to prevent hacking this protection, you should also secure the communication with correct authentication and message signing. Of course it depends on which "tech level" users you are willing to protect your software against.)
Upvotes: 1
Reputation: 190
1.Create a web API that will register the date to the server database.
2.Create another API That returns true or false depending on your player expire logic and fire the API when the game starts every time.
Upvotes: 1