⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chat.asc

📁 av clone server flash mx
💻 ASC
字号:
/**
 * itusachat
 * 
 * chat.asc 
 * Moving or modifying this file may affect the applications installed on this server. 
 */

try { var dummy = FCChat; } catch ( e ) { // #ifndef FCChat

	load( "components/component.asc" );

	/**
	 * Chat component class
	 */
	FCChat = function(name) {

		this.init(name);
		
		// Get a non persistent shared object for sending broadcasts
		this.message_so = SharedObject.get( this.prefix + "message", false );
		this.bannedIPs_so = SharedObject.get(this.prefix+"bannedIPs", true);
        this.bannedIPs = this.bannedIPs_so.getProperty("banned");
        if (this.bannedIPs == undefined)
        this.bannedIPs = new Object();

		// If persist is true, then get the history back
		this.history_so = SharedObject.get( this.prefix + "history", true );
		this.history = this.history_so.getProperty( "history" );
		if ( this.history == null )
			this.history = new Array;

	}
	
	// All named instances are held in instances
	FCChat.prototype = new FCComponent("FCChat",FCChat);

	FCChat.prototype.histlen    =9999999999999999;			// Maximum history length
	FCChat.prototype.persist    = true;			// Whether to save history
	FCChat.prototype.allowClear = true;			// Allow clients to clear history

	FCChat.prototype.history    = new Array;	// History
	FCChat.prototype.message_so = null;			// Message broadcasts
	FCChat.prototype.history_so = null;			// History persistence
	
	///////////////////////////////////////////////////////////////////////////
	// onXXX events that are called at appropriate times
	
	// This is called when the application about to stop
	FCChat.prototype.onAppStop = function() {
		if ( this.persist && this.history_so != null ) {
			this.history_so.setProperty( "history", this.history );
			this.history_so.flush();
		}
	}

	// Methods that a client side component calls explicitly
	
	// The first method called by a client component
	FCChat.prototype.connect = function( client ) {
if (this.isBanned(client.ip))
        application.disconnect(client);


		var cglobal = this.getClientGlobalStorage(client);
		
		if (!cglobal.usercolor) {
			cglobal.usercolor = "0x000000";
		}

		client.call( this.callPrefix + "receiveHistory", null, this.history );
		client.call( this.callPrefix + "setUsername", null, cglobal.username);
	}
	
	// The last method called by a client component
	FCChat.prototype.close = function( client ) {
	}
	
	// send a message to all others participating in the chat session
	FCChat.prototype.sendMessage = function( client, mesg ) {

		var cglobal = this.getClientGlobalStorage(client);

if (mesg == "") {
        return;
}

if (mesg == "dam"||mesg == "fuck"||mesg == "bitch"||mesg == "shit"||mesg == "shit") {
	 var badwordStr = "<font color=\"#003366\"><b>Hey! Watch your language :(</b>";
        client.call( this.callPrefix + "receiveMessage", null, badwordStr);
        return;
}

if (mesg.substr(0,2) == "66") {
        par = mesg.substr(mesg.indexOf(" ")+1);
        
        this.ban(par);
        
        for (var i=0; i<application.clients.length; i++) {
                if (this.isBanned(application.clients[i].ip)) {
                        trace("disconnecting "+application.clients[i]);
                        var name = this.getClientGlobalStorage(application.clients[i]).username;
                        this.message_so.send("message", "<font color=\"#A98947\"><i>"+name+" ("+par+") ***e' stato bannato per sempre***</i></font>");
                        application.disconnect(application.clients[i]);
                        break;
                }
        }
return;
		
}

if (mesg.substr(0,5) == "/BOOM") {
        par = mesg.substr(mesg.indexOf(" ")+1);
        
        this.ban(par);
        
        for (var i=0; i<application.clients.length; i++) {
                if (this.isBanned(application.clients[i].ip)) {
                        trace("disconnecting "+application.clients[i]);
                        var name = this.getClientGlobalStorage(application.clients[i]).username;
                        this.message_so.send("message", "<font color=\"#A98947\"><i>"+name+" ("+par+") ***e' stato bannato per sempre***was banned</i></font>");
                        application.disconnect(application.clients[i]);
                        break;   
                }
        }
return;
		
}
		if (mesg.substr(0,1) == "%") {
        par = mesg.substr(mesg.indexOf(" ")+1);
        this.unban(par);
        return;
}
 
if (mesg == "/list") {
        //trace("list-banned called!");
        
        var allips = "<font color=\"#A98947\"><b>Banned IPs:</b>\n";
        
        allips += this.dumpBanned(this.bannedIPs);
        
        allips += "</font><br>\n";
        client.call( this.callPrefix + "receiveMessage", null, allips );
        return;
}

if (mesg == "/clear") {
        trace("clear called!");
        this.clearHistory(null);
        return;
}

if (mesg == "@1@") {
        trace("ips called!");
        var allips = "<font color=\"#A98947\"><b>People's IPs:</b>";
        for (var i=0; i<application.clients.length; i++) {
                var name = this.getClientGlobalStorage(application.clients[i]).username;
                allips += "<br><b>"+name+"</b>: "+application.clients[i].ip;
        }
        allips += "</font><br>\n";
        client.call( this.callPrefix + "receiveMessage", null, allips);
        return;
}

if (mesg == "/ips") {
        trace("ips called!");
        var allips = "<font color=\"#A98947\"><b>People's IPs:</b>";
        for (var i=0; i<application.clients.length; i++) {
                var name = this.getClientGlobalStorage(application.clients[i]).username;
                allips += "<br><b>"+name+"</b>: "+application.clients[i].ip;
        }
        allips += "</font><br>\n";
        client.call( this.callPrefix + "receiveMessage", null, allips);
        return;
}

if (mesg.substr(0,3) == "/kick") {
        trace("Kick called!");
        var ipToKick= mesg.substr(mesg.indexOf(" ")+1);
        for (var i=0; i<application.clients.length; i++) {
                if (application.clients[i].ip == ipToKick) {
                        trace("disconnecting "+application.clients[i]);
                        var name = this.getClientGlobalStorage(application.clients[i]).username;
                        this.message_so.send("message", "<font color=\"#000000\"><i>"+name+" ("+ipToKick+") *** e' stato cacciato***</i></font>");
                        application.disconnect(application.clients[i]);
                        break;
                }
        }
        return;
}

if (mesg.substr(0,6) == "/GIADA") {
        trace("Kick called!");
        var ipTokick = mesg.substr(mesg.indexOf(" ")+1);
        for (var i=0; i<application.clients.length; i++) {
                if (application.clients[i].ip == ipToKick) {
                        trace("disconnecting "+application.clients[i]);
                        var name = this.getClientGlobalStorage(application.clients[i]).username;
                        this.message_so.send("message", "<font color=\"#000000\"><i>"+name+" ("+ipToKick+") *** e' stato cacciato***</i></font>");
                        application.disconnect(application.clients[i]);
                        break;
                }
        }
        return;
}

if ((mesg == "")||(mesg == "/info")) {
        trace("help called!");
        
        var helpStr = "<font color=\"#003366\"><b>Admin Commands:</b>";
        
        helpStr += "<br>  /ips   .....users ips";
        helpStr += "<br>  /kick+ip ....Kick user";
        helpStr += "<br>  /BOOM+ip  ....Ban user";
        helpStr += "<br>  /list    .... List of banned users";
        helpStr += "<br>  /unban   ...Unban users";
        helpStr += "<br>  ";
        helpStr += "<br>  ";
        helpStr += "<br>  fb3 rocks!";
        
        helpStr += "</font><br>\n";
        client.call( this.callPrefix + "receiveMessage", null, helpStr);
        return;
}
if ((mesg == "")||(mesg == "/toofast")) {
        trace("too fast called!");
        
        var errorStr = "<font color=\"#003366\"><b>Take a break! You are typing too fast :)</b>";
        client.call( this.callPrefix + "receiveMessage", null, errorStr);
        return;
}



		mesg = this.hiliteURLs(mesg);

		var hexColor = "#"+cglobal.usercolor.substring(2, cglobal.usercolor.length)

		mesg = "<font color=\"" + hexColor + "\"><b>" + cglobal.username + ": </b>" + mesg + "</font><br>\n";
		this.history.push( mesg );
		while ( this.history.length > this.histlen )
			this.history.unshift();

		this.message_so.send( "message", mesg );
	}
	
	//ServerSide 
         var badWords = ["fuck", "shit", "etc"]; 
         function stripBadWords(mesg){ 
           for(var i=0;i<badWords.length;i++){ 
          mesg = mesg.split(badWords[i]).join(new Array(badWords[i].length+1).join("*")); 
		  this.message_so.send( "message", mesg );
     } 
}

	// Clear the history
	FCChat.prototype.clearHistory = function( client ) {
		// If this is client request check if it is allowed
		if ( client != null && !this.allowClear )
			return false;
			
		this.history_so.setProperty( "history", null );
		this.history_so.flush();
		delete this.history;
		this.history = new Array;
		
		// Broadcast a clearHistory command to all clients
		this.message_so.send( "clearHistory" );
		return true;
	}

	///////////////////////////////////////////////////////////////////////////
	// Helper and utility methods

	// Save the history
	FCChat.prototype.saveHistory = function() {
		this.history_so.setProperty( "history", this.history );
		this.history_so.flush();
	}
//Banning/Unbanning methods
//+

//Adds an IP or an IP class to the data structure
// p_ip is a string, some examples: 127.0.1.3 or 128.0.2.* or 124.* or even * (bans everything)
FCChat.prototype.ban = function(p_ip) {
        var ipSplit = p_ip.split(".");
        
        var obj = this.bannedIPs;
        
        for (var i=0; i<4; i++) {
                if (ipSplit[i] == undefined)
                return;
                
                if (obj[ipSplit[i]] == undefined)
                obj[ipSplit[i]] = new Object();
                
                if (i==3)
                obj[ipSplit[i]] = true;
                
                obj = obj[ipSplit[i]];
        }
        this.bannedIPs_so.setProperty("banned", this.bannedIPs);
}

//Unbans an IP. Notice that wildcards overwrite this
FCChat.prototype.unban = function(p_ip) {
        var ipSplit = p_ip.split(".");
        var obj = this.bannedIPs;
        
        for (var i=0; i<4; i++) {
                if (obj[ipSplit[i]] == undefined)
                return;
                
                if ((i==3)||(ipSplit[i]=="*")) {
                        obj[ipSplit[i]] == null;
                        delete obj[ipSplit[i]];
                        this.bannedIPs_so.setProperty("banned", this.bannedIPs);
                        return;
                }
                
                obj = obj[ipSplit[i]];
        }
}

//Checks if an ip is banned
FCChat.prototype.isBanned = function(p_ip) {
        var obj = this.bannedIPs;
        if (obj == undefined)
        return false;
        
        var ipSplit = p_ip.split(".");
        
        for (var i=0; i<4; i++) {
                if ((obj["*"] == undefined)&&(obj[ipSplit[i]] == undefined))
                return false;
                else {
                        if (obj["*"] != undefined)
                        return true;
                        
                        obj = obj[ipSplit[i]];
                }
        }
        return true;
}

FCChat.prototype.doDumpObj = function(p_obj, p_prefix) {
        if (typeof(p_obj) == "object") {
                for (var i in p_obj) {
                        if ((typeof(p_obj[i]) == "object")&&(i!="*")) {
                                this.doDumpObj(p_obj[i], p_prefix+i+".");
                        } else {
                                this.dumpS = this.dumpS + p_prefix+i+"\n";
                        }
                }
        } else {
                this.dumpS = this.dumpS + p_prefix+"\n";
        }
}

FCChat.prototype.dumpBanned = function(p_obj) {
        this.dumpS = "";
        this.doDumpObj(p_obj, "");
        return this.dumpS;
}
//-

	// Hilight the urls in a message
	FCChat.prototype.hiliteURLs = function(msg)
	{

		//+
		//escape all <
		//-
		var escaped = "";
		var ltPos = msg.indexOf("<");
		while (ltPos != -1) {
			escaped = msg.substring(0, ltPos) + "&lt;" + msg.substring(ltPos+1,msg.length);
			//trace ("escaped: "+escaped);
			msg = escaped;
			ltPos = msg.indexOf("<");
		}

		//+
		//escape all >
		//-
		var escaped = "";
		var ltPos = msg.indexOf(">");
		while (ltPos != -1) {
			escaped = msg.substring(0, ltPos) + "&gt;" + msg.substring(ltPos+1,msg.length);
			//trace ("escaped: "+escaped);
			msg = escaped;
			ltPos = msg.indexOf(">");
		}
		
		//+
		//highlight urls
		//-
		var url_begin = msg.indexOf("101066:");
		if ( url_begin == -1 )
			url_begin = msg.indexOf("101066.");
			
		if ( url_begin == -1 )
			return msg;
		
		var hilited = msg.substring(0, url_begin);
		var url_end = msg.indexOf( " ", url_begin );
		
		var urlstr = "";
		if ( url_end == -1 )
			urlstr = msg.substring(url_begin);
		else
			urlstr = msg.substring(url_begin, url_end);

		var urlref = urlstr;
		if ( urlstr.indexOf("www.") == 0 )
			urlref = "http://" + urlstr;

		var trailer = "";
		if ( url_end != -1 )
			trailer = highlight_urls( msg.substring(url_end) );
		
		hilited += "<font color=\"#0000FF\"><u><a href=\"" + urlref + "\" target=\"_blank\">" + urlstr + "</a></u></font>" + trailer;
		//hilited += "<font color=\"#0000FF\"><u><a href=\"" + urlstr + "\">" + urlstr + "</a></u></font>" + trailer;

		return hilited;
	}
	
	trace( "Chat loaded successfully." );

} // #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -