THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/04/2009 at 16:03, xxxxxxxx wrote:
The Code:
Below is sample code for a "License Server aware" SNCheck() routine, that can be built with the R10.1 SDK and taking all of the above into account. Obviously some sensitive details are left out...
-------------------- S N I P ------------------------
// - SNHookClass.SNCheck
//*---------------------------------------------------------------------------*
LONG SNCheck(const String& c4dsn, const String& sn, LONG regdate, LONG curdate)
//*---------------------------------------------------------------------------*
{
if( !regdate && !sn.Content() )
return SN_WRONGNUMBER;
bool bCalledByServer = false;
LONG licCount = 1; // initialize a "license count" (if you need/care to know that)
// set up some new strings (that can be altered)
String c4d_sn = c4dsn; // initialize the C4D serial number to the one passed in
String plug_sn = sn; // initialize the plugin license key to the one passed in
// only need to check for multi-license if this is R11 or later...
if( GetC4DVersion() >= 1100 )
{
#ifndef SERIAL_MULTILICENSE
#define SERIAL_MULTILICENSE 2 // this #define lets us build with the R10.1 SDK
#endif
SerialInfo si;
GeGetSerialInfo(SERIAL_MULTILICENSE, &si);
// See if this is a multi-license-server based installation
if(si.nr.Content())
{
// if you need to find the license count, you can do it like so...
LONG licCount = si.nr.SubStr(3,3).StringToLong(NULL);
// GePrint("Using multilicense for " + FormatNumber(licCount, FORMAT_LONG, 0) + " seats");
//--------------------------------------------------------------------------------
// since this is a multi-license based config, we'll switch over to use the serial
// number from GeGetSerialInfo() instead of the one passed into this routine (the
// one passed in is the original 'stand-alone, single seat' version, that doesn't
// have the seat count info embedded).
//--------------------------------------------------------------------------------
c4d_sn = si.nr;
//--------------------------------------------------------------------------------
// Note that we also need to skip over the extra data added to the front of the
// plugin's license key (11 digits/characters and a dash)...
//--------------------------------------------------------------------------------
LONG dashPos;
if(sn.FindFirst("-", &dashPos,0))
{
plug_sn = sn.SubStr(dashPos+1, sn.GetLength()-dashPos-1);
}
//--------------------------------------------------------------------------------
// At this point, we have switched over to using the multi-license serial number
// and patched up our plugin's license key to match. Assuming these are the
// strings you used to generate your plugin's license key to begin with (however
// you go about doing that), you should be good to go - the rest of your code
// after this point may not even need to know if this is a single or multi-license
// configuration, but you can always set up a boolean or check for "20" as the
// first 2 characters of the c4d_sn string if you need to later.
//
// In this case (at least for some code below here), I'll set a boolean...
//--------------------------------------------------------------------------------
bCalledByServer = true;
}
}
// Demo/Beta modes
if (plug_sn.GetLength() == 4L)
{
//----------------------------------------------------------------------------------
//**********************************************************************************
// NOTE: When called from within a License-Server environment, 'regdate' is INVALID
// (it appears to be uninitialized/garbage value), so there's no way to use
// that variable for DEMO-expiration tests.
//
// There are some other issues related to actually allowing timed trial periods
// within a License-Server environment, but if you decide to allow it, your plugin
// will need to track the regdate by some other means.
//**********************************************************************************
//----------------------------------------------------------------------------------
if( bCalledByServer )
return SN_WRONGNUMBER;
LONG numDays = 0L;
if (!plug_sn.Compare("DEMO"))
numDays = 30L;
else
return SN_WRONGNUMBER;
// etc...... continue whatever 'DEMO' mode parsing as needed below here and then\n
// (if not DEMO mode), call your license key validation routine, etc.
// ............etc.
}
// ........snip...... //
return SN_WRONGNUMBER;
}