LicenseSystem.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // BEGIN LICENSE MANAGEMENT
  23. #pragma once
  24. #include <Atomic/Core/Object.h>
  25. #include "../Net/CurlManager.h"
  26. using namespace Atomic;
  27. namespace ToolCore
  28. {
  29. class LicenseSystem : public Object
  30. {
  31. OBJECT(LicenseSystem);
  32. public:
  33. struct LicenseParse
  34. {
  35. bool licenseWindows_;
  36. bool licenseMac_;
  37. bool licenseAndroid_;
  38. bool licenseIOS_;
  39. bool licenseHTML5_;
  40. bool licenseModule3D_;
  41. LicenseParse()
  42. {
  43. licenseWindows_ = false;
  44. licenseMac_ = false;
  45. licenseAndroid_ = false;
  46. licenseIOS_ = false;
  47. licenseHTML5_ = false;
  48. licenseModule3D_ = false;
  49. }
  50. };
  51. /// Construct.
  52. LicenseSystem(Context* context);
  53. /// Destruct.
  54. virtual ~LicenseSystem();
  55. void Initialize();
  56. bool GetSourceBuild();
  57. bool GetLicenseWindows() { return licenseWindows_; }
  58. bool GetLicenseMac() { return licenseMac_; }
  59. bool GetLicenseAndroid() { return licenseAndroid_; }
  60. bool GetLicenseIOS() { return licenseIOS_; }
  61. bool GetLicenseHTML5() { return licenseHTML5_; }
  62. bool GetLicenseModule3D() { return licenseModule3D_; }
  63. /// Returns whether there are any platform licenses available
  64. bool IsStandardLicense();
  65. void Activate(const String& key, const LicenseParse& parse);
  66. /// Returns true if request to deactivate is made
  67. bool Deactivate();
  68. void ResetLicense();
  69. bool LoadLicense();
  70. /// Basic key validation
  71. bool ValidateKey(const String &key);
  72. /// Activate on server
  73. void RequestServerActivation(const String& key);
  74. const String& GetKey() { return key_; }
  75. String GenerateMachineID();
  76. String GetEmail() { return email_;}
  77. void LicenseAgreementConfirmed();
  78. int ParseResponse(const String& response, LicenseParse &parse);
  79. private:
  80. void RequestServerVerification(const String& key);
  81. void SaveLicense();
  82. void RemoveLicense();
  83. void CreateOrUpdateLicenseCache();
  84. void HandleVerification(StringHash eventType, VariantMap& eventData);
  85. void HandleDeactivate(StringHash eventType, VariantMap& eventData);
  86. void HandleEditorShutdown(StringHash eventType, VariantMap& eventData);
  87. void HandleActivationResult(StringHash eventType, VariantMap& eventData);
  88. bool eulaAgreementConfirmed_;
  89. String licenseFilePath_;
  90. String licenseCachePath_;
  91. String eulaAgreementPath_;
  92. String key_;
  93. String email_;
  94. bool licenseWindows_;
  95. bool licenseMac_;
  96. bool licenseAndroid_;
  97. bool licenseIOS_;
  98. bool licenseHTML5_;
  99. bool licenseModule3D_;
  100. SharedPtr<CurlRequest> serverActivation_;
  101. SharedPtr<CurlRequest> serverVerification_;
  102. SharedPtr<CurlRequest> deactivate_;
  103. };
  104. }
  105. // END LICENSE MANAGEMENT