.
Moderate BBCode support as well, all made by myself. <Using bbcode instead of HTML in user inputs for security>
Pear was used to utilize it's faster DB queries. (php doesn't use direct, unprocessed queries.)
When i'm through with it, it will only end up as a module for my web package.
Since it has too many things that are specifically tied with my web.
That.. If switched, will give the chatbox more possible functions and easier communication with the game server.
But on second hand, the XAT chatbox could be decompiled, and you can use the info from the chatbox source to build a server. But, why would you want to do that? You can't even copy text from XAT boxes.
And, lol.
Get into Asp.Net and make a new web package.
I'm sure someone here can figure out how to integrate a Asp.Net(C#) chatbox with their gameserver.
The chatbox isn't live on my site because I'm building my own CMS.
The reason I'm reinventing the wheel is because I want the forum to be a full part of the game aswell.
I just finished my webshop 3 weeks ago, including support for paypal IPN and instant item delivery.
One obvious down side to javascript chatboxes is the lower response time. (You have to refresh the messages)
But i'm looking into how Facebook does it. They know something I don't.. Cause, you don't have to refresh the friend chat, and messages load almost instantly. And I'll figure it out sooner or later.
I suppose if you didn't want to refresh you could just spam the server with XHR's.. but who would want to do that ;D
Facebook uses a javascript event listener to initiate a refresh. Never heard of such a function.
Facebook doesn't use asp.net, they use PHP. So.. I'm trying to figure out what they're using to initiate the refresh.
They're using prototypes fancy listener functions. Just realized facebook doesn't use jquery.
I'm sticking to jquery.ajax.... Mainly because coding javascript around prototype core is... something for those with a professional education...
Code:
var ChannelRebuildReasons={Unknown:0,AsyncError:1,TooLong:2,Refresh:3,RefreshDelay:4,UIRestart:5,NeedSeq:6,PrevFailed:7,IFrameLoadGiveUp:8,IFrameLoadRetry:9,IFrameLoadRetryWorked:10,PageTransitionRetry:11,ChannelUnknown:100,ChannelNoCUser:101,ChannelInvalidCUser:102,ChannelInvalidChanstr:103,ChannelChDistribTimeout:104,ChannelGetChannelOther:105,ChannelNodeShutdown:106,ChannelTermination:107,ChannelUserMismatch:108,ChannelUserMismatchShady:109,ChannelBadXs:110,ChannelSeqNeg:111,ChannelSeqTooBig:112,ChannelSeqTooSmall:113,ChannelUnexpectedJoin:114,ChannelInvalidXsCookie:115};
var CrossDocument={};(function(){CrossDocument.setListener=function(eventHandler){if(window.postMessage){if(window.addEventListener){window.addEventListener('message',eventHandler,false);}else window.onmessage=eventHandler;}else if(document.postMessage)document.addEventListener('message',eventHandler,false);};CrossDocument.mkPostMessage=function(targetWindow,targetDocument,msgHandler){if(window.postMessage){if("object"==typeof window.postMessage){return function(message,origin){targetWindow.postMessage(message,origin);};}else return bind(targetWindow,targetWindow.postMessage);}else if(document.postMessage){return bind(targetDocument,targetDocument.postMessage);}else return bind(targetWindow,msgHandler);};CrossDocument.targetOrigin=function(parent){if(window.postMessage||document.postMessage){var parentLoc=parent.location;var parentHost=parentLoc.hostname;if(parentHost=='facebook.com'||parentHost.substring(parentHost.length-13)=='.facebook.com')return parentLoc.protocol+'//'+parentLoc.host;}else return null;};var _handleMessage=function(msgCallback,msgStr){if(!msgStr||msgStr.charAt(0)!='{')return;var msg=eval('('+msgStr+')');return msgCallback(msg);};CrossDocument.mkEventHandler=function(msgCallback){return function(event){event=event||window.event;var domain=(event.domain||event.origin);if(domain.substring(domain.length-13)!='.facebook.com'&&domain.substring(domain.length-15)!='://facebook.com'&&domain!='facebook.com')return;return _handleMessage(msgCallback,event.data);};};CrossDocument.mkMessageHandler=function(msgCallback){return function(msgStr){return _handleMessage(msgCallback,msgStr);};};})();
Dcode=function(){var a,d={},b={_:'%',A:'%22%3a',B:'%2c%22',C:'%2c%22sb%22%3a1%2c%22t%22%3a%7b%7d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a',D:'%7b%22',E:'%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22blo%22%3a0%2c%22bvt%22%3a',F:'ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1',G:'%2c%22ch%22%3a%7b%22h%22%3a%22channel',H:'%22%2c%22p%22%3a80%2c%22sub%22%3a%5b',I:'%7d%7d',J:'%7b%22v%22%3a2%2c%22time%22%3a1',K:'%2c%22lc%22%3a1%2c%22cvr%22%3a%7b%22r%22%3a1%2c%22ts%22%3a1',L:'%5d%2c%22p%5f',M:'%22%3a0%2c%22',N:'%22%3a%7b%22i%22%3a0%2c%22all%46lids%22%3a%5bnull%5d',O:'0000',P:'%22%3a1',Q:'%7d',R:'%2c%22pt%22%3a0%2c%22vis%22%3a0%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22blo%22%3a0%2c%22bvt%22%3a0%2c%22ct%22%3a0%2c%22sb%22%3a1%2c%22t%22%3a%7b%7d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%7d%2c2bl%22%3a%7b%22ac%22%3a0%2c%22ut',S:'%22%3a%7b%22ol%22%3a%2d1%2c%22exp%22%3a1',T:'fl%22%3a%5b%22%2d1%22%5d%2c%22all%46lids%22%3a%5b%22%2d1%22%5d',U:'ud%22%3a900%2c%22lc%22%3a0%2c%22cvr%22%3a%7b',V:'%2c%22ut%22%3a1',W:'%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls',X:'%2c%22lc%22%3a1%2c%22cvr%22%3a%7b%22r%22%3a0%2e',Y:'%22%3a%7b%22n%22%3a%22%',Z:'%2c%22ud%22%3a'};function c(){var f=[];for(var e in b){d[b[e]]=e;f.push(b[e]);}f.reverse();a=new RegExp(f.join("|"),'g');}return {encode:function(e){c();return encodeURIComponent(e).replace(/([_A-Z])|%../g,function(g,f){return f?'%'+f.charCodeAt(0).toString(16):g;}).toLowerCase().replace(a,function(f){return d[f];});},decode:function(e){return decodeURIComponent(e.replace(/[_A-Z]/g,function(f){return b[f];}));}};}();
function CookieManager(b,a){this.version=b;this.cookieName='presence';this.dictEncode=a;this.storers={};}CookieManager.prototype={register:function(b,a){this.storers[b]=a;},store:function(){var a=this._getCookie();if(a&&a.v&&this.version<a.v){presence.versionShutdown();return;}var b={v:this.version,time:parseInt(presence.getTime()*.001)};for(var d in this.storers)b[d]=this.storers[d]();var c=JSON.encode(b);if(this.dictEncode)c='D'+Dcode.encode(c);setCookie(this.cookieName,c,null);},clear:function(){clearCookie(this.cookieName);},_getCookie:function(){try{var data=getCookie(this.cookieName);if(this.lastD===data){return this.lastV;}else{this.lastD=data;this.lastV=null;}if(data&&data.charAt(0)=='D')data=Dcode.decode(data.substring(1));if(data)return this.lastV=JSON.decode(data);}catch(a){}return null;},getSubCookie:function(b){var a=this._getCookie();if(!a)return null;return a[b];}};
function rand32(){return Math.floor(Math.random()*4294967295);}function verifyNumber(a){if(typeof a=='undefined'||isNaN(a)||a==Number.POSITIVE_INFINITY||a==Number.NEGATIVE_INFINITY)a=0;return a;}
PresenceMessage={STARTED:'presence/started',SHUTDOWN:'presence/shutdown',RESTARTED:'presence/restarted',WINDOW_RESIZED:'presence/window-resized',TAB_CLOSED:'presence/tab-closed',TAB_OPENED:'presence/tab-opened',PRESENCE_UPDATER_READY:'presence/updater-ready',getAppMessageType:function(a,b){return 'presence/app_message:'+a+':'+b;},getArbiterMessageType:function(a){return 'presence/message:'+a;}};
function TinyPresence(g,c,b,a,e,d,f){this.user=g;this.name=c;this.firstName=b;this.alias=a;this.sitevars=f;this.popoutURL=env_get('www_base')+'presence/popout.php';this.updateServerTime(e);this.pageLoadTime=this.getTime();this._init(d);}TinyPresence.prototype={cookiePollTime:2000,popoutHeartbeatTime:1000,popoutHeartbeatAllowance:4000,popoutHeartbeatFirstAllowance:15000,shutdownDelay:5000,restartDelay:3000,POPOUT_TYPE_NONE:0,POPOUT_TYPE_CHAT:1,_init:function(a){this.stateStorers=[];this.stateLoaders=[];this.windowID=rand32()+1;this.cookiePoller=null;this.heartbeat=null;this.stateUpdateTime=0;this.loaded=false;this.isShutdown=false;this.isShuttingDown=false;this.isRestarting=false;this.isPermaShutdown=false;this.shutdownTime=0;this.justPoppedOut=false;this.syncPaused=0;this.inPopoutWindow=a==this.POPOUT_TYPE_CHAT;this.poppedOut=this.inPopoutWindow;presenceCookieManager.register('state',this._getCookieData.bind(this));Arbiter.subscribe("page_transition",this.checkRebuild.bind(this));this.load();},updateServerTime:function(a){this.timeSkew=new Date().getTime()-a;},getTime:function(){return new Date().getTime()-this.timeSkew;},debug:function(a){},warn:function(a){this.logError("13003:warning:"+a);},error:function(a){this.logError("13002:error:"+a);},logError:function(a){if(window.send_error_signal)send_error_signal("presence",a);},load:function(){var b=presenceCookieManager.getSubCookie('state');if(!b){this.debug('presence: got null state cookie, loading with current state');this._load(this._getCookieData());return;}try{this._load(b);}catch(a){this.error('presence: got load exception: '+a.toString());this._load(this._getCookieData());}},_load:function(b){this.syncPaused++;this.stateUpdateTime=verifyNumber(b.ut);this.popoutTime=verifyNumber(b.pt);this.poppedOut=!!b.p;if(this.poppedOut){if(this.inPopoutWindow)if(!this.heartbeat)this.heartbeat=setInterval(this._popoutHeartbeat.bind(this),this.popoutHeartbeatTime);}else if(this.inPopoutWindow){if(!this.loaded){this.poppedOut=true;this.doSync();}}else this.justPoppedOut=true;if(!this.inPopoutWindow&&!this.cookiePoller)this.cookiePoller=setInterval(this._pollCookie.bind(this),this.cookiePollTime);this.state=b;for(var a=0;a<this.stateLoaders.length;a++)this.stateLoaders[a](b);this.syncPaused--;this._loaded();},_loaded:function(){this.loaded=true;},_pollCookie:function(){var e=presenceCookieManager.getSubCookie('state');if(!e)return;var d=this.popoutTime;if(e.ut>this.stateUpdateTime){this.load(e);return;}if(this.poppedOut&&!this.inPopoutWindow){var a=verifyNumber(e.pt);var b=new Date().getTime()-a;var c=this.popoutHeartbeatTime+this.popoutHeartbeatAllowance;if(this.justPoppedOut)if(a==d){c+=this.popoutHeartbeatFirstAllowance;}else this.justPoppedOut=false;this.popoutTime=a;if(b>c){this.poppedOut=false;this.doSync();}}},_popoutHeartbeat:function(){this._pollCookie();if(this.poppedOut)presenceCookieManager.store();},_getCookieData:function(){var b={p:this.poppedOut?1:0,ut:this.stateUpdateTime,pt:this.inPopoutWindow?new Date().getTime():this.popoutTime};for(var a=0;a<this.stateStorers.length;a++)b=this.stateStorers[a](b);this.state=b;return this.state;},doSync:function(a){if(this.syncPaused)return;if(a){this._doSync();}else this._doSync.bind(this).defer();},_doSync:function(){this.stateUpdateTime=new Date().getTime();presenceCookieManager.store();this._load(this.state);},pauseSync:function(){this.syncPaused++;},resumeSync:function(){this.syncPaused--;this.doSync();},handleMsg:function(a,b){this._handleMsg.bind(this,a,b).defer();},_handleMsg:function(a,b){if(typeof b=='string'){if(b=='shutdown'){this.connectionShutdown();}else if(b=='restart')if(this.isShutdown)this.restart();return;}if(this.isShutdown)return false;if(!b.type)return;Arbiter.inform(PresenceMessage.getArbiterMessageType(b.type),{sender:this,channel:a,obj:b});},checkRebuild:function(){if(this.isShutdown&&!this.isPermaShutdown)channelManager.rebuild(ChannelRebuildReasons.PageTransitionRetry);},getErrorDescription:function(a){var c=a.getError();var b=a.getErrorDescription();if(!b)b=_tx("An error occurred.");if(c==1357001)b=_tx("Your session has timed out. Please log in.");return b;},checkLoginError:function(a){var b=a.getError();if(b==1357001||b==1357004||b==1348009){this.loginShutdown();return true;}return false;},checkMaintenanceError:function(a){if(a.getError()==1356007){this.maintenanceShutdown();return true;}return false;},permaShutdown:function(){this.isPermaShutdown=true;var a=_tx("Facebook {Chat} is experiencing technical problems.",{Chat:_tx("Chat")});this.shutdown(false,a,"perma_shutdown");},loginShutdown:function(){var a=_tx("Your session has timed out. Please log in.");this.shutdown(false,a,"login_shutdown");},connectionShutdown:function(b){var a=_tx("Could not connect to Facebook {Chat} at this time.",{Chat:_tx("Chat")});this.shutdown(b,a,"connection_shutdown");},maintenanceShutdown:function(){var a=_tx("Facebook {Chat} is down for maintenance at this time.",{Chat:_tx("Chat")});this.shutdown(false,a,"maintenance_shutdown");channelManager.stop();},versionShutdown:function(){var a=_tx("Please refresh the page to get the latest version of Facebook {Chat}.",{Chat:_tx("Chat")});this.shutdown(false,a,"version_shutdown");channelManager.stop();},shutdown:function(d,c,a){this.isRestarting=false;this.isShuttingDown=true;var b=new Date().getTime();this.shutdownTime=b;if(!d){this._shutdown(c,0,a);}else setTimeout(this._shutdown.bind(this,c,b,a),this.shutdownDelay);},_shutdown:function(b,c,a){if(!this.isShuttingDown&&c==this.shutdownTime)return;if(c&&this.isShutdown)return;if(typeof b!='string'||!b)b=_tx("Facebook {Chat} is experiencing technical problems.",{Chat:_tx("Chat")});if(typeof a!='string'||!a)a="undefined";this.warn("presence:displaying_shutdown:"+a);if(this.isShutdown)return;this.logError("13001:shutdown:presence:"+a);this.isShutdown=true;Arbiter.inform(PresenceMessage.SHUTDOWN,{sender:this});},restart:function(a){this.isShuttingDown=false;this.isRestarting=true;if(!a){this._restart(0);}else this._restart.bind(this,this.shutdownTime).defer(this.restartDelay);},_restart:function(a){if(!this.isRestarting||(a&&a!=this.shutdownTime))return;this.debug("presence: restarting");this.isShutdown=false;this.load();Arbiter.inform(PresenceMessage.RESTARTED,{sender:this});},start:function(){Arbiter.inform(PresenceMessage.STARTED,{sender:this});},registerStateStorer:function(a){this.stateStorers.push(a);},registerStateLoader:function(a){this.stateLoaders.push(a);},hasUserCookie:function(){var a=this.user==getCookie('c_user');if(!a)this.permaShutdown();return a;}};
function ChannelManager(b,f,e,a,d,c){this.user=f;this.iframeCheckTime=15000;this.iframeCheckRetryTime=15000;this.iframeLoadMaxRetries=1;this.expectResponseTimeout=5000;this.retryInterval=e;this.channelConfig=a;this._init(b,d);this.loginErrorGk=c;}ChannelManager.prototype={_init:function(c,d){this.channelManagerId=rand32();this.channel={name:null,iframeHost:null,iframePort:null,iframePath:null};this.isActionRequest=true;this.isReady=false;this.isRebuilding=false;this.iframeIsLoaded=false;this.iframeEverLoaded=false;this.iframeCheckFailedCount=0;this.permaShutdown=false;this.shouldClearSubdomain=false;this.subframe=c;this.postMessage=null;var a=presenceCookieManager.getSubCookie('ch');if(d){this.iframeSubdomain=null;}else{this.iframeSubdomain=0;if(a&&a.sub){for(var b=0;b<a.sub.length;b++)if(!a.sub[b]){this.iframeSubdomain=b;break;}if(b==a.sub.length)this.iframeSubdomain=a.sub.length;}}var e=ua.safari();this.pollForMessages=(e>523&&e<525);this.useRandomSubdomain=!!ua.ie();this.handleIframeEvent=CrossDocument.mkEventHandler(this._handleIframeMessage.bind(this));this.handleIframeMessage=CrossDocument.mkMessageHandler(this._handleIframeMessage.bind(this));CrossDocument.setListener(this.handleIframeEvent.bind(this));presenceCookieManager.register('ch',this._getCookieInfo.bind(this));if(typeof window.onpageshow!='undefined'){Event.listen(window,'pagehide',this._onUnload.bind(this));Event.listen(window,'pageshow',this.rebuild.bind(this,ChannelRebuildReasons.Refresh));}else onunloadRegister(this._onUnload.bind(this));},sendIframeMessage:function(b){if(!this.postMessage)return;var c=JSON.encode(b);try{this.postMessage(c,this.targetOrigin);}catch(a){presence.error('channel: iframe msg error: '+'message "'+c+'" and error '+a.toString());}},_handleIframeMessage:function(a){if(a.type=='init'){this.iframeLoaded();}else if(a.type=='channelMsg'){this.handleChannelMsg(a.channel,a.msg);}else if(a.type=='log')window.chatErrorLog&&window.chatErrorLog.log(a.msg);},_onUnload:function(){this.shouldClearSubdomain=true;presence.doSync(true);},addChannel:function(a,d,b,f,e,c){if(this.channel.name!==null){presence.error("channel: addChannel called twice");return;}this.channel.name=a;this.channel.currentSeq=d;this.channel.msgHandler=b;this.channel.startHandler=f;this.channel.shutdownHandler=e;this.channel.restartHandler=c;},_getCookieInfo:function(){var b={};if(this.channel.iframeHost&&this.channel.iframePort){b.h=this.channel.iframeHost;b.p=this.channel.iframePort;if(null!==this.iframeSubdomain){var a=presenceCookieManager.getSubCookie('ch');var e=(a&&a.sub)?a.sub:[];var d=e.length;if(this.shouldClearSubdomain){e[this.iframeSubdomain]=0;}else{e[this.iframeSubdomain]=1;for(var c=d;c<=this.iframeSubdomain;c++)if(!e[c])e[c]=0;}b.sub=e;}b[this.channel.name]=this.channel.currentSeq;}b.ri=this.retryInterval;return b;},stop:function(){this.stopped=true;this.setReady(false);},setReady:function(a){this.isReady=a;var b={type:'isReady',isReady:a,isActionRequest:this.isActionRequest};if(a&&this.isActionRequest)this.isActionRequest=false;if(a){b.channelName=this.channel.name;b.currentSeq=this.channel.currentSeq;b.channelManagerId=this.channelManagerId;b.channelConfig=this.channelConfig;}this.sendIframeMessage(b);},setActionRequest:function(a){this.sendIframeMessage({type:'isActionRequest',isActionRequest:a});},expectResponse:function(){this.sendIframeMessage({type:'expectResponse',newTimeout:this.expectResponseTimeout});},_iframeUrl:function(a,c,b){var d;if(null===this.iframeSubdomain){d='';}else{d=this.iframeSubdomain;if(this.useRandomSubdomain)d+=''+rand32();d+='.';}return 'http://'+d+a+'.facebook.com:'+c+b;},iframeLoad:function(d,b,e,c){this.isReady=c;this.iframeIsLoaded=false;this.channel.iframePath=d;this.channel.iframeHost=b;this.channel.iframePort=e;var g=this._iframeUrl(b,e,d);this._iframeCheck.bind(this).defer(this.iframeCheckTime);var f=null;if(!ua.ie()||ua.ie()<8)try{f=this.subframe.contentDocument;}catch(a){}if(f){try{f.location.replace(g);}catch(a){presence.error('channel: error setting location: '+a.toString());}}else if(this.subframe.contentWindow){this.subframe.src=g;}else if(this.subframe.document){this.subframe.src=g;}else presence.error('channel: error setting subframe url');presence.debug('channel: done with iframeLoad, subframe sent to '+g);},iframeLoaded:function(){if(!this.iframeIsLoaded){this.iframeIsLoaded=true;this.postMessage=CrossDocument.mkPostMessage(this.subframe.contentWindow,this.subframe.contentDocument,this.subframe.contentWindow.channelUplink.handleParentMessage);this.targetOrigin="*";this.setReady(this.isReady);if(this.pollForMessages)this.msgCheckInterval=setInterval(this.handleChannelMsgCheck.bind(this),100);if(this.iframeCheckFailedCount){this.channel.restartHandler(false);this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadRetryWorked);}else this.channel.startHandler();this.iframeCheckFailedCount=0;this.iframeEverLoaded=true;}},_iframeCheck:function(){if(!this.iframeIsLoaded){presence.error("channel: uplink iframe never loaded: shutting down ("+this.channel.iframeHost+":"+this.channel.iframePort+")");this.iframeCheckFailedCount++;this.channel.iframeHost=this.channel.iframePort=this.channel.iframePath=0;presenceCookieManager.store();if(this.iframeCheckFailedCount<=this.iframeLoadMaxRetries){this.iframeCheckTime=this.iframeCheckRetryTime;this.channel.iframePath=null;this.rebuild(ChannelRebuildReasons.IFrameLoadRetry);}else{this.channel.shutdownHandler();this._sendDummyReconnect(ChannelRebuildReasons.IFrameLoadGiveUp);}}else this.retryInterval=0;},_sendDummyReconnect:function(b){var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setOption('suppressErrorHandlerWarning',true).setMethod('GET').setReadOnly(true).setAllowCrossPageTransition(true);a.specifiesWriteRequiredParams()&&a.send();},_rebuildResponse:function(c){var b=c.getPayload();var a=b.user_channel;presence.debug('got rebuild response with channel '+a+', seq '+b.seq+', host '+b.host+', port '+b.port);this.channel.currentSeq=b.seq;this.isRebuilding=false;if(b.path!=this.channel.iframePath||b.host!=this.channel.iframeHost||b.port!=this.channel.iframePort){this.iframeLoad(b.path,b.host,b.port,true);}else this.setReady(true);presenceCookieManager.store();presenceUpdater.pauseUpdate();if(typeof chatOptions!='undefined')chatOptions.setVisibility(b.visibility);this.channel.restartHandler(true);presenceUpdater.resumeUpdate(['buddy_list']);},_retryRebuild:function(c,a){if(a){this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;}else if(this.retryInterval==0){this.retryInterval=this.channelConfig.MIN_RETRY_INTERVAL;}else{this.retryInterval*=2;if(this.retryInterval>=this.channelConfig.MAX_RETRY_INTERVAL)this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;}var b=this.retryInterval*(.75+Math.random()*.5);presence.warn('channel: retry: manager trying again in '+(b*.001)+' secs');setTimeout(this._rebuildSend.bind(this,c),this.retryInterval);},_rebuildError:function(a,b){this.channel.shutdownHandler(true);presence.error('channel: got rebuild error: '+b.getErrorDescription());if(presence.checkMaintenanceError(b)){presence.warn('channel: manager not trying again');}else if(presence.checkLoginError(b)){if(presence.inPopoutWindow||this.loginErrorGk){this._retryRebuild(ChannelRebuildReasons.PrevFailed,true);}else presence.warn('channel: manager not trying again');}else this._retryRebuild(ChannelRebuildReasons.PrevFailed,false);},_rebuildTransportError:function(a,b){this.channel.shutdownHandler(true);presence.error('channel: got rebuild transport error: '+b.getErrorDescription());this._retryRebuild(a,false);},_rebuildSend:function(b){if(!presence.hasUserCookie())return;if(typeof b!='number')b=ChannelRebuildReasons.Unknown;presence.debug('channel: sending rebuild');var a=new AsyncRequest().setURI('/ajax/presence/reconnect.php').setData({reason:b,iframe_loaded:this.iframeEverLoaded}).setHandler(this._rebuildResponse.bind(this)).setErrorHandler(this._rebuildError.bind(this,b)).setTransportErrorHandler(this._rebuildTransportError.bind(this,b)).setOption('suppressErrorAlerts',true).setMethod('GET').setReadOnly(true).setAllowCrossPageTransition(true);return a.specifiesWriteRequiredParams()&&a.send();},rebuild:function(a){if(this.stopped)return;if(this.isRebuilding){presence.debug('channel: rebuild called, but already rebuilding');return;}this.setReady(false);this.isRebuilding=true;presence.debug('channel: rebuilding');if(a==ChannelRebuildReasons.RefreshDelay)this.retryInterval=this.channelConfig.MAX_RETRY_INTERVAL;setTimeout(this._rebuildSend.bind(this,a),this.retryInterval);},handleChannelMsgCheck:function(){if(this.pendingMsg){this._handleChannelMsg(this.pendingMsg.channel,this.pendingMsg.seq,this.pendingMsg.msg);this.pendingMsg=null;}},handleChannelMsg:function(a,b){if(this.pollForMessages){this.pendingMsg={channel:a,msg:b};}else this._handleChannelMsg(a,b);},_handleChannelMsg:function(a,c){if(c.type=='seq'){presence.pauseSync();this.channel.currentSeq=c.Seq;presence.resumeSync();}else if(c.type=='shutdown'||c.type=='permaShutdown'){if(!window.loaded||this.permaShutdown)return;if(c.type=='permaShutdown'){presence.error('channel:permaShutdown');this.permaShutdown=true;}else{presence.error('channel:refresh_'+c.reason);this.rebuild(c.reason);}this.channel.shutdownHandler(true);}else if(c.type=='fullReload'){presence.error('channel:fullReload');presenceCookieManager.clear();window.location.reload(true);}else try{this.channel.msgHandler(a,c);}catch(b){presence.error('channel: error in channel handlers: '+b.toString()+', msg: '+c);}}};
function Presence(g,c,b,a,e,d,f){this.parent.construct(this,g,c,b,a,e,d,f);}Presence.extend('TinyPresence');Presence.prototype={minWidth:100,minHeight:100,defWidth:900,defHeight:650,defX:30,defY:30,_init:function(b){if(b!==this.POPOUT_TYPE_CHAT){this.holder=$('fbDockChat');}else{this.holder=$('presence');this.popoutSidebar=ge('presence_popout_sidebar');}this.parent._init(b);this.popoutWidth=this.defWidth;this.popoutHeight=this.defHeight;this.popoutClicked=false;this.popinClicked=false;if(this.inPopoutWindow){Util.fallbackErrorHandler=null;onbeforeunloadRegister(this.popin.bind(this,false));onunloadRegister(this.popin.bind(this,false));}if(this.inPopoutWindow){Event.listen(window,'resize',this._windowOnResize.bind(this));Event.listen(window,'keypress',this._documentKeyPress.bind(this));}var c=ua.safari();this.isSafari2=(c&&c<500);this.isOpera=(ua.opera()>0);var a=ua.firefox();this.isFF2=(a&&a<3);this.isWindows=ua.windows();if(this.inPopoutWindow){this._windowOnResize.bind(this).defer();setTimeout(this._windowOnResize.bind(this),3000);}},_load:function(a){this.parent._load(a);if(this.poppedOut){if(!this.inPopoutWindow)CSS.addClass(this.holder,'popped_out');}else{if(this.inPopoutWindow)if(this.loaded)if(!this.popinClicked)window.close();CSS.removeClass(this.holder,'popped_out');}if(this.inPopoutWindow){this._handleResize.bind(this,0,0).defer();setTimeout(this._handleResize.bind(this,0,0),100);}this.parent._loaded();},_loaded:bagofholding,_handleMsg:function(a,b){this.parent._handleMsg(a,b);if(typeof b=='string'||!b.type)return;if(this.isShutdown)return false;if(b.type=='app_msg')if(b.event_name=='beep_event'){Bootloader.loadComponents('beeper',function(){Beeper.ensureInitialized();LiveMessageReceiver.route(b);});}else LiveMessageReceiver.route(b);},popout:function(){if(this.inPopoutWindow||this.poppedOut){this.popin(true);return;}if(this.popoutClicked)return;this.popoutClicked=true;var a=window.open(this.popoutURL,"fbChatWindow","status=0,toolbar=0,location=0,menubar=0,"+"directories=0,resizable=1,scrollbars=0,"+"width="+this.popoutWidth+",height="+this.popoutHeight+","+"left="+this.defX+",top="+this.defY);CSS.removeClass(this.holder,'popped_out');this.poppedOut=true;this.justPoppedOut=true;this.popoutTime=(new Date()).getTime();this.doSync();this.popoutClicked=false;},popin:function(a){if(typeof a=='undefined')a=true;if(this.inPopoutWindow){if(this.popinClicked)return;this.popinClicked=true;}this.poppedOut=false;this.doSync();if(this.inPopoutWindow&&a)window.close();},_windowOnResize:function(){if(!this.inPopoutWindow)return;this.contentResized={};var a=Vector2.getViewportDimensions();this._handleResize(a.x-this.virtPopoutWidth,a.y-this.virtPopoutHeight);if(this.inPopoutWindow)this.popoutHeight=a.y;},_handleResize:function(b,c){var a=this.loaded?100:10;if(this.handleResizeTimer)clearTimeout(this.handleResizeTimer);this.handleResizeTimer=setTimeout(function(){this.virtPopoutWidth+=b;this.virtPopoutHeight+=c;this.popoutWidth=Math.max(this.virtPopoutWidth,this.minWidth);this.popoutHeight=Math.max(this.virtPopoutHeight,this.minHeight);Arbiter.inform(PresenceMessage.WINDOW_RESIZED,{sender:this});},a);},_documentKeyPress:function(a){if(!this.inPopoutWindow)return;a=$E(a);var b=a?a.keyCode:-1;if(b==KEYS.ESC)Event.kill(a);},renderLink:function(b,c,a){return '<a href="'+b+'"'+(this.inPopoutWindow?' target="_blank"':'')+(a?a:'')+'>'+c+'</a>';},_shutdown:function(c,d,b){this.parent._shutdown(c,d,b);if((!this.isShuttingDown&&d===this.shutdownTime)||(d&&this.isShutdown))return;if(!this.inPopoutWindow){if(window.chatOptions&&chatOptions.visibility)CSS.addClass(this.holder,'presence_error');var a=$('fbChatErrorNub');TooltipLink.setTooltipText(DOM.find(a,'a.fbNubButton'),c);}else{if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();this.shutdownErrorDialog=ErrorDialog.show(_tx("Facebook Chat Error"),c);}},_restart:function(a){this.parent._restart(a);if(!this.isRestarting||(a&&a!=this.shutdownTime))return;if(!this.inPopoutWindow){CSS.removeClass(this.holder,'presence_error');}else if(this.shutdownErrorDialog)this.shutdownErrorDialog.hide();},isOnline:function(){return this.state&&this.state.vis;}};function getFirstName(c){var d=c.split(" ");var b=d[0];var a=b.length;if(typeof d[1]!='undefined'&&(a==1||(a==2&&b.indexOf('.')!=-1)||(a==3&&b.toLowerCase()=='the')))b+=' '+d[1];return b;}
function LiveMessageReceiver(a){this.eventName=a;this.subs=null;this.handler=bagofholding;this.shutdownHandler=null;this.restartHandler=null;this.registered=false;this.appId=1;}LiveMessageReceiver.prototype.setAppId=function(a){this.appId=a;return this;};LiveMessageReceiver.prototype.setHandler=function(a){this.handler=a;this._dirty();return this;};LiveMessageReceiver.prototype.setRestartHandler=function(a){this.restartHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype.setShutdownHandler=function(a){this.shutdownHandler=a.shield();this._dirty();return this;};LiveMessageReceiver.prototype._dirty=function(){if(this.registered){this.unregister();this.register();}};LiveMessageReceiver.prototype.register=function(){var b=function(d,c){return this.handler(c);}.bind(this);var a=PresenceMessage.getAppMessageType(this.appId,this.eventName);this.subs={};this.subs.main=Arbiter.subscribe(a,b);if(this.shutdownHandler)this.subs.shut=Arbiter.subscribe(PresenceMessage.SHUTDOWN,this.shutdownHandler);if(this.restartHandler)this.subs.restart=Arbiter.subscribe(PresenceMessage.RESTARTED,this.restartHandler);this.registered=true;return this;};LiveMessageReceiver.prototype.unregister=function(){if(!this.subs)return this;for(var a in this.subs)if(this.subs[a])Arbiter.unsubscribe(this.subs[a]);this.subs=null;this.registered=false;return this;};LiveMessageReceiver.route=function(b){var a=function(c){var d=PresenceMessage.getAppMessageType(b.app_id,b.event_name);Arbiter.inform(d,c,Arbiter.BEHAVIOR_PERSISTENT);};if(b.hasCapture){new AsyncRequest().setHandler(function(c){a(c.getPayload());}).setAllowCrossPageTransition(true).handleResponse(b.response);}else a(b.response);};
function PresenceUpdater(){this.timerGranularity=presence.sitevars.UPDATE_GRANULARITY?presence.sitevars.UPDATE_GRANULARITY*1000:60000;this._init();}PresenceUpdater.prototype={_init:function(){this.handlers=[];this.updatePaused=0;this.updateNumber=0;this._runTimer();bind(Arbiter,Arbiter.inform,PresenceMessage.PRESENCE_UPDATER_READY,true,Arbiter.BEHAVIOR_STATE).defer();},register:function(a,b,d,c,e){this.handlers.push({asyncParam:a,checkCB:b,responseCB:d,errorCB:c,transportErrorCB:e});},_runTimer:function(){clearTimeout(this.timer);this.timer=setTimeout(this.checkForUpdate.bind(this,false,[],false),this.timerGranularity);},forceUpdate:function(a){if(this.updatePaused)return;if(a!==undefined&&a.length>0){this.checkForUpdate(false,a,false);}else this.checkForUpdate(true,[],false);},pauseUpdate:function(){this.updatePaused++;},resumeUpdate:function(a){this.updatePaused--;this.forceUpdate(a);},checkForUpdate:function(d,e,c){if(!c)clearTimeout(this.timer);if(presence.isShutdown){if(!c)this._runTimer();return;}var j=presence.getTime();var b=[];var a={user:presence.user};for(var h=0;h<this.handlers.length;h++){var g=this.handlers[h];var f=d||(e.indexOf(g.asyncParam)!=-1);var i=g.checkCB(j,a,f);if(i){a[g.asyncParam]=1;b.push(g);}}if(b.length>0){this._sendUpdate(a,b,c);}else if(!c)this._runTimer();},runHandler:function(a){this.checkForUpdate(false,[a],true);},_initialHandler:function(b,a){if(b!=this.updateNumber)return false;},_onResponse:function(a,b,f){var g=f.getPayload();presence.updateServerTime(g.time);var h=presence.getTime();for(var d=0;d<a.length;d++){var c=a[d];var e=g[c.asyncParam];if(typeof e=='undefined'||!e){c.errorCB(f);}else c.responseCB(e,h);}presenceCookieManager.store();if(!b)this._runTimer();},_onError:function(a,c){for(var b=0;b<a.length;b++)a[b].errorCB(c);this._runTimer();},_onTransportError:function(a,c){for(var b=0;b<a.length;b++)a[b].transportErrorCB(c);this._runTimer();},_sendUpdate:function(a,b,c){if(!presence.hasUserCookie())return;this.updateNumber++;var f=a.notifications?'/ajax/presence/update.php':'/ajax/chat/buddy_list.php';var e=URI.getRequestURI().getQueryData();var d={};for(key in e)if(key.indexOf('buddy')==0)d[key]=e[key];if(d)f=new URI(f).setQueryData(d);this.async=new AsyncRequest().setInitialHandler(this._initialHandler.bind(this,this.updateNumber)).setHandler(this._onResponse.bind(this,b,c)).setErrorHandler(this._onError.bind(this,b)).setTransportErrorHandler(this._onTransportError.bind(this,b)).setOption('suppressErrorAlerts',true).setData(a).setURI(f).setAllowCrossPageTransition(true).send();}};