diff --git a/exec/ircbot.js b/exec/ircbot.js index bbd894e14799308da6cbc6e7fe6020a0728d8503..b9fc58adbb02b13d482db553af82c18f408361e0 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 12095e4d039b0f9c9fc7ab42d629327baa7fef8a..53139e0f0d026736175bdaf32014d0f4fadb2d99 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));