Game Development in Flash & PHP
Presenter: Tianyang (TYLER Projects) For PHP User Group 21-02-2008
Overview FLASH Embedding Preloaders Communicating Communica ting with PHP Security
PHP Database Security
Q&A
Embedding Flash
Eolas and XHTML problems - Use free SWFObject javascript to create embed code
Preloader Large files – Important to show download progress function loadClient() { var loader:Loader = new Loader(); configureListeners(loader.contentLoaderInfo); var request:URLRequest = new URLRequest URLRequest(url); (url); loader.load(request); addChild(loader); } function configureListe configureListeners(dispatche ners(dispatcher:IEventDispatc r:IEventDispatcher):void her):void { dispatcher.addEventListener(Event.COMPLETE, completeHandler); } function completeHandler(event:Event):void completeHandler(event:Event):void { removeChild(loaderClip); removeChild(lo aderClip); // Remove preloader progress clip } IOErrorEvent.IO_ERROR IOErrorEvent.I O_ERROR // File not found etc... HTTPStatusEvent.HTTP_STATUS // 404 error etc... ProgressEvent.PROGRESS ProgressEven t.PROGRESS // Update progress bar Misc other events: Event.UNLOAD, OPEN, INIT etc...
Communicating with PHP var req:URLRequest = new URLRequest(“submit URLRequest(“submit.php”); .php”); var variables:U v ariables:URL RLV Variables = new URL URLV Variables() ariables();; variables.op = "getResource"; "getResource"; // Data to send req.data = variables; req.method = URLRequestMethod.POST; var loader:URLLoader = new URLLoader(req URLLoader(req); ); loader.addEventListener loader .addEventListener(Event.COMPLETE,load (Event.COMPLETE,loadInfoHandler); InfoHandler); loader.addEventListener loader .addEventListener(IOErrorEvent.IO_ERROR,Erro (IOErrorEvent.IO_ERROR,ErrorHandler); rHandler);
Communicating with PHP
function loadInfoComplet loadInfoCompleteHandler(event:Eve eHandler(event:Event):void nt):void { var xml:XML = new XML(event.target.da XML(event.target.data); ta); var tobj = xml.elements('myoutp xml.elements('myoutputlist'); utlist'); mydata = xml.elements('myoutp xml.elements('myoutputlist')[0].attribute utlist')[0].attribute("var1"); ("var1"); }
Security
Client-side Not secured Variables easily changeable via memory editors Single-player games vs Multi-player Decompiler
Solution Obfuscation Manipulating variables Server-side processing
Storing Player Data Data to store: Highscore List User IDs, Name Resources: Cash, Items etc... Game variables
Table Types Static MyISAM vs InnoDB Memory
Do query caching for highscore Proper indexing
Security
Clean Inputs: Use intval() for all integer values Filter special characters for strings
Q&A
To show: Demo from battlestations. Contact:
[email protected] Try the game: http://apps.facebook.com/battlestations