Article 1TTPE CodeSOD: It Takes One Function

CodeSOD: It Takes One Function

by
Ellis Morning
from The Daily WTF on (#1TTPE)

512px-Longleat_maze.jpg

This anonymous submission is the result of our submitter decompiling a Flash application to see how it worked. It's not often that one thinks to himself, "Wow, some case statements would've been a lot better," but here we are.

 private function onMessage(param1:MessageEvent) : void { e = param1; var decoded:Object = JSON.parse(e.data.body); if(!(decoded.tags && decoded.tags[0] == "trnupdate")) { f_bwt("[XMPPConnectionManager] - Message received:\n",JSON.stringify(e.data.body)); } if(decoded.tags) { if(decoded.tags[1] == "ok") { var _loc3_:* = decoded.tags[0]; if("getcashgames" !== _loc3_) { if("lobby_subscribe" !== _loc3_) { if("getcgtickets" !== _loc3_) { if("gettourtickets" !== _loc3_) { if("getflopsseen" !== _loc3_) { if("getbonuses" !== _loc3_) { if("getplayerstatus" !== _loc3_) { if("getdeeplink" !== _loc3_) { if("getbuyins" !== _loc3_) { if("getmoneyinplay" !== _loc3_) { if("createidentity" !== _loc3_) { if("setidentity" !== _loc3_) { if("setachbadge" !== _loc3_) { if("gethands" !== _loc3_) { if("gethanddetails" !== _loc3_) { if("gettournames" !== _loc3_) { if("getssoticket" !== _loc3_) { if("getregistrations" !== _loc3_) { if("addPlayer" !== _loc3_) { if("removePlayer" !== _loc3_) { if("checkFilter" !== _loc3_) { if("leave" !== _loc3_) { if("getnotiscount" !== _loc3_) { if("getnotis" !== _loc3_) { if("acknotis" !== _loc3_) { if("delnotis" !== _loc3_) { if("play" !== _loc3_) { if("getflopsneeded" !== _loc3_) { if("getRail" === _loc3_) { dispatchEventWith("xmppConnectionManager.getRail",false,decoded.payLoad); } } else { f_bwt(decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.slotPlaySuccess",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.deleteNotification",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.archiveNotification",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.getNotifications",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.getNotificationCount",false,decoded.payLoad); } } else { i_gbi.instance.s_xks(decoded); } } else { dispatchEventWith("xmppConnectionManager.tournamentValidityCheckSuccess",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.tournamentUnregistrationSuccess",false,decoded.payLoad); GameAndTournamentData.instance.y_gvy(decoded.payLoad.trid).unregister(); dispatchEventWith("xmppConnectionManager.tournamentUpdateReceived",false,decoded.payLoad); x_shy(); } } else { dispatchEventWith("xmppConnectionManager.tournamentRegistrationSuccess",false,decoded.payLoad); GameAndTournamentData.instance.y_gvy(decoded.payLoad.trid).register(); dispatchEventWith("xmppConnectionManager.tournamentUpdateReceived",false,decoded.payLoad); x_shy(); } } else { d_vin.instance.tournamentRegistrations = decoded.payLoad; dispatchEventWith("xmppConnectionManager.tournamentRegistrationsReceived",false,decoded.payLoad); if(!_subscribedToTournamentFeeds) { t_ecg("tournament",2); t_ecg("sitngo",1); _subscribedToTournamentFeeds = true; var i:int = 0; while(i = 1500) { _showTournamentDataLoader = false; dispatchEventWith("xmppConnectionManager.tournamentUpdateReceived",false,decoded.payLoad); dispatchEventWith("xmppConnectionManager.tournamentListUpdated"); } }; i_gbi.instance.s_xks(decoded); _lastUpdate = getTimer(); if(_firstTournamentUpdate) { _firstTournamentUpdate = false; Starling.juggler.delayCall(function():void { dispatchEventWith("xmppConnectionManager.tournamentUpdateReceived",false,decoded.payLoad); },2); } else { Starling.juggler.delayCall(checkUpdate,1.7); } } else if(decoded.tags[0] == "sngupdate") { i_gbi.instance.s_xks(decoded); dispatchEventWith("xmppConnectionManager.sngUpdateReceived",false,decoded.payLoad); if(!_allowSNGRejoin) { _savedSNGJoinMessage = {}; } } else if(decoded.tags[0] == "cgupdate") { GameAndTournamentData.instance.updateCashGames(decoded.payLoad); } else if(decoded.tags[0] == "mscounter" || decoded.tags[0] == "msfactors") { e_dql.instance.handleMessage(decoded); if(_tableConnection) { _tableConnection.l_fpt(decoded); } } else if(decoded.tags[1] == "error") { try { x_dyr.write(!!("error: [" + decoded.tags[0] + "][" + decoded.tags[1] + "]" + decoded.payLoad)?" - code: " + decoded.payLoad.errorcode + "; message: " + decoded.payLoad.message:" (no payLoad)"); } catch(err:Error) { f_bwt("[XMPPConnectionManager] - Decoded.tags[1] error: " + err.message); } var _loc5_:* = decoded.tags[0]; if("createidentity" !== _loc5_) { if("addPlayer" !== _loc5_) { if("removePlayer" !== _loc5_) { if("gethanddetails" !== _loc5_) { if("getchallenges" !== _loc5_) { if("discardchallenge" !== _loc5_) { if("challengehistory" !== _loc5_) { if("play" !== _loc5_) { if("checkFilter" !== _loc5_) { if("joinSNGQueues" !== _loc5_) { if("gettournames" === _loc5_) { dispatchEventWith("xmppConnectionManager.tournamentNamesReceived",false,decoded.payLoad); } } else if(decoded.payLoad.errorcode == "INSUFFICIENT_FUNDS") { t_bya(decoded.payLoad.instance); } else if(_allowSNGRejoin) { t_eqj = function():void { if(_savedSNGJoinMessage && _savedSNGTargetJID) { sendMessage(_savedSNGJoinMessage,_savedSNGTargetJID); } }; Starling.juggler.delayCall(t_eqj,1); } } else if(decoded.payLoad.errorcode == "WRONG_PASSWORD") { dispatchEventWith("xmppConnectionManager.tournamentPasswordWrong",false,decoded.payLoad); } else { dispatchEventWith("xmppConnectionManager.tournamentValidityCheckError",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.slotPlayError",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.challengehistoryReceived"); } } else { dispatchEventWith("xmppConnectionManager.discardchallengeReceived"); } } else { dispatchEventWith("xmppConnectionManager.challengesReceived"); } } else { dispatchEventWith("xmppConnectionManager.handDetailsReceived",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.tournamentRegistrationError",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.tournamentRegistrationError",false,decoded.payLoad); } } else { dispatchEventWith("xmppConnectionManager.createIdentityFailed",false,decoded.payLoad); } if("errorcode" in decoded.payLoad && decoded.payLoad.errorcode == "REGISTRATION_CLOSED") { if(decoded.payLoad.trid) { GameAndTournamentData.instance.y_gvy(decoded.payLoad.trid).registrationEnded = true; } else if(decoded.payLoad.sngid) { GameAndTournamentData.instance.y_gvy(decoded.payLoad.sngid).registrationEnded = true; } dispatchEventWith("xmppConnectionManager.tournamentUpdateReceived",false,decoded.payLoad); } } if(decoded && "payLoad" in decoded && "errorcode" in decoded.payLoad && decoded.payLoad.errorcode == "PLAYER_DISABLED") { x_okk(); } if(decoded.tags[0] == "hello") { b_hds(e.data.from.bareJID,decoded.payLoad.instance + "-table"); i_gbi.instance.s_xks(decoded); } if(decoded.tags[0] == "hello" && decoded.tags[1] == "init" && false) { if(decoded.payLoad.refid) { if(decoded.payLoad.sngid) { z_ftr(decoded.payLoad.refid); } if(Root.e_bdt && Root.e_bdt.tournamentData) { Root.e_bdt.tournamentData.sngTournamentId = decoded.payLoad.refid; } } else if(Root.e_bdt && Root.e_bdt.tournamentData) { Root.e_bdt.tournamentData.sngTournamentId = -1; } } } if(decoded.payLoad && !(decoded.payLoad is Number)) { if(decoded.payLoad.instance || decoded.payLoad.p && decoded.payLoad.p[0]) { if(decoded.tags[0] == "notify" && decoded.tags[1] == "sngqueue") { b_hds(e.data.from.bareJID,decoded.payLoad.instance + "-table"); i_gbi.instance.s_xks(decoded); } var instance:String = !!decoded.payLoad.instance?decoded.payLoad.instance:decoded.payLoad.p[0]; decoded.from = e.data.from.bareJID; if(_tableConnection) { _tableConnection.p_ymi(instance,decoded); } z_pjv.record(instance,e.data.body); x_xdz.instance.update(decoded); if(decoded.tags[0] == "pturn" && decoded.payLoad.p[1] == decoded.payLoad.d[0]) { dispatchEventWith("xmppConnectionManager.gameUserTurn",false,{"instanceId":decoded.payLoad.p[0]}); } else if(decoded.tags[0] == "act" && decoded.payLoad.p[1] == decoded.payLoad.d[0]) { dispatchEventWith("xmppConnectionManager.gameUserAct",false,{"instanceId":decoded.payLoad.p[0]}); } else if(decoded.tags[0] == "select" && decoded.tags[1] == "buyin") { dispatchEventWith("xmppConnectionManager.gameUserTurn",false,{"instanceId":decoded.payLoad.instance}); } else if(decoded.tags[0] == "buyin" && decoded.tags[1] == "ok") { dispatchEventWith("xmppConnectionManager.gameUserAct",false,{"instanceId":decoded.payLoad.instance}); } } else if(decoded.tags[0] == "notify") { if(_tableConnection) { _tableConnection.l_fpt(decoded); } i_qdz.instance.s_xks(decoded.payLoad); if(decoded.tags[1] == "balance") { if(decoded.payLoad.balance is Number) { d_vin.instance.balance = decoded.payLoad.balance; } else { d_vin.instance.balance = decoded.payLoad.balance.eur; var eur:Number = decoded.payLoad.balance.eur; var ntv:Number = decoded.payLoad.balance.native; var rate:Number = int(ntv / eur * 100000) / 100000; d_vin.instance.exchangeRate = rate; m_vuc.instance.g_qwf("currencyExchangeRate",rate); } dispatchEventWith("xmppConnectionManager.balanceChanged",false,decoded.payLoad); } else if(decoded.tags[1] == "ach") { if(d_vin.instance.l_asy) { d_vin.instance.e_lbz(decoded.payLoad.props.achid,"achieved"); EventProxy.instance.dispatchEventWith("updateAchievements"); } else { p_krj(); } } if(decoded.tags[1] != "balance" && decoded.tags[1] != "sitouttime" && decoded.tags[1] != "tour") { dispatchEventWith("xmppConnectionManager.notificationReceived",false,decoded); } if(decoded.payLoad.msg) { if(decoded.payLoad.msg[0] == 9 || decoded.payLoad.msg[0] == 11 || decoded.payLoad.msg[0] == 15) { j_dja(); } else if(decoded.payLoad.msg[0] == 16 || decoded.payLoad.msg[0] == 19) { u_whk(); } else if(decoded.payLoad.msg[0] == 17 || decoded.payLoad.msg[0] == 27) { x_shy(); } if(decoded.payLoad.msg[0] == 5) { q_scp(); } } } else if(decoded.tags[0] == "getmissions") { o_maz.instance.l_kym(decoded.payLoad); _tableConnection.l_fpt(decoded); } else if(decoded.tags[0] == "besthandspromo") { p_kmb.instance.n_mbf(decoded.payLoad); _tableConnection.l_fpt(decoded); } else if(decoded.tags[0] == "getachievements") { d_vin.instance.l_asy = decoded.payLoad.latest; dispatchEventWith("xmppConnectionManager.achievementsReceived"); } else if(decoded.tags[0] == "getchallenges") { dispatchEventWith("xmppConnectionManager.challengesReceived",false,decoded.payLoad); } else if(decoded.tags[0] == "discardchallenge") { dispatchEventWith("xmppConnectionManager.discardchallengeReceived",false,decoded.payLoad); } else if(decoded.tags[0] == "challengehistory") { dispatchEventWith("xmppConnectionManager.challengehistoryReceived",false,decoded.payLoad); } else if(decoded.tags[0] == "getspins") { q_xph.instance.f_nac = decoded.payLoad; } else if(decoded.tags[0] == "slotupdate") { q_xph.instance.k_rho = decoded.payLoad; } else if(decoded.tags[0] == "getflopsneeded") { q_xph.instance.n_smu = decoded.payLoad; } } if(decoded.tags[0] == "trnupdate") { if(_tableConnection) { if(decoded.payLoad.tournamentType == "SNG") { f_bwt("[XMPPConnectionManager] - SNG trnupdate message received:"); f_bwt(JSON.stringify(decoded)); _tableConnection.l_roq(decoded.payLoad.trid,decoded); } else { _tableConnection.v_ljh(decoded.payLoad.trid,"MTT"); } } } else if(decoded.tags[0] == "sngupdate" && decoded.tags[1] == "rules") { if(_tableConnection) { _tableConnection.v_ljh(decoded.payLoad.sngid,"SNG"); } } if(decoded.tags[1] == "removed") { f_bwt("[XMPPConnectionManager] - Tournament " + decoded.payLoad.trid + " was removed."); f_bwt(e.data.body); } } 
inedo50.png [Advertisement] Otter, ProGet, BuildMaster - robust, powerful, scalable, and reliable additions to your existing DevOps toolchain. TheDailyWtf?d=yIl2AUoC8zAR5npOHfgRx8
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments