Browse Source

License System

Josh Engebretson 10 years ago
parent
commit
e6cf38e004

+ 4 - 1
Script/AtomicEditor/editor/Editor.ts

@@ -2,13 +2,14 @@
 import EditorUI = require("../ui/EditorUI");
 import UIEvents = require("../ui/UIEvents");
 import AssetImport = require("../assets/AssetImport");
-
+import EditorLicense = require("./EditorLicense");
 import EditorEvents = require("./EditorEvents");
 
 class Editor extends Atomic.ScriptObject {
 
     project: ToolCore.Project;
     assetImport: AssetImport;
+    editorLicense:EditorLicense;
 
     static instance: Editor;
 
@@ -18,6 +19,8 @@ class Editor extends Atomic.ScriptObject {
 
         Editor.instance = this;
 
+        this.editorLicense = new EditorLicense();
+
         EditorUI.initialize();
 
         Atomic.getResourceCache().autoReloadResources = true;

+ 32 - 0
Script/AtomicEditor/editor/EditorLicense.ts

@@ -0,0 +1,32 @@
+
+import EditorUI = require("../ui/EditorUI");
+
+class EditorLicense extends Atomic.ScriptObject {
+
+    constructor() {
+
+        super();
+
+        this.subscribeToEvent("LicenseEulaRequired", (eventData) => this.handleLicenseEulaRequired(eventData));
+        this.subscribeToEvent("LicenseActivationRequired", (eventData) => this.handleLicenseActivationRequired(eventData));
+
+    }
+
+    handleLicenseEulaRequired(eventData) {
+
+        var ops = EditorUI.getModelOps();
+        ops.showEULAWindow();
+
+    }
+
+    handleLicenseActivationRequired(eventData) {
+
+        var ops = EditorUI.getModelOps();
+        ops.showActivationWindow();
+
+    }
+
+
+}
+
+export = EditorLicense;

+ 6 - 1
Script/AtomicEditor/tsconfig.json

@@ -14,6 +14,7 @@
         "./assets/AssetImport.ts",
         "./editor/Editor.ts",
         "./editor/EditorEvents.ts",
+        "./editor/EditorLicense.ts",
         "./main.ts",
         "./ui/EditorStrings.ts",
         "./ui/EditorUI.ts",
@@ -38,10 +39,14 @@
         "./ui/inspector/ModelInspector.ts",
         "./ui/inspector/NodeInspector.ts",
         "./ui/inspector/TextureSelector.ts",
+        "./ui/license/ActivationSuccessWindow.ts",
+        "./ui/license/ActivationWindow.ts",
+        "./ui/license/EULAWindow.ts",
         "./ui/modal/CreateProject.ts",
         "./ui/modal/MessageModal.ts",
         "./ui/modal/ModalOps.ts",
         "./ui/modal/ModalWindow.ts",
-        "./ui/modal/NewProject.ts"
+        "./ui/modal/NewProject.ts",
+        "./ui/modal/ProgressModal.ts"
     ]
 }

+ 34 - 0
Script/AtomicEditor/ui/license/ActivationSuccessWindow.ts

@@ -0,0 +1,34 @@
+
+import EditorEvents = require("../../editor/EditorEvents");
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("../modal/ModalWindow");
+
+class ActivationSuccessWindow extends ModalWindow {
+
+    constructor() {
+
+        super();
+
+        this.init("Product Activation Successful", "AtomicEditor/editor/ui/activationsuccess.tb.txt");
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "ok") {
+
+                this.hide();
+
+                return true;
+            }
+
+        }
+
+    }
+
+}
+
+export = ActivationSuccessWindow;

+ 85 - 0
Script/AtomicEditor/ui/license/ActivationWindow.ts

@@ -0,0 +1,85 @@
+
+import EditorEvents = require("../../editor/EditorEvents");
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("../modal/ModalWindow");
+import ProgressModal = require("../modal/ProgressModal");
+
+class ActivationWidow extends ModalWindow {
+
+    constructor() {
+
+        super();
+
+        this.init("Product Activation", "AtomicEditor/editor/ui/activation.tb.txt");
+
+        this.licenseKeyEdit = <Atomic.UIEditField> this.getWidget("license_key");
+
+        this.subscribeToEvent("LicenseActivationError", (eventData) => this.handleLicenseActivationError(eventData));
+        this.subscribeToEvent("LicenseActivationSuccess", (eventData) => this.handleLicenseActivationSuccess(eventData));
+
+        this.progressModal = new ProgressModal("Activation", "Activating, please wait...");
+
+    }
+
+    handleLicenseActivationError(ev) {
+
+      this.progressModal.hide();
+
+      EditorUI.showModalError("Activation Error",
+          ev.message);
+
+    }
+
+    handleLicenseActivationSuccess(ev) {
+
+      this.progressModal.hide();
+
+      this.hide();
+
+      EditorUI.getModelOps().showActivationSuccessWindow();
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "quit") {
+
+                this.sendEvent(EditorEvents.Quit);
+                return true;
+
+            } else if (id == "get_key") {
+
+                var fileSystem = Atomic.getFileSystem();
+                fileSystem.systemOpen("https://store.atomicgameengine.com/site");
+
+            } else if (id == "activate") {
+
+                var key = this.licenseKeyEdit.text.trim().toUpperCase();
+                var licenseSystem = ToolCore.getLicenseSystem();
+                if (!licenseSystem.validateKey(key)) {
+
+                    EditorUI.showModalError("Invalid Product Key",
+                        "The key entered is invalid\n\nProduct keys are in the form of ATOMIC-XXXX-XXXX-XXXX-XXXX");
+
+                    return true;
+                }
+
+                this.progressModal.show();
+
+                licenseSystem.requestServerActivation(key);
+
+            }
+
+
+        }
+
+    }
+    progressModal:ProgressModal;
+    licenseKeyEdit: Atomic.UIEditField;
+}
+
+export = ActivationWidow;

+ 74 - 0
Script/AtomicEditor/ui/license/EULAWindow.ts

@@ -0,0 +1,74 @@
+
+import EditorEvents = require("../../editor/EditorEvents");
+import EditorUI = require("../EditorUI");
+import ModalWindow = require("../modal/ModalWindow");
+
+class EULAWindow extends ModalWindow {
+
+    constructor() {
+
+        super();
+
+        this.settings = Atomic.UI_WINDOW_SETTINGS_DEFAULT & ~Atomic.UI_WINDOW_SETTINGS_CLOSE_BUTTON;
+
+        this.init("License Agreement", "AtomicEditor/editor/ui/eulaagreement.tb.txt");
+
+        this.age_license = <Atomic.UIEditField> this.getWidget("age_license");
+        this.thirdparty_license = <Atomic.UIEditField> this.getWidget("thirdparty_license");
+        this.externaltool_license = <Atomic.UIEditField> this.getWidget("externaltool_license");
+        this.eulaCheck = <Atomic.UICheckBox> this.getWidget("eula_check");
+
+        var container = this.getWidget("tabcontainer");
+        container.value = 0;
+
+        var cache = Atomic.getResourceCache();
+
+        var file = cache.getFile("AtomicEditor/eulas/atomic_game_engine_eula.txt");
+        this.age_license.text = file.readText();
+
+        file = cache.getFile("AtomicEditor/eulas/atomic_thirdparty_eula.txt");
+        this.thirdparty_license.text = file.readText();
+
+        file = cache.getFile("AtomicEditor/eulas/atomic_external_tools_eula.txt");
+        this.externaltool_license.text = file.readText();
+
+    }
+
+    handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+
+        if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
+
+            var id = ev.target.id;
+
+            if (id == "quit") {
+
+                this.sendEvent(EditorEvents.Quit);
+                return true;
+
+            } else if (id == "ok") {
+
+                if (!this.eulaCheck.value) {
+                  EditorUI.showModalError("License Agreement", "Please agree to licensing terms and conditions to continue");
+                    return true;
+                }
+
+                this.hide();
+
+                var licenseSystem = ToolCore.getLicenseSystem();
+                licenseSystem.licenseAgreementConfirmed();
+
+                return true;
+            }
+
+        }
+
+    }
+
+    age_license: Atomic.UIEditField;
+    thirdparty_license: Atomic.UIEditField;
+    externaltool_license: Atomic.UIEditField;
+    eulaCheck: Atomic.UICheckBox;
+
+}
+
+export = EULAWindow;

+ 34 - 0
Script/AtomicEditor/ui/modal/ModalOps.ts

@@ -3,6 +3,10 @@ import ModalWindow = require("./ModalWindow");
 import NewProject = require("./NewProject");
 import CreateProject = require("./CreateProject");
 
+import EULAWindow = require("../license/EULAWindow");
+import ActivationWindow = require("../license/ActivationWindow");
+import ActivationSuccessWindow = require("../license/ActivationSuccessWindow");
+
 class ModalOps extends Atomic.ScriptObject {
 
     constructor() {
@@ -32,6 +36,36 @@ class ModalOps extends Atomic.ScriptObject {
         }
     }
 
+    showEULAWindow() {
+
+      if (this.show()) {
+
+          this.opWindow = new EULAWindow();
+
+      }
+
+    }
+
+    showActivationWindow() {
+
+      if (this.show()) {
+
+          this.opWindow = new ActivationWindow();
+
+      }
+
+    }
+
+    showActivationSuccessWindow() {
+
+      if (this.show()) {
+
+          this.opWindow = new ActivationSuccessWindow();
+
+      }
+
+    }
+
     private show(): boolean {
 
         if (this.dimmer.parent) {

+ 47 - 0
Script/AtomicEditor/ui/modal/ProgressModal.ts

@@ -0,0 +1,47 @@
+
+import EditorUI = require("../EditorUI");
+
+class ProgressModal extends Atomic.UIWindow {
+
+    constructor(title: string, message: string) {
+
+        super();
+
+        this.settings = Atomic.UI_WINDOW_SETTINGS_DEFAULT & ~Atomic.UI_WINDOW_SETTINGS_CLOSE_BUTTON;
+
+        this.text = title;
+        this.load("AtomicEditor/editor/ui/progressmodal.tb.txt");
+
+        var messageField = <Atomic.UITextField> this.getWidget("message");
+        messageField.text = message;
+
+        this.resizeToFitContent();
+        this.center();
+
+        this.dimmer = new Atomic.UIDimmer();
+
+    }
+
+    show() {
+
+        var view = EditorUI.getView();
+        view.addChild(this.dimmer);
+        view.addChild(this);
+
+    }
+
+    hide() {
+
+        if (this.dimmer.parent)
+            this.dimmer.parent.removeChild(this.dimmer, false);
+
+        if (this.parent)
+            this.parent.removeChild(this, false);
+
+    }
+
+    dimmer: Atomic.UIDimmer;
+
+}
+
+export = ProgressModal;

+ 14 - 2
Script/TypeScript/Atomic.d.ts

@@ -679,6 +679,16 @@ declare module Atomic {
    export var UI_WIDGET_Z_REL_AFTER: UI_WIDGET_Z_REL;
 
 
+   // enum UI_WINDOW_SETTINGS
+   export type UI_WINDOW_SETTINGS = number;
+   export var UI_WINDOW_SETTINGS_NONE: UI_WINDOW_SETTINGS;
+   export var UI_WINDOW_SETTINGS_TITLEBAR: UI_WINDOW_SETTINGS;
+   export var UI_WINDOW_SETTINGS_RESIZABLE: UI_WINDOW_SETTINGS;
+   export var UI_WINDOW_SETTINGS_CLOSE_BUTTON: UI_WINDOW_SETTINGS;
+   export var UI_WINDOW_SETTINGS_CAN_ACTIVATE: UI_WINDOW_SETTINGS;
+   export var UI_WINDOW_SETTINGS_DEFAULT: UI_WINDOW_SETTINGS;
+
+
    // enum CompressedFormat
    export type CompressedFormat = number;
    export var CF_NONE: CompressedFormat;
@@ -7422,11 +7432,12 @@ declare module Atomic {
 
    export class UIWindow extends UIWidget {
 
-      settings: number;
+      settings: UI_WINDOW_SETTINGS;
 
       constructor(createWidget?: boolean);
 
-      setSettings(settings: number): void;
+      getSettings(): UI_WINDOW_SETTINGS;
+      setSettings(settings: UI_WINDOW_SETTINGS): void;
       resizeToFitContent(): void;
       addChild(child: UIWidget): void;
       close(): void;
@@ -7808,6 +7819,7 @@ declare module Atomic {
       isPackaged(): boolean;
       // Return the fullpath to the file
       getFullPath(): string;
+      readText():string;
 
    }
 

+ 1 - 0
Script/TypeScript/AtomicWork.d.ts

@@ -105,4 +105,5 @@ declare module ToolCore {
     export function getToolEnvironment(): ToolEnvironment;
     export function getToolSystem(): ToolSystem;
     export function getAssetDatabase(): AssetDatabase;
+    export function getLicenseSystem(): LicenseSystem;
 }

+ 30 - 0
Script/TypeScript/ToolCore.d.ts

@@ -357,6 +357,36 @@ declare module ToolCore {
 
    }
 
+   export class LicenseSystem extends Atomic.AObject {
+
+      key: string;
+      email: string;
+
+      // Construct.
+      constructor();
+
+      initialize(): void;
+      licenseWindows(): boolean;
+      licenseMac(): boolean;
+      licenseAndroid(): boolean;
+      licenseIOS(): boolean;
+      licenseHTML5(): boolean;
+      licenseModule3D(): boolean;
+      // Returns whether there are any platform licenses available
+      isStandardLicense(): boolean;
+      resetLicense(): void;
+      loadLicense(): boolean;
+      // Basic key validation
+      validateKey(key: string): boolean;
+      // Activate on server
+      requestServerActivation(key: string): void;
+      getKey(): string;
+      generateMachineID(): string;
+      getEmail(): string;
+      licenseAgreementConfirmed(): void;
+
+   }
+
 
 
 }

+ 9 - 1
Source/Atomic/UI/UIWindow.cpp

@@ -23,8 +23,16 @@ UIWindow::UIWindow(Context* context, bool createWidget) : UIWidget(context, fals
         GetSubsystem<UI>()->WrapWidget(this, widget_);
     }
 }
+UI_WINDOW_SETTINGS UIWindow::GetSettings()
+{
+    if (!widget_)
+        return UI_WINDOW_SETTINGS_DEFAULT;
+
+    return (UI_WINDOW_SETTINGS) ((TBWindow*)widget_)->GetSettings();
+
+}
 
-void UIWindow::SetSettings(unsigned settings)
+void UIWindow::SetSettings(UI_WINDOW_SETTINGS settings)
 {
     if (!widget_)
         return;

+ 22 - 3
Source/Atomic/UI/UIWindow.h

@@ -1,22 +1,41 @@
 
 #pragma once
 
+#include<TurboBadger/tb_window.h>
+
 #include "UIWidget.h"
 
 namespace Atomic
 {
 
 
+enum UI_WINDOW_SETTINGS {
+    ///< Chrome less window without any other settings.
+    UI_WINDOW_SETTINGS_NONE			= tb::WINDOW_SETTINGS_NONE,
+    ///< Show a title bar that can also move the window.
+    UI_WINDOW_SETTINGS_TITLEBAR		= tb::WINDOW_SETTINGS_TITLEBAR,
+    ///< Show a widget for resizing the window.
+    UI_WINDOW_SETTINGS_RESIZABLE	= tb::WINDOW_SETTINGS_RESIZABLE,
+    ///< Show a widget for closing the window.
+    UI_WINDOW_SETTINGS_CLOSE_BUTTON	= tb::WINDOW_SETTINGS_CLOSE_BUTTON,
+    ///< Can be activated and deactivate other windows.
+    UI_WINDOW_SETTINGS_CAN_ACTIVATE	= tb::WINDOW_SETTINGS_CAN_ACTIVATE,
+
+    UI_WINDOW_SETTINGS_DEFAULT = tb::WINDOW_SETTINGS_DEFAULT
+};
+
+
 class UIWindow : public UIWidget
 {
     OBJECT(UIWindow)
 
-public:
+    public:
 
-    UIWindow(Context* context, bool createWidget = true);
+        UIWindow(Context* context, bool createWidget = true);
     virtual ~UIWindow();
 
-    void SetSettings(unsigned settings);
+    UI_WINDOW_SETTINGS GetSettings();
+    void SetSettings(UI_WINDOW_SETTINGS settings);
 
     void ResizeToFitContent();
 

+ 4 - 0
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -16,6 +16,8 @@
 
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/ToolEnvironment.h>
+#include <ToolCore/License/LicenseEvents.h>
+#include <ToolCore/License/LicenseSystem.h>
 
 #include "AEEditorApp.h"
 #include "AEPreferences.h"
@@ -89,6 +91,8 @@ void AEEditorApp::Start()
         return;
     }
 
+    GetSubsystem<LicenseSystem>()->Initialize();
+
 }
 
 void AEEditorApp::Setup()

+ 3 - 0
Source/AtomicJS/Packages/Atomic/IO.json

@@ -8,6 +8,9 @@
 		}
 	},
 	"typescript_decl" : {
+		"File" : [
+			"readText():string;"
+		],
 		"FileSystem" : [
 			"scanDir(pathName:string, filter:string, flags:number, recursive:boolean);"
 		]

+ 2 - 2
Source/AtomicJS/Packages/ToolCore/ToolCore.json

@@ -1,11 +1,11 @@
 {
 	"name" : "ToolCore",
 	"sources" : ["Source/ToolCore", "Source/ToolCore/Project", "Source/ToolCore/Platform", "Source/ToolCore/Command",
-							 "Source/ToolCore/Import", "Source/ToolCore/Assets"],
+							 "Source/ToolCore/Import", "Source/ToolCore/Assets", "Source/ToolCore/License"],
 	"classes" : ["ToolEnvironment", "ToolSystem", "Project", "ProjectFile", "Platform", "PlatformMac", "PlatformWeb",
 							 "PlatformWindows", "Command", "PlayCmd", "OpenAssetImporter",
 							 "Asset", "AssetDatabase", "AssetImporter", "ModelImporter", "MaterialImporter", "AnimationImportInfo",
-							 "PrefabImporter"],
+							 "PrefabImporter", "LicenseSystem"],
 	"typescript_decl" : {
 
 		"AssetDatabase" : [

+ 3 - 8
Source/ToolCore/License/LicenseSystem.cpp

@@ -100,10 +100,8 @@ void LicenseSystem::LicenseAgreementConfirmed()
     file->WriteInt(1);
     file->Close();
 
-    /*
-    UIModalOps* ops = GetSubsystem<UIModalOps>();
-    ops->ShowActivation();
-    */
+    if (!LoadLicense() || !key_.Length())
+        SendEvent(E_LICENSE_ACTIVATIONREQUIRED);
 }
 
 String LicenseSystem::GenerateMachineID()
@@ -596,13 +594,10 @@ void LicenseSystem::RequestServerActivation(const String& key)
         LOGERROR("UIActivation::RequestServerActivation - request already exists");
         return;
     }
-
-    LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
-
     key_ = key;
     CurlManager* cm = GetSubsystem<CurlManager>();
     String post;
-    String id = licenseSystem->GenerateMachineID();
+    String id = GenerateMachineID();
     post.AppendWithFormat("key=%s&id=%s", key.CString(), id.CString());
 
     // todo, this should be a verify url (shouldn't auto add id)

+ 11 - 1
Source/ToolCoreJS/ToolCoreJS.cpp

@@ -4,6 +4,7 @@
 #include <ToolCore/ToolSystem.h>
 #include <ToolCore/Assets/AssetDatabase.h>
 #include <ToolCore/Project/Project.h>
+#include <ToolCore/License/LicenseSystem.h>
 
 using namespace Atomic;
 
@@ -31,6 +32,13 @@ static int js_atomic_GetToolSystem(duk_context* ctx)
     return 1;
 }
 
+static int js_atomic_GetLicenseSystem(duk_context* ctx)
+{
+    JSVM* vm = JSVM::GetJSVM(ctx);
+    js_push_class_object_instance(ctx, vm->GetSubsystem<LicenseSystem>());
+    return 1;
+}
+
 static int js_atomic_GetAssetDatabase(duk_context* ctx)
 {
     JSVM* vm = JSVM::GetJSVM(ctx);
@@ -38,7 +46,6 @@ static int js_atomic_GetAssetDatabase(duk_context* ctx)
     return 1;
 }
 
-
 static int AssetDatabase_GetFolderAssets(duk_context* ctx)
 {
     JSVM* vm = JSVM::GetJSVM(ctx);
@@ -109,6 +116,9 @@ void jsapi_init_toolcore(JSVM* vm)
     duk_push_c_function(ctx, js_atomic_GetToolSystem, 0);
     duk_put_prop_string(ctx, -2, "getToolSystem");
 
+    duk_push_c_function(ctx, js_atomic_GetLicenseSystem, 0);
+    duk_put_prop_string(ctx, -2, "getLicenseSystem");
+
     duk_push_c_function(ctx, js_atomic_GetAssetDatabase, 0);
     duk_put_prop_string(ctx, -2, "getAssetDatabase");