From 46a9efec0f861d63cdc43fe1d99e3dc8a0656b72 Mon Sep 17 00:00:00 2001
From: cyan <>
Date: Tue, 18 May 2010 20:27:02 +0000
Subject: [PATCH] * More changes for DCC functionality

---
 exec/ircbot.js                | 41 ++++++++++++++++++++++++++++++-----
 exec/load/ircbot_functions.js |  6 ++++-
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/exec/ircbot.js b/exec/ircbot.js
index bbd894e147..b9fc58adbb 100644
--- a/exec/ircbot.js
+++ b/exec/ircbot.js
@@ -175,9 +175,6 @@ function main() {
 					}
 				}
 			}
-			
-			
-			mswait(10); /* Don't peg the CPU */
 		}
 
 		/* Take care of DCC chat sessions */
@@ -185,18 +182,44 @@ function main() {
 			if (!dcc_chats[c].sock.is_connected) {
 				log("Closing session.");
 				dcc_chats[c].sock.close();
+				delete dcc_chats[c];
 				continue;
 			}
 			if (dcc_chats[c].waiting_for_password) {
-				if (var dcc_pwd=dcc_chats[c].sock.readln()) {
-					dcc_chats[c].o("Acknowledged.");
+				var dcc_pwd;
+				if (dcc_pwd=dcc_chats[c].sock.readln()) {
+					var usr = new User(system.matchuser(dcc_chats[c].id));
+					if (!usr ||
+						(dcc_pwd.toUpperCase() != usr.security.password)) {
+						dcc_chats[c].o(null,"Access Denied.");
+						dcc_chats[c].sock.close();
+						delete dcc_chats[c];
+						continue;
+					}
+					if (dcc_pwd.toUpperCase() == usr.security.password) {
+						dcc_chats[c].waiting_for_password = false;
+						dcc_chats[c].o(null,"Welcome aboard.");
+					}
 				}
 				continue;
 			}
+			var line = dcc_chats[c].sock.readln();
+			if (!line || line == "")
+				continue;
+			var usr = new User(system.matchuser(dcc_chats[c].id));
+			var cmd = line.split(" ");
+			cmd[0] = cmd[0].toUpperCase();
+			try {
+				dcc_chats[c].check_bot_command(cmd);
+			} catch (err) {
+				dcc_chats[c].o(null,"ERROR: " + err);
+			}
 		}
 
 		if ( (time() - Config_Last_Write) > config_write_delay )
 			save_everything();
+
+		mswait(10); /* Don't peg the CPU */
 	}
 }
 
@@ -275,6 +298,14 @@ function DCC_Chat(sock,id) {
 	this.waiting_for_password = true;
 	/* Functions */
 	this.o = DCC_Out;
+	this.check_bot_command = function(cmd) {
+		Server_check_bot_command(this,Bot_Commands,null,this.id,null,cmd);
+		for(var bot_cmd in Modules) {
+			Server_check_bot_command(this,Modules[bot_cmd].Bot_Commands,
+				null,this.id,null,cmd
+			);
+		}
+	}
 }
 
 function DCC_Out(target,str) {
diff --git a/exec/load/ircbot_functions.js b/exec/load/ircbot_functions.js
index 12095e4d03..53139e0f0d 100644
--- a/exec/load/ircbot_functions.js
+++ b/exec/load/ircbot_functions.js
@@ -137,6 +137,11 @@ function Server_command(srv,cmdline,onick,ouh) {
 function Server_CTCP(onick,ouh,cmd) {
 	switch (cmd[0]) {
 		case "DCC":
+			var usr = new User(system.matchuser(onick));
+			if (!usr.number) {
+				this.o(onick, "I don't talk to strangers.", "NOTICE");
+				return;
+			}
 			if (cmd[4]) {
 				if ((cmd[1].toUpperCase() == "CHAT")
 					&& (cmd[2].toUpperCase() == "CHAT")
@@ -146,7 +151,6 @@ function Server_CTCP(onick,ouh,cmd) {
 						var port = parseInt(cmd[4]);
 						var sock = new Socket();
 						sock.connect(ip, port, 3 /* Timeout */);
-						log("*** DCC Socket Status: " + sock.is_connected);
 						if (sock.is_connected) {
 							sock.write("Enter your password.\r\n");
 							dcc_chats.push(new DCC_Chat(sock,onick));
-- 
GitLab