📄 chatmanager.as
字号:
function ChatManager(settings) { this.settings = settings; this.enableSocketServer = settings.enableSocketServer; if(this.enableSocketServer) { this.socketServer = new socketServer(settings.socketServer.host, settings.socketServer.port, this); this.socketServer.setManageIncomingHandler( this, 'onLoad'); this.socketServer.doConnect(); } this.connid = 0; this.userid = 0; this.user_role = 0; this.user_gender = ''; this.ui = null; this.currMessageID = 0; this.interval = null; this.intervalTime = this.settings.msgRequestInterval * 1000;};ChatManager.prototype.debug = function(msg) { return; var str = 'ChatManager (connid:' + this.connid + ', userid:' + this.userid + ', currMessageID:' + this.currMessageID + '):' + msg; trace('str >>> ' + str);};ChatManager.prototype.enableAutopoll = function(enabled) { if(this.enableSocketServer) { /* if( this.socketServer.incommings.length >= 1) { var xml = this.socketServer.incommings[0]; this.onLoad( true, xml ); } */ } else if(enabled) { if(this.interval) clearInterval(this.interval); this.interval = setInterval(this, 'loadMessages', this.intervalTime); } else { if(this.interval) clearInterval(this.interval); this.interval = null; }};ChatManager.prototype.setUI = function(ui) { this.ui = ui; var initialSkin = this.settings.skin.preset[this.settings.skin.defaultSkin].clone(); var initialBigSkin = this.settings.bigSkin.preset[this.settings.bigSkin.defaultSkin].clone(); var initialText = new Object(); for(var itm in this.settings.text.itemToChange) { initialText[itm] = new Object(); initialText[itm].size = this.settings.text.itemToChange[itm].fontSize; initialText[itm].font = this.settings.text.itemToChange[itm].fontFamily; initialText[itm].presence = this.settings.text.itemToChange[itm].presence; } _global.FlashChatNS.DefaultSkin = initialBigSkin.swf_name; //initialSkin.backgroundImage = null; //initialSkin.dialogBackgroundImage = null; this.ui.setInitialBigSkin(initialBigSkin); this.ui.setInitialSkin(initialSkin); this.ui.setInitialText(initialText); this.ui.setLanguages(this.settings.languages); this.ui.setInitialLanguageId(this.settings.defaultLanguage); this.ui.firstInit = true;};ChatManager.prototype.getRequester = function() { var req = this.enableSocketServer? new Object() : new XMLRequester(); req.id = this.connid; req.c = 'msgl'; req.b = this.currMessageID + 1; return req;};ChatManager.prototype.sendAndLoad = function(req) { if(this.userid || req.c == 'lin' || req.c == 'tzset') { if( this.enableSocketServer ) { this.socketServer.sendRequest( req ); } else { req.sendAndLoad(_root.documentRoot + 'getxml.php', this, 'POST'); this.enableAutopoll(false); } }};ChatManager.prototype.onLoad = function(succ, xmlResponse) { var startPoller = true; this.debug(xmlResponse.toString()); if(this.settings.debug) { if(!this.logger) this.logger = new LocalConnection(); this.logger.send('logger', 'log', xmlResponse.toString()); } if(succ) { if(xmlResponse.childNodes[0].nodeType == 1 && xmlResponse.childNodes[0].nodeName == 'response') { var response = xmlResponse.childNodes[0]; if(this.connid != response.attributes.id) { this.connid = response.attributes.id; } for(var i = 0; i < response.childNodes.length; i++) { var node = response.childNodes[i]; if(node.nodeType == 1) { if(!node.attributes.u) node.attributes.u = 0; if(!node.attributes.r) node.attributes.r = 0; var start = (node.attributes.id != undefined)?Number(node.attributes.id):0; if(start > this.currMessageID || this.enableSocketServer) { this.currMessageID = start; switch(node.nodeName) { case 'error': trace(node.firstChild.nodeValue); this.ui.errorAlert(node.firstChild.nodeValue, node.attributes.u, node.attributes.r); break; case 'lin': if(!this.userid) { this.userid = node.attributes.u; this.user_role = node.attributes.rs; this.user_gender = node.attributes.gn; this.ui.loggedin(this.userid, this.user_role, this.user_gender); for (var j = 0; j < this.settings.layouts.length; j ++) { if (this.settings.layouts[j].role == node.attributes.r) { this.settings.layout = this.settings.layouts[j]; break; } } this.ui.setSettings(this.settings); } getURL("javascript:setConnid('" + this.connid + "');void(0);"); break; case 'lout': this.userid = 0; this.ui.loggedout(node.firstChild.nodeValue); startPoller = false; break; case 'lng': var langini = new XML(node.firstChild.nodeValue); var lang = new CLanguage(); lang.init(langini.firstChild); this.ui.setLanguage(lang); break; case 'glng': var langini = new XML(node.firstChild.nodeValue); var lang = new CLanguage(); lang.init(langini.firstChild); this.ui.applyLanguage(lang, true); break; case 'adr': this.ui.roomAdded(node.attributes.r, node.firstChild.nodeValue); break; case 'srl': this.ui.setRoomLock(node.attributes.r, Boolean(node.firstChild.nodeValue)); break; case 'nadr': this.ui.notCreated(node.firstChild.nodeValue); break; case 'rmr': this.ui.removeRoom(node.attributes.r); break; case 'adu': var usr_name = replaceHTMLSpecChars( node.firstChild.nodeValue ); this.ui.userAdded(node.attributes.u, usr_name, node.attributes.r, null, null, node.attributes.t, Number(node.attributes.rs), node.attributes.gn); break; case 'rmu': this.ui.userRemoved(node.attributes.u, node.attributes.t); trace('Remove user: ' + node.attributes.u + ' t ' + node.attributes.t); break; case 'mvu': //here goes a dirty hack!!! if(this.settings.layout.role == 8) break; this.ui.userMovedTo(node.attributes.u, node.attributes.r, node.attributes.t); break; case 'msgu': this.ui.messageAddedTo(node.attributes.u, node.attributes.a, node.attributes.r, node.firstChild.nodeValue, node.attributes.l, 'isUrgent', node.attributes.t); break; case 'msgb': case 'msg': this.ui.messageAddedTo(node.attributes.u, node.attributes.a, node.attributes.r, node.firstChild.nodeValue, node.attributes.l, '', node.attributes.t); break; case 'invu': this.ui.invitedTo(node.attributes.u, node.attributes.r, node.firstChild.nodeValue); break; case 'inva': this.ui.invitationAccepted(node.attributes.u, node.attributes.r, node.firstChild.nodeValue); break; case 'invd': this.ui.invitationDeclined(node.attributes.u, node.attributes.r, node.firstChild.nodeValue); break; case 'ignu': //here goes a dirty hack!!! if(node.attributes.a == undefined) { node.attributes.a = node.attributes.u; node.attributes.u = this.userid; } this.ui.ignored(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'nignu': this.ui.unignored(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'banu': this.ui.banned(node.attributes.u, node.attributes.a, node.attributes.r, node.firstChild.nodeValue); break; case 'nbanu': this.ui.unbanned(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'ustc': state = Number(node.firstChild.nodeValue); this.intervalTime = ((state == ChatUI.prototype.USER_STATE_AWAY) ? this.settings.msgRequestIntervalAway : this.settings.msgRequestInterval) * 1000; this.ui.userStateChanged(node.attributes.u, state); break; case 'uclc': this.ui.userColorChanged(node.attributes.u, Number(node.firstChild.nodeValue)); break; case 'usrp': //this.ui.setUserProfileText(node.attributes.u, node.firstChild.nodeValue); _root.createEmptyMovieClip('profiler', 90); _root.profiler.flashchatid = this.connid; _root.profiler.getURL(node.firstChild.nodeValue, '_blank', 'POST'); break; case 'help': this.ui.setHelpText(node.firstChild.nodeValue); break; case 'rang': //here goes a dirty hack!!! if(this.settings.layout.role == 8 && this.userid != node.attributes.u) break; this.ui.bellRang(node.attributes.u, node.attributes.t); break; case 'back': this.ui.back(node.attributes.r); break; case 'backt': this.ui.backtime(node.attributes.r); break; case 'alrt': this.ui.alert(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'ralrt': this.ui.roomAlert(node.attributes.u, node.firstChild.nodeValue); break; case 'calrt': this.ui.chatAlert(node.attributes.u, node.firstChild.nodeValue); break; case 'gag': this.ui.gag(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'ngag': this.ui.ungagged(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'cfrm': this.ui.confirm(node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'fileshare': //---share if(node.attributes.a == undefined && node.attributes.u == this.ui.selfUserId) { break;//not show window if send to room! } this.ui.fileShare(node.firstChild.nodeValue); break; case 'load_av_bg': this.ui.loadAvatarBG(node.firstChild.nodeValue); break; case 'mavt': case 'ravt': this.ui.setAvatar(node.nodeName, node.attributes.u, node.attributes.a, node.firstChild.nodeValue); break; case 'sgen': this.ui.setGender(node.attributes.u, node.firstChild.nodeValue); break; case 'notf': this.ui.userNotify(node.attributes.u); break; default: this.debug('Unknown response:' + node.toString()); break; } } } } } } //if( this.enableSocketServer ) this.socketServer.incommings.splice(0, 1); this.enableAutopoll(startPoller);}//sendersChatManager.prototype.sendTimeZone = function() { var req = this.getRequester(); req.c = 'tzset'; req.tz = new Date().getTimezoneOffset(); this.sendAndLoad(req);}ChatManager.prototype.loadMessages = function() { this.sendAndLoad(this.getRequester()); /* var req = this.getRequester(); req.c = 'msg'; req.t = "FLOOD test FLOOD test FLOOD test FLOOD test FLOOD test FLOOD test FLOOD test"; this.sendAndLoad(req); */}ChatManager.prototype.login = function(login, password, lang, roomID) { var req = this.getRequester(); req.c = 'lin'; req.lg = login; req.ps = password; req.l = lang; if(roomID != undefined) req.r = roomID; req.tz = new Date().getTimezoneOffset(); this.sendAndLoad(req);};ChatManager.prototype.logout = function() { //this.ui.saveUserSettings(); var req = this.getRequester(); req.c = 'lout'; this.sendAndLoad(req); //implement logout behavior if(this.settings.logout.redirect)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -