Skip to content

Commit 6aa2468

Browse files
committed
[[ LicenseCheck ]] Add a simple license check API to externals V1 API.
The V1 externals API has been extended with a new API LicenseCheck(). This API takes the minimum edition (one of Community, Indy, Business) which the external requires. If the engine is not licensed at that level or above, it will cause the external handler to fail and raise an error in the engine. If a call to the API fails in an external initialize handler, then it will cause all future calls to the external to fail with an error. In addition to the new external API, the deploy command will now include an edition byte in the standalone capsule - allowing license checks to occur in standalones rather than just in the IDE.
1 parent 3b764f0 commit 6aa2468

File tree

8 files changed

+364
-101
lines changed

8 files changed

+364
-101
lines changed

engine/src/capsule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ enum MCCapsuleSectionType
101101
// AL-2015-02-10: [[ Standalone Inclusions ]] Library consists of the mappings from universal names
102102
// of resources to their platform-specific paths relative to the executable.
103103
kMCCapsuleSectionTypeLibrary,
104+
105+
// MW-2016-02-17: [[ LicenseChecks ]] License consists of the array-encoded
106+
// 'revLicenseInfo' array in use at the point the standalone was built.
107+
kMCCapsuleSectionTypeLicense,
104108
};
105109

106110
// Each section begins with a header that defines its type and length. This is

engine/src/deploy.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,56 @@ static bool MCDeployWriteDefinePrologueSection(const MCDeployParameters& p_param
365365
return MCDeployCapsuleDefine(p_capsule, kMCCapsuleSectionTypePrologue, &t_prologue, sizeof(t_prologue));
366366
}
367367

368+
static bool MCDeployWriteDefineLicenseSection(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
369+
{
370+
MCAutoArrayRef t_license;
371+
if (!MCArrayCreateMutable(&t_license))
372+
return false;
373+
374+
// The edition byte encoding is development/standalone engine pair
375+
// specific.
376+
unsigned char t_edition;
377+
switch(MClicenseparameters . license_class)
378+
{
379+
case kMCLicenseClassNone:
380+
t_edition = 0;
381+
break;
382+
383+
case kMCLicenseClassCommunity:
384+
t_edition = 1;
385+
break;
386+
387+
case kMCLicenseClassCommercial:
388+
t_edition = 2;
389+
break;
390+
391+
case kMCLicenseClassProfessional:
392+
t_edition = 3;
393+
break;
394+
}
395+
396+
397+
return MCDeployCapsuleDefine(p_capsule,
398+
kMCCapsuleSectionTypeLicense,
399+
&t_edition,
400+
sizeof(t_edition));
401+
}
402+
368403
// This method generates the standalone specific capsule elements. This is
369404
// just a Standalone Prologue section at the moment.
370405
static bool MCDeployWriteCapsuleDefineStandaloneSections(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
371406
{
372407
bool t_success;
373408
t_success = true;
374409

410+
// First emit the prologue.
375411
if (t_success)
376412
t_success = MCDeployWriteDefinePrologueSection(p_params, p_capsule);
377413

414+
// Next emit the license info.
415+
if (t_success)
416+
t_success = MCDeployWriteDefineLicenseSection(p_params, p_capsule);
417+
378418
return t_success;
379419
}
380420

engine/src/executionerrors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,9 @@ enum Exec_errors
26952695

26962696
// {EE-0882} save: error in file format expression
26972697
EE_SAVE_BADNOFORMATEXP,
2698+
2699+
// {EE-0883} external: unlicensed
2700+
EE_EXTERNAL_UNLICENSED,
26982701
};
26992702

27002703
extern const char *MCexecutionerrors;

0 commit comments

Comments
 (0)