THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/10/2009 at 14:45, xxxxxxxx wrote:
LONG SNCheck(const String& c4dsn, const String& sn, LONG regdate, LONG curdate)
SNCheck is called for you when you call Register(). Here's my entire Main.cpp with SNHookClass. Note that I donot check the serial number when running Demo, Net, Server.
> // Includes \> #ifdef MACOS \> #include "Rijndael_Mac.h" \> #else \> #include "Rijndael.h" \> #endif \> #include "c4d.h" \> #include "lib_sn.h" \> #include "general.h" \> \> // Size of serial number string \> #define ENTRY_SIZE 17 \> \> // KDZSerial: Serial Number Hook Class \> class KDZSerial : public SNHookClass \> { \> private: \> // Data \> const String SNPluginName; \> // Methods \> // - KDZSerial.checkSerial \> //\*---------------------------------------------------------------------------\* \> Bool checkSerial(const String& c4dsn, const String& sn) \> //\*---------------------------------------------------------------------------\* \> { \> // Key is 11-Digit C4D SN + 5-Char PluginCode + NullTerminator \> char key[ENTRY_SIZE]; \> c4dsn.GetCString(&key;[0], c4dsn.GetCStringLen()+1L, St7bit); \> // Example \> key[11] = 'x'; \> key[12] = 'x'; \> key[13] = 'x'; \> key[14] = 'x'; \> key[15] = 'x'; \> key[16] = 0; \> \> // Encrypt plugin serial no. using AES \> char dout[ENTRY_SIZE] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; \> // One block testing \> CRijndael oRijndael; \> if (!oRijndael.MakeKey(&key;[0], "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16, 16)) \> { \> MessageDialog(GeLoadString(PDRERR_SNMAKEKEY)); \> return FALSE; \> } \> char din[ENTRY_SIZE]; \> memcpy(&din;[0], &key;[0], ENTRY_SIZE); \> if (!oRijndael.EncryptBlock(din, dout)) \> { \> MessageDialog(GeLoadString(PDRERR_SNENCRYPTION)); \> return FALSE; \> } \> dout[16] = 0; // Null-terminate \> \> UINT i; \> UCHAR val; \> // Convert to AlphaNumerics for user serial number entry \> for (i = 0; i != 16; ++i) \> { \> val = (UCHAR)dout[i]; \> // Beyond AlphaNumerics \> if (val > 122) val /= 3; \> // Below AlphaNumberics \> if (val < 48) val += 48; \> // Between numerals and UC Alpha \> if ((val > 57) && (val < 65)) val += 24; \> // Between UC Alpha and LC Alpha \> if ((val > 90) && (val < 97)) val += 12; \> dout[i] = (char)val; \> } \> dout[16] = 0; // Null-terminate \> \> sn.GetCString(&key;[0], sn.GetCStringLen()+1L, St7bit); //ENTRY_SIZE, St7bit); \> // Check sn against Encrypted-AlphaNumericized dout \> for (i = 0; i != 16; ++i) \> { \> //GePrint("key["+LongToString(i)+"]=\'"+LongToString(key[i])+"\' == chk["+LongToString(i)+"]=\'"+LongToString(dout[i])+"\'"); \> if (key[i] != dout[i]) \> { \> MessageDialog(GeLoadString(PDRERR_SNINVALID)); \> return FALSE; \> } \> } \> return TRUE; \> } \> public: \> // Data \> // - mode = 0 (not registered/not demo), 1 (demo), 2 (registered) \> UCHAR mode; \> LONG time; \> // Methods \> // - Constructor \> //\*---------------------------------------------------------------------------\* \> KDZSerial() : SNPluginName("PipeDream") \> //\*---------------------------------------------------------------------------\* \> { \> mode = 0; \> } \> // - SNHookClass.SNCheck \> //\*---------------------------------------------------------------------------\* \> LONG SNCheck(const String& c4dsn, const String& sn, LONG regdate, LONG curdate) \> //\*---------------------------------------------------------------------------\* \> { \> if (!sn.Content()) return SN_WRONGNUMBER; \> \> // Demo mode (14 day trial) \> if (sn.GetLength() == 4L) \> { \> // Case-insensitive serial number 'demo' \> if (sn.LexCompare("DEMO")) return SN_WRONGNUMBER; \> \> if (!regdate) \> { \> mode = 1; \> return SN_OKAY; \> } \> \> // Calculate timeout of Demo or Beta modes \> LONG timeout = 14L - (curdate - regdate); \> if (timeout < 0L) return SN_EXPIRED; \> time = timeout; \> mode = 1; \> if (timeout <= 14L) return SN_EXPIRE_14 - timeout; \> return SN_OKAY; \> } \> // Registered user \> else if (sn.GetLength() == 16L) \> { \> if (checkSerial(c4dsn, sn)) \> { \> mode = 2; \> return SN_OKAY; \> } \> } \> #ifdef C4D_R11 \> // Multi-License Server \> else \> { \> // Check for R11 Multi-License \> SerialInfo mlsn; \> GeGetSerialInfo(SERIAL_MULTILICENSE, &mlsn;); \> if (mlsn.nr.Content()) \> { \> //-------------------------------------------------------------------------------- \> // 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)... \> //-------------------------------------------------------------------------------- \> String plug_sn = sn; \> LONG dashPos; \> if (plug_sn.FindFirst("-", &dashPos;, 0L)) \> { \> plug_sn = plug_sn.SubStr(dashPos+1L, plug_sn.GetLength()-dashPos-1L); \> if (checkSerial(mlsn.nr, plug_sn)) \> { \> mode = 2; \> return SN_OKAY; \> } \> } \> } \> } \> #else \> else MessageDialog(GeLoadString(PDRERR_SNSIZE)); \> #endif \> \> return SN_WRONGNUMBER; \> } \> // - SNHookClass.GetTitle \> //\*---------------------------------------------------------------------------\* \> const String& GetTitle() \> //\*---------------------------------------------------------------------------\* \> { \> return SNPluginName; \> } \> }; \> \> static KDZSerial\* kdzSerial = NULL; \> \> //\*---------------------------------------------------------------------------\* \> Bool RegisterKDZSerial() \> //\*---------------------------------------------------------------------------\* \> { \> kdzSerial = gNew KDZSerial(); \> if (!kdzSerial) return ErrorException::Throw(GeLoadString(PDRERR_MEMORY), "main.RegisterKDZSerial.kdzSerial"); \> return kdzSerial->Register(ID_PIPEDREAMOBJ, SNFLAG_OWN); \> } \> //\*---------------------------------------------------------------------------\* \> void FreeKDZSerial() \> //\*---------------------------------------------------------------------------\* \> { \> gDelete(kdzSerial); \> } \> \> \> // Plugin Functions ================================================================================================== \> \> // Declare Global Plugin Registrants \> Bool RegisterPipeDreamObj(); \> Bool RegisterPipeDreamTag(); \> \> //\*---------------------------------------------------------------------------\* \> Bool PluginStart() \> //\*---------------------------------------------------------------------------\* \> { \> Bool network = FALSE; \> LONG vtype = GeGetVersionType(); \> if ((vtype & VERSION_SERVER) || (vtype & VERSION_NET)) network = TRUE; \> #ifdef C4D_R11 \> if (vtype & VERSION_DEMO) GePrint("C4D Demo"); \> else if (vtype & (VERSION_SAVABLEDEMO|VERSION_SAVABLEDEMO_ACTIVE)) GePrint("C4D Savable Demo"); \> else if (vtype & VERSION_SERVER) GePrint("C4D Server"); \> else if (vtype & VERSION_NET) GePrint("C4D Net"); \> else \> { \> // serial number check \> if (!(kdzSerial && kdzSerial->mode)) return FALSE; \> } \> #else \> if (!((vtype & VERSION_DEMO) || network)) \> { \> // serial number check \> if (!(kdzSerial && kdzSerial->mode)) return FALSE; \> } \> #endif \> \> GePrint(" "); \> GePrint(GeLoadString(PDRS_PLUGIN_BANNER)); \> GePrint("-- "+GeLoadString(PDRS_PLUGIN_NAME)+" "+GeLoadString(PDRS_PLUGIN_EDITION)+" v"+GeLoadString(PDRS_PLUGIN_VERSION)+" "+GeLoadString(PDRS_PLUGIN_COPYRIGHT)); \> if (kdzSerial) \> { \> if (kdzSerial->mode == 1) GePrint("-- Trial: "+LongToString(kdzSerial->time)+" days left"); \> else if (kdzSerial->mode == 2) \> { \> SerialInfo si; \> GeGetSerialInfo(SERIAL_CINEMA4D, &si;); \> GePrint("-- Licensed to: "+si.name); \> } \> } \> GePrint(GeLoadString(PDRS_PLUGIN_BANNER)); \> GePrint(" "); \> \> return RegisterPipeDreamObj() && RegisterPipeDreamTag(); \> } \> \> //\*---------------------------------------------------------------------------\* \> void PluginEnd() \> //\*---------------------------------------------------------------------------\* \> { \> } \> \> //\*---------------------------------------------------------------------------\* \> Bool PluginMessage(LONG id, void\* data) \> //\*---------------------------------------------------------------------------\* \> { \> if (id == C4DPL_INIT_SYS) \> { \> // initialize global resource object \> if (!resource.Init()) return FALSE; \> \> // initialize and register Serial Number Hook \> LONG vtype = GeGetVersionType(); \> #ifdef C4D_R11 \> if (vtype & VERSION_DEMO) { GePrint("C4D Demo"); return TRUE; } \> if (vtype & (VERSION_SAVABLEDEMO|VERSION_SAVABLEDEMO_ACTIVE)) { GePrint("C4D Savable Demo"); return TRUE; } \> if (vtype & VERSION_SERVER) { GePrint("C4D Server"); return TRUE; } \> if (vtype & VERSION_NET) { GePrint("C4D Net"); return TRUE; } \> #else \> if ((vtype & VERSION_DEMO) || (vtype & VERSION_SERVER) || (vtype & VERSION_NET)) return TRUE; \> #endif \> return RegisterKDZSerial(); \> } \> else if (id == C4DPL_ENDACTIVITY) \> { \> FreeKDZSerial(); \> return TRUE; \> } \> else if (id == C4DMSG_PRIORITY) return TRUE; \> return FALSE; \> }