initial commit, kind of working.
This commit is contained in:
@@ -0,0 +1,954 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import com.newgrounds.crypto.RC4;
|
||||
import com.newgrounds.encoders.json.JSON;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.events.Event;
|
||||
import flash.net.SharedObject;
|
||||
import flash.system.Security;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
|
||||
public class API
|
||||
{
|
||||
|
||||
private static var _bridge:Bridge;
|
||||
|
||||
private static var _movieName:String;
|
||||
|
||||
private static var _movieVersion:String;
|
||||
|
||||
private static var _root:DisplayObject;
|
||||
|
||||
private static var _newVersion:Boolean;
|
||||
|
||||
private static var _adFeedURL:String;
|
||||
|
||||
private static var _imageFilePath:String;
|
||||
|
||||
private static var _saveFilePath:String;
|
||||
|
||||
private static var _requestedSaveFileId:uint;
|
||||
|
||||
private static var _requestedSaveGroupId:uint;
|
||||
|
||||
public static const RELEASE_MODE:String = "releaseMode";
|
||||
|
||||
public static const DEBUG_MODE_LOGGED_IN:String = "debugModeLoggedIn";
|
||||
|
||||
public static const DEBUG_MODE_LOGGED_OUT:String = "debugModeLoggedOut";
|
||||
|
||||
public static const DEBUG_MODE_NEW_VERSION:String = "debugModeNewVersion";
|
||||
|
||||
public static const DEBUG_MODE_HOST_BLOCKED:String = "debugModeHostBlocked";
|
||||
|
||||
private static const TEST_AD_FEED_URL:String = "http://www.ngads.com/adtest.php";
|
||||
|
||||
private static var _dispatcher:APIEventDispatcher = new APIEventDispatcher();
|
||||
|
||||
private static var _connection:APIConnection = new APIConnection();
|
||||
|
||||
private static var _debugMode:String = DEBUG_MODE_LOGGED_IN;
|
||||
|
||||
private static var _adsApproved:Boolean = false;
|
||||
|
||||
private static var _medals:Object = new Object();
|
||||
|
||||
private static var _medalsArray:Array = [];
|
||||
|
||||
private static var _scoreBoards:Object = new Object();
|
||||
|
||||
private static var _scoreBoardsArray:Array = [];
|
||||
|
||||
private static var _saveGroups:Object = new Object();
|
||||
|
||||
private static var _saveGroupsArray:Array = [];
|
||||
|
||||
private static var _sharedObjects:Object = new Object();
|
||||
|
||||
public static const VERSION:String = "3.0.4.1 beta AS3";
|
||||
|
||||
public function API()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get connected() : Boolean
|
||||
{
|
||||
return _connection.connected;
|
||||
}
|
||||
|
||||
public static function get isNetworkHost() : Boolean
|
||||
{
|
||||
return _connection.isNetworkHost;
|
||||
}
|
||||
|
||||
public static function get apiId() : String
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.apiId;
|
||||
}
|
||||
|
||||
public static function get debugMode() : String
|
||||
{
|
||||
return _debugMode;
|
||||
}
|
||||
|
||||
public static function set debugMode(param1:String) : void
|
||||
{
|
||||
_debugMode = param1;
|
||||
}
|
||||
|
||||
public static function get publisherId() : uint
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.publisherId;
|
||||
}
|
||||
|
||||
public static function get sessionId() : String
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.sessionId;
|
||||
}
|
||||
|
||||
public static function get hostDomain() : String
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.hostDomain;
|
||||
}
|
||||
|
||||
public static function get hostURL() : String
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.hostURL;
|
||||
}
|
||||
|
||||
public static function get isNewgrounds() : Boolean
|
||||
{
|
||||
return _connection.publisherId == 1;
|
||||
}
|
||||
|
||||
public static function get hasUserSession() : Boolean
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.hasUserSession;
|
||||
}
|
||||
|
||||
public static function get username() : String
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.username;
|
||||
}
|
||||
|
||||
public static function get userId() : uint
|
||||
{
|
||||
_connection.assertInitialized();
|
||||
return _connection.userId;
|
||||
}
|
||||
|
||||
private static function assertConnected(param1:String = null) : Boolean
|
||||
{
|
||||
if(_connection.assertConnected())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(param1)
|
||||
{
|
||||
dispatchEvent(param1,null,APIEvent.ERROR_NOT_CONNECTED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get adsApproved() : Boolean
|
||||
{
|
||||
return _adsApproved;
|
||||
}
|
||||
|
||||
public static function get adFeedURL() : String
|
||||
{
|
||||
return _adFeedURL;
|
||||
}
|
||||
|
||||
public static function get medals() : Array
|
||||
{
|
||||
return _medalsArray;
|
||||
}
|
||||
|
||||
public static function get scoreBoards() : Array
|
||||
{
|
||||
return _scoreBoardsArray;
|
||||
}
|
||||
|
||||
public static function get saveGroups() : Array
|
||||
{
|
||||
return _saveGroupsArray;
|
||||
}
|
||||
|
||||
public static function connect(param1:DisplayObject, param2:String, param3:String = null, param4:String = "") : void
|
||||
{
|
||||
APIEventDispatcher.globalDispatcher = _dispatcher;
|
||||
Security.loadPolicyFile("http://apifiles.ngfiles.com/crossdomain.xml");
|
||||
if(_connection.initialized)
|
||||
{
|
||||
Logger.logError("Connection already in progress. Please call API.disconnect() before attempting another connection.");
|
||||
dispatchEvent(APIEvent.API_CONNECTED,false,APIEvent.ERROR_NOT_CONNECTED);
|
||||
return;
|
||||
}
|
||||
if(!param2 || param2 == "")
|
||||
{
|
||||
Logger.logError("No apiId given. Please use the API ID from your API settings page.");
|
||||
dispatchEvent(APIEvent.API_CONNECTED,false,APIEvent.ERROR_INVALID_ARGUMENT);
|
||||
return;
|
||||
}
|
||||
Logger.logMessage("====== Newgrounds API v" + VERSION + " ======");
|
||||
_connection.connectionState = APIConnection.CONNECTING;
|
||||
_root = param1;
|
||||
_movieVersion = param4;
|
||||
_connection.apiId = param2;
|
||||
var _loc5_:uint = uint(param2.indexOf(":"));
|
||||
if(_loc5_ != -1)
|
||||
{
|
||||
_connection.trackerId = uint(param2.substring(0,_loc5_));
|
||||
}
|
||||
else
|
||||
{
|
||||
_connection.trackerId = uint(param2);
|
||||
}
|
||||
if(!_connection.trackerId)
|
||||
{
|
||||
Logger.logError("Invalid API ID: " + param2);
|
||||
dispatchEvent(APIEvent.API_CONNECTED,false,APIEvent.ERROR_INVALID_ARGUMENT);
|
||||
return;
|
||||
}
|
||||
_connection.encryptionKey = param3;
|
||||
_connection.initialized = true;
|
||||
if(!_root.loaderInfo)
|
||||
{
|
||||
Logger.logWarning("The root DisplayObject is currently not on the stage. Connection will be completed once it is added to stage.");
|
||||
}
|
||||
_root.addEventListener(Event.ENTER_FRAME,checkRootLoaderInfo);
|
||||
checkRootLoaderInfo(null);
|
||||
}
|
||||
|
||||
private static function doConnect(param1:Object) : void
|
||||
{
|
||||
if(isNetworkHost && _debugMode != RELEASE_MODE)
|
||||
{
|
||||
Logger.logMessage("Live file detected, turning off debug mode.");
|
||||
_debugMode = RELEASE_MODE;
|
||||
}
|
||||
if(Boolean(param1) && Boolean(param1.NewgroundsAPI_SandboxID))
|
||||
{
|
||||
_bridge = new Bridge(param1.NewgroundsAPI_SandboxID);
|
||||
APICommand.bridge = _bridge;
|
||||
}
|
||||
if(_debugMode == RELEASE_MODE)
|
||||
{
|
||||
if(param1)
|
||||
{
|
||||
if(param1.NewgroundsAPI_UserName)
|
||||
{
|
||||
_connection.username = param1.NewgroundsAPI_UserName;
|
||||
}
|
||||
if(param1.NewgroundsAPI_UserID)
|
||||
{
|
||||
_connection.userId = param1.NewgroundsAPI_UserID;
|
||||
}
|
||||
if(param1.NewgroundsAPI_PublisherID)
|
||||
{
|
||||
_connection.publisherId = param1.NewgroundsAPI_PublisherID;
|
||||
}
|
||||
if(param1.NewgroundsAPI_UserpageFormat)
|
||||
{
|
||||
_connection.userpageFormat = param1.NewgroundsAPI_UserpageFormat;
|
||||
}
|
||||
if(param1.NewgroundsAPI_SessionID)
|
||||
{
|
||||
_connection.sessionId = param1.NewgroundsAPI_SessionID;
|
||||
}
|
||||
if(param1.NewgroundsAPI_SaveGroupID)
|
||||
{
|
||||
_requestedSaveGroupId = param1.NewgroundsAPI_SaveGroupID;
|
||||
}
|
||||
if(param1.NewgroundsAPI_SaveFileID)
|
||||
{
|
||||
_requestedSaveFileId = param1.NewgroundsAPI_SaveFileID;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_connection.debug = true;
|
||||
if(_debugMode == DEBUG_MODE_LOGGED_IN || _debugMode == DEBUG_MODE_LOGGED_OUT)
|
||||
{
|
||||
_connection.publisherId = 1;
|
||||
}
|
||||
if(_debugMode == DEBUG_MODE_LOGGED_IN)
|
||||
{
|
||||
_connection.sessionId = "D3bu64p1U53R";
|
||||
_connection.userId = 10;
|
||||
_connection.username = "API-Debugger";
|
||||
}
|
||||
}
|
||||
_connection.sendSimpleCommand("connectMovie",onConnect,{
|
||||
"host":_connection.hostDomain,
|
||||
"movie_version":_movieVersion,
|
||||
"publisher_id":_connection.publisherId
|
||||
});
|
||||
}
|
||||
|
||||
private static function onConnect(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:Object = param1.data;
|
||||
if(!param1.success)
|
||||
{
|
||||
Logger.logError("Unable to connect to the API.");
|
||||
_connection.reset();
|
||||
dispatchEvent(APIEvent.API_CONNECTED,param1.data,param1.error);
|
||||
return;
|
||||
}
|
||||
if(debugMode != RELEASE_MODE)
|
||||
{
|
||||
_adFeedURL = TEST_AD_FEED_URL;
|
||||
}
|
||||
else if(_loc2_.ad_url)
|
||||
{
|
||||
_adFeedURL = unescape(_loc2_.ad_url);
|
||||
}
|
||||
switch(_loc2_.ad_status)
|
||||
{
|
||||
case -1:
|
||||
Logger.logWarning("Your movie is not approved to run Flash Ads.");
|
||||
break;
|
||||
case 0:
|
||||
Logger.logWarning("Your movie is still awaiting approval to run Flash Ads.");
|
||||
break;
|
||||
case 1:
|
||||
Logger.logMessage("Your movie is approved to run Flash Ads!");
|
||||
}
|
||||
_adsApproved = _loc2_.ad_status == 1;
|
||||
if(_debugMode == DEBUG_MODE_HOST_BLOCKED || Boolean(_loc2_.deny_host))
|
||||
{
|
||||
Logger.logWarning(_connection.hostDomain + " does not have permission to host this movie!","Update your API configuration to allow this host.");
|
||||
dispatchEvent(APIEvent.API_CONNECTED,{"officialURL":unescape(_loc2_.movie_url)},APIEvent.ERROR_HOST_BLOCKED);
|
||||
_connection.reset();
|
||||
return;
|
||||
}
|
||||
_movieName = _loc2_.movieName ? _loc2_.movieName : "";
|
||||
Logger.logMessage("Connecting to the Newgrounds API Gateway...","----- " + _loc2_.movie_name + " -----");
|
||||
if(_debugMode == DEBUG_MODE_NEW_VERSION)
|
||||
{
|
||||
_loc2_.movie_version = "Debug Mode";
|
||||
}
|
||||
if(_loc2_.movie_version)
|
||||
{
|
||||
Logger.logMessage("A new version of this movie is available.","Current version:\t" + _movieVersion,"Newest version:\t" + _loc2_.movie_version,"Use API.loadOfficialVersion() to link to the latest version.");
|
||||
_newVersion = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_newVersion = false;
|
||||
}
|
||||
if(_loc2_.request_portal_url)
|
||||
{
|
||||
_connection.sendSimpleCommand("setPortalID",null,{"portal_url":_connection.hostURL});
|
||||
}
|
||||
_connection.sendSimpleCommand("preloadSettings",onMetadataLoaded,{
|
||||
"publisher_id":_connection.publisherId,
|
||||
"user_id":_connection.userId
|
||||
});
|
||||
}
|
||||
|
||||
private static function onMetadataLoaded(param1:APIEvent) : void
|
||||
{
|
||||
var _loc3_:uint = 0;
|
||||
var _loc4_:uint = 0;
|
||||
var _loc6_:Object = null;
|
||||
var _loc7_:Object = null;
|
||||
var _loc8_:Boolean = false;
|
||||
var _loc9_:Boolean = false;
|
||||
var _loc10_:Medal = null;
|
||||
var _loc11_:Object = null;
|
||||
var _loc12_:ScoreBoard = null;
|
||||
var _loc13_:Object = null;
|
||||
var _loc14_:Array = null;
|
||||
var _loc15_:Array = null;
|
||||
var _loc16_:SaveGroup = null;
|
||||
var _loc17_:Object = null;
|
||||
var _loc18_:Object = null;
|
||||
var _loc2_:Object = param1.data;
|
||||
if(!param1.success)
|
||||
{
|
||||
Logger.logWarning("Unable to load movie metadata.");
|
||||
disconnect();
|
||||
dispatchEvent(APIEvent.API_CONNECTED,null,param1.error);
|
||||
return;
|
||||
}
|
||||
var _loc5_:uint = 0;
|
||||
if(_loc2_.medals)
|
||||
{
|
||||
_loc5_ = uint(_loc2_.medals.length);
|
||||
if(hasUserSession)
|
||||
{
|
||||
_loc6_ = loadLocal("medals_unlocked_" + username);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc6_ = loadLocal("medals_unlocked");
|
||||
}
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < _loc5_)
|
||||
{
|
||||
_loc7_ = _loc2_.medals[_loc3_];
|
||||
_loc8_ = Boolean(_loc7_.medal_unlocked);
|
||||
_loc9_ = Boolean(_loc6_) && Boolean(_loc6_[_loc7_.medal_id]);
|
||||
_loc10_ = new Medal(_connection,_loc7_.medal_id,_loc7_.medal_name,hasUserSession ? _loc8_ : _loc9_,_loc7_.medal_value,_loc7_.medal_difficulty,_loc7_.medal_icon);
|
||||
_loc10_.addEventListener(APIEvent.MEDAL_UNLOCKED,onMedalUnlocked,false,0,true);
|
||||
_loc10_.addEventListener(APIEvent.MEDAL_UNLOCK_CONFIRMED,onMedalUnlockConfirmed,false,0,true);
|
||||
_medals[_loc10_.name] = _loc10_;
|
||||
_medalsArray.push(_loc10_);
|
||||
Logger.logMessage(_loc10_);
|
||||
if(hasUserSession && _loc9_ && !_loc8_)
|
||||
{
|
||||
Logger.logMessage("Server missed the \"" + _loc10_.name + "\" unlock. Resending...");
|
||||
_loc10_.unlock();
|
||||
}
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
Logger.logMessage(_loc5_ + " medal" + (_loc5_ != 1 ? "s" : "") + " initialized.");
|
||||
_loc5_ = 0;
|
||||
if(_loc2_.score_boards)
|
||||
{
|
||||
_loc5_ = uint(_loc2_.score_boards.length);
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < _loc5_)
|
||||
{
|
||||
_loc11_ = _loc2_.score_boards[_loc3_];
|
||||
_loc12_ = new ScoreBoard(_connection,_loc11_.name,_loc11_.id);
|
||||
_scoreBoards[_loc12_.name] = _loc12_;
|
||||
_scoreBoardsArray.push(_loc12_);
|
||||
Logger.logMessage(_loc12_);
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
Logger.logMessage(_loc5_ + " scoreboard" + (_loc5_ != 1 ? "s" : "") + " initialized.");
|
||||
_loc5_ = 0;
|
||||
if(_loc2_.save_groups)
|
||||
{
|
||||
_loc5_ = uint(_loc2_.save_groups.length);
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < _loc5_)
|
||||
{
|
||||
_loc13_ = _loc2_.save_groups[_loc3_];
|
||||
_loc14_ = [];
|
||||
if(_loc13_.keys)
|
||||
{
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _loc13_.keys.length)
|
||||
{
|
||||
_loc17_ = _loc13_.keys[_loc4_];
|
||||
_loc14_.push(new SaveKey(_loc17_.name,_loc17_.id,_loc17_.type));
|
||||
_loc4_++;
|
||||
}
|
||||
}
|
||||
_loc15_ = [];
|
||||
if(_loc13_.ratings)
|
||||
{
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < _loc13_.ratings.length)
|
||||
{
|
||||
_loc18_ = _loc13_.ratings[_loc3_];
|
||||
_loc15_.push(new SaveRating(_loc18_.name,_loc18_.id,_loc18_.float,_loc18_.min,_loc18_.max));
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
_loc16_ = new SaveGroup(_connection,_loc13_.group_name,_loc13_.group_id,_loc13_.group_type,_loc14_,_loc15_);
|
||||
_saveGroups[_loc16_.name] = _loc16_;
|
||||
_saveGroupsArray.push(_loc16_);
|
||||
Logger.logMessage(_loc16_);
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
Logger.logMessage(_loc5_ + " save group" + (_loc5_ != 1 ? "s" : "") + " initialized.");
|
||||
if(_loc2_.save_file_path)
|
||||
{
|
||||
_saveFilePath = _loc2_.save_file_path + "/";
|
||||
SaveFile._saveFilePath = _saveFilePath;
|
||||
Logger.logInternal("Save file path: " + _saveFilePath);
|
||||
}
|
||||
if(_loc2_.image_file_path)
|
||||
{
|
||||
_imageFilePath = _loc2_.image_file_path + "/";
|
||||
SaveFile._imageFilePath = _imageFilePath;
|
||||
Logger.logInternal("Image file path: " + _imageFilePath);
|
||||
}
|
||||
Logger.logMessage("Connection complete!");
|
||||
_connection.connectionState = APIConnection.CONNECTED;
|
||||
dispatchEvent(APIEvent.API_CONNECTED,{
|
||||
"movieName":_movieName,
|
||||
"newVersion":_newVersion
|
||||
});
|
||||
if(Boolean(_requestedSaveFileId) && Boolean(_requestedSaveGroupId))
|
||||
{
|
||||
API.addEventListener(APIEvent.FILE_LOADED,onRequestedFileLoaded);
|
||||
API.loadSaveFile(_requestedSaveFileId,false);
|
||||
}
|
||||
}
|
||||
|
||||
public static function disconnect() : void
|
||||
{
|
||||
var _loc1_:Medal = null;
|
||||
if(!_connection.connected)
|
||||
{
|
||||
Logger.logWarning("The Newgrounds API is already disconnected.");
|
||||
return;
|
||||
}
|
||||
_connection.reset();
|
||||
for each(_loc1_ in _medals)
|
||||
{
|
||||
_loc1_.removeEventListener(APIEvent.MEDAL_UNLOCKED,onMedalUnlocked);
|
||||
_loc1_.removeEventListener(APIEvent.MEDAL_UNLOCK_CONFIRMED,onMedalUnlockConfirmed);
|
||||
}
|
||||
_newVersion = false;
|
||||
_medals = new Object();
|
||||
_medalsArray = [];
|
||||
_scoreBoards = new Object();
|
||||
_scoreBoardsArray = [];
|
||||
_saveGroups = new Object();
|
||||
_saveGroupsArray = [];
|
||||
_sharedObjects = new Object();
|
||||
_imageFilePath = null;
|
||||
_saveFilePath = null;
|
||||
Logger.logMessage("Disconnected from the Newgrounds API.");
|
||||
}
|
||||
|
||||
public static function loadNewgrounds() : void
|
||||
{
|
||||
_connection.loadInBrowser("loadNewgrounds");
|
||||
}
|
||||
|
||||
public static function loadOfficialVersion() : void
|
||||
{
|
||||
if(_connection.assertInitialized())
|
||||
{
|
||||
_connection.loadInBrowser("loadOfficialVersion",false);
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadMySite() : void
|
||||
{
|
||||
if(_connection.assertInitialized())
|
||||
{
|
||||
_connection.loadInBrowser("loadMySite");
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadCustomLink(param1:String) : void
|
||||
{
|
||||
if(_connection.assertInitialized())
|
||||
{
|
||||
_connection.loadInBrowser("loadCustomLink",true,{"link":param1});
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMedal(param1:String) : Medal
|
||||
{
|
||||
return _medals[param1];
|
||||
}
|
||||
|
||||
public static function unlockMedal(param1:String) : void
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var _loc2_:Medal = _medals[param1];
|
||||
if(!_loc2_)
|
||||
{
|
||||
Logger.logError("No medal named \"" + param1 + "\" was found.");
|
||||
return;
|
||||
}
|
||||
_loc2_.unlock();
|
||||
}
|
||||
|
||||
private static function onMedalUnlocked(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:Medal = null;
|
||||
var _loc3_:Object = null;
|
||||
if(param1.success)
|
||||
{
|
||||
_loc2_ = Medal(param1.data);
|
||||
if(hasUserSession)
|
||||
{
|
||||
_loc3_ = loadLocal("medals_unlocked_" + username);
|
||||
if(!_loc3_)
|
||||
{
|
||||
_loc3_ = new Object();
|
||||
}
|
||||
_loc3_[_loc2_.id] = true;
|
||||
saveLocal("medals_unlocked_" + username,_loc3_);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc3_ = loadLocal("medals_unlocked");
|
||||
if(!_loc3_)
|
||||
{
|
||||
_loc3_ = new Object();
|
||||
}
|
||||
_loc3_[Medal(param1.data).id] = true;
|
||||
saveLocal("medals_unlocked",_loc3_);
|
||||
Logger.logMessage("User is not logged in. Medal \"" + _loc2_.name + "\" unlocked locally.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onMedalUnlockConfirmed(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
if(hasUserSession)
|
||||
{
|
||||
_loc2_ = loadLocal("medals_unlocked_" + username);
|
||||
if(!_loc2_)
|
||||
{
|
||||
_loc2_ = new Object();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete _loc2_[Medal(param1.data).id];
|
||||
}
|
||||
saveLocal("medals_unlocked_" + username,_loc2_);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getScoreBoard(param1:String) : ScoreBoard
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _scoreBoards[param1];
|
||||
}
|
||||
|
||||
public static function loadScores(param1:String, param2:String = "All-Time", param3:uint = 1, param4:uint = 10, param5:String = null) : ScoreBoard
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var _loc6_:ScoreBoard = _scoreBoards[param1];
|
||||
if(!_loc6_)
|
||||
{
|
||||
Logger.logError("No scoreboard named \"" + param1 + "\" was found.");
|
||||
dispatchEvent(APIEvent.SCORES_LOADED,null,APIEvent.ERROR_INVALID_ARGUMENT);
|
||||
return null;
|
||||
}
|
||||
_loc6_.period = param2;
|
||||
_loc6_.firstResult = param3;
|
||||
_loc6_.numResults = param4;
|
||||
_loc6_.tag = param5;
|
||||
_loc6_.loadScores();
|
||||
return _loc6_;
|
||||
}
|
||||
|
||||
public static function postScore(param1:String, param2:Number, param3:String = null) : void
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!hasUserSession)
|
||||
{
|
||||
Logger.logError("The user must be logged-in to post a score.");
|
||||
dispatchEvent(APIEvent.SCORES_LOADED,null,APIEvent.ERROR_NOT_LOGGED_IN);
|
||||
return;
|
||||
}
|
||||
var _loc4_:ScoreBoard = _scoreBoards[param1];
|
||||
if(!_loc4_)
|
||||
{
|
||||
Logger.logError("No scoreboard named \"" + param1 + "\" was found.");
|
||||
dispatchEvent(APIEvent.SCORES_LOADED,null,APIEvent.ERROR_INVALID_ARGUMENT);
|
||||
return;
|
||||
}
|
||||
_loc4_.postScore(param2,param3);
|
||||
}
|
||||
|
||||
public static function getSaveGroup(param1:String) : SaveGroup
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _saveGroups[param1];
|
||||
}
|
||||
|
||||
private static function getSaveGroupById(param1:uint) : SaveGroup
|
||||
{
|
||||
var _loc2_:SaveGroup = null;
|
||||
for each(_loc2_ in _saveGroups)
|
||||
{
|
||||
if(_loc2_.id == param1)
|
||||
{
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function createSaveFile(param1:String) : SaveFile
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var _loc2_:SaveGroup = getSaveGroup(param1);
|
||||
if(!_loc2_)
|
||||
{
|
||||
Logger.logError("The save group \"" + param1 + "\" was not found.");
|
||||
return null;
|
||||
}
|
||||
return new SaveFile(_loc2_);
|
||||
}
|
||||
|
||||
public static function loadSaveFile(param1:uint, param2:Boolean = true) : void
|
||||
{
|
||||
_connection.sendSimpleCommand("loadSaveFile",onFileLoaded,{
|
||||
"save_id":param1,
|
||||
"get_contents":param2
|
||||
});
|
||||
}
|
||||
|
||||
private static function onFileLoaded(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:SaveFile = null;
|
||||
if(param1.success)
|
||||
{
|
||||
_loc2_ = SaveFile.fromObject(getSaveGroupById(param1.data.group_id),param1.data.file);
|
||||
if(param1.data.get_contents)
|
||||
{
|
||||
_loc2_.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(APIEvent.FILE_LOADED,_loc2_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("Unable to load file:",param1.error);
|
||||
dispatchEvent(APIEvent.FILE_LOADED,null,param1.error);
|
||||
}
|
||||
}
|
||||
|
||||
public static function createSaveQuery(param1:String) : SaveQuery
|
||||
{
|
||||
if(!assertConnected())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var _loc2_:SaveGroup = getSaveGroup(param1);
|
||||
if(!_loc2_)
|
||||
{
|
||||
Logger.logError("The save group \"" + param1 + "\" was not found.");
|
||||
return null;
|
||||
}
|
||||
return new SaveQuery(_loc2_);
|
||||
}
|
||||
|
||||
public static function createSaveQueryByDate(param1:String, param2:Boolean = true) : SaveQuery
|
||||
{
|
||||
var _loc3_:SaveQuery = createSaveQuery(param1);
|
||||
if(!_loc3_)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_loc3_.sortOn(SaveQuery.CREATED_ON,param2);
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
public static function createSaveQueryByName(param1:String, param2:String, param3:Boolean = false, param4:Boolean = true) : SaveQuery
|
||||
{
|
||||
var _loc5_:SaveQuery = createSaveQuery(param1);
|
||||
_loc5_.addCondition(SaveQuery.FILE_NAME,param3 ? SaveQuery.OPERATOR_EQUAL : SaveQuery.OPERATOR_CONTAINS,param2);
|
||||
return _loc5_;
|
||||
}
|
||||
|
||||
public static function createSaveQueryByRating(param1:String, param2:String, param3:Boolean = true) : SaveQuery
|
||||
{
|
||||
var _loc4_:SaveQuery = createSaveQuery(param1);
|
||||
_loc4_.sortOn(param2,param3);
|
||||
return _loc4_;
|
||||
}
|
||||
|
||||
public static function onRequestedFileLoaded(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:SaveFile = null;
|
||||
API.removeEventListener(APIEvent.FILE_LOADED,onRequestedFileLoaded);
|
||||
if(param1.success)
|
||||
{
|
||||
_loc2_ = param1.data as SaveFile;
|
||||
if(_loc2_)
|
||||
{
|
||||
dispatchEvent(APIEvent.FILE_REQUESTED,_loc2_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = true) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2,param3,param4,param5);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
|
||||
private static function dispatchEvent(param1:String, param2:* = null, param3:String = null) : void
|
||||
{
|
||||
_dispatcher.dispatchEvent(new APIEvent(param1,param2,param3));
|
||||
}
|
||||
|
||||
public static function saveLocal(param1:String, param2:Object) : Boolean
|
||||
{
|
||||
var sharedObject:SharedObject = null;
|
||||
var sharedObjectName:String = null;
|
||||
var saveId:String = param1;
|
||||
var saveData:Object = param2;
|
||||
try
|
||||
{
|
||||
sharedObjectName = "ng_ap_secure_" + _connection.trackerId + "_" + RC4.encrypt(saveId,_connection.encryptionKey);
|
||||
if(!_sharedObjects[saveId])
|
||||
{
|
||||
_sharedObjects[saveId] = SharedObject.getLocal(sharedObjectName);
|
||||
}
|
||||
sharedObject = _sharedObjects[saveId];
|
||||
sharedObject.data.data = encodeData(saveData);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
Logger.logError("Unable to save local data.",error);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function loadLocal(param1:String) : Object
|
||||
{
|
||||
var sharedObject:SharedObject = null;
|
||||
var sharedObjectName:String = null;
|
||||
var saveId:String = param1;
|
||||
try
|
||||
{
|
||||
sharedObjectName = "ng_ap_secure_" + _connection.trackerId + "_" + RC4.encrypt(saveId,_connection.encryptionKey);
|
||||
if(!_sharedObjects[saveId])
|
||||
{
|
||||
_sharedObjects[saveId] = SharedObject.getLocal(sharedObjectName);
|
||||
}
|
||||
sharedObject = _sharedObjects[saveId];
|
||||
if(Boolean(sharedObject) && Boolean(sharedObject.data) && Boolean(sharedObject.data.data))
|
||||
{
|
||||
return decodeData(sharedObject.data.data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
Logger.logError("Unable to load local data.",error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function logCustomEvent(param1:String) : void
|
||||
{
|
||||
if(assertConnected())
|
||||
{
|
||||
Logger.logMessage("Logged event: " + param1);
|
||||
_connection.sendSimpleCommand("logCustomEvent",null,{"event":param1});
|
||||
}
|
||||
}
|
||||
|
||||
public static function encodeData(param1:Object) : String
|
||||
{
|
||||
if(!_connection.assertInitialized())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return RC4.encrypt(com.newgrounds.encoders.json.JSON.encode(param1),_connection.encryptionKey);
|
||||
}
|
||||
|
||||
public static function decodeData(param1:String) : Object
|
||||
{
|
||||
if(!_connection.assertInitialized())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return com.newgrounds.encoders.json.JSON.decode(RC4.decrypt(param1,_connection.encryptionKey)) as Object;
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function stopPendingCommands() : void
|
||||
{
|
||||
APICommand.stopPendingCommands();
|
||||
Logger.logMessage("Pending commands stopped.");
|
||||
}
|
||||
|
||||
public static function setFont(param1:TextField, param2:String) : void
|
||||
{
|
||||
var _loc3_:TextFormat = null;
|
||||
var _loc4_:Boolean = false;
|
||||
var _loc5_:TextFormat = null;
|
||||
if(Boolean(param1) && Boolean(param2))
|
||||
{
|
||||
_loc3_ = param1.getTextFormat();
|
||||
_loc4_ = param1.embedFonts;
|
||||
_loc5_ = new TextFormat(param2);
|
||||
param1.defaultTextFormat = _loc5_;
|
||||
param1.setTextFormat(_loc5_);
|
||||
param1.embedFonts = true;
|
||||
if(param1.textWidth == 0)
|
||||
{
|
||||
param1.embedFonts = _loc4_;
|
||||
param1.setTextFormat(_loc3_);
|
||||
param1.defaultTextFormat = _loc3_;
|
||||
}
|
||||
else
|
||||
{
|
||||
param1.antiAliasType = "advanced";
|
||||
param1.sharpness = 120;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function checkRootLoaderInfo(param1:Event) : void
|
||||
{
|
||||
var event:Event = param1;
|
||||
var loaderInfo:LoaderInfo = _root.loaderInfo;
|
||||
if(loaderInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
while(loaderInfo.loader)
|
||||
{
|
||||
loaderInfo = loaderInfo.loader.loaderInfo;
|
||||
}
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_root.removeEventListener(Event.ENTER_FRAME,checkRootLoaderInfo);
|
||||
_connection.hostURL = loaderInfo.url;
|
||||
doConnect(loaderInfo.parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,515 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import com.newgrounds.crypto.MD5;
|
||||
import com.newgrounds.crypto.RC4;
|
||||
import com.newgrounds.encoders.BaseN;
|
||||
import com.newgrounds.encoders.json.JSON;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.net.URLVariables;
|
||||
import flash.net.navigateToURL;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class APICommand extends APIEventDispatcher
|
||||
{
|
||||
|
||||
public static var bridge:Bridge;
|
||||
|
||||
private static const TIMEOUT_INTERVAL:uint = 10000;
|
||||
|
||||
private static const THROTTLE_INTERVAL:uint = 5000;
|
||||
|
||||
private static const THROTTLE_THRESHOLD:uint = 7;
|
||||
|
||||
private static var _throttleCount:uint = 0;
|
||||
|
||||
private static var _commandQueue:Array = [];
|
||||
|
||||
private static const ENCRYPTOR_RADIX:String = "/g8236klvBQ#&|;Zb*7CEA59%s`Oue1wziFp$rDVY@TKxUPWytSaGHJ>dmoMR^<0~4qNLhc(I+fjn)X";
|
||||
|
||||
private static var _encryptor:BaseN = new BaseN(ENCRYPTOR_RADIX);
|
||||
|
||||
private static var _pendingCommands:Array = [];
|
||||
|
||||
private static const CRLF:String = "\r\n";
|
||||
|
||||
private static var _throttleTimer:Timer = (function():Timer
|
||||
{
|
||||
var _loc1_:* = new Timer(THROTTLE_INTERVAL,0);
|
||||
_loc1_.addEventListener(TimerEvent.TIMER,onThrottleTimer);
|
||||
_loc1_.start();
|
||||
return _loc1_;
|
||||
})();
|
||||
|
||||
private var _command:String;
|
||||
|
||||
private var _parameters:Object;
|
||||
|
||||
private var _secureParameters:Object;
|
||||
|
||||
private var _files:Object;
|
||||
|
||||
private var _preventCache:Boolean;
|
||||
|
||||
private var _hasTimeout:Boolean;
|
||||
|
||||
private var _timeoutTimer:Timer;
|
||||
|
||||
private var _loader:URLLoader;
|
||||
|
||||
public function APICommand(param1:String)
|
||||
{
|
||||
super();
|
||||
this._command = param1;
|
||||
this._parameters = new Object();
|
||||
this._secureParameters = new Object();
|
||||
this._timeoutTimer = new Timer(TIMEOUT_INTERVAL,1);
|
||||
this._timeoutTimer.addEventListener(TimerEvent.TIMER,this.onTimeout);
|
||||
this._hasTimeout = true;
|
||||
}
|
||||
|
||||
public static function stopPendingCommands() : void
|
||||
{
|
||||
var _loc1_:APICommand = null;
|
||||
for each(_loc1_ in _pendingCommands)
|
||||
{
|
||||
_loc1_.close();
|
||||
}
|
||||
_pendingCommands = [];
|
||||
}
|
||||
|
||||
private static function onThrottleTimer(param1:*) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
if(_throttleCount > 0)
|
||||
{
|
||||
--_throttleCount;
|
||||
}
|
||||
if(_commandQueue.length)
|
||||
{
|
||||
_loc2_ = _commandQueue.shift();
|
||||
_loc2_.command.send(_loc2_.connection);
|
||||
}
|
||||
}
|
||||
|
||||
private static function encryptHex(param1:String) : String
|
||||
{
|
||||
var _loc2_:uint = param1.length % 6;
|
||||
var _loc3_:String = "";
|
||||
var _loc4_:uint = 0;
|
||||
while(_loc4_ < param1.length)
|
||||
{
|
||||
_loc3_ += _encryptor.encodeUint(uint("0x" + param1.substr(_loc4_,6)),4);
|
||||
_loc4_ += 6;
|
||||
}
|
||||
return _loc2_.toString() + _loc3_;
|
||||
}
|
||||
|
||||
public function get command() : String
|
||||
{
|
||||
return this._command;
|
||||
}
|
||||
|
||||
public function set command(param1:String) : void
|
||||
{
|
||||
this._command = param1;
|
||||
}
|
||||
|
||||
public function get hasTimeout() : Boolean
|
||||
{
|
||||
return this._hasTimeout;
|
||||
}
|
||||
|
||||
public function set hasTimeout(param1:Boolean) : void
|
||||
{
|
||||
this._hasTimeout = param1;
|
||||
}
|
||||
|
||||
public function get parameters() : Object
|
||||
{
|
||||
return this._parameters;
|
||||
}
|
||||
|
||||
public function set parameters(param1:Object) : void
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
this._parameters = new Object();
|
||||
if(param1)
|
||||
{
|
||||
for(_loc2_ in param1)
|
||||
{
|
||||
this._parameters[_loc2_] = param1[_loc2_];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get preventCache() : Boolean
|
||||
{
|
||||
return this._preventCache;
|
||||
}
|
||||
|
||||
public function set preventCache(param1:Boolean) : void
|
||||
{
|
||||
this._preventCache = param1;
|
||||
}
|
||||
|
||||
public function get secureParameters() : Object
|
||||
{
|
||||
return this._secureParameters;
|
||||
}
|
||||
|
||||
public function set secureParameters(param1:Object) : void
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
this._secureParameters = new Object();
|
||||
if(param1)
|
||||
{
|
||||
for(_loc2_ in param1)
|
||||
{
|
||||
this._secureParameters[_loc2_] = param1[_loc2_];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get hasSecureParameters() : Boolean
|
||||
{
|
||||
var _loc1_:String = null;
|
||||
var _loc2_:int = 0;
|
||||
var _loc3_:* = this._secureParameters;
|
||||
for(_loc1_ in _loc3_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addFile(param1:String, param2:ByteArray, param3:String, param4:String = "application/octet-stream") : void
|
||||
{
|
||||
if(!this._files)
|
||||
{
|
||||
this._files = new Object();
|
||||
}
|
||||
var _loc5_:Object = {
|
||||
"filename":param1,
|
||||
"data":param2,
|
||||
"dataField":param3,
|
||||
"contentType":param4
|
||||
};
|
||||
this._files[param1] = _loc5_;
|
||||
}
|
||||
|
||||
public function removeFile(param1:String) : void
|
||||
{
|
||||
if(this._files)
|
||||
{
|
||||
delete this._files[param1];
|
||||
}
|
||||
}
|
||||
|
||||
public function clearFiles() : void
|
||||
{
|
||||
this._files = null;
|
||||
}
|
||||
|
||||
public function close() : void
|
||||
{
|
||||
var _loc1_:uint = 0;
|
||||
if(this._loader)
|
||||
{
|
||||
try
|
||||
{
|
||||
this._loader.close();
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
this._timeoutTimer.stop();
|
||||
_loc1_ = 0;
|
||||
while(_loc1_ < _pendingCommands.length)
|
||||
{
|
||||
if(_pendingCommands[_loc1_] == this)
|
||||
{
|
||||
_pendingCommands.splice(_loc1_,1);
|
||||
break;
|
||||
}
|
||||
_loc1_++;
|
||||
}
|
||||
this._loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function loadInBrowser(param1:APIConnection, param2:Boolean) : void
|
||||
{
|
||||
var _loc4_:String = null;
|
||||
var _loc5_:String = null;
|
||||
this._parameters.command_id = this._command;
|
||||
this._parameters.tracker_id = param1.apiId ? param1.apiId : 1;
|
||||
if(param1.debug)
|
||||
{
|
||||
this._parameters.debug = 1;
|
||||
}
|
||||
var _loc3_:String = param1.apiURL + "?host=" + escape(param1.hostDomain);
|
||||
for(_loc4_ in this._parameters)
|
||||
{
|
||||
_loc3_ += "&" + escape(_loc4_) + "=" + escape(this._parameters[_loc4_]);
|
||||
}
|
||||
if(param2)
|
||||
{
|
||||
_loc5_ = "_blank";
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = "_top";
|
||||
}
|
||||
navigateToURL(new URLRequest(_loc3_),_loc5_);
|
||||
}
|
||||
|
||||
public function send(param1:APIConnection) : void
|
||||
{
|
||||
if(_throttleCount >= THROTTLE_THRESHOLD)
|
||||
{
|
||||
_commandQueue.push({
|
||||
"connection":param1,
|
||||
"command":this
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sendInternal(param1);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendInternal(param1:APIConnection) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc3_:String = null;
|
||||
var _loc4_:* = undefined;
|
||||
var _loc5_:uint = 0;
|
||||
var _loc6_:String = null;
|
||||
var _loc7_:Object = null;
|
||||
var _loc8_:String = null;
|
||||
var _loc9_:String = null;
|
||||
var _loc10_:String = null;
|
||||
var _loc11_:String = null;
|
||||
_loc2_ = new URLVariables();
|
||||
_loc2_.command_id = this._command;
|
||||
_loc2_.tracker_id = param1.apiId;
|
||||
if(param1.debug)
|
||||
{
|
||||
_loc2_.debug = 1;
|
||||
}
|
||||
if(this._preventCache)
|
||||
{
|
||||
_loc2_.seed = Math.random();
|
||||
}
|
||||
for(_loc3_ in this._parameters)
|
||||
{
|
||||
_loc4_ = this._parameters[_loc3_];
|
||||
if(_loc4_ != null)
|
||||
{
|
||||
if(_loc4_ is Boolean)
|
||||
{
|
||||
_loc2_[_loc3_] = int(_loc4_);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_[_loc3_] = _loc4_;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.hasSecureParameters)
|
||||
{
|
||||
_loc7_ = new Object();
|
||||
for(_loc3_ in this._secureParameters)
|
||||
{
|
||||
_loc4_ = this._secureParameters[_loc3_];
|
||||
if(_loc4_ != null)
|
||||
{
|
||||
if(_loc4_ is Boolean)
|
||||
{
|
||||
_loc7_[_loc3_] = int(_loc4_);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc7_[_loc3_] = _loc4_;
|
||||
}
|
||||
}
|
||||
}
|
||||
_loc8_ = "";
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < 16)
|
||||
{
|
||||
_loc8_ += ENCRYPTOR_RADIX.charAt(uint(Math.random() * ENCRYPTOR_RADIX.length));
|
||||
_loc5_++;
|
||||
}
|
||||
_loc2_.command_id = "securePacket";
|
||||
_loc7_.command_id = this._command;
|
||||
_loc7_.as_version = 3;
|
||||
_loc7_.session_id = param1.sessionId;
|
||||
_loc7_.user_email = param1.userEmail;
|
||||
_loc7_.publisher_id = param1.publisherId;
|
||||
_loc7_.seed = _loc8_;
|
||||
_loc9_ = MD5.hash(_loc8_);
|
||||
_loc10_ = RC4.encrypt(com.newgrounds.encoders.json.JSON.encode(_loc7_),param1.encryptionKey);
|
||||
_loc2_.secure = encryptHex(_loc9_ + _loc10_);
|
||||
}
|
||||
Logger.logInternal("Sending packet:",_loc2_);
|
||||
if(this._files)
|
||||
{
|
||||
_loc11_ = "";
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < 32)
|
||||
{
|
||||
_loc11_ += String.fromCharCode(uint(97 + Math.random() * 25));
|
||||
_loc5_++;
|
||||
}
|
||||
_loc6_ = "multipart/form-data; boundary=\"" + _loc11_ + "\"";
|
||||
_loc2_ = this.buildMultipartData(_loc11_,_loc2_,this._files);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(_loc3_ in _loc2_)
|
||||
{
|
||||
if(typeof _loc2_[_loc3_] == "object")
|
||||
{
|
||||
_loc2_[_loc3_] = com.newgrounds.encoders.json.JSON.encode(_loc2_[_loc3_]);
|
||||
}
|
||||
}
|
||||
_loc6_ = "application/x-www-form-urlencoded";
|
||||
}
|
||||
_pendingCommands.push(this);
|
||||
++_throttleCount;
|
||||
this.startLoader(param1.apiURL,_loc2_,_loc6_);
|
||||
}
|
||||
|
||||
private function onTimeout(param1:*) : void
|
||||
{
|
||||
this.close();
|
||||
Logger.logError("Command timed out.");
|
||||
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE,null,APIEvent.ERROR_TIMED_OUT));
|
||||
}
|
||||
|
||||
private function onError(param1:String) : void
|
||||
{
|
||||
Logger.logError("Error when sending command:",param1);
|
||||
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE,null,APIEvent.ERROR_UNKNOWN));
|
||||
this.close();
|
||||
}
|
||||
|
||||
private function onComplete(param1:String) : void
|
||||
{
|
||||
var response:Object = null;
|
||||
var data:String = param1;
|
||||
try
|
||||
{
|
||||
if(!data || data == "")
|
||||
{
|
||||
throw new Error();
|
||||
}
|
||||
Logger.logInternal("Received packet:",data);
|
||||
response = com.newgrounds.encoders.json.JSON.decode(data);
|
||||
if(!response)
|
||||
{
|
||||
throw new Error();
|
||||
}
|
||||
if(bridge)
|
||||
{
|
||||
bridge.sendEvent(response.command_id,response);
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE,response,Boolean(response) && Boolean(response.success) ? APIEvent.ERROR_NONE : APIEvent.ERROR_COMMAND_FAILED));
|
||||
}
|
||||
catch(e:*)
|
||||
{
|
||||
Logger.logError("Invalid response returned from server: " + data);
|
||||
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE,null,APIEvent.ERROR_BAD_RESPONSE));
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
private function startLoader(param1:String, param2:Object, param3:String) : void
|
||||
{
|
||||
var _loc4_:URLRequest = new URLRequest(param1);
|
||||
_loc4_.data = param2;
|
||||
_loc4_.method = URLRequestMethod.POST;
|
||||
_loc4_.contentType = param3;
|
||||
this._loader = new URLLoader();
|
||||
this._loader.addEventListener(Event.COMPLETE,this.as3CompleteHandler);
|
||||
this._loader.addEventListener(Event.OPEN,this.as3UpdateHandler);
|
||||
this._loader.addEventListener(ProgressEvent.PROGRESS,this.as3UpdateHandler);
|
||||
this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.as3ErrorHandler);
|
||||
this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.as3ErrorHandler);
|
||||
this._loader.load(_loc4_);
|
||||
if(this._hasTimeout)
|
||||
{
|
||||
this._timeoutTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private function as3CompleteHandler(param1:Event) : void
|
||||
{
|
||||
this.onComplete(this._loader.data);
|
||||
}
|
||||
|
||||
private function as3UpdateHandler(param1:Event) : void
|
||||
{
|
||||
if(this._timeoutTimer.running)
|
||||
{
|
||||
this._timeoutTimer.reset();
|
||||
this._timeoutTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
private function as3ErrorHandler(param1:Event) : void
|
||||
{
|
||||
this.onError(param1.toString());
|
||||
}
|
||||
|
||||
private function buildMultipartData(param1:String, param2:Object, param3:Object) : ByteArray
|
||||
{
|
||||
var _loc5_:String = null;
|
||||
var _loc6_:Object = null;
|
||||
var _loc4_:ByteArray = new ByteArray();
|
||||
_loc4_.endian = Endian.BIG_ENDIAN;
|
||||
param1 = "--" + param1;
|
||||
for(_loc5_ in param2)
|
||||
{
|
||||
_loc4_.writeUTFBytes(param1 + CRLF);
|
||||
_loc4_.writeUTFBytes("Content-Disposition: form-data; name=\"" + _loc5_ + "\"" + CRLF);
|
||||
_loc4_.writeUTFBytes(CRLF);
|
||||
_loc4_.writeUTFBytes(param2[_loc5_].toString() + CRLF);
|
||||
}
|
||||
if(this._files)
|
||||
{
|
||||
for each(_loc6_ in param3)
|
||||
{
|
||||
_loc4_.writeUTFBytes(param1 + CRLF);
|
||||
_loc4_.writeUTFBytes("Content-Disposition: form-data; name=\"Filename\"" + CRLF);
|
||||
_loc4_.writeUTFBytes(CRLF);
|
||||
_loc4_.writeUTFBytes(_loc6_.filename + CRLF);
|
||||
_loc4_.writeUTFBytes(param1 + CRLF);
|
||||
_loc4_.writeUTFBytes("Content-Disposition: form-data; name=\"" + _loc6_.dataField + "\"; filename=\"" + _loc6_.filename + "\"" + CRLF);
|
||||
_loc4_.writeUTFBytes("Content-Type: " + _loc6_.contentType + CRLF);
|
||||
_loc4_.writeUTFBytes(CRLF);
|
||||
_loc4_.writeBytes(_loc6_.data);
|
||||
_loc4_.writeUTFBytes(CRLF);
|
||||
}
|
||||
_loc4_.writeUTFBytes(param1 + CRLF);
|
||||
_loc4_.writeUTFBytes("Content-Disposition: form-data; name=\"Upload\"" + CRLF);
|
||||
_loc4_.writeUTFBytes(CRLF);
|
||||
_loc4_.writeUTFBytes("Submit Query" + CRLF);
|
||||
}
|
||||
_loc4_.writeUTFBytes(param1 + "--");
|
||||
_loc4_.position = 0;
|
||||
return _loc4_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.system.Security;
|
||||
|
||||
public class APIConnection
|
||||
{
|
||||
|
||||
public static const NOT_CONNECTED:String = "notConnected";
|
||||
|
||||
public static const CONNECTING:String = "connecting";
|
||||
|
||||
public static const CONNECTED:String = "connected";
|
||||
|
||||
public var initialized:Boolean;
|
||||
|
||||
public var connectionState:String = "notConnected";
|
||||
|
||||
public var apiURL:String = "http://www.ngads.com/gateway_v2.php";
|
||||
|
||||
public var apiId:String;
|
||||
|
||||
public var debug:Boolean;
|
||||
|
||||
public var trackerId:uint;
|
||||
|
||||
public var publisherId:uint;
|
||||
|
||||
public var encryptionKey:String;
|
||||
|
||||
public var sessionId:String;
|
||||
|
||||
public var userEmail:String;
|
||||
|
||||
public var username:String;
|
||||
|
||||
public var userId:uint;
|
||||
|
||||
public var userpageFormat:uint;
|
||||
|
||||
private var _hostURL:String;
|
||||
|
||||
public var hostDomain:String;
|
||||
|
||||
public function APIConnection()
|
||||
{
|
||||
super();
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public function get hostURL() : String
|
||||
{
|
||||
return this._hostURL;
|
||||
}
|
||||
|
||||
public function set hostURL(param1:String) : void
|
||||
{
|
||||
var _loc2_:Array = null;
|
||||
this._hostURL = param1;
|
||||
this.hostDomain = null;
|
||||
if(this._hostURL)
|
||||
{
|
||||
_loc2_ = this._hostURL.split("/");
|
||||
if(_loc2_[0] != "file:" && this._hostURL != "localhost")
|
||||
{
|
||||
this.hostDomain = _loc2_[2];
|
||||
}
|
||||
}
|
||||
if(!this.hostDomain)
|
||||
{
|
||||
this.hostDomain = "localhost";
|
||||
}
|
||||
}
|
||||
|
||||
public function get sandboxType() : String
|
||||
{
|
||||
return Security.sandboxType;
|
||||
}
|
||||
|
||||
public function get isNetworkHost() : Boolean
|
||||
{
|
||||
switch(this.sandboxType)
|
||||
{
|
||||
case "localWithFile":
|
||||
case "localWithNetwork":
|
||||
case "localTrusted":
|
||||
case "application":
|
||||
return false;
|
||||
case "remote":
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get hasUserSession() : Boolean
|
||||
{
|
||||
return this.sessionId != null && this.sessionId != "" && this.publisherId != 0;
|
||||
}
|
||||
|
||||
public function get connected() : Boolean
|
||||
{
|
||||
return this.connectionState == CONNECTED;
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
this.connectionState = NOT_CONNECTED;
|
||||
this.encryptionKey = null;
|
||||
this.sessionId = null;
|
||||
this.userEmail = null;
|
||||
this.username = null;
|
||||
this.userId = 0;
|
||||
this.userpageFormat = 0;
|
||||
}
|
||||
|
||||
public function assertInitialized() : Boolean
|
||||
{
|
||||
if(!this.initialized)
|
||||
{
|
||||
Logger.logError("You must initialized the API using API.connect() before using this command.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function assertConnected() : Boolean
|
||||
{
|
||||
if(!this.connectionState == CONNECTED)
|
||||
{
|
||||
Logger.logError("You must establish a connection using API.connect() before using this command.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendSimpleCommand(param1:String, param2:Function, param3:Object = null, param4:Object = null) : void
|
||||
{
|
||||
var _loc5_:APICommand = new APICommand(param1);
|
||||
_loc5_.parameters = param3;
|
||||
_loc5_.secureParameters = param4;
|
||||
if(param2 != null)
|
||||
{
|
||||
_loc5_.addEventListener(APIEvent.COMMAND_COMPLETE,param2);
|
||||
}
|
||||
_loc5_.send(this);
|
||||
}
|
||||
|
||||
public function sendCommand(param1:APICommand) : void
|
||||
{
|
||||
param1.send(this);
|
||||
}
|
||||
|
||||
public function loadInBrowser(param1:String, param2:Boolean = true, param3:Object = null) : void
|
||||
{
|
||||
var _loc4_:APICommand = new APICommand(param1);
|
||||
_loc4_.parameters = param3;
|
||||
_loc4_.loadInBrowser(this,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.events.Event;
|
||||
|
||||
public class APIEvent extends Event
|
||||
{
|
||||
|
||||
internal static const COMMAND_COMPLETE:String = "commandComplete";
|
||||
|
||||
internal static const MEDAL_UNLOCK_CONFIRMED:String = "medalUnlockConfirmed";
|
||||
|
||||
internal static const ICON_LOADED:String = "iconLoaded";
|
||||
|
||||
public static const API_CONNECTED:String = "movieConnected";
|
||||
|
||||
public static const LOG:String = "log";
|
||||
|
||||
public static const MEDAL_UNLOCKED:String = "medalUnlocked";
|
||||
|
||||
public static const SCORES_LOADED:String = "scoresLoaded";
|
||||
|
||||
public static const SCORE_POSTED:String = "scorePosted";
|
||||
|
||||
public static const QUERY_COMPLETE:String = "queryComplete";
|
||||
|
||||
public static const FILE_LOADED:String = "fileLoaded";
|
||||
|
||||
public static const FILE_SAVED:String = "fileSaved";
|
||||
|
||||
public static const FILE_REQUESTED:String = "fileRequested";
|
||||
|
||||
public static const VOTE_COMPLETE:String = "voteComplete";
|
||||
|
||||
public static const ERROR_NONE:String = "noError";
|
||||
|
||||
public static const ERROR_UNKNOWN:String = "unknownError";
|
||||
|
||||
public static const ERROR_COMMAND_FAILED:String = "commandFailed";
|
||||
|
||||
public static const ERROR_NOT_CONNECTED:String = "notConnected";
|
||||
|
||||
public static const ERROR_INVALID_ARGUMENT:String = "invalidArgument";
|
||||
|
||||
public static const ERROR_TIMED_OUT:String = "timedOut";
|
||||
|
||||
public static const ERROR_BAD_FILE:String = "badFile";
|
||||
|
||||
public static const ERROR_BAD_RESPONSE:String = "badResponse";
|
||||
|
||||
public static const ERROR_SENDING_COMMAND:String = "errorSendingCommand";
|
||||
|
||||
public static const ERROR_HOST_BLOCKED:String = "hostBlocked";
|
||||
|
||||
public static const ERROR_ALREADY_VOTED:String = "alreadyVoted";
|
||||
|
||||
public static const ERROR_NOT_LOGGED_IN:String = "notLoggedIn";
|
||||
|
||||
private var _data:*;
|
||||
|
||||
private var _success:Boolean;
|
||||
|
||||
private var _error:String;
|
||||
|
||||
public function APIEvent(param1:String, param2:* = null, param3:String = null)
|
||||
{
|
||||
super(param1);
|
||||
if(!param3 || param3 == "" || param3 == ERROR_NONE)
|
||||
{
|
||||
this._error = ERROR_NONE;
|
||||
this._success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._error = param3;
|
||||
this._success = false;
|
||||
}
|
||||
if(param2)
|
||||
{
|
||||
this._data = param2;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._data = {};
|
||||
}
|
||||
}
|
||||
|
||||
override public function clone() : Event
|
||||
{
|
||||
return new APIEvent(type,this._data,this._error);
|
||||
}
|
||||
|
||||
public function get success() : Boolean
|
||||
{
|
||||
return this._success;
|
||||
}
|
||||
|
||||
public function get data() : *
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public function get error() : String
|
||||
{
|
||||
return this._error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
internal class APIEventDispatcher extends EventDispatcher
|
||||
{
|
||||
|
||||
private static var _globalDispatcher:EventDispatcher;
|
||||
|
||||
private static var _ticker:Sprite;
|
||||
|
||||
private static var _eventQueue:Array = initEventQueue();
|
||||
|
||||
public function APIEventDispatcher()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get globalDispatcher() : EventDispatcher
|
||||
{
|
||||
return _globalDispatcher;
|
||||
}
|
||||
|
||||
public static function set globalDispatcher(param1:EventDispatcher) : void
|
||||
{
|
||||
_globalDispatcher = param1;
|
||||
}
|
||||
|
||||
private static function initEventQueue() : Array
|
||||
{
|
||||
_ticker = new Sprite();
|
||||
_ticker.addEventListener(Event.ENTER_FRAME,runEventQueue);
|
||||
return [];
|
||||
}
|
||||
|
||||
private static function runEventQueue(param1:*) : void
|
||||
{
|
||||
var _loc3_:Array = null;
|
||||
var _loc4_:uint = 0;
|
||||
var _loc5_:Object = null;
|
||||
var _loc2_:uint = _eventQueue.length;
|
||||
if(_loc2_)
|
||||
{
|
||||
_loc3_ = _eventQueue;
|
||||
_eventQueue = [];
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _loc2_)
|
||||
{
|
||||
_loc5_ = _loc3_[_loc4_];
|
||||
_loc5_.dispatcher.actualDispatchEvent(_loc5_.event);
|
||||
_loc4_++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public function dispatchEvent(param1:Event) : Boolean
|
||||
{
|
||||
_eventQueue.push({
|
||||
"dispatcher":this,
|
||||
"event":param1
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private function actualDispatchEvent(param1:Event) : void
|
||||
{
|
||||
var _loc2_:Boolean = super.dispatchEvent(param1);
|
||||
if(Boolean(_globalDispatcher) && this != _globalDispatcher)
|
||||
{
|
||||
_globalDispatcher.dispatchEvent(param1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Loader;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.system.LoaderContext;
|
||||
|
||||
public class BitmapLoader extends APIEventDispatcher
|
||||
{
|
||||
|
||||
internal static var _cacheSeed:uint = 0;
|
||||
|
||||
private static const LOADER_CONTEXT:LoaderContext = new LoaderContext(true);
|
||||
|
||||
private var _url:String;
|
||||
|
||||
private var _bitmapData:BitmapData;
|
||||
|
||||
private var _loaded:Boolean = true;
|
||||
|
||||
private var _loader:Loader;
|
||||
|
||||
public function BitmapLoader(param1:BitmapData, param2:String)
|
||||
{
|
||||
super();
|
||||
this._bitmapData = param1;
|
||||
this._url = param2;
|
||||
}
|
||||
|
||||
public function get url() : String
|
||||
{
|
||||
return this._url;
|
||||
}
|
||||
|
||||
public function set url(param1:String) : void
|
||||
{
|
||||
this._loaded = false;
|
||||
this._url = param1;
|
||||
}
|
||||
|
||||
public function get bitmapData() : BitmapData
|
||||
{
|
||||
return this._bitmapData;
|
||||
}
|
||||
|
||||
public function set bitmapData(param1:BitmapData) : void
|
||||
{
|
||||
this._bitmapData = param1;
|
||||
this._loaded = true;
|
||||
}
|
||||
|
||||
public function get loaded() : Boolean
|
||||
{
|
||||
return this._loaded;
|
||||
}
|
||||
|
||||
private function createLoader() : Loader
|
||||
{
|
||||
var _loc1_:Loader = new Loader();
|
||||
var _loc2_:URLRequest = new URLRequest(this._url);
|
||||
_loc2_.method = URLRequestMethod.GET;
|
||||
_loc2_.data = _cacheSeed.toString();
|
||||
_loc1_.load(_loc2_,LOADER_CONTEXT);
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
private function disposeLoader() : void
|
||||
{
|
||||
if(this._loader)
|
||||
{
|
||||
try
|
||||
{
|
||||
this._loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,this.onLoadComplete);
|
||||
this._loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,this.onLoadComplete);
|
||||
this._loader.unload();
|
||||
}
|
||||
catch(error:*)
|
||||
{
|
||||
}
|
||||
this._loader = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function load() : void
|
||||
{
|
||||
if(!this._url || this._url == "")
|
||||
{
|
||||
this.onLoadComplete(null);
|
||||
return;
|
||||
}
|
||||
this.disposeLoader();
|
||||
this._loader = this.createLoader();
|
||||
this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoadComplete);
|
||||
this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onLoadComplete);
|
||||
}
|
||||
|
||||
public function attachBitmap(param1:DisplayObjectContainer) : Sprite
|
||||
{
|
||||
var _loc2_:Sprite = new Sprite();
|
||||
if(Boolean(!this._loaded) && Boolean(this._url) && this._url != "")
|
||||
{
|
||||
if(!this._loader)
|
||||
{
|
||||
this.load();
|
||||
}
|
||||
_loc2_.addChild(this.createLoader());
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_.addChild(new Bitmap(this._bitmapData));
|
||||
}
|
||||
if(param1)
|
||||
{
|
||||
param1.addChild(_loc2_);
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private function onLoadComplete(param1:Event) : void
|
||||
{
|
||||
var bitmapData:BitmapData = null;
|
||||
var event:Event = param1;
|
||||
try
|
||||
{
|
||||
if(Boolean(event && event.type == Event.COMPLETE) && Boolean(this._loader) && this._loader.content is Bitmap)
|
||||
{
|
||||
bitmapData = Bitmap(this._loader.content).bitmapData;
|
||||
this._bitmapData = bitmapData;
|
||||
this._loaded = true;
|
||||
}
|
||||
}
|
||||
catch(error:SecurityError)
|
||||
{
|
||||
if(bitmapData)
|
||||
{
|
||||
bitmapData.dispose();
|
||||
}
|
||||
}
|
||||
this.disposeLoader();
|
||||
dispatchEvent(new APIEvent(APIEvent.ICON_LOADED,this,this._loaded ? null : APIEvent.ERROR_BAD_FILE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.StatusEvent;
|
||||
import flash.net.LocalConnection;
|
||||
|
||||
public class Bridge
|
||||
{
|
||||
|
||||
private var _inConnection:LocalConnection;
|
||||
|
||||
private var _outConnection:LocalConnection;
|
||||
|
||||
private var _widgetId:String;
|
||||
|
||||
public function Bridge(param1:String)
|
||||
{
|
||||
super();
|
||||
this._widgetId = param1;
|
||||
this._inConnection = new LocalConnection();
|
||||
this._outConnection = new LocalConnection();
|
||||
this._inConnection.client = this;
|
||||
try
|
||||
{
|
||||
this._inConnection.connect("rec_" + this._widgetId);
|
||||
}
|
||||
catch(error:*)
|
||||
{
|
||||
}
|
||||
this._outConnection.addEventListener(StatusEvent.STATUS,this.onStatus);
|
||||
Logger.addEventListener(APIEvent.LOG,this.onLogMessage);
|
||||
}
|
||||
|
||||
private function onLogMessage(param1:APIEvent) : void
|
||||
{
|
||||
try
|
||||
{
|
||||
this._outConnection.send(this._widgetId,"sendEvent","trace",String(param1.data));
|
||||
}
|
||||
catch(error:*)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public function sendEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
if(this._outConnection)
|
||||
{
|
||||
param2 = {"data":param2};
|
||||
this._outConnection.send(this._widgetId,"sendEvent",param1,param2);
|
||||
}
|
||||
}
|
||||
|
||||
public function receiveEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
}
|
||||
|
||||
private function onStatus(param1:Event) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
public class Logger
|
||||
{
|
||||
|
||||
internal static const PRIORITY_INTERNAL:uint = 0;
|
||||
|
||||
public static const PRIORITY_MESSAGE:uint = 1;
|
||||
|
||||
public static const PRIORITY_WARNING:uint = 2;
|
||||
|
||||
public static const PRIORITY_ERROR:uint = 3;
|
||||
|
||||
public static const PRIORITY_MAX:uint = 4;
|
||||
|
||||
private static const HEADER:String = "[Newgrounds API] :: ";
|
||||
|
||||
private static var _eventDispatcher:EventDispatcher = new EventDispatcher();
|
||||
|
||||
private static var _messageLevel:uint = PRIORITY_MESSAGE;
|
||||
|
||||
private static var _throwLevel:uint = PRIORITY_MAX;
|
||||
|
||||
public function Logger()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
internal static function logInternal(... rest) : void
|
||||
{
|
||||
log(PRIORITY_INTERNAL,rest);
|
||||
}
|
||||
|
||||
public static function logMessage(... rest) : void
|
||||
{
|
||||
log(PRIORITY_MESSAGE,rest);
|
||||
}
|
||||
|
||||
public static function logWarning(... rest) : void
|
||||
{
|
||||
log(PRIORITY_WARNING,rest);
|
||||
}
|
||||
|
||||
public static function logError(... rest) : void
|
||||
{
|
||||
log(PRIORITY_ERROR,rest);
|
||||
}
|
||||
|
||||
public static function log(param1:uint = 1, param2:Array = null) : void
|
||||
{
|
||||
var _loc3_:uint = 0;
|
||||
if(param1 >= _messageLevel)
|
||||
{
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < param2.length)
|
||||
{
|
||||
trace(HEADER + param2[_loc3_]);
|
||||
_eventDispatcher.dispatchEvent(new APIEvent(APIEvent.LOG,param2[_loc3_]));
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
if(param1 >= _throwLevel)
|
||||
{
|
||||
throw new Error(param2.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_eventDispatcher.addEventListener(param1,param2,false,0,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import com.newgrounds.assets.DefaultMedalIcon;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Sprite;
|
||||
|
||||
public class Medal extends APIEventDispatcher
|
||||
{
|
||||
|
||||
public static const ICON_WIDTH:uint = 50;
|
||||
|
||||
public static const ICON_HEIGHT:uint = 50;
|
||||
|
||||
public static const DIFFICULTY_EASY:String = "Easy";
|
||||
|
||||
public static const DIFFICULTY_MODERATE:String = "Moderate";
|
||||
|
||||
public static const DIFFICULTY_CHALLENGING:String = "Challenging";
|
||||
|
||||
public static const DIFFICULTY_DIFFICULT:String = "Difficult";
|
||||
|
||||
public static const DIFFICULTY_BRUTAL:String = "Brutal";
|
||||
|
||||
private static const DIFFICULTIES:Array = ["Unknown",DIFFICULTY_EASY,DIFFICULTY_MODERATE,DIFFICULTY_CHALLENGING,DIFFICULTY_DIFFICULT,DIFFICULTY_BRUTAL];
|
||||
|
||||
public static const DEFAULT_ICON:BitmapData = new DefaultMedalIcon(ICON_WIDTH,ICON_HEIGHT);
|
||||
|
||||
private var _connection:APIConnection;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _value:uint;
|
||||
|
||||
private var _unlocked:Boolean;
|
||||
|
||||
private var _difficulty:String;
|
||||
|
||||
private var _iconLoader:BitmapLoader;
|
||||
|
||||
public function Medal(param1:APIConnection, param2:uint, param3:String, param4:Boolean, param5:uint, param6:uint, param7:String)
|
||||
{
|
||||
super();
|
||||
this._connection = param1;
|
||||
this._id = param2;
|
||||
this._name = param3;
|
||||
this._unlocked = param4;
|
||||
this._value = param5;
|
||||
this._difficulty = DIFFICULTIES[param6];
|
||||
this._iconLoader = new BitmapLoader(DEFAULT_ICON,param7);
|
||||
this._iconLoader.load();
|
||||
}
|
||||
|
||||
public function get difficulty() : String
|
||||
{
|
||||
return this._difficulty;
|
||||
}
|
||||
|
||||
public function get icon() : BitmapData
|
||||
{
|
||||
return this._iconLoader.bitmapData;
|
||||
}
|
||||
|
||||
public function get id() : uint
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get unlocked() : Boolean
|
||||
{
|
||||
return this._unlocked;
|
||||
}
|
||||
|
||||
public function get value() : uint
|
||||
{
|
||||
return this._value;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "Medal: " + this._name + "\t\t(" + (this._unlocked ? "unlocked, " : "locked, ") + this._value + "pts, " + this._difficulty + ")";
|
||||
}
|
||||
|
||||
public function attachIcon(param1:DisplayObjectContainer) : Sprite
|
||||
{
|
||||
return this._iconLoader.attachBitmap(param1);
|
||||
}
|
||||
|
||||
public function unlock() : void
|
||||
{
|
||||
if(!this._connection.debug && this._unlocked)
|
||||
{
|
||||
Logger.logWarning("Medal \"" + this._name + "\" is already unlocked.");
|
||||
return;
|
||||
}
|
||||
Logger.logMessage("Unlocking medal \"" + this.name + "\"...");
|
||||
this._unlocked = true;
|
||||
this._connection.sendSimpleCommand("unlockMedal",this.onUnlockConfirmed,null,{"medal_id":this.id});
|
||||
dispatchEvent(new APIEvent(APIEvent.MEDAL_UNLOCKED,this));
|
||||
}
|
||||
|
||||
private function onUnlockConfirmed(param1:APIEvent) : void
|
||||
{
|
||||
if(param1.success)
|
||||
{
|
||||
Logger.logMessage("Medal \"" + this.name + "\" unlocked.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("Failed to unlock \"" + this.name + "\"!");
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.MEDAL_UNLOCK_CONFIRMED,this,param1.error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,691 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
import com.newgrounds.assets.DefaultSaveIcon;
|
||||
import com.newgrounds.encoders.PNGEncoder;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.IBitmapDrawable;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.getQualifiedClassName;
|
||||
|
||||
public class SaveFile extends APIEventDispatcher
|
||||
{
|
||||
|
||||
private static var _currentFile:SaveFile;
|
||||
|
||||
public static const ICON_WIDTH:uint = 90;
|
||||
|
||||
public static const ICON_HEIGHT:uint = 90;
|
||||
|
||||
private static const STATUS_PRIVATE:uint = 0;
|
||||
|
||||
private static const STATUS_SHARED:uint = 1;
|
||||
|
||||
private static const STATUS_UNAPPROVED:uint = 2;
|
||||
|
||||
private static const STATUS_APPROVED:uint = 3;
|
||||
|
||||
internal static var _imageFilePath:String = "";
|
||||
|
||||
internal static var _saveFilePath:String = "";
|
||||
|
||||
public static const DEFAULT_ICON:BitmapData = new DefaultSaveIcon(ICON_WIDTH,ICON_HEIGHT);
|
||||
|
||||
private var _group:SaveGroup;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _description:String;
|
||||
|
||||
private var _authorId:uint;
|
||||
|
||||
private var _authorName:String;
|
||||
|
||||
private var _createdDate:String;
|
||||
|
||||
private var _modifiedDate:String;
|
||||
|
||||
private var _views:uint;
|
||||
|
||||
private var _readOnly:Boolean;
|
||||
|
||||
private var _public:Boolean;
|
||||
|
||||
private var _approved:Boolean;
|
||||
|
||||
private var _draft:Boolean;
|
||||
|
||||
private var _iconLoader:BitmapLoader;
|
||||
|
||||
private var _keys:Object = new Object();
|
||||
|
||||
private var _ratings:Object = new Object();
|
||||
|
||||
private var _dataURL:String;
|
||||
|
||||
private var _data:*;
|
||||
|
||||
private var _dataLoaded:Boolean;
|
||||
|
||||
private var _encodedData:*;
|
||||
|
||||
private var _encoderQueue:Array;
|
||||
|
||||
private var _encoding:Boolean;
|
||||
|
||||
private var _encodingParent:Object;
|
||||
|
||||
private var _encodingProperty:String;
|
||||
|
||||
private var _fileSize:uint;
|
||||
|
||||
private var _dataLoader:URLLoader;
|
||||
|
||||
public function SaveFile(param1:SaveGroup)
|
||||
{
|
||||
super();
|
||||
this._iconLoader = new BitmapLoader(DEFAULT_ICON,null);
|
||||
this._group = param1;
|
||||
}
|
||||
|
||||
public static function get currentFile() : SaveFile
|
||||
{
|
||||
return _currentFile;
|
||||
}
|
||||
|
||||
internal static function fromObject(param1:SaveGroup, param2:Object) : SaveFile
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
var _loc5_:Object = null;
|
||||
var _loc6_:SaveKey = null;
|
||||
var _loc7_:SaveRating = null;
|
||||
var _loc3_:SaveFile = new SaveFile(param1);
|
||||
_loc3_._name = param2.filename;
|
||||
_loc3_._description = param2.description;
|
||||
_loc3_._id = param2.save_id;
|
||||
_loc3_._authorId = param2.user_id;
|
||||
_loc3_._authorName = param2.user_name;
|
||||
_loc3_._createdDate = param2.created;
|
||||
_loc3_._modifiedDate = param2.last_update;
|
||||
_loc3_._views = param2.views;
|
||||
if(Boolean(param2.thumb) && param2.thumb != "")
|
||||
{
|
||||
_loc3_._iconLoader.url = _imageFilePath + param2.thumb;
|
||||
}
|
||||
_loc3_._dataURL = _saveFilePath + param2.file;
|
||||
_loc3_._fileSize = param2.file_size;
|
||||
_loc3_._approved = param2.status != STATUS_UNAPPROVED;
|
||||
_loc3_._readOnly = false;
|
||||
_loc3_._public = param2.status != STATUS_PRIVATE && param2.status != STATUS_UNAPPROVED;
|
||||
for each(_loc4_ in param2.keys)
|
||||
{
|
||||
_loc6_ = param1.getKeyById(_loc4_.id);
|
||||
if(_loc6_)
|
||||
{
|
||||
_loc3_._keys[_loc6_.name] = _loc6_.validateValue(_loc4_.value);
|
||||
}
|
||||
}
|
||||
for each(_loc5_ in param2.ratings)
|
||||
{
|
||||
_loc7_ = param1.getRatingById(_loc5_.id);
|
||||
if(_loc7_)
|
||||
{
|
||||
_loc3_._ratings[_loc7_.name] = _loc7_.validateValue(_loc5_.score);
|
||||
}
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
public function get group() : SaveGroup
|
||||
{
|
||||
return this._group;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function set name(param1:String) : void
|
||||
{
|
||||
this._name = param1;
|
||||
}
|
||||
|
||||
public function get description() : String
|
||||
{
|
||||
return this._description;
|
||||
}
|
||||
|
||||
public function set description(param1:String) : void
|
||||
{
|
||||
this._description = param1;
|
||||
}
|
||||
|
||||
public function get id() : uint
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get data() : Object
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public function set data(param1:Object) : void
|
||||
{
|
||||
this._data = param1;
|
||||
}
|
||||
|
||||
public function get bytesLoaded() : uint
|
||||
{
|
||||
if(this._data)
|
||||
{
|
||||
return this.bytesTotal;
|
||||
}
|
||||
if(!this._dataLoader)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this._dataLoader.bytesLoaded;
|
||||
}
|
||||
|
||||
public function get bytesTotal() : uint
|
||||
{
|
||||
return this._fileSize;
|
||||
}
|
||||
|
||||
public function get readOnly() : Boolean
|
||||
{
|
||||
return this._readOnly;
|
||||
}
|
||||
|
||||
public function get draft() : Boolean
|
||||
{
|
||||
return this._draft;
|
||||
}
|
||||
|
||||
public function set draft(param1:Boolean) : void
|
||||
{
|
||||
this._draft = param1;
|
||||
}
|
||||
|
||||
public function get authorId() : uint
|
||||
{
|
||||
return this._authorId;
|
||||
}
|
||||
|
||||
public function get authorName() : String
|
||||
{
|
||||
return this._authorName;
|
||||
}
|
||||
|
||||
public function get keys() : Object
|
||||
{
|
||||
return this._keys;
|
||||
}
|
||||
|
||||
public function get ratings() : Object
|
||||
{
|
||||
return this._ratings;
|
||||
}
|
||||
|
||||
public function get views() : uint
|
||||
{
|
||||
return this._views;
|
||||
}
|
||||
|
||||
public function get createdDate() : String
|
||||
{
|
||||
return this._createdDate;
|
||||
}
|
||||
|
||||
public function get updatedDate() : String
|
||||
{
|
||||
return this._modifiedDate;
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "Save File: " + this._name;
|
||||
}
|
||||
|
||||
public function get icon() : BitmapData
|
||||
{
|
||||
return this._iconLoader.bitmapData;
|
||||
}
|
||||
|
||||
public function set icon(param1:BitmapData) : void
|
||||
{
|
||||
this.createIcon(param1);
|
||||
}
|
||||
|
||||
public function get iconLoaded() : Boolean
|
||||
{
|
||||
return this._iconLoader.loaded;
|
||||
}
|
||||
|
||||
public function createIcon(param1:IBitmapDrawable) : void
|
||||
{
|
||||
var _loc3_:Number = NaN;
|
||||
var _loc4_:Number = NaN;
|
||||
var _loc8_:Number = NaN;
|
||||
var _loc9_:Rectangle = null;
|
||||
var _loc2_:BitmapData = new BitmapData(ICON_WIDTH,ICON_HEIGHT,false,0);
|
||||
var _loc5_:Number = 0;
|
||||
var _loc6_:Number = 0;
|
||||
_loc3_ = Number(Object(param1).width);
|
||||
_loc4_ = Number(Object(param1).height);
|
||||
if(param1 is DisplayObject)
|
||||
{
|
||||
_loc9_ = DisplayObject(param1).getBounds(null);
|
||||
_loc5_ = _loc9_.left;
|
||||
_loc6_ = _loc9_.top;
|
||||
}
|
||||
var _loc7_:Matrix = new Matrix();
|
||||
_loc8_ = Math.min(ICON_WIDTH / _loc3_,ICON_HEIGHT / _loc4_);
|
||||
_loc7_.translate(-_loc5_,-_loc6_);
|
||||
_loc7_.scale(_loc8_,_loc8_);
|
||||
_loc7_.translate((ICON_WIDTH - _loc3_ * _loc8_) / 2,(ICON_HEIGHT - _loc4_ * _loc8_) / 2);
|
||||
_loc2_.draw(param1,_loc7_);
|
||||
this._iconLoader.bitmapData = _loc2_;
|
||||
}
|
||||
|
||||
public function attachIcon(param1:DisplayObjectContainer) : Sprite
|
||||
{
|
||||
if(this._iconLoader)
|
||||
{
|
||||
return this._iconLoader.attachBitmap(param1);
|
||||
}
|
||||
Logger.logError("No icon available for this sumbission.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save() : void
|
||||
{
|
||||
if(!this._group.connection.hasUserSession)
|
||||
{
|
||||
Logger.logError("The user must be logged-in to save a file.");
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED,null,APIEvent.ERROR_NOT_LOGGED_IN));
|
||||
return;
|
||||
}
|
||||
++BitmapLoader._cacheSeed;
|
||||
_currentFile = this;
|
||||
this.encodeData(true);
|
||||
}
|
||||
|
||||
private function doSave() : void
|
||||
{
|
||||
var _loc3_:String = null;
|
||||
var _loc4_:Array = null;
|
||||
var _loc5_:String = null;
|
||||
var _loc6_:SaveKey = null;
|
||||
var _loc7_:SaveRating = null;
|
||||
var _loc8_:ByteArray = null;
|
||||
var _loc1_:APICommand = new APICommand("saveFile");
|
||||
_loc1_.secureParameters.group = this._group.id;
|
||||
_loc1_.secureParameters.user_name = this._group.connection.username;
|
||||
_loc1_.secureParameters.filename = this._name;
|
||||
_loc1_.secureParameters.description = this._description;
|
||||
if(this._draft)
|
||||
{
|
||||
_loc1_.secureParameters.draft = true;
|
||||
}
|
||||
if(Boolean(this._id) && !this._readOnly)
|
||||
{
|
||||
_loc1_.secureParameters.overwrite = 1;
|
||||
_loc1_.secureParameters.save_id = this._id;
|
||||
}
|
||||
var _loc2_:Array = [];
|
||||
for(_loc3_ in this._keys)
|
||||
{
|
||||
_loc6_ = this._group.getKey(_loc3_);
|
||||
if(_loc6_)
|
||||
{
|
||||
_loc2_.push({
|
||||
"id":_loc6_.id,
|
||||
"value":_loc6_.validateValue(this._keys[_loc3_])
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("No key named \"" + _loc3_ + "\" in save group \"" + this._group.name + "\".");
|
||||
}
|
||||
}
|
||||
_loc1_.secureParameters.keys = _loc2_;
|
||||
_loc4_ = [];
|
||||
for(_loc5_ in this._ratings)
|
||||
{
|
||||
_loc7_ = this._group.getRating(_loc5_);
|
||||
if(_loc7_)
|
||||
{
|
||||
_loc4_.push({
|
||||
"id":_loc7_.id,
|
||||
"value":_loc7_.validateValue(this._ratings[_loc5_])
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("No rating named \"" + _loc5_ + "\" in save group \"" + this._group.name + "\".");
|
||||
}
|
||||
}
|
||||
_loc1_.secureParameters.ratings = _loc4_;
|
||||
_loc8_ = new ByteArray();
|
||||
_loc8_.writeObject(this._encodedData);
|
||||
_loc8_.compress();
|
||||
_loc1_.addFile("file",_loc8_,"file");
|
||||
if(this.iconLoaded)
|
||||
{
|
||||
_loc1_.addFile("thumbnail",PNGEncoder.encode(this.icon),"thumbnail");
|
||||
}
|
||||
_loc1_.addEventListener(APIEvent.COMMAND_COMPLETE,this.onSaveComplete);
|
||||
this._group.connection.sendCommand(_loc1_);
|
||||
}
|
||||
|
||||
private function encodeData(param1:Boolean) : void
|
||||
{
|
||||
this._encoderQueue = [];
|
||||
this._encoding = param1;
|
||||
if(param1)
|
||||
{
|
||||
this._encodedData = this._data;
|
||||
this.preEncodeObject(this,"_encodedData");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.preEncodeObject(this,"_data");
|
||||
}
|
||||
this.encodeObject();
|
||||
}
|
||||
|
||||
private function preEncodeObject(param1:Object, param2:String) : void
|
||||
{
|
||||
var _loc4_:Boolean = false;
|
||||
var _loc6_:Boolean = false;
|
||||
var _loc7_:String = null;
|
||||
var _loc3_:Object = param1[param2];
|
||||
try
|
||||
{
|
||||
if(this._encoding)
|
||||
{
|
||||
_loc4_ = _loc3_ is BitmapData;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = _loc3_.type == "__bitmap";
|
||||
}
|
||||
}
|
||||
catch(error:*)
|
||||
{
|
||||
}
|
||||
var _loc5_:Object = _loc3_;
|
||||
_loc6_ = _loc3_ is ByteArray;
|
||||
if(_loc4_)
|
||||
{
|
||||
this._encoderQueue.push({
|
||||
"parent":param1,
|
||||
"property":param2
|
||||
});
|
||||
}
|
||||
else if(typeof _loc3_ == "object" && !_loc6_)
|
||||
{
|
||||
if(this._encoding)
|
||||
{
|
||||
if(_loc3_ is Array)
|
||||
{
|
||||
_loc5_ = [];
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = {};
|
||||
}
|
||||
for(_loc7_ in _loc3_)
|
||||
{
|
||||
_loc5_[_loc7_] = _loc3_[_loc7_];
|
||||
}
|
||||
param1[param2] = _loc5_;
|
||||
}
|
||||
for(_loc7_ in _loc5_)
|
||||
{
|
||||
this.preEncodeObject(_loc5_,_loc7_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function encodeObject() : void
|
||||
{
|
||||
var _loc5_:Object = null;
|
||||
if(!this._encoderQueue.length)
|
||||
{
|
||||
if(this._encoding)
|
||||
{
|
||||
this.doSave();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dataLoaded = true;
|
||||
this.checkLoadComplete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var _loc1_:Object = this._encoderQueue.pop();
|
||||
var _loc2_:Object = _loc1_.parent;
|
||||
var _loc3_:String = _loc1_.property;
|
||||
var _loc4_:Object = _loc2_[_loc3_];
|
||||
if(this._encoding)
|
||||
{
|
||||
_loc5_ = {
|
||||
"type":"__bitmap",
|
||||
"width":_loc4_.width,
|
||||
"height":_loc4_.height,
|
||||
"transparent":_loc4_.transparent
|
||||
};
|
||||
_loc2_[_loc3_] = _loc5_;
|
||||
_loc5_.data = new ByteArray();
|
||||
_loc5_.data.writeBytes(_loc4_.getPixels(_loc4_.rect));
|
||||
_loc5_.data.position = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = new BitmapData(_loc4_.width,_loc4_.height,_loc4_.transparent);
|
||||
_loc5_.setPixels(_loc5_.rect,_loc4_.data);
|
||||
_loc2_[_loc3_] = _loc5_;
|
||||
}
|
||||
this.encodeObject();
|
||||
}
|
||||
|
||||
private function onIconLoaded(param1:APIEvent) : void
|
||||
{
|
||||
if(!param1.success && Boolean(this._iconLoader.url))
|
||||
{
|
||||
Logger.logWarning("Unable to load the icon for this save file.");
|
||||
}
|
||||
this._iconLoader.removeEventListener(APIEvent.ICON_LOADED,this.onIconLoaded);
|
||||
this.checkLoadComplete();
|
||||
}
|
||||
|
||||
private function checkLoadComplete() : void
|
||||
{
|
||||
if(this._dataLoaded && this.iconLoaded)
|
||||
{
|
||||
Logger.logMessage("Data loaded.");
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED,this));
|
||||
}
|
||||
}
|
||||
|
||||
private function onDataLoaded(param1:*) : void
|
||||
{
|
||||
var byteArray:ByteArray = null;
|
||||
var data:* = param1;
|
||||
try
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
byteArray = data;
|
||||
byteArray.uncompress();
|
||||
this._data = byteArray.readObject();
|
||||
this.encodeData(false);
|
||||
}
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
Logger.logError("Error while loading data:",error);
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED,this,APIEvent.ERROR_BAD_FILE));
|
||||
}
|
||||
}
|
||||
|
||||
private function onDataError(param1:String) : void
|
||||
{
|
||||
Logger.logError("Unable to load data:",param1);
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED,this,APIEvent.ERROR_BAD_FILE));
|
||||
}
|
||||
|
||||
private function onSaveComplete(param1:APIEvent) : void
|
||||
{
|
||||
if(param1.success)
|
||||
{
|
||||
Logger.logMessage("File \"" + this._name + "\" saved!");
|
||||
if(param1.data)
|
||||
{
|
||||
this._id = param1.data.save_id;
|
||||
this._dataURL = unescape(param1.data.file_url);
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED,this));
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("Error saving file \"" + this._name + "\":",param1.error);
|
||||
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED,this,param1.error));
|
||||
}
|
||||
}
|
||||
|
||||
public function sendVote(param1:String, param2:Number) : void
|
||||
{
|
||||
var _loc3_:SaveRating = this._group.getRating(param1);
|
||||
if(!_loc3_)
|
||||
{
|
||||
Logger.logError("No save rating named \"" + param1 + "\" exists for this save group.");
|
||||
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE,{},APIEvent.ERROR_INVALID_ARGUMENT));
|
||||
return;
|
||||
}
|
||||
param2 = _loc3_.validateValue(param2);
|
||||
if(isNaN(param2))
|
||||
{
|
||||
Logger.logError("Invalid vote (" + param2 + "). " + param1 + " allows a range of " + _loc3_.minimum + "-" + _loc3_.maximum + ".");
|
||||
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE,{},APIEvent.ERROR_INVALID_ARGUMENT));
|
||||
return;
|
||||
}
|
||||
Logger.logMessage("Voting " + param2 + " for " + param1 + " on " + this._name + "...");
|
||||
this._group.connection.sendSimpleCommand("rateSaveFile",this.onVoteComplete,null,{
|
||||
"group":this._group.id,
|
||||
"save_id":this._id,
|
||||
"rating_id":_loc3_.id,
|
||||
"vote":param2
|
||||
});
|
||||
}
|
||||
|
||||
private function onVoteComplete(param1:APIEvent) : void
|
||||
{
|
||||
var _loc3_:SaveRating = null;
|
||||
var _loc2_:String = param1.error;
|
||||
if(param1.data.already_voted)
|
||||
{
|
||||
Logger.logError("Vote failed. You\'ve already voted on this rating today.");
|
||||
_loc2_ = APIEvent.ERROR_ALREADY_VOTED;
|
||||
}
|
||||
if(_loc2_ == APIEvent.ERROR_NONE)
|
||||
{
|
||||
_loc3_ = this._group.getRatingById(param1.data.rating_id);
|
||||
if(_loc3_)
|
||||
{
|
||||
this._ratings[_loc3_.name] = _loc3_.validateValue(param1.data.score);
|
||||
}
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE,this,_loc2_));
|
||||
}
|
||||
|
||||
public function clone() : SaveFile
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
var _loc1_:SaveFile = new SaveFile(this._group);
|
||||
_loc1_._data = this._data;
|
||||
_loc1_._description = this._description;
|
||||
_loc1_._draft = this._draft;
|
||||
_loc1_._fileSize = this._fileSize;
|
||||
_loc1_._iconLoader.bitmapData = this._iconLoader.bitmapData;
|
||||
for(_loc2_ in this._keys)
|
||||
{
|
||||
_loc1_._keys[_loc2_] = this._keys[_loc2_];
|
||||
}
|
||||
for(_loc2_ in this._ratings)
|
||||
{
|
||||
_loc1_._ratings[_loc2_] = this._ratings[_loc2_];
|
||||
}
|
||||
_loc1_._name = this._name;
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function load() : void
|
||||
{
|
||||
_currentFile = this;
|
||||
this._dataLoaded = false;
|
||||
this._data = null;
|
||||
if(!this.iconLoaded)
|
||||
{
|
||||
this._iconLoader.addEventListener(APIEvent.ICON_LOADED,this.onIconLoaded);
|
||||
this._iconLoader.load();
|
||||
}
|
||||
this._dataLoader = new URLLoader();
|
||||
this._dataLoader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
this._dataLoader.addEventListener(Event.COMPLETE,this.as3DataLoaded);
|
||||
this._dataLoader.addEventListener(IOErrorEvent.IO_ERROR,this.as3DataError);
|
||||
this._dataLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.as3DataError);
|
||||
this._dataLoader.load(new URLRequest(this._dataURL));
|
||||
}
|
||||
|
||||
private function as3DataLoaded(param1:Event) : void
|
||||
{
|
||||
this.onDataLoaded(this._dataLoader.data);
|
||||
}
|
||||
|
||||
private function as3DataError(param1:Event) : void
|
||||
{
|
||||
this.onDataError(param1.toString());
|
||||
}
|
||||
|
||||
private function decodeObject(param1:Object) : Object
|
||||
{
|
||||
var _loc2_:BitmapData = null;
|
||||
var _loc3_:String = null;
|
||||
if(getQualifiedClassName(param1) == "Object")
|
||||
{
|
||||
if(param1.type == "__bitmap")
|
||||
{
|
||||
_loc2_ = new BitmapData(param1.width,param1.height,param1.transparent);
|
||||
_loc2_.setPixels(_loc2_.rect,param1.data);
|
||||
param1 = _loc2_;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(_loc3_ in param1)
|
||||
{
|
||||
param1[_loc3_] = this.decodeObject(param1[_loc3_]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class SaveGroup
|
||||
{
|
||||
|
||||
public static const TYPE_SYSTEM:uint = 0;
|
||||
|
||||
public static const TYPE_PRIVATE:uint = 1;
|
||||
|
||||
public static const TYPE_PUBLIC:uint = 2;
|
||||
|
||||
public static const TYPE_MODERATED:uint = 3;
|
||||
|
||||
private var _connection:APIConnection;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _type:uint;
|
||||
|
||||
private var _keysArray:Array;
|
||||
|
||||
private var _ratingsArray:Array;
|
||||
|
||||
private var _keys:Object;
|
||||
|
||||
private var _ratings:Object;
|
||||
|
||||
public function SaveGroup(param1:APIConnection, param2:String, param3:uint, param4:uint, param5:Array, param6:Array)
|
||||
{
|
||||
var _loc7_:uint = 0;
|
||||
var _loc8_:SaveKey = null;
|
||||
var _loc9_:SaveRating = null;
|
||||
super();
|
||||
this._connection = param1;
|
||||
this._id = param3;
|
||||
this._name = param2;
|
||||
this._type = param4;
|
||||
this._keysArray = param5;
|
||||
this._ratingsArray = param6;
|
||||
this._keys = new Object();
|
||||
this._ratings = new Object();
|
||||
for each(_loc8_ in param5)
|
||||
{
|
||||
this._keys[_loc8_.name] = _loc8_;
|
||||
}
|
||||
for each(_loc9_ in param6)
|
||||
{
|
||||
this._ratings[_loc9_.name] = _loc9_;
|
||||
}
|
||||
}
|
||||
|
||||
public function get connection() : APIConnection
|
||||
{
|
||||
return this._connection;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get type() : uint
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function get id() : uint
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get keys() : Array
|
||||
{
|
||||
return this._keysArray;
|
||||
}
|
||||
|
||||
public function get ratings() : Array
|
||||
{
|
||||
return this._ratingsArray;
|
||||
}
|
||||
|
||||
public function getKey(param1:String) : SaveKey
|
||||
{
|
||||
return this._keys[param1];
|
||||
}
|
||||
|
||||
public function getRating(param1:String) : SaveRating
|
||||
{
|
||||
return this._ratings[param1];
|
||||
}
|
||||
|
||||
public function getKeyById(param1:uint) : SaveKey
|
||||
{
|
||||
var _loc2_:SaveKey = null;
|
||||
for each(_loc2_ in this._keys)
|
||||
{
|
||||
if(_loc2_.id == param1)
|
||||
{
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRatingById(param1:uint) : SaveRating
|
||||
{
|
||||
var _loc2_:SaveRating = null;
|
||||
for each(_loc2_ in this._ratings)
|
||||
{
|
||||
if(_loc2_.id == param1)
|
||||
{
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return "SaveGroup: " + this.name + " Keys: " + this._keysArray + " Ratings: " + this._ratingsArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class SaveKey
|
||||
{
|
||||
|
||||
public static const TYPE_FLOAT:uint = 1;
|
||||
|
||||
public static const TYPE_INTEGER:uint = 2;
|
||||
|
||||
public static const TYPE_STRING:uint = 3;
|
||||
|
||||
public static const TYPE_BOOLEAN:uint = 4;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _type:uint;
|
||||
|
||||
public function SaveKey(param1:String, param2:uint, param3:uint)
|
||||
{
|
||||
super();
|
||||
this._name = param1;
|
||||
this._id = param2;
|
||||
this._type = param3;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get id() : uint
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get type() : uint
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public function validateValue(param1:*) : *
|
||||
{
|
||||
var _loc2_:int = 0;
|
||||
switch(this._type)
|
||||
{
|
||||
case TYPE_INTEGER:
|
||||
param1 = Number(param1);
|
||||
if(!isNaN(param1))
|
||||
{
|
||||
_loc2_ = int(param1);
|
||||
if(_loc2_ != param1)
|
||||
{
|
||||
Logger.logWarning("Float value " + param1 + " given for integer key \"" + this._name + "\". Clamping to " + _loc2_ + ".");
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
param1 = Number(param1);
|
||||
if(!isNaN(param1))
|
||||
{
|
||||
return isNaN(Number(param1));
|
||||
}
|
||||
break;
|
||||
case TYPE_BOOLEAN:
|
||||
return Boolean(param1);
|
||||
case TYPE_STRING:
|
||||
return param1 ? param1.toString() : "";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class SaveQuery extends APIEventDispatcher
|
||||
{
|
||||
|
||||
public static const FILE_ID:String = "fileId";
|
||||
|
||||
public static const AUTHOR_ID:String = "authorId";
|
||||
|
||||
public static const AUTHOR_NAME:String = "authorName";
|
||||
|
||||
public static const FILE_NAME:String = "fileName";
|
||||
|
||||
public static const CREATED_ON:String = "createdOn";
|
||||
|
||||
public static const UPDATED_ON:String = "updatedOn";
|
||||
|
||||
public static const FILE_VIEWS:String = "fileViews";
|
||||
|
||||
public static const FILE_STATUS:String = "fileStatus";
|
||||
|
||||
private static const FILE_FIELDS:Array = [FILE_ID,AUTHOR_ID,AUTHOR_NAME,FILE_NAME,CREATED_ON,UPDATED_ON,FILE_VIEWS,FILE_STATUS];
|
||||
|
||||
public static const OPERATOR_EQUAL:String = "=";
|
||||
|
||||
public static const OPERATOR_LESS_THAN:String = "<";
|
||||
|
||||
public static const OPERATOR_GREATER_THAN:String = ">";
|
||||
|
||||
public static const OPERATOR_NOT_EQUAL:String = "!=";
|
||||
|
||||
public static const OPERATOR_LESS_OR_EQUAL:String = "<=";
|
||||
|
||||
public static const OPERATOR_GREATER_OR_EQUAL:String = ">=";
|
||||
|
||||
public static const OPERATOR_CONTAINS:String = "*";
|
||||
|
||||
public static const OPERATOR_NOT_CONTAINS:String = "!*";
|
||||
|
||||
public static const OPERATOR_NOT_BEGINS_WITH:String = "!*=";
|
||||
|
||||
public static const OPERATOR_NOT_ENDS_WITH:String = "!=*";
|
||||
|
||||
public static const OPERATOR_BEGINS_WITH:String = "*=";
|
||||
|
||||
public static const OPERATOR_ENDS_WITH:String = "=*";
|
||||
|
||||
private static const TABLE_FILES:uint = 1;
|
||||
|
||||
private static const TABLE_KEYS:uint = 2;
|
||||
|
||||
private static const TABLE_RATINGS:uint = 3;
|
||||
|
||||
private var _connection:APIConnection;
|
||||
|
||||
private var _group:SaveGroup;
|
||||
|
||||
private var _page:uint = 1;
|
||||
|
||||
private var _resultsPerPage:uint = 10;
|
||||
|
||||
private var _isRandomized:Boolean = false;
|
||||
|
||||
private var _files:Array = [];
|
||||
|
||||
private var _totalResults:uint;
|
||||
|
||||
private var _lookupKeys:Array = [];
|
||||
|
||||
private var _lookupRatings:Array = [];
|
||||
|
||||
private var _fileConditions:Array = [];
|
||||
|
||||
private var _keyConditions:Array = [];
|
||||
|
||||
private var _ratingConditions:Array = [];
|
||||
|
||||
private var _sortFields:Array = [];
|
||||
|
||||
public function SaveQuery(param1:SaveGroup)
|
||||
{
|
||||
super();
|
||||
this._group = param1;
|
||||
this._connection = param1.connection;
|
||||
this.includeAllFields();
|
||||
}
|
||||
|
||||
public function get group() : SaveGroup
|
||||
{
|
||||
return this._group;
|
||||
}
|
||||
|
||||
public function get resultsPerPage() : uint
|
||||
{
|
||||
return this._resultsPerPage;
|
||||
}
|
||||
|
||||
public function set resultsPerPage(param1:uint) : void
|
||||
{
|
||||
this._resultsPerPage = Math.min(Math.max(param1,1),100);
|
||||
}
|
||||
|
||||
public function get page() : uint
|
||||
{
|
||||
return this._page;
|
||||
}
|
||||
|
||||
public function set page(param1:uint) : void
|
||||
{
|
||||
this._page = Math.max(param1,1);
|
||||
}
|
||||
|
||||
public function prevPage() : void
|
||||
{
|
||||
--this.page;
|
||||
}
|
||||
|
||||
public function nextPage() : void
|
||||
{
|
||||
++this.page;
|
||||
}
|
||||
|
||||
public function get isRandomized() : Boolean
|
||||
{
|
||||
return this._isRandomized;
|
||||
}
|
||||
|
||||
public function set isRandomized(param1:Boolean) : void
|
||||
{
|
||||
this._isRandomized = param1;
|
||||
}
|
||||
|
||||
public function get files() : Array
|
||||
{
|
||||
return this._files;
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
this._page = 1;
|
||||
this._resultsPerPage = 10;
|
||||
this._isRandomized = false;
|
||||
this._lookupKeys = [];
|
||||
this._lookupRatings = [];
|
||||
this._fileConditions = [];
|
||||
this._keyConditions = [];
|
||||
this._ratingConditions = [];
|
||||
this._files = [];
|
||||
this.includeAllFields();
|
||||
}
|
||||
|
||||
public function clone() : SaveQuery
|
||||
{
|
||||
var _loc1_:SaveQuery = new SaveQuery(this._group);
|
||||
_loc1_._page = this._page;
|
||||
_loc1_._resultsPerPage = this._resultsPerPage;
|
||||
_loc1_._isRandomized = this._isRandomized;
|
||||
_loc1_._lookupKeys = this._lookupKeys.concat();
|
||||
_loc1_._lookupRatings = this._lookupRatings.concat();
|
||||
_loc1_._fileConditions = this._fileConditions.concat();
|
||||
_loc1_._keyConditions = this._keyConditions.concat();
|
||||
_loc1_._ratingConditions = this._ratingConditions.concat();
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
private function includeAllFields() : void
|
||||
{
|
||||
var _loc1_:SaveKey = null;
|
||||
var _loc2_:SaveRating = null;
|
||||
for each(_loc1_ in this._group.keys)
|
||||
{
|
||||
this._lookupKeys.push(_loc1_.id);
|
||||
}
|
||||
for each(_loc2_ in this._group.ratings)
|
||||
{
|
||||
this._lookupRatings.push(_loc2_.id);
|
||||
}
|
||||
}
|
||||
|
||||
public function addCondition(param1:String, param2:String, param3:*) : void
|
||||
{
|
||||
var _loc4_:int = 0;
|
||||
var _loc5_:SaveKey = null;
|
||||
var _loc6_:Array = null;
|
||||
var _loc7_:SaveRating = null;
|
||||
_loc4_ = FILE_FIELDS.indexOf(param1);
|
||||
if(_loc4_ >= 0)
|
||||
{
|
||||
this._fileConditions.push({
|
||||
"field":_loc4_,
|
||||
"operator":param2,
|
||||
"value":param3
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = this._group.getKey(param1);
|
||||
if(_loc5_)
|
||||
{
|
||||
param3 = _loc5_.validateValue(param3);
|
||||
this._keyConditions.push({
|
||||
"key_id":_loc5_.id,
|
||||
"operator":param2,
|
||||
"value":param3
|
||||
});
|
||||
return;
|
||||
}
|
||||
_loc6_ = param1.split(".");
|
||||
_loc7_ = this._group.getRating(_loc6_[0]);
|
||||
if(_loc7_)
|
||||
{
|
||||
param3 = _loc7_.validateValue(param3);
|
||||
this._ratingConditions.push({
|
||||
"rating_id":_loc7_.id,
|
||||
"operator":param2,
|
||||
"value":param3,
|
||||
"column":(_loc6_[1] ? _loc6_[1] : "score")
|
||||
});
|
||||
return;
|
||||
}
|
||||
Logger.logError("The save group \"" + this._group.name + "\" does not have a field named \"" + param1 + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
public function sortOn(param1:String, param2:Boolean = false) : void
|
||||
{
|
||||
var _loc3_:int = 0;
|
||||
var _loc4_:SaveKey = null;
|
||||
var _loc5_:Array = null;
|
||||
var _loc6_:SaveRating = null;
|
||||
_loc3_ = FILE_FIELDS.indexOf(param1);
|
||||
if(_loc3_ >= 0)
|
||||
{
|
||||
this._sortFields.push({
|
||||
"table":TABLE_FILES,
|
||||
"field":_loc3_,
|
||||
"desc":param2
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = this._group.getKey(param1);
|
||||
if(_loc4_)
|
||||
{
|
||||
this._sortFields.push({
|
||||
"table":TABLE_KEYS,
|
||||
"field":_loc4_.id,
|
||||
"desc":param2
|
||||
});
|
||||
return;
|
||||
}
|
||||
_loc5_ = param1.split(".");
|
||||
_loc6_ = this._group.getRating(_loc5_[0]);
|
||||
if(_loc6_)
|
||||
{
|
||||
this._sortFields.push({
|
||||
"table":TABLE_RATINGS,
|
||||
"field":_loc6_.id,
|
||||
"desc":param2,
|
||||
"extra":(_loc5_[1] ? _loc5_[1] : "score")
|
||||
});
|
||||
return;
|
||||
}
|
||||
Logger.logError("The save group \"" + this._group.name + "\" does not have a field named \"" + param1 + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
public function execute() : void
|
||||
{
|
||||
var _loc1_:Object = {};
|
||||
_loc1_.page = this._page;
|
||||
_loc1_.num_results = this._resultsPerPage;
|
||||
if(this._isRandomized)
|
||||
{
|
||||
_loc1_.randomize = 1;
|
||||
}
|
||||
if(Boolean(this._lookupKeys) && Boolean(this._lookupKeys.length))
|
||||
{
|
||||
_loc1_.lookup_keys = this._lookupKeys;
|
||||
}
|
||||
if(Boolean(this._lookupRatings) && Boolean(this._lookupRatings.length))
|
||||
{
|
||||
_loc1_.lookup_ratings = this._lookupRatings;
|
||||
}
|
||||
if(Boolean(this._fileConditions) && Boolean(this._fileConditions.length))
|
||||
{
|
||||
_loc1_.file_conditions = this._fileConditions;
|
||||
}
|
||||
if(Boolean(this._keyConditions) && Boolean(this._keyConditions.length))
|
||||
{
|
||||
_loc1_.key_conditions = this._keyConditions;
|
||||
}
|
||||
if(Boolean(this._ratingConditions) && Boolean(this._ratingConditions.length))
|
||||
{
|
||||
_loc1_.rating_conditions = this._ratingConditions;
|
||||
}
|
||||
if(Boolean(this._sortFields) && Boolean(this._sortFields.length))
|
||||
{
|
||||
_loc1_.sort_conditions = this._sortFields;
|
||||
}
|
||||
this._connection.sendSimpleCommand("lookupSaveFiles",this.onQueryComplete,{
|
||||
"publisher_id":this._connection.publisherId,
|
||||
"group_id":this._group.id,
|
||||
"query":_loc1_
|
||||
});
|
||||
}
|
||||
|
||||
private function onQueryComplete(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc3_:uint = 0;
|
||||
var _loc4_:SaveFile = null;
|
||||
if(param1.success)
|
||||
{
|
||||
_loc2_ = param1.data;
|
||||
this._files = [];
|
||||
if(_loc2_.files)
|
||||
{
|
||||
_loc3_ = 0;
|
||||
while(_loc3_ < _loc2_.files.length)
|
||||
{
|
||||
_loc4_ = SaveFile.fromObject(this._group,_loc2_.files[_loc3_]);
|
||||
if(_loc4_)
|
||||
{
|
||||
this._files.push(_loc4_);
|
||||
}
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.QUERY_COMPLETE,this));
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("Query failed: " + param1.error);
|
||||
dispatchEvent(new APIEvent(APIEvent.QUERY_COMPLETE,this,param1.error));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class SaveRating
|
||||
{
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _isFloat:Boolean;
|
||||
|
||||
private var _minimum:Number;
|
||||
|
||||
private var _maximum:Number;
|
||||
|
||||
public function SaveRating(param1:String, param2:uint, param3:Boolean, param4:Number, param5:Number)
|
||||
{
|
||||
super();
|
||||
this._name = param1;
|
||||
this._id = param2;
|
||||
this._isFloat = param3;
|
||||
this._minimum = param4;
|
||||
this._maximum = param5;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get id() : uint
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get isFloat() : Boolean
|
||||
{
|
||||
return this._isFloat;
|
||||
}
|
||||
|
||||
public function get minimum() : Number
|
||||
{
|
||||
return this._minimum;
|
||||
}
|
||||
|
||||
public function get maximum() : Number
|
||||
{
|
||||
return this._maximum;
|
||||
}
|
||||
|
||||
public function validateValue(param1:*) : Number
|
||||
{
|
||||
var _loc3_:int = 0;
|
||||
var _loc2_:Number = Number(param1);
|
||||
if(isNaN(_loc2_))
|
||||
{
|
||||
Logger.logError("Invalid value for rating \"" + this._name + "\".");
|
||||
return NaN;
|
||||
}
|
||||
if(_loc2_ < this._minimum)
|
||||
{
|
||||
Logger.logWarning(_loc2_ + " is out of acceptable range for rating \"" + this._name + "\". Clamping to " + this._minimum + ".");
|
||||
return this._minimum;
|
||||
}
|
||||
if(_loc2_ > this._maximum)
|
||||
{
|
||||
Logger.logWarning(_loc2_ + " is out of acceptable range for rating \"" + this._name + "\". Clamping to " + this._maximum + ".");
|
||||
return this._maximum;
|
||||
}
|
||||
if(!this.isFloat)
|
||||
{
|
||||
_loc3_ = int(_loc2_);
|
||||
if(_loc3_ != _loc2_)
|
||||
{
|
||||
Logger.logWarning("Float value " + _loc2_ + " given for integer rating \"" + this._name + "\". Clamping to " + _loc3_ + ".");
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class Score
|
||||
{
|
||||
|
||||
private var _numericValue:Number;
|
||||
|
||||
private var _rank:uint;
|
||||
|
||||
private var _username:String;
|
||||
|
||||
private var _score:String;
|
||||
|
||||
private var _tag:String;
|
||||
|
||||
public function Score(param1:uint, param2:String, param3:String, param4:Number, param5:String)
|
||||
{
|
||||
super();
|
||||
this._rank = param1;
|
||||
this._username = param2;
|
||||
this._score = param3;
|
||||
this._numericValue = param4;
|
||||
this._tag = param5;
|
||||
}
|
||||
|
||||
public function get numericValue() : Number
|
||||
{
|
||||
return this._numericValue;
|
||||
}
|
||||
|
||||
public function get rank() : uint
|
||||
{
|
||||
return this._rank;
|
||||
}
|
||||
|
||||
public function get score() : String
|
||||
{
|
||||
return this._score;
|
||||
}
|
||||
|
||||
public function get tag() : String
|
||||
{
|
||||
return this._tag;
|
||||
}
|
||||
|
||||
public function get username() : String
|
||||
{
|
||||
return this._username;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
return this._rank + ".\t" + this._username + "\t" + this._score;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.newgrounds
|
||||
{
|
||||
public class ScoreBoard extends APIEventDispatcher
|
||||
{
|
||||
|
||||
public static const TODAY:String = "Today";
|
||||
|
||||
public static const THIS_WEEK:String = "This Week";
|
||||
|
||||
public static const THIS_MONTH:String = "This Month";
|
||||
|
||||
public static const THIS_YEAR:String = "This Year";
|
||||
|
||||
public static const ALL_TIME:String = "All-Time";
|
||||
|
||||
private var _connection:APIConnection;
|
||||
|
||||
private var _name:String;
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _period:String = "All-Time";
|
||||
|
||||
private var _firstResult:uint = 1;
|
||||
|
||||
private var _numResults:uint = 10;
|
||||
|
||||
private var _tag:String;
|
||||
|
||||
private var _scores:Array;
|
||||
|
||||
public function ScoreBoard(param1:APIConnection, param2:String, param3:uint)
|
||||
{
|
||||
super();
|
||||
this._connection = param1;
|
||||
this._name = param2;
|
||||
this._id = param3;
|
||||
}
|
||||
|
||||
public function get name() : String
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public function get scores() : Array
|
||||
{
|
||||
return this._scores;
|
||||
}
|
||||
|
||||
public function get period() : String
|
||||
{
|
||||
return this._period;
|
||||
}
|
||||
|
||||
public function set period(param1:String) : void
|
||||
{
|
||||
this._period = param1;
|
||||
}
|
||||
|
||||
public function get firstResult() : uint
|
||||
{
|
||||
return this._firstResult;
|
||||
}
|
||||
|
||||
public function set firstResult(param1:uint) : void
|
||||
{
|
||||
this._firstResult = Math.max(1,param1);
|
||||
}
|
||||
|
||||
public function get numResults() : uint
|
||||
{
|
||||
return this._numResults;
|
||||
}
|
||||
|
||||
public function set numResults(param1:uint) : void
|
||||
{
|
||||
this._numResults = param1;
|
||||
}
|
||||
|
||||
public function get tag() : String
|
||||
{
|
||||
return this._tag;
|
||||
}
|
||||
|
||||
public function set tag(param1:String) : void
|
||||
{
|
||||
this._tag = param1;
|
||||
}
|
||||
|
||||
public function get page() : uint
|
||||
{
|
||||
return Math.ceil((this._firstResult - 1) / this._numResults) + 1;
|
||||
}
|
||||
|
||||
public function prevPage() : void
|
||||
{
|
||||
if(this.firstResult > this._numResults)
|
||||
{
|
||||
this.firstResult -= this._numResults;
|
||||
}
|
||||
}
|
||||
|
||||
public function nextPage() : void
|
||||
{
|
||||
this.firstResult += this._numResults;
|
||||
}
|
||||
|
||||
public function loadScores() : void
|
||||
{
|
||||
this._connection.sendSimpleCommand("loadScores",this.onScoresLoaded,{
|
||||
"publisher_id":this._connection.publisherId,
|
||||
"board":this._id,
|
||||
"page":(this._firstResult - 1) / this._numResults + 1,
|
||||
"num_results":this._numResults,
|
||||
"period":this._period,
|
||||
"tag":this._tag
|
||||
});
|
||||
}
|
||||
|
||||
public function postScore(param1:Number, param2:String = null) : void
|
||||
{
|
||||
if(isNaN(param1))
|
||||
{
|
||||
Logger.logError("Cannot post invalid score: " + param1);
|
||||
dispatchEvent(new APIEvent(APIEvent.SCORE_POSTED,null,APIEvent.ERROR_INVALID_ARGUMENT));
|
||||
return;
|
||||
}
|
||||
Logger.logMessage("Posting a score of " + param1 + " by " + this._connection.username + " to scoreboard \"" + this._name + "\"...");
|
||||
this._connection.sendSimpleCommand("postScore",this.onScorePosted,null,{
|
||||
"user_name":this._connection.username,
|
||||
"board":this._id,
|
||||
"value":param1,
|
||||
"tag":param2
|
||||
});
|
||||
}
|
||||
|
||||
private function onScoresLoaded(param1:APIEvent) : void
|
||||
{
|
||||
var _loc3_:uint = 0;
|
||||
var _loc4_:uint = 0;
|
||||
var _loc5_:Object = null;
|
||||
var _loc2_:Object = param1.data;
|
||||
this._scores = [];
|
||||
if(_loc2_.first_result)
|
||||
{
|
||||
_loc3_ = uint(_loc2_.first_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc3_ = this._firstResult;
|
||||
}
|
||||
if(_loc2_.scores)
|
||||
{
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _loc2_.scores.length)
|
||||
{
|
||||
_loc5_ = _loc2_.scores[_loc4_];
|
||||
if(_loc5_)
|
||||
{
|
||||
this._scores[_loc4_] = new Score(_loc3_,_loc5_.username,_loc5_.value,_loc5_.numeric_value,_loc5_.tag);
|
||||
}
|
||||
_loc4_++;
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.SCORES_LOADED,this));
|
||||
}
|
||||
|
||||
private function onScorePosted(param1:APIEvent) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc3_:Object = null;
|
||||
if(param1.success)
|
||||
{
|
||||
Logger.logMessage("Score posted!");
|
||||
_loc2_ = param1.data;
|
||||
_loc3_ = {};
|
||||
_loc3_.score = _loc2_.value;
|
||||
_loc3_.scoreBoard = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.logError("Error posting score: " + param1.error);
|
||||
}
|
||||
dispatchEvent(new APIEvent(APIEvent.SCORE_POSTED,_loc3_,param1.error));
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "Scoreboard: " + this._name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.newgrounds.assets
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
|
||||
[Embed(source="/_assets/2_com.newgrounds.assets.DefaultMedalIcon_com.newgrounds.assets.DefaultMedalIcon.png")]
|
||||
public dynamic class DefaultMedalIcon extends BitmapData
|
||||
{
|
||||
|
||||
public function DefaultMedalIcon(param1:Number, param2:Number)
|
||||
{
|
||||
super(param1,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.newgrounds.assets
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
|
||||
[Embed(source="/_assets/41_com.newgrounds.assets.DefaultSaveIcon_com.newgrounds.assets.DefaultSaveIcon.png")]
|
||||
public dynamic class DefaultSaveIcon extends BitmapData
|
||||
{
|
||||
|
||||
public function DefaultSaveIcon(param1:Number, param2:Number)
|
||||
{
|
||||
super(param1,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.newgrounds.crypto
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class MD5
|
||||
{
|
||||
|
||||
public static var digest:ByteArray;
|
||||
|
||||
private static var hexChars:String = "0123456789abcdef";
|
||||
|
||||
public function MD5()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function hash(param1:String) : String
|
||||
{
|
||||
var _loc2_:ByteArray = new ByteArray();
|
||||
_loc2_.writeUTFBytes(param1);
|
||||
return hashBinary(_loc2_);
|
||||
}
|
||||
|
||||
public static function hashBytes(param1:ByteArray) : String
|
||||
{
|
||||
return hashBinary(param1);
|
||||
}
|
||||
|
||||
public static function hashBinary(param1:ByteArray) : String
|
||||
{
|
||||
var _loc6_:int = 0;
|
||||
var _loc7_:int = 0;
|
||||
var _loc8_:int = 0;
|
||||
var _loc9_:int = 0;
|
||||
var _loc2_:int = 1732584193;
|
||||
var _loc3_:int = -271733879;
|
||||
var _loc4_:int = -1732584194;
|
||||
var _loc5_:int = 271733878;
|
||||
var _loc10_:Array = createBlocks(param1);
|
||||
var _loc11_:int = int(_loc10_.length);
|
||||
var _loc12_:int = 0;
|
||||
while(_loc12_ < _loc11_)
|
||||
{
|
||||
_loc6_ = _loc2_;
|
||||
_loc7_ = _loc3_;
|
||||
_loc8_ = _loc4_;
|
||||
_loc9_ = _loc5_;
|
||||
_loc2_ = ff(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 0)],7,-680876936);
|
||||
_loc5_ = ff(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 1)],12,-389564586);
|
||||
_loc4_ = ff(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 2)],17,606105819);
|
||||
_loc3_ = ff(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 3)],22,-1044525330);
|
||||
_loc2_ = ff(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 4)],7,-176418897);
|
||||
_loc5_ = ff(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 5)],12,1200080426);
|
||||
_loc4_ = ff(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 6)],17,-1473231341);
|
||||
_loc3_ = ff(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 7)],22,-45705983);
|
||||
_loc2_ = ff(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 8)],7,1770035416);
|
||||
_loc5_ = ff(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 9)],12,-1958414417);
|
||||
_loc4_ = ff(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 10)],17,-42063);
|
||||
_loc3_ = ff(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 11)],22,-1990404162);
|
||||
_loc2_ = ff(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 12)],7,1804603682);
|
||||
_loc5_ = ff(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 13)],12,-40341101);
|
||||
_loc4_ = ff(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 14)],17,-1502002290);
|
||||
_loc3_ = ff(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 15)],22,1236535329);
|
||||
_loc2_ = gg(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 1)],5,-165796510);
|
||||
_loc5_ = gg(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 6)],9,-1069501632);
|
||||
_loc4_ = gg(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 11)],14,643717713);
|
||||
_loc3_ = gg(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 0)],20,-373897302);
|
||||
_loc2_ = gg(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 5)],5,-701558691);
|
||||
_loc5_ = gg(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 10)],9,38016083);
|
||||
_loc4_ = gg(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 15)],14,-660478335);
|
||||
_loc3_ = gg(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 4)],20,-405537848);
|
||||
_loc2_ = gg(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 9)],5,568446438);
|
||||
_loc5_ = gg(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 14)],9,-1019803690);
|
||||
_loc4_ = gg(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 3)],14,-187363961);
|
||||
_loc3_ = gg(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 8)],20,1163531501);
|
||||
_loc2_ = gg(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 13)],5,-1444681467);
|
||||
_loc5_ = gg(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 2)],9,-51403784);
|
||||
_loc4_ = gg(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 7)],14,1735328473);
|
||||
_loc3_ = gg(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 12)],20,-1926607734);
|
||||
_loc2_ = hh(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 5)],4,-378558);
|
||||
_loc5_ = hh(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 8)],11,-2022574463);
|
||||
_loc4_ = hh(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 11)],16,1839030562);
|
||||
_loc3_ = hh(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 14)],23,-35309556);
|
||||
_loc2_ = hh(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 1)],4,-1530992060);
|
||||
_loc5_ = hh(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 4)],11,1272893353);
|
||||
_loc4_ = hh(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 7)],16,-155497632);
|
||||
_loc3_ = hh(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 10)],23,-1094730640);
|
||||
_loc2_ = hh(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 13)],4,681279174);
|
||||
_loc5_ = hh(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 0)],11,-358537222);
|
||||
_loc4_ = hh(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 3)],16,-722521979);
|
||||
_loc3_ = hh(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 6)],23,76029189);
|
||||
_loc2_ = hh(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 9)],4,-640364487);
|
||||
_loc5_ = hh(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 12)],11,-421815835);
|
||||
_loc4_ = hh(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 15)],16,530742520);
|
||||
_loc3_ = hh(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 2)],23,-995338651);
|
||||
_loc2_ = ii(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 0)],6,-198630844);
|
||||
_loc5_ = ii(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 7)],10,1126891415);
|
||||
_loc4_ = ii(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 14)],15,-1416354905);
|
||||
_loc3_ = ii(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 5)],21,-57434055);
|
||||
_loc2_ = ii(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 12)],6,1700485571);
|
||||
_loc5_ = ii(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 3)],10,-1894986606);
|
||||
_loc4_ = ii(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 10)],15,-1051523);
|
||||
_loc3_ = ii(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 1)],21,-2054922799);
|
||||
_loc2_ = ii(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 8)],6,1873313359);
|
||||
_loc5_ = ii(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 15)],10,-30611744);
|
||||
_loc4_ = ii(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 6)],15,-1560198380);
|
||||
_loc3_ = ii(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 13)],21,1309151649);
|
||||
_loc2_ = ii(_loc2_,_loc3_,_loc4_,_loc5_,_loc10_[int(_loc12_ + 4)],6,-145523070);
|
||||
_loc5_ = ii(_loc5_,_loc2_,_loc3_,_loc4_,_loc10_[int(_loc12_ + 11)],10,-1120210379);
|
||||
_loc4_ = ii(_loc4_,_loc5_,_loc2_,_loc3_,_loc10_[int(_loc12_ + 2)],15,718787259);
|
||||
_loc3_ = ii(_loc3_,_loc4_,_loc5_,_loc2_,_loc10_[int(_loc12_ + 9)],21,-343485551);
|
||||
_loc2_ += _loc6_;
|
||||
_loc3_ += _loc7_;
|
||||
_loc4_ += _loc8_;
|
||||
_loc5_ += _loc9_;
|
||||
_loc12_ += 16;
|
||||
}
|
||||
digest = new ByteArray();
|
||||
digest.writeInt(_loc2_);
|
||||
digest.writeInt(_loc3_);
|
||||
digest.writeInt(_loc4_);
|
||||
digest.writeInt(_loc5_);
|
||||
digest.position = 0;
|
||||
return toHex(_loc2_) + toHex(_loc3_) + toHex(_loc4_) + toHex(_loc5_);
|
||||
}
|
||||
|
||||
private static function f(param1:int, param2:int, param3:int) : int
|
||||
{
|
||||
return param1 & param2 | ~param1 & param3;
|
||||
}
|
||||
|
||||
private static function g(param1:int, param2:int, param3:int) : int
|
||||
{
|
||||
return param1 & param3 | param2 & ~param3;
|
||||
}
|
||||
|
||||
private static function h(param1:int, param2:int, param3:int) : int
|
||||
{
|
||||
return param1 ^ param2 ^ param3;
|
||||
}
|
||||
|
||||
private static function i(param1:int, param2:int, param3:int) : int
|
||||
{
|
||||
return param2 ^ (param1 | ~param3);
|
||||
}
|
||||
|
||||
private static function transform(param1:Function, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int, param8:int) : int
|
||||
{
|
||||
var _loc9_:int = param2 + int(param1(param3,param4,param5)) + param6 + param8;
|
||||
return rol(_loc9_,param7) + param3;
|
||||
}
|
||||
|
||||
private static function ff(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int) : int
|
||||
{
|
||||
return transform(f,param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
private static function gg(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int) : int
|
||||
{
|
||||
return transform(g,param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
private static function hh(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int) : int
|
||||
{
|
||||
return transform(h,param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
private static function ii(param1:int, param2:int, param3:int, param4:int, param5:int, param6:int, param7:int) : int
|
||||
{
|
||||
return transform(i,param1,param2,param3,param4,param5,param6,param7);
|
||||
}
|
||||
|
||||
private static function createBlocks(param1:ByteArray) : Array
|
||||
{
|
||||
var _loc2_:Array = new Array();
|
||||
var _loc3_:int = param1.length * 8;
|
||||
var _loc4_:int = 255;
|
||||
var _loc5_:int = 0;
|
||||
while(_loc5_ < _loc3_)
|
||||
{
|
||||
_loc2_[int(_loc5_ >> 5)] = _loc2_[int(_loc5_ >> 5)] | (param1[_loc5_ / 8] & _loc4_) << _loc5_ % 32;
|
||||
_loc5_ += 8;
|
||||
}
|
||||
_loc2_[int(_loc3_ >> 5)] = _loc2_[int(_loc3_ >> 5)] | 128 << _loc3_ % 32;
|
||||
_loc2_[int((_loc3_ + 64 >>> 9 << 4) + 14)] = _loc3_;
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
public static function rol(param1:int, param2:int) : int
|
||||
{
|
||||
return param1 << param2 | param1 >>> 32 - param2;
|
||||
}
|
||||
|
||||
public static function ror(param1:int, param2:int) : uint
|
||||
{
|
||||
var _loc3_:int = 32 - param2;
|
||||
return param1 << _loc3_ | param1 >>> 32 - _loc3_;
|
||||
}
|
||||
|
||||
public static function toHex(param1:int, param2:Boolean = false) : String
|
||||
{
|
||||
var _loc4_:int = 0;
|
||||
var _loc5_:int = 0;
|
||||
var _loc3_:String = "";
|
||||
if(param2)
|
||||
{
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < 4)
|
||||
{
|
||||
_loc3_ += hexChars.charAt(param1 >> (3 - _loc4_) * 8 + 4 & 0x0F) + hexChars.charAt(param1 >> (3 - _loc4_) * 8 & 0x0F);
|
||||
_loc4_++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < 4)
|
||||
{
|
||||
_loc3_ += hexChars.charAt(param1 >> _loc5_ * 8 + 4 & 0x0F) + hexChars.charAt(param1 >> _loc5_ * 8 & 0x0F);
|
||||
_loc5_++;
|
||||
}
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.newgrounds.crypto
|
||||
{
|
||||
public class RC4
|
||||
{
|
||||
|
||||
private static var sbox:Array = new Array(255);
|
||||
|
||||
private static var mykey:Array = new Array(255);
|
||||
|
||||
public function RC4()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encrypt(param1:String, param2:String) : String
|
||||
{
|
||||
var _loc3_:Array = strToChars(param1);
|
||||
var _loc4_:Array = strToChars(param2);
|
||||
var _loc5_:Array = calculate(_loc3_,_loc4_);
|
||||
return charsToHex(_loc5_);
|
||||
}
|
||||
|
||||
public static function encryptbin(param1:String, param2:String) : Array
|
||||
{
|
||||
var _loc3_:Array = strToChars(param1);
|
||||
var _loc4_:Array = strToChars(param2);
|
||||
return calculate(_loc3_,_loc4_);
|
||||
}
|
||||
|
||||
public static function decrypt(param1:String, param2:String) : String
|
||||
{
|
||||
var _loc3_:Array = hexToChars(param1);
|
||||
var _loc4_:Array = strToChars(param2);
|
||||
var _loc5_:Array = calculate(_loc3_,_loc4_);
|
||||
return charsToStr(_loc5_);
|
||||
}
|
||||
|
||||
private static function initialize(param1:Array) : void
|
||||
{
|
||||
var _loc3_:uint = 0;
|
||||
var _loc2_:uint = 0;
|
||||
var _loc4_:uint = param1.length;
|
||||
var _loc5_:uint = 0;
|
||||
while(_loc5_ <= 255)
|
||||
{
|
||||
mykey[_loc5_] = param1[_loc5_ % _loc4_];
|
||||
sbox[_loc5_] = _loc5_;
|
||||
_loc5_++;
|
||||
}
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ <= 255)
|
||||
{
|
||||
_loc2_ = (_loc2_ + sbox[_loc5_] + mykey[_loc5_]) % 256;
|
||||
_loc3_ = uint(sbox[_loc5_]);
|
||||
sbox[_loc5_] = sbox[_loc2_];
|
||||
sbox[_loc2_] = _loc3_;
|
||||
_loc5_++;
|
||||
}
|
||||
}
|
||||
|
||||
private static function calculate(param1:Array, param2:Array) : Array
|
||||
{
|
||||
var _loc6_:uint = 0;
|
||||
var _loc7_:uint = 0;
|
||||
var _loc8_:uint = 0;
|
||||
var _loc10_:uint = 0;
|
||||
initialize(param2);
|
||||
var _loc3_:uint = 0;
|
||||
var _loc4_:uint = 0;
|
||||
var _loc5_:Array = new Array();
|
||||
var _loc9_:uint = 0;
|
||||
while(_loc9_ < param1.length)
|
||||
{
|
||||
_loc3_ = (_loc3_ + 1) % 256;
|
||||
_loc4_ = (_loc4_ + sbox[_loc3_]) % 256;
|
||||
_loc7_ = uint(sbox[_loc3_]);
|
||||
sbox[_loc3_] = sbox[_loc4_];
|
||||
sbox[_loc4_] = _loc7_;
|
||||
_loc10_ = (sbox[_loc3_] + sbox[_loc4_]) % 256;
|
||||
_loc6_ = uint(sbox[_loc10_]);
|
||||
_loc8_ = uint(param1[_loc9_] ^ _loc6_);
|
||||
_loc5_.push(_loc8_);
|
||||
_loc9_++;
|
||||
}
|
||||
return _loc5_;
|
||||
}
|
||||
|
||||
private static function charsToHex(param1:Array) : String
|
||||
{
|
||||
var _loc2_:String = new String("");
|
||||
var _loc3_:Array = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
|
||||
var _loc4_:uint = 0;
|
||||
while(_loc4_ < param1.length)
|
||||
{
|
||||
_loc2_ += _loc3_[param1[_loc4_] >> 4] + _loc3_[param1[_loc4_] & 0x0F];
|
||||
_loc4_++;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private static function hexToChars(param1:String) : Array
|
||||
{
|
||||
var _loc2_:Array = new Array();
|
||||
var _loc3_:uint = param1.substr(0,2) == "0x" ? 2 : 0;
|
||||
while(_loc3_ < param1.length)
|
||||
{
|
||||
_loc2_.push(parseInt(param1.substr(_loc3_,2),16));
|
||||
_loc3_ += 2;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private static function charsToStr(param1:Array) : String
|
||||
{
|
||||
var _loc2_:String = new String("");
|
||||
var _loc3_:uint = 0;
|
||||
while(_loc3_ < param1.length)
|
||||
{
|
||||
_loc2_ += String.fromCharCode(param1[_loc3_]);
|
||||
_loc3_++;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private static function strToChars(param1:String) : Array
|
||||
{
|
||||
var _loc2_:Array = new Array();
|
||||
var _loc3_:uint = 0;
|
||||
while(_loc3_ < param1.length)
|
||||
{
|
||||
_loc2_.push(param1.charCodeAt(_loc3_));
|
||||
_loc3_++;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.newgrounds.encoders
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
public class BaseN
|
||||
{
|
||||
|
||||
private static const DEFAULT_HASH:String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~@#$%^&*()+|;/";
|
||||
|
||||
private var _hash:String;
|
||||
|
||||
private var _base:uint;
|
||||
|
||||
private var _reverseHash:Dictionary;
|
||||
|
||||
public function BaseN(param1:String)
|
||||
{
|
||||
super();
|
||||
if(param1)
|
||||
{
|
||||
this._hash = param1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._hash = DEFAULT_HASH;
|
||||
}
|
||||
this._base = this._hash.length;
|
||||
this._reverseHash = new Dictionary();
|
||||
var _loc2_:uint = 0;
|
||||
while(_loc2_ < this._hash.length)
|
||||
{
|
||||
this._reverseHash[this._hash.charAt(_loc2_)] = _loc2_;
|
||||
_loc2_++;
|
||||
}
|
||||
}
|
||||
|
||||
public function encodeUint(param1:uint, param2:uint = 1) : String
|
||||
{
|
||||
var _loc3_:String = "";
|
||||
var _loc4_:uint = param1;
|
||||
while(_loc4_ != 0)
|
||||
{
|
||||
_loc3_ = this._hash.charAt(_loc4_ % this._base) + _loc3_;
|
||||
_loc4_ /= this._base;
|
||||
}
|
||||
while(_loc3_.length < param2)
|
||||
{
|
||||
_loc3_ = this._hash.charAt(0) + _loc3_;
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
public function decodeUint(param1:String) : uint
|
||||
{
|
||||
var _loc2_:uint = 0;
|
||||
var _loc3_:uint = 0;
|
||||
while(_loc3_ < param1.length)
|
||||
{
|
||||
_loc2_ *= this._base;
|
||||
_loc2_ += this._reverseHash[param1.charAt(_loc3_)];
|
||||
_loc3_++;
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.newgrounds.encoders
|
||||
{
|
||||
import flash.display.BitmapData;
|
||||
import flash.geom.*;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class PNGEncoder
|
||||
{
|
||||
|
||||
private static var crcTable:Array;
|
||||
|
||||
private static var crcTableComputed:Boolean = false;
|
||||
|
||||
public function PNGEncoder()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encode(param1:BitmapData) : ByteArray
|
||||
{
|
||||
var _loc6_:uint = 0;
|
||||
var _loc7_:int = 0;
|
||||
var _loc2_:ByteArray = new ByteArray();
|
||||
_loc2_.writeUnsignedInt(2303741511);
|
||||
_loc2_.writeUnsignedInt(218765834);
|
||||
var _loc3_:ByteArray = new ByteArray();
|
||||
_loc3_.writeInt(param1.width);
|
||||
_loc3_.writeInt(param1.height);
|
||||
_loc3_.writeUnsignedInt(134610944);
|
||||
_loc3_.writeByte(0);
|
||||
writeChunk(_loc2_,1229472850,_loc3_);
|
||||
var _loc4_:ByteArray = new ByteArray();
|
||||
var _loc5_:int = 0;
|
||||
while(_loc5_ < param1.height)
|
||||
{
|
||||
_loc4_.writeByte(0);
|
||||
if(!param1.transparent)
|
||||
{
|
||||
_loc7_ = 0;
|
||||
while(_loc7_ < param1.width)
|
||||
{
|
||||
_loc6_ = param1.getPixel(_loc7_,_loc5_);
|
||||
_loc4_.writeUnsignedInt(uint((_loc6_ & 0xFFFFFF) << 8 | 0xFF));
|
||||
_loc7_++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc7_ = 0;
|
||||
while(_loc7_ < param1.width)
|
||||
{
|
||||
_loc6_ = param1.getPixel32(_loc7_,_loc5_);
|
||||
_loc4_.writeUnsignedInt(uint((_loc6_ & 0xFFFFFF) << 8 | _loc6_ >>> 24));
|
||||
_loc7_++;
|
||||
}
|
||||
}
|
||||
_loc5_++;
|
||||
}
|
||||
_loc4_.compress();
|
||||
writeChunk(_loc2_,1229209940,_loc4_);
|
||||
writeChunk(_loc2_,1229278788,null);
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private static function writeChunk(param1:ByteArray, param2:uint, param3:ByteArray) : void
|
||||
{
|
||||
var _loc8_:uint = 0;
|
||||
var _loc9_:uint = 0;
|
||||
var _loc10_:uint = 0;
|
||||
if(!crcTableComputed)
|
||||
{
|
||||
crcTableComputed = true;
|
||||
crcTable = [];
|
||||
_loc9_ = 0;
|
||||
while(_loc9_ < 256)
|
||||
{
|
||||
_loc8_ = _loc9_;
|
||||
_loc10_ = 0;
|
||||
while(_loc10_ < 8)
|
||||
{
|
||||
if(_loc8_ & 1)
|
||||
{
|
||||
_loc8_ = uint(uint(3988292384) ^ uint(_loc8_ >>> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc8_ = uint(_loc8_ >>> 1);
|
||||
}
|
||||
_loc10_++;
|
||||
}
|
||||
crcTable[_loc9_] = _loc8_;
|
||||
_loc9_++;
|
||||
}
|
||||
}
|
||||
var _loc4_:uint = 0;
|
||||
if(param3 != null)
|
||||
{
|
||||
_loc4_ = param3.length;
|
||||
}
|
||||
param1.writeUnsignedInt(_loc4_);
|
||||
var _loc5_:uint = param1.position;
|
||||
param1.writeUnsignedInt(param2);
|
||||
if(param3 != null)
|
||||
{
|
||||
param1.writeBytes(param3);
|
||||
}
|
||||
var _loc6_:uint = param1.position;
|
||||
param1.position = _loc5_;
|
||||
_loc8_ = 4294967295;
|
||||
var _loc7_:int = 0;
|
||||
while(_loc7_ < _loc6_ - _loc5_)
|
||||
{
|
||||
_loc8_ = uint(crcTable[(_loc8_ ^ param1.readUnsignedByte()) & uint(255)] ^ uint(_loc8_ >>> 8));
|
||||
_loc7_++;
|
||||
}
|
||||
_loc8_ = uint(_loc8_ ^ uint(4294967295));
|
||||
param1.position = _loc6_;
|
||||
param1.writeUnsignedInt(_loc8_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.newgrounds.encoders.json
|
||||
{
|
||||
public class JSON
|
||||
{
|
||||
|
||||
public function JSON()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function encode(param1:Object) : String
|
||||
{
|
||||
return encodeJson(param1);
|
||||
}
|
||||
|
||||
public static function decode(param1:String) : Object
|
||||
{
|
||||
return decodeJson(param1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
package com.newgrounds.encoders.json
|
||||
{
|
||||
public const decodeJson:Function = initDecodeJson();
|
||||
}
|
||||
|
||||
import com.newgrounds.encoders.json.§com.newgrounds.encoders.json.decodeJson§;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
function initDecodeJson():Function
|
||||
{
|
||||
var i:int;
|
||||
var parseStringEscaped:Function;
|
||||
var position:uint = 0;
|
||||
var byteInput:ByteArray = null;
|
||||
var char:uint = 0;
|
||||
var charConvert:ByteArray = null;
|
||||
var isNumberChar:ByteArray = null;
|
||||
var stringHelper:ByteArray = null;
|
||||
var isWhitespace:ByteArray = null;
|
||||
var parseNumber:Function = null;
|
||||
var parseWhitespace:Function = null;
|
||||
var parse:Object = null;
|
||||
charConvert = new ByteArray();
|
||||
charConvert.length = 256;
|
||||
charConvert[34] = 34;
|
||||
charConvert[92] = 92;
|
||||
charConvert[47] = 47;
|
||||
charConvert[98] = 8;
|
||||
charConvert[102] = 12;
|
||||
charConvert[110] = 10;
|
||||
charConvert[114] = 13;
|
||||
charConvert[116] = 9;
|
||||
isNumberChar = new ByteArray();
|
||||
isNumberChar.length = 256;
|
||||
isNumberChar[43] = 1;
|
||||
isNumberChar[45] = 1;
|
||||
isNumberChar[46] = 1;
|
||||
isNumberChar[48] = 1;
|
||||
isNumberChar[49] = 1;
|
||||
isNumberChar[50] = 1;
|
||||
isNumberChar[51] = 1;
|
||||
isNumberChar[52] = 1;
|
||||
isNumberChar[53] = 1;
|
||||
isNumberChar[54] = 1;
|
||||
isNumberChar[55] = 1;
|
||||
isNumberChar[56] = 1;
|
||||
isNumberChar[57] = 1;
|
||||
isNumberChar[69] = 1;
|
||||
isNumberChar[101] = 1;
|
||||
stringHelper = new ByteArray();
|
||||
stringHelper.length = 256;
|
||||
i = 0;
|
||||
while(i < 256)
|
||||
{
|
||||
stringHelper[i++] = 1;
|
||||
}
|
||||
stringHelper[34] = 0;
|
||||
stringHelper[92] = 0;
|
||||
isWhitespace = new ByteArray();
|
||||
isWhitespace.length = 256;
|
||||
isWhitespace[9] = 1;
|
||||
isWhitespace[10] = 1;
|
||||
isWhitespace[13] = 1;
|
||||
isWhitespace[32] = 1;
|
||||
parseNumber = function():Number
|
||||
{
|
||||
if(position === 1)
|
||||
{
|
||||
byteInput.position = 0;
|
||||
return parseFloat(byteInput.readUTFBytes(byteInput.length));
|
||||
}
|
||||
byteInput.position = position - 1;
|
||||
while(isNumberChar[byteInput[position++]])
|
||||
{
|
||||
}
|
||||
return Number(byteInput.readUTFBytes(position-- - byteInput.position - 1));
|
||||
};
|
||||
parseWhitespace = function():Object
|
||||
{
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
return parse[byteInput[position++]]();
|
||||
};
|
||||
parseStringEscaped = function(param1:String):String
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
if((char = byteInput[position++]) === 117)
|
||||
{
|
||||
byteInput.position = position;
|
||||
char = parseInt(byteInput.readUTFBytes(4),16);
|
||||
position = position + 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(char = charConvert[char]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
byteInput.position = position;
|
||||
}
|
||||
param1 = param1 + String.fromCharCode(char);
|
||||
while(stringHelper[byteInput[position++]])
|
||||
{
|
||||
}
|
||||
if(position - 1 > byteInput.position)
|
||||
{
|
||||
param1 = param1 + byteInput.readUTFBytes(position - 1 - byteInput.position);
|
||||
}
|
||||
if(byteInput[position - 1] !== 92)
|
||||
{
|
||||
return param1;
|
||||
}
|
||||
}
|
||||
throw new Error("Unknown escaped character encountered at position " + (position - 1));
|
||||
};
|
||||
parse = {
|
||||
34:function():String
|
||||
{
|
||||
if(stringHelper[byteInput[position++]])
|
||||
{
|
||||
byteInput.position = position - 1;
|
||||
while(stringHelper[byteInput[position++]])
|
||||
{
|
||||
}
|
||||
if(byteInput[position - 1] === 92)
|
||||
{
|
||||
return parseStringEscaped(byteInput.readUTFBytes(position - 1 - byteInput.position));
|
||||
}
|
||||
return byteInput.readUTFBytes(position - 1 - byteInput.position);
|
||||
}
|
||||
if(byteInput[position - 1] === 92)
|
||||
{
|
||||
return parseStringEscaped("");
|
||||
}
|
||||
return "";
|
||||
},
|
||||
123:function():Object
|
||||
{
|
||||
var _loc2_:* = undefined;
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
if(byteInput[position] === 125)
|
||||
{
|
||||
position++;
|
||||
return {};
|
||||
}
|
||||
var _loc1_:* = {};
|
||||
loop1:
|
||||
while(true)
|
||||
{
|
||||
do
|
||||
{
|
||||
_loc2_ = parse[byteInput[position++]]();
|
||||
if(byteInput[position] !== 58)
|
||||
{
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
if(byteInput[position++] !== 58)
|
||||
{
|
||||
break loop1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
position++;
|
||||
}
|
||||
_loc1_[_loc2_] = parse[byteInput[position++]]();
|
||||
}
|
||||
while(byteInput[position++] === 44);
|
||||
if(byteInput[position - 1] === 125)
|
||||
{
|
||||
return _loc1_;
|
||||
}
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
if(byteInput[position++] !== 44)
|
||||
{
|
||||
if(byteInput[position - 1] !== 125)
|
||||
{
|
||||
throw new Error("Expected , or } at " + (position - 1));
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
}
|
||||
throw new Error("Expected : at " + (position - 1));
|
||||
},
|
||||
91:function():Object
|
||||
{
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
if(byteInput[position] === 93)
|
||||
{
|
||||
position++;
|
||||
return [];
|
||||
}
|
||||
var _loc1_:* = [];
|
||||
while(true)
|
||||
{
|
||||
do
|
||||
{
|
||||
_loc1_[_loc1_.length] = parse[byteInput[position++]]();
|
||||
}
|
||||
while(byteInput[position++] === 44);
|
||||
if(byteInput[position - 1] === 93)
|
||||
{
|
||||
break;
|
||||
}
|
||||
position--;
|
||||
while(isWhitespace[byteInput[position]])
|
||||
{
|
||||
position++;
|
||||
}
|
||||
if(byteInput[position++] !== 44)
|
||||
{
|
||||
if(byteInput[position - 1] !== 93)
|
||||
{
|
||||
throw new Error("Expected , or ] at " + (position - 1));
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
}
|
||||
return _loc1_;
|
||||
},
|
||||
116:function():Boolean
|
||||
{
|
||||
if(byteInput[position] === 114 && byteInput[position + 1] === 117 && byteInput[position + 2] === 101)
|
||||
{
|
||||
position = position + 3;
|
||||
return true;
|
||||
}
|
||||
throw new Error("Expected \"true\" at position " + position);
|
||||
},
|
||||
102:function():Boolean
|
||||
{
|
||||
if(byteInput[position] === 97 && byteInput[position + 1] === 108 && byteInput[position + 2] === 115 && byteInput[position + 3] === 101)
|
||||
{
|
||||
position = position + 4;
|
||||
return false;
|
||||
}
|
||||
throw new Error("Expected \"false\" at position " + (position - 1));
|
||||
},
|
||||
110:function():Object
|
||||
{
|
||||
if(byteInput[position] === 117 && byteInput[position + 1] === 108 && byteInput[position + 2] === 108)
|
||||
{
|
||||
position = position + 3;
|
||||
return null;
|
||||
}
|
||||
throw new Error("Expected \"null\" at position " + position);
|
||||
},
|
||||
110:function():void
|
||||
{
|
||||
throw new Error("Unexpected end of array at " + position);
|
||||
},
|
||||
125:function():void
|
||||
{
|
||||
throw new Error("Unexpected end of object at " + position);
|
||||
},
|
||||
44:function():void
|
||||
{
|
||||
throw new Error("Unexpected comma at " + position);
|
||||
},
|
||||
45:parseNumber,
|
||||
48:parseNumber,
|
||||
49:parseNumber,
|
||||
50:parseNumber,
|
||||
51:parseNumber,
|
||||
52:parseNumber,
|
||||
53:parseNumber,
|
||||
54:parseNumber,
|
||||
55:parseNumber,
|
||||
56:parseNumber,
|
||||
57:parseNumber,
|
||||
13:parseWhitespace,
|
||||
10:parseWhitespace,
|
||||
9:parseWhitespace,
|
||||
32:parseWhitespace
|
||||
};
|
||||
return function(param1:*):Object
|
||||
{
|
||||
var input:* = param1;
|
||||
if(input is String)
|
||||
{
|
||||
byteInput = new ByteArray();
|
||||
byteInput.writeUTFBytes(input as String);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(input is ByteArray))
|
||||
{
|
||||
throw new Error("Unexpected input <" + input + ">");
|
||||
}
|
||||
byteInput = input as ByteArray;
|
||||
}
|
||||
position = 0;
|
||||
try
|
||||
{
|
||||
return parse[byteInput[position++]]();
|
||||
}
|
||||
catch(e:TypeError)
|
||||
{
|
||||
if(position - 1 < byteInput.length)
|
||||
{
|
||||
e.message = "Unexpected character " + String.fromCharCode(byteInput[position - 1]) + " (0x" + byteInput[position - 1].toString(16) + ")" + " at position " + (position - 1) + " (" + e.message + ")";
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.newgrounds.encoders.json
|
||||
{
|
||||
public const encodeJson:Function = initDecodeJson();
|
||||
}
|
||||
|
||||
import com.newgrounds.encoders.json.§com.newgrounds.encoders.json.encodeJson§;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.IDataOutput;
|
||||
|
||||
function initDecodeJson():Function
|
||||
{
|
||||
var parseArray:Function;
|
||||
var result:IDataOutput = null;
|
||||
var i:int = 0;
|
||||
var j:int = 0;
|
||||
var strLen:int = 0;
|
||||
var str:String = null;
|
||||
var char:int = 0;
|
||||
var tempBytes:ByteArray = null;
|
||||
var blockNonFiniteNumbers:Boolean = false;
|
||||
var charConvert:Array = null;
|
||||
var parseString:Function = null;
|
||||
var parse:Object = null;
|
||||
tempBytes = new ByteArray();
|
||||
charConvert = new Array(256);
|
||||
j = 0;
|
||||
while(j < 10)
|
||||
{
|
||||
charConvert[j] = j + 48 | 0x30303000;
|
||||
j++;
|
||||
}
|
||||
while(j < 16)
|
||||
{
|
||||
charConvert[j] = j + 55 | 0x30303000;
|
||||
j++;
|
||||
}
|
||||
while(j < 26)
|
||||
{
|
||||
charConvert[j] = j + 32 | 0x30303100;
|
||||
j++;
|
||||
}
|
||||
while(j < 32)
|
||||
{
|
||||
charConvert[j] = j + 39 | 0x30303100;
|
||||
j++;
|
||||
}
|
||||
while(j < 256)
|
||||
{
|
||||
charConvert[j] = j;
|
||||
j++;
|
||||
}
|
||||
charConvert[10] = 23662;
|
||||
charConvert[13] = 23666;
|
||||
charConvert[9] = 23668;
|
||||
charConvert[8] = 23650;
|
||||
charConvert[12] = 23654;
|
||||
charConvert[8] = 23650;
|
||||
charConvert[34] = 23586;
|
||||
charConvert[92] = 23644;
|
||||
charConvert[127] = 808466246;
|
||||
parseArray = function(param1:Array):void
|
||||
{
|
||||
result.writeByte(91);
|
||||
var _loc2_:* = 0;
|
||||
var _loc3_:int = param1.length - 1;
|
||||
if(_loc3_ >= 0)
|
||||
{
|
||||
while(_loc2_ < _loc3_)
|
||||
{
|
||||
parse[typeof param1[_loc2_]](param1[_loc2_]);
|
||||
result.writeByte(44);
|
||||
_loc2_++;
|
||||
}
|
||||
parse[typeof param1[_loc2_]](param1[_loc2_]);
|
||||
}
|
||||
result.writeByte(93);
|
||||
};
|
||||
parseString = function(param1:String):void
|
||||
{
|
||||
result.writeByte(34);
|
||||
tempBytes.position = 0;
|
||||
tempBytes.length = 0;
|
||||
tempBytes.writeUTFBytes(param1);
|
||||
i = 0;
|
||||
j = 0;
|
||||
strLen = tempBytes.length;
|
||||
while(j < strLen)
|
||||
{
|
||||
char = charConvert[tempBytes[j++]];
|
||||
if(char > 256)
|
||||
{
|
||||
if(j - 1 > i)
|
||||
{
|
||||
result.writeBytes(tempBytes,i,j - 1 - i);
|
||||
}
|
||||
if(char > 65536)
|
||||
{
|
||||
result.writeShort(23669);
|
||||
result.writeUnsignedInt(char);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.writeShort(char);
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
if(strLen > i)
|
||||
{
|
||||
result.writeBytes(tempBytes,i,strLen - i);
|
||||
}
|
||||
result.writeByte(34);
|
||||
};
|
||||
parse = {
|
||||
"object":function(param1:Object):void
|
||||
{
|
||||
var _loc2_:* = undefined;
|
||||
if(param1)
|
||||
{
|
||||
if(param1 is Array)
|
||||
{
|
||||
parseArray(param1);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.writeByte(123);
|
||||
_loc2_ = true;
|
||||
for(str in param1)
|
||||
{
|
||||
if(_loc2_)
|
||||
{
|
||||
_loc2_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.writeByte(44);
|
||||
}
|
||||
parseString(str);
|
||||
result.writeByte(58);
|
||||
parse[typeof param1[str]](param1[str]);
|
||||
}
|
||||
result.writeByte(125);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.writeUnsignedInt(1853189228);
|
||||
}
|
||||
},
|
||||
"string":parseString,
|
||||
"number":function(param1:Number):void
|
||||
{
|
||||
if(blockNonFiniteNumbers && !isFinite(param1))
|
||||
{
|
||||
throw new Error("Number " + param1 + " is not encodable");
|
||||
}
|
||||
result.writeUTFBytes(String(param1));
|
||||
},
|
||||
"boolean":function(param1:Boolean):void
|
||||
{
|
||||
if(param1)
|
||||
{
|
||||
result.writeUnsignedInt(1953658213);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.writeByte(102);
|
||||
result.writeUnsignedInt(1634497381);
|
||||
}
|
||||
},
|
||||
"xml":function(param1:Object):void
|
||||
{
|
||||
if(!param1.toXMLString is Function || (param1 = param1.toXMLString() as String) == null)
|
||||
{
|
||||
throw new Error("unserializable XML object encountered");
|
||||
}
|
||||
parseString(param1);
|
||||
},
|
||||
"undefined":function(param1:Boolean):void
|
||||
{
|
||||
result.writeUnsignedInt(1853189228);
|
||||
}
|
||||
};
|
||||
return function(param1:Object, param2:IDataOutput = null, param3:Boolean = false):String
|
||||
{
|
||||
var byteOutput:* = undefined;
|
||||
var input:Object = param1;
|
||||
var writeTo:IDataOutput = param2;
|
||||
var strictNumberSupport:Boolean = param3;
|
||||
blockNonFiniteNumbers = strictNumberSupport;
|
||||
try
|
||||
{
|
||||
if(writeTo)
|
||||
{
|
||||
result = writeTo;
|
||||
result.endian = "bigEndian";
|
||||
parse[typeof input](input);
|
||||
byteOutput.position = 0;
|
||||
return byteOutput.readUTFBytes(byteOutput.length);
|
||||
}
|
||||
switch(typeof input)
|
||||
{
|
||||
case "xml":
|
||||
if(!input.toXMLString is Function || (input = input.toXMLString() as String) == null)
|
||||
{
|
||||
throw new Error("unserializable XML object encountered");
|
||||
}
|
||||
break;
|
||||
case "object":
|
||||
case "string":
|
||||
break;
|
||||
case "number":
|
||||
if(blockNonFiniteNumbers && !isFinite(input as Number))
|
||||
{
|
||||
throw new Error("Number " + input + " is not encodable");
|
||||
}
|
||||
return String(input);
|
||||
break;
|
||||
case "boolean":
|
||||
return input ? "true" : "false";
|
||||
case "undefined":
|
||||
return "null";
|
||||
default:
|
||||
throw new Error("Unexpected type \"" + typeof input + "\" encountered");
|
||||
}
|
||||
result = byteOutput = new ByteArray();
|
||||
result.endian = "bigEndian";
|
||||
parse[typeof input](input);
|
||||
byteOutput.position = 0;
|
||||
return byteOutput.readUTFBytes(byteOutput.length);
|
||||
}
|
||||
catch(e:TypeError)
|
||||
{
|
||||
throw new Error("Unexpected type encountered");
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user