Browse Source

Adding AtomicTool licensing stuff, updating npm packages

Josh Engebretson 10 years ago
parent
commit
d0659c35b8

+ 2 - 1
CLI/atomic-cli-mac-data/package.json

@@ -7,5 +7,6 @@
   "files" : ["data"],
   "files" : ["data"],
   "main": "./data/index.js",
   "main": "./data/index.js",
   "name": "atomic-cli-mac-data",
   "name": "atomic-cli-mac-data",
-  "version": "0.0.1"
+  "version": "0.0.1",
+  "os" : ["darwin"]
 }
 }

+ 3 - 1
CLI/atomic-cli-windows-data/package.json

@@ -7,5 +7,7 @@
   "files" : ["data"],
   "files" : ["data"],
   "main": "./data/index.js",
   "main": "./data/index.js",
   "name": "atomic-cli-windows-data",
   "name": "atomic-cli-windows-data",
-  "version": "0.0.1"
+  "version": "0.0.1",
+  "os" : ["win32"]
+
 }
 }

+ 1 - 1
CLI/atomic-cli-windows/package.json

@@ -24,5 +24,5 @@
   "preferGlobal": true,
   "preferGlobal": true,
   "repository": "https://github.com/AtomicGameEngine/AtomicGameEngine",
   "repository": "https://github.com/AtomicGameEngine/AtomicGameEngine",
   "os" : ["win32"],
   "os" : ["win32"],
-  "version": "0.0.3"
+  "version": "0.0.4"
 }
 }

+ 3 - 3
CLI/atomic-cli/package.json

@@ -16,8 +16,8 @@
   "devDependencies" : {
   "devDependencies" : {
   },
   },
   "optionalDependencies" : {
   "optionalDependencies" : {
-    "atomic-cli-mac" : "0.0.3",
-    "atomic-cli-windows" : "0.0.3"
+    "atomic-cli-mac" : "latest",
+    "atomic-cli-windows" : "latest"
   },
   },
   "description": "CLI for the Atomic Game Engine",
   "description": "CLI for the Atomic Game Engine",
   "engines": {
   "engines": {
@@ -33,5 +33,5 @@
   "name": "atomic-cli",
   "name": "atomic-cli",
   "preferGlobal": true,
   "preferGlobal": true,
   "repository": "https://github.com/AtomicGameEngine/AtomicGameEngine",
   "repository": "https://github.com/AtomicGameEngine/AtomicGameEngine",
-  "version": "0.2.9"
+  "version": "0.3.0"
 }
 }

+ 30 - 4
Source/AtomicTool/AtomicTool.cpp

@@ -6,6 +6,7 @@
 
 
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/Build/BuildSystem.h>
 #include <ToolCore/Build/BuildSystem.h>
+#include <ToolCore/License/LicenseEvents.h>
 #include <ToolCore/License/LicenseSystem.h>
 #include <ToolCore/License/LicenseSystem.h>
 #include <ToolCore/Command/Command.h>
 #include <ToolCore/Command/Command.h>
 #include <ToolCore/Command/CommandParser.h>
 #include <ToolCore/Command/CommandParser.h>
@@ -56,7 +57,7 @@ void AtomicTool::Setup()
         ErrorExit("Unable to parse --data-path");
         ErrorExit("Unable to parse --data-path");
 
 
     engineParameters_["Headless"] = true;
     engineParameters_["Headless"] = true;
-    engineParameters_["LogLevel"] = LOG_WARNING;
+    engineParameters_["LogLevel"] = LOG_INFO;
     engineParameters_["ResourcePaths"] = "";
     engineParameters_["ResourcePaths"] = "";
 }
 }
 
 
@@ -76,12 +77,37 @@ void AtomicTool::HandleCommandError(StringHash eventType, VariantMap& eventData)
     ErrorExit(error);
     ErrorExit(error);
 }
 }
 
 
+void AtomicTool::HandleLicenseEulaRequired(StringHash eventType, VariantMap& eventData)
+{
+
+}
+
+void AtomicTool::HandleLicenseActivationRequired(StringHash eventType, VariantMap& eventData)
+{
+
+}
+
+void AtomicTool::HandleLicenseSuccess(StringHash eventType, VariantMap& eventData)
+{
+    command_->Run();
+}
+
+void AtomicTool::HandleLicenseError(StringHash eventType, VariantMap& eventData)
+{
+
+}
+
 void AtomicTool::Start()
 void AtomicTool::Start()
 {
 {
     // Subscribe to events
     // Subscribe to events
     SubscribeToEvent(E_COMMANDERROR, HANDLER(AtomicTool, HandleCommandError));
     SubscribeToEvent(E_COMMANDERROR, HANDLER(AtomicTool, HandleCommandError));
     SubscribeToEvent(E_COMMANDFINISHED, HANDLER(AtomicTool, HandleCommandFinished));
     SubscribeToEvent(E_COMMANDFINISHED, HANDLER(AtomicTool, HandleCommandFinished));
 
 
+    SubscribeToEvent(E_LICENSE_EULAREQUIRED, HANDLER(AtomicTool, HandleLicenseEulaRequired));
+    SubscribeToEvent(E_LICENSE_ACTIVATIONREQUIRED, HANDLER(AtomicTool, HandleLicenseActivationRequired));
+    SubscribeToEvent(E_LICENSE_ERROR, HANDLER(AtomicTool, HandleLicenseError));
+    SubscribeToEvent(E_LICENSE_SUCCESS, HANDLER(AtomicTool, HandleLicenseSuccess));
+
     const Vector<String>& arguments = GetArguments();
     const Vector<String>& arguments = GetArguments();
 
 
     ToolSystem* tsystem = new ToolSystem(context_);
     ToolSystem* tsystem = new ToolSystem(context_);
@@ -149,12 +175,12 @@ void AtomicTool::Start()
 
 
     }
     }
 
 
+    command_ = cmd;
+
     // BEGIN LICENSE MANAGEMENT
     // BEGIN LICENSE MANAGEMENT
-    // GetSubsystem<LicenseSystem>()->Initialize();
+    GetSubsystem<LicenseSystem>()->Initialize();
     // END LICENSE MANAGEMENT
     // END LICENSE MANAGEMENT
 
 
-    cmd->Run();
-
 }
 }
 
 
 void AtomicTool::Stop()
 void AtomicTool::Stop()

+ 5 - 0
Source/AtomicTool/AtomicTool.h

@@ -30,6 +30,11 @@ public:
 
 
 private:
 private:
 
 
+    void HandleLicenseEulaRequired(StringHash eventType, VariantMap& eventData);
+    void HandleLicenseActivationRequired(StringHash eventType, VariantMap& eventData);
+    void HandleLicenseSuccess(StringHash eventType, VariantMap& eventData);
+    void HandleLicenseError(StringHash eventType, VariantMap& eventData);
+
     void HandleCommandFinished(StringHash eventType, VariantMap& eventData);
     void HandleCommandFinished(StringHash eventType, VariantMap& eventData);
     void HandleCommandError(StringHash eventType, VariantMap& eventData);
     void HandleCommandError(StringHash eventType, VariantMap& eventData);
 
 

+ 45 - 0
Source/ToolCore/License/LicenseEvents.h

@@ -0,0 +1,45 @@
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+// Please see LICENSE.md in repository root for license information
+// https://github.com/AtomicGameEngine/AtomicGameEngine
+
+#pragma once
+
+#include <Atomic/Core/Object.h>
+
+using namespace Atomic;
+
+namespace ToolCore
+{
+
+// requires EULA agreement
+EVENT(E_LICENSE_EULAREQUIRED, LicenseEulaRequired)
+{
+
+}
+
+// activation required
+EVENT(E_LICENSE_ACTIVATIONREQUIRED, LicenseActivationRequired)
+{
+
+}
+
+// license verification required
+EVENT(E_LICENSE_VERIFICATIONREQUIRED, LicenseVerificationRequired)
+{
+
+}
+
+// license success
+EVENT(E_LICENSE_SUCCESS, LicenseSuccess)
+{
+
+}
+
+
+// license error
+EVENT(E_LICENSE_ERROR, LicenseError)
+{
+
+}
+
+}

+ 78 - 49
Source/ToolCore/License/LicenseSystem.cpp

@@ -18,10 +18,12 @@
 
 
 #include <Atomic/Core/CoreEvents.h>
 #include <Atomic/Core/CoreEvents.h>
 #include <Atomic/Core/Context.h>
 #include <Atomic/Core/Context.h>
+#include <Atomic/Core/Timer.h>
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/IO/FileSystem.h>
 #include <Atomic/IO/File.h>
 #include <Atomic/IO/File.h>
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/Log.h>
 
 
+#include "LicenseEvents.h"
 #include "LicenseSystem.h"
 #include "LicenseSystem.h"
 
 
 #include <Poco/MD5Engine.h>
 #include <Poco/MD5Engine.h>
@@ -35,8 +37,28 @@ LicenseSystem::LicenseSystem(Context* context) :
     , eulaAgreementConfirmed_(false)
     , eulaAgreementConfirmed_(false)
 
 
 {
 {
-    ResetLicense();
+    FileSystem* filesystem = GetSubsystem<FileSystem>();
+
+    licenseFilePath_ = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
+    licenseFilePath_ = AddTrailingSlash(licenseFilePath_);
+
+    if (!filesystem->DirExists(licenseFilePath_))
+    {
+        Poco::File dirs(licenseFilePath_.CString());
+        dirs.createDirectories();
+    }
+
+    licenseCachePath_ = licenseFilePath_;
+
+    licenseCachePath_ += "AtomicLicenseCache";
+
+    licenseFilePath_ += "AtomicLicense";
+
+    eulaAgreementPath_ = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
+    eulaAgreementPath_ = AddTrailingSlash(eulaAgreementPath_);
+    eulaAgreementPath_ += "EulaConfirmed";
 
 
+    ResetLicense();
 }
 }
 
 
 LicenseSystem::~LicenseSystem()
 LicenseSystem::~LicenseSystem()
@@ -48,23 +70,21 @@ void LicenseSystem::Initialize()
 {
 {
 
 
     FileSystem* filesystem = GetSubsystem<FileSystem>();
     FileSystem* filesystem = GetSubsystem<FileSystem>();
-    String eulaConfirmedFilePath = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
-    eulaConfirmedFilePath = AddTrailingSlash(eulaConfirmedFilePath);
-    eulaConfirmedFilePath += "EulaConfirmed";
 
 
-    eulaAgreementConfirmed_ = filesystem->FileExists(eulaConfirmedFilePath);
+    eulaAgreementConfirmed_ = filesystem->FileExists(eulaAgreementPath_);
+
+    if (!eulaAgreementConfirmed_)
+    {
+        SendEvent(E_LICENSE_EULAREQUIRED);
+        return;
+    }
 
 
-    if (!LoadLicense() || !key_.Length() || !eulaAgreementConfirmed_)
+    if (!LoadLicense() || !key_.Length())
     {
     {
         ResetLicense();
         ResetLicense();
-        /*
-        UIModalOps* ops = GetSubsystem<UIModalOps>();
 
 
-        if (eulaAgreementConfirmed_)
-            ops->ShowActivation();
-        else
-            ops->ShowEulaAgreement();
-        */
+        SendEvent(E_LICENSE_ACTIVATIONREQUIRED);
+        return;
     }
     }
     else
     else
     {
     {
@@ -76,12 +96,7 @@ void LicenseSystem::LicenseAgreementConfirmed()
 {
 {
     eulaAgreementConfirmed_ = true;
     eulaAgreementConfirmed_ = true;
 
 
-    FileSystem* filesystem = GetSubsystem<FileSystem>();
-    String eulaConfirmedFilePath = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
-    eulaConfirmedFilePath = AddTrailingSlash(eulaConfirmedFilePath);
-    eulaConfirmedFilePath += "EulaConfirmed";
-
-    SharedPtr<File> file(new File(context_, eulaConfirmedFilePath, FILE_WRITE));
+    SharedPtr<File> file(new File(context_, eulaAgreementPath_, FILE_WRITE));
     file->WriteInt(1);
     file->WriteInt(1);
     file->Close();
     file->Close();
 
 
@@ -126,14 +141,11 @@ bool LicenseSystem::LoadLicense()
     ResetLicense();
     ResetLicense();
 
 
     FileSystem* filesystem = GetSubsystem<FileSystem>();
     FileSystem* filesystem = GetSubsystem<FileSystem>();
-    String licenseFilePath = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
-    licenseFilePath = AddTrailingSlash(licenseFilePath);
-    licenseFilePath += "AtomicLicense";
 
 
-    if (!filesystem->FileExists(licenseFilePath))
+    if (!filesystem->FileExists(licenseFilePath_))
         return false;
         return false;
 
 
-    SharedPtr<File> file(new File(context_, licenseFilePath, FILE_READ));
+    SharedPtr<File> file(new File(context_, licenseFilePath_, FILE_READ));
 
 
     file->ReadInt(); // version
     file->ReadInt(); // version
 
 
@@ -183,19 +195,7 @@ bool LicenseSystem::ValidateKey(const String& key)
 
 
 void LicenseSystem::SaveLicense()
 void LicenseSystem::SaveLicense()
 {
 {
-    FileSystem* filesystem = GetSubsystem<FileSystem>();
-    String licenseFilePath = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
-    licenseFilePath = AddTrailingSlash(licenseFilePath);
-
-    if (!filesystem->DirExists(licenseFilePath))
-    {
-        Poco::File dirs(licenseFilePath.CString());
-        dirs.createDirectories();
-    }
-
-    licenseFilePath += "AtomicLicense";
-
-    SharedPtr<File> file(new File(context_, licenseFilePath, FILE_WRITE));
+    SharedPtr<File> file(new File(context_, licenseFilePath_, FILE_WRITE));
     file->WriteInt(1); // version
     file->WriteInt(1); // version
     file->WriteString(key_);
     file->WriteString(key_);
 
 
@@ -214,13 +214,14 @@ void LicenseSystem::RemoveLicense()
 {
 {
     FileSystem* filesystem = GetSubsystem<FileSystem>();
     FileSystem* filesystem = GetSubsystem<FileSystem>();
 
 
-    String licenseFilePath = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
-    licenseFilePath = AddTrailingSlash(licenseFilePath);
-    licenseFilePath += "AtomicLicense";
+    if (filesystem->FileExists(licenseFilePath_))
+    {
+        filesystem->Delete(licenseFilePath_);
+    }
 
 
-    if (filesystem->FileExists(licenseFilePath))
+    if (filesystem->FileExists(licenseCachePath_))
     {
     {
-        filesystem->Delete(licenseFilePath);
+        filesystem->Delete(licenseCachePath_);
     }
     }
 }
 }
 
 
@@ -238,6 +239,24 @@ void LicenseSystem::RequestServerVerification(const String& key)
         return;
         return;
     }
     }
 
 
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+    if (fileSystem->FileExists(licenseCachePath_))
+    {
+        Time* time = GetSubsystem<Time>();
+        unsigned currentTime = time->GetTimeSinceEpoch();
+        unsigned fileTime = fileSystem->GetLastModifiedTime(licenseCachePath_);
+        unsigned deltaMinutes = (currentTime - fileTime)/60;
+        if (deltaMinutes < 1)
+        {
+            LOGINFOF("%u minutes, using cached license", deltaMinutes);
+            SendEvent(E_LICENSE_SUCCESS);
+            return;
+        }
+    }
+
+    LOGINFO("LicenseSystem::RequestServerLicense - requesting verification");
+
     key_ = key;
     key_ = key;
     CurlManager* cm = GetSubsystem<CurlManager>();
     CurlManager* cm = GetSubsystem<CurlManager>();
     String post;
     String post;
@@ -347,6 +366,21 @@ SharedPtr<CurlRequest>& LicenseSystem::Deactivate()
 
 
 }
 }
 
 
+void LicenseSystem::CreateOrUpdateLicenseCache()
+{
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    Time* time = GetSubsystem<Time>();
+
+    if (!fileSystem->FileExists(licenseCachePath_))
+    {
+        SharedPtr<File> file(new File(context_, licenseCachePath_, FILE_WRITE));
+        file->WriteInt(1);
+        file->Close();
+    }
+
+    fileSystem->SetLastModifiedTime(licenseCachePath_, time->GetTimeSinceEpoch());
+}
+
 void LicenseSystem::HandleVerification(StringHash eventType, VariantMap& eventData)
 void LicenseSystem::HandleVerification(StringHash eventType, VariantMap& eventData)
 {
 {
 
 
@@ -436,14 +470,9 @@ void LicenseSystem::HandleVerification(StringHash eventType, VariantMap& eventDa
                     SaveLicense();
                     SaveLicense();
                 }
                 }
 
 
-                //if (!HasPlatformLicense())
-                //{
-                //    UIModalOps* ops = GetSubsystem<UIModalOps>();
-                //    if (!ops->ModalActive())
-                //        ops->ShowPlatformsInfo();
-
-               // }
+                CreateOrUpdateLicenseCache();
 
 
+                SendEvent(E_LICENSE_SUCCESS);
             }
             }
 
 
         }
         }

+ 6 - 0
Source/ToolCore/License/LicenseSystem.h

@@ -82,12 +82,18 @@ private:
     void SaveLicense();
     void SaveLicense();
     void RemoveLicense();
     void RemoveLicense();
 
 
+    void CreateOrUpdateLicenseCache();
+
     void HandleVerification(StringHash eventType, VariantMap& eventData);
     void HandleVerification(StringHash eventType, VariantMap& eventData);
     void HandleDeactivate(StringHash eventType, VariantMap& eventData);
     void HandleDeactivate(StringHash eventType, VariantMap& eventData);
     void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
     void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
 
 
     bool eulaAgreementConfirmed_;
     bool eulaAgreementConfirmed_;
 
 
+    String licenseFilePath_;
+    String licenseCachePath_;
+    String eulaAgreementPath_;
+
     String key_;
     String key_;
     String email_;
     String email_;
     bool licenseWindows_;
     bool licenseWindows_;