Improved licensing system somewhat - not completely done yet

This commit is contained in:
Thulinma 2017-01-15 16:45:09 +01:00
parent e4110502ee
commit 8a66913869

View file

@ -26,13 +26,18 @@ namespace Controller{
if (Storage.isMember("license") && Storage.isMember("license_id")){ if (Storage.isMember("license") && Storage.isMember("license_id")){
INFO_MSG("Reading license from storage") INFO_MSG("Reading license from storage")
readLicense(Storage["license_id"].asInt(), Storage["license"].asStringRef()); readLicense(Storage["license_id"].asInt(), Storage["license"].asStringRef());
if (!isLicensed()){
updateLicense();
}
}else{
updateLicense();
} }
} }
bool isLicensed(){ bool isLicensed(){
uint64_t now = Util::epoch(); uint64_t now = Util::epoch();
#if DEBUG >= DLVL_DEVEL #if DEBUG >= DLVL_DEVEL
INFO_MSG("Verifying license against %llu:", now); INFO_MSG("Verifying license against %llu: %s", now, currentLicense.toString().c_str());
std::cout << currentLicense.toPrettyString() << std::endl;
#endif #endif
//The loop below is timechecker loop //The loop below is timechecker loop
if (!currentLicense.isMember("valid_from") || !currentLicense.isMember("valid_till")){ if (!currentLicense.isMember("valid_from") || !currentLicense.isMember("valid_till")){
@ -53,7 +58,6 @@ namespace Controller{
} }
bool checkLicense(){ bool checkLicense(){
updateLicense();
if (!currentLicense.isMember("interval")){ if (!currentLicense.isMember("interval")){
currentLicense["interval"] = 3600ll; currentLicense["interval"] = 3600ll;
} }
@ -179,6 +183,7 @@ namespace Controller{
unsigned long now = Util::epoch(); unsigned long now = Util::epoch();
while (conf.is_active){ while (conf.is_active){
if (Util::epoch() - now > currentLicense["interval"].asInt()){ if (Util::epoch() - now > currentLicense["interval"].asInt()){
updateLicense();
if (checkLicense()){ if (checkLicense()){
now = Util::epoch(); now = Util::epoch();
} }