LicenseSystem.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. // BEGIN LICENSE MANAGEMENT
  5. #pragma once
  6. #include <Atomic/Core/Object.h>
  7. #include "../Net/CurlManager.h"
  8. using namespace Atomic;
  9. namespace ToolCore
  10. {
  11. class LicenseSystem : public Object
  12. {
  13. OBJECT(LicenseSystem);
  14. public:
  15. struct LicenseParse
  16. {
  17. bool licenseWindows_;
  18. bool licenseMac_;
  19. bool licenseAndroid_;
  20. bool licenseIOS_;
  21. bool licenseHTML5_;
  22. bool licenseModule3D_;
  23. LicenseParse()
  24. {
  25. licenseWindows_ = false;
  26. licenseMac_ = false;
  27. licenseAndroid_ = false;
  28. licenseIOS_ = false;
  29. licenseHTML5_ = false;
  30. licenseModule3D_ = false;
  31. }
  32. };
  33. /// Construct.
  34. LicenseSystem(Context* context);
  35. /// Destruct.
  36. virtual ~LicenseSystem();
  37. void Initialize();
  38. bool GetSourceBuild();
  39. bool LicenseWindows() { return licenseWindows_; }
  40. bool LicenseMac() { return licenseMac_; }
  41. bool LicenseAndroid() { return licenseAndroid_; }
  42. bool LicenseIOS() { return licenseIOS_; }
  43. bool LicenseHTML5() { return licenseHTML5_; }
  44. bool LicenseModule3D() { return licenseModule3D_; }
  45. /// Returns whether there are any platform licenses available
  46. bool IsStandardLicense();
  47. void Activate(const String& key, const LicenseParse& parse);
  48. /// Returns true if request to deactivate is made
  49. bool Deactivate();
  50. void ResetLicense();
  51. bool LoadLicense();
  52. /// Basic key validation
  53. bool ValidateKey(const String &key);
  54. /// Activate on server
  55. void RequestServerActivation(const String& key);
  56. const String& GetKey() { return key_; }
  57. String GenerateMachineID();
  58. String GetEmail() { return email_;}
  59. void LicenseAgreementConfirmed();
  60. int ParseResponse(const String& response, LicenseParse &parse);
  61. private:
  62. void RequestServerVerification(const String& key);
  63. void SaveLicense();
  64. void RemoveLicense();
  65. void CreateOrUpdateLicenseCache();
  66. void HandleVerification(StringHash eventType, VariantMap& eventData);
  67. void HandleDeactivate(StringHash eventType, VariantMap& eventData);
  68. void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
  69. void HandleActivationResult(StringHash eventType, VariantMap& eventData);
  70. bool eulaAgreementConfirmed_;
  71. String licenseFilePath_;
  72. String licenseCachePath_;
  73. String eulaAgreementPath_;
  74. String key_;
  75. String email_;
  76. bool licenseWindows_;
  77. bool licenseMac_;
  78. bool licenseAndroid_;
  79. bool licenseIOS_;
  80. bool licenseHTML5_;
  81. bool licenseModule3D_;
  82. SharedPtr<CurlRequest> serverActivation_;
  83. SharedPtr<CurlRequest> serverVerification_;
  84. SharedPtr<CurlRequest> deactivate_;
  85. };
  86. }
  87. // END LICENSE MANAGEMENT