Skip to content
Snippets Groups Projects
Commit b2dd3d5b authored by cyan's avatar cyan
Browse files

* Added ability to pipe output from one channel into another

parent c2ae8b6c
No related branches found
No related tags found
No related merge requests found
......@@ -31,11 +31,11 @@ Config_Last_Write = time(); /* Store when the config was last written. */
load("load/ircbot_functions.js");
/* Global Arrays */
bot_servers = new Array();
quotes = new Array();
masks = new Object();
dcc_chats = new Array();
squelch_list = new Array();
Bot_Servers = new Object();
Quotes = new Array();
Masks = new Object();
DCC_Chats = new Array();
Squelch_List = new Array();
var config_filename = "ircbot.ini";
for (cmdarg=0;cmdarg<argc;cmdarg++) {
......@@ -54,7 +54,7 @@ if (config.open("r")) {
command_prefix = config.iniGetValue(null, "command_prefix");
real_name = config.iniGetValue(null, "real_name");
config_write_delay=parseInt(config.iniGetValue(null, "config_write_delay"));
// squelch_list = config.iniGetValue(null, "squelch_list").split(",");
// Squelch_List = config.iniGetValue(null, "Squelch_List").split(",");
/* Modules */
var ini_modules = config.iniGetSections("module_");
......@@ -77,7 +77,8 @@ if (config.open("r")) {
var ini_server_secs = config.iniGetSections("server_");
for (s in ini_server_secs) {
var mysec = ini_server_secs[s];
bot_servers.push(new Bot_IRC_Server(
var network = mysec.replace("server_", "").toUpperCase();
Bot_Servers[network] = (new Bot_IRC_Server(
0, /* Socket */
config.iniGetValue(mysec, "addresses"),
config.iniGetValue(mysec, "nick"),
......@@ -114,9 +115,9 @@ for (f in user_settings_files) {
uid_str = uid_str.slice(1);
}
printf("***Reading: " + us_file.name + "\r\n");
var read_masks = us_file.iniGetValue(null, "masks");
if (read_masks)
masks[parseInt(uid_str)] = read_masks.split(",");
var read_Masks = us_file.iniGetValue(null, "masks");
if (read_Masks)
Masks[parseInt(uid_str)] = read_Masks.split(",");
}
}
......@@ -124,9 +125,9 @@ log("*** Entering Main Loop. ***");
function main() {
while (!js.terminated) {
for (my_srv in bot_servers) {
for (my_srv in Bot_Servers) {
var cmdline;
var srv = bot_servers[my_srv];
var srv = Bot_Servers[my_srv];
if (!srv.sock &&(srv.lastcon <time())) { //we're not connected.
var consock = IRC_client_connect(srv.host, srv.nick,
command_prefix, real_name, srv.port);
......@@ -178,41 +179,41 @@ function main() {
}
/* Take care of DCC chat sessions */
for (c in dcc_chats) {
if (!dcc_chats[c].sock.is_connected) {
for (c in DCC_Chats) {
if (!DCC_Chats[c].sock.is_connected) {
log("Closing session.");
dcc_chats[c].sock.close();
delete dcc_chats[c];
DCC_Chats[c].sock.close();
delete DCC_Chats[c];
continue;
}
if (dcc_chats[c].waiting_for_password) {
if (DCC_Chats[c].waiting_for_password) {
var dcc_pwd;
if (dcc_pwd=dcc_chats[c].sock.readln()) {
var usr = new User(system.matchuser(dcc_chats[c].id));
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];
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.");
DCC_Chats[c].waiting_for_password = false;
DCC_Chats[c].o(null,"Welcome aboard.");
}
}
continue;
}
var line = dcc_chats[c].sock.readln();
var line = DCC_Chats[c].sock.readln();
if (!line || line == "")
continue;
var usr = new User(system.matchuser(dcc_chats[c].id));
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);
DCC_Chats[c].check_bot_command(cmd);
} catch (err) {
dcc_chats[c].o(null,"ERROR: " + err);
DCC_Chats[c].o(null,"ERROR: " + err);
}
}
......
......@@ -602,3 +602,60 @@ Bot_Commands["OBJKEYS"].command = function (target,onick,ouh,srv,lvl,cmd) {
return;
}
Bot_Commands["PIPE"] = new Bot_Command(80,false,false);
Bot_Commands["PIPE"].command = function (target,onick,ouh,srv,lvl,cmd) {
if (!cmd[1]) {
var pipelist = "";
for (s in Bot_Servers) {
if (Bot_Servers[s].pipe) {
for (p in Bot_Servers[s].pipe) {
pipelist += p + "(" + s + ") ";
}
}
}
if (!pipelist) {
srv.o(target, "No channels being piped on any network.");
return;
}
return;
}
if (!cmd[3]) {
srv.o(target, "Invalid number of arguments. Usage: ADD <chan> <net>");
return;
}
cmd[1] = cmd[1].toUpperCase();
var pipe_chan = cmd[2].toUpperCase();
var pipe_srv = Bot_Servers[cmd[3].toUpperCase()];
if (!pipe_srv) {
srv.o(target, "No such network.");
return;
}
if (!pipe_srv.channel[pipe_chan]) {
srv.o(target, "I'm not on that channel.");
return;
}
if (!pipe_srv.pipe)
pipe_srv.pipe = new Object();
if (cmd[1] == "ADD") {
if (pipe_srv.pipe[pipe_chan]) {
srv.o(target, "I'm already piping that channel!");
return;
}
pipe_srv.pipe[pipe_chan] = new Object();
pipe_srv.pipe[pipe_chan].srv = srv;
pipe_srv.pipe[pipe_chan].target = target;
srv.o(target, "Now piping " + cmd[2] + " on " + cmd[3]);
return;
} else if (cmd[1] == "DEL") {
if (!pipe_srv.pipe[pipe_chan]) {
srv.o(target, "I'm not piping that!");
return;
}
delete pipe_srv.pipe[pipe_chan];
srv.o(target, "Okay, stopped piping " + cmd[2] + " on " + cmd[3]);
return;
}
srv.o(target, "Invalid arguments.");
return;
}
......@@ -82,8 +82,8 @@ Bot_Commands["DIE"].usage =
Bot_Commands["DIE"].help =
"Causes me to die. You don't want that, do you?";
Bot_Commands["DIE"].command = function (target,onick,ouh,srv,lvl,cmd) {
for (s in bot_servers) {
bot_servers[s].writeout("QUIT :" + onick + " told me to die. :(");
for (s in Bot_Servers) {
Bot_Servers[s].writeout("QUIT :" + onick + " told me to die. :(");
}
js.terminated=true;
return;
......@@ -91,8 +91,8 @@ Bot_Commands["DIE"].command = function (target,onick,ouh,srv,lvl,cmd) {
Bot_Commands["RESTART"] = new Bot_Command(90,false,false);
Bot_Commands["RESTART"].command = function (target,onick,ouh,srv,lvl,cmd) {
for (s in bot_servers) {
bot_servers[s].writeout("QUIT :Restarting as per " + onick);
for (s in Bot_Servers) {
Bot_Servers[s].writeout("QUIT :Restarting as per " + onick);
}
exit();
return;
......
......@@ -84,11 +84,17 @@ function Server_command(srv,cmdline,onick,ouh) {
break;
case "PRIVMSG":
if ((cmd[1][0] == "#") || (cmd[1][0] == "&")) {
var chan = srv.channel[cmd[1].toUpperCase()];
var chan_str = cmd[1].toUpperCase();
var chan = srv.channel[chan_str];
if (!chan)
break;
if (!chan.is_joined)
break;
if (srv.pipe && srv.pipe[chan_str]) {
var thispipe = srv.pipe[chan_str];
thispipe.srv.o(thispipe.target, "<" + onick + "> "
+ IRC_string(cmd.join(" "), 2));
}
cmd[2] = cmd[2].substr(1).toUpperCase();
if ((cmd[2].toUpperCase() == truncsp(get_cmd_prefix()))
&& cmd[3]) {
......@@ -227,20 +233,20 @@ function save_everything() {
config.iniSetValue(null, "command_prefix", command_prefix);
config.iniSetValue(null, "real_name", real_name);
config.iniSetValue(null, "config_write_delay", config_write_delay);
config.iniSetValue(null, "squelch_list", squelch_list.join(","));
config.iniSetValue(null, "squelch_list", Squelch_List.join(","));
for (m in masks) {
for (m in Masks) {
var uid_str = format("%04u", m);
var us_filename = system.data_dir + "user/" +uid_str+ ".ircbot.ini";
var us_file = new File(us_filename);
if (us_file.open(file_exists(us_filename) ? 'r+':'w+')) {
us_file.iniSetValue(null, "masks", masks[m].join(","));
us_file.iniSetValue(null, "masks", Masks[m].join(","));
us_file.close();
}
}
for (q in quotes) {
config.iniSetValue("quotes", q, quotes[q]);
for (q in Quotes) {
config.iniSetValue("quotes", q, Quotes[q]);
}
config.close();
......@@ -273,8 +279,8 @@ function Server_Bot_Access(nick,uh) {
if (!usrnum)
return 0;
var thisuser = new User(usrnum);
for (m in masks[usrnum]) {
if (wildmatch(uh,masks[usrnum][m]))
for (m in Masks[usrnum]) {
if (wildmatch(uh,Masks[usrnum][m]))
return thisuser.security.level;
}
return 0; // assume failure
......@@ -286,8 +292,8 @@ function Server_writeout(str) {
}
function Server_target_out(target,str,msgtype) {
for (c in squelch_list) {
if (target.toUpperCase() == squelch_list[c].toUpperCase())
for (c in Squelch_List) {
if (target.toUpperCase() == Squelch_List[c].toUpperCase())
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment