Specify credentials via -DAPI_NG_APP_ID=value and -DAPI_NG_ENC_KEY=value at build time

This commit is contained in:
EliteMasterEric
2024-11-04 15:05:33 -05:00
committed by Cameron Taylor
parent b75a550c5b
commit aa08dcfbbc
2 changed files with 37 additions and 7 deletions
+32 -1
View File
@@ -9,10 +9,23 @@ class Prebuild
{
static inline final BUILD_TIME_FILE:String = '.build_time';
static final NG_CREDS_PATH:String = './source/funkin/api/newgrounds/NewgroundsCredentials.hx';
static final NG_CREDS_TEMPLATE:String = "package funkin.api.newgrounds;
class NewgroundsCredentials
{
public static final APP_ID:String = #if API_NG_APP_ID haxe.macro.Compiler.getDefine(\"API_NG_APP_ID\") #else 'INSERT APP ID HERE' #end;
public static final ENCRYPTION_KEY:String = #if API_NG_ENC_KEY haxe.macro.Compiler.getDefine(\"API_NG_ENC_KEY\") #else 'INSERT ENCRYPTION KEY HERE' #end;
}";
static function main():Void
{
saveBuildTime();
trace('Building...');
saveBuildTime();
buildCredsFile();
}
static function saveBuildTime():Void
@@ -22,4 +35,22 @@ class Prebuild
fo.writeDouble(now);
fo.close();
}
static function buildCredsFile():Void
{
#if sys
if (sys.FileSystem.exists(NG_CREDS_PATH))
{
trace('NewgroundsCredentials.hx already exists, skipping.');
}
else
{
trace('Creating NewgroundsCredentials.hx...');
var fileContents:String = NG_CREDS_TEMPLATE;
sys.io.File.saveContent(NG_CREDS_PATH, fileContents);
}
#end
}
}
@@ -36,14 +36,13 @@ class NewgroundsClient
private function new()
{
if (NewgroundsCredentials.ENCRYPTION_KEY.contains(' '))
{
trace('[NEWGROUNDS] Encryption key not valid, disabling...');
return;
}
trace('[NEWGROUNDS] Initializing client...');
#if FEATURE_NEWGROUNDS_DEBUG
trace('[NEWGROUNDS] App ID: ${NewgroundsCredentials.APP_ID}');
trace('[NEWGROUNDS] Encryption Key: ${NewgroundsCredentials.ENCRYPTION_KEY}');
#end
if (!hasValidCredentials())
{
FlxG.log.warn("Tried to initialize Newgrounds client, but credentials are invalid!");