Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 362e3583 authored by Randy Sommerfeld's avatar Randy Sommerfeld

Don't auto-connect if no port is defined in C:Line, minor Y:Line changes

parent a50517e4
......@@ -151,8 +151,10 @@ function Read_Config_File() {
Admin3 = "";
if (typeof CLines !== 'undefined') {
for (i in CLines) {
if (CLines[i].next_connect)
if (CLines[i].next_connect) {
js.clearTimeout(CLines[i].next_connect);
delete CLines[i].next_connect;
}
}
}
CLines = [];
......
......@@ -225,23 +225,18 @@ function remove_kline(kl_hm) {
}
/* this = cline */
function connect_to_server(port) {
function Automatic_Server_Connect() {
var sock = new Socket();
sock.array_buffer = false; /* JS78, we want strings */
sock.cline = this;
sock.outbound = true;
if (!port && this.port)
port = this.port;
else if (!port)
port = Default_Port;
if ( Servers[this.servername.toLowerCase()]
|| YLines[this.ircclass].active >= YLines[this.ircclass].maxlinks
) {
this.next_connect = js.setTimeout(
connect_to_server,
Automatic_Server_Connect,
YLines[this.ircclass].connfreq * 1000,
this
);
......@@ -249,13 +244,13 @@ function connect_to_server(port) {
}
umode_notice(USERMODE_ROUTING,"Routing",format(
"Auto-connecting to %s (%s) on port %d",
"Auto-connecting to %s (%s) on port %u",
this.servername,
this.host,
port
this.port
));
sock.connect(this.host, port, handle_outbound_server_connect);
sock.connect(this.host, this.port, handle_outbound_server_connect);
if (this.next_connect)
delete this.next_connect;
......@@ -283,11 +278,7 @@ function handle_outbound_server_connect() {
YLines[this.cline.ircclass].connfreq
));
this.close();
this.cline.next_connect = js.setTimeout(
connect_to_server,
YLines[this.cline.ircclass].connfreq * 1000,
this.cline
);
Reset_Autoconnect(this.cline, YLines[this.cline.ircclass].connfreq * 1000);
}
this.cline.lastconnect = system.timer;
}
......@@ -1628,6 +1619,7 @@ function IRCClient_do_connect(con_server,con_port) {
var con_cline;
var msg;
var con_type;
var sock;
con_cline = Find_CLine_by_Server(con_server);
......@@ -1641,7 +1633,7 @@ function IRCClient_do_connect(con_server,con_port) {
con_port = String(Default_Port);
if (!con_port.match(/^[0-9]+$/)) {
this.server_notice("Invalid port: " + con_port);
return 0;
return false;
}
msg = format(" CONNECT %s %u from %s [%s@%s]",
con_cline.servername,
......@@ -1660,14 +1652,19 @@ function IRCClient_do_connect(con_server,con_port) {
con_type,
msg
));
if (con_cline.next_connect)
js.clearTimeout(con_cline.next_connect);
con_cline.next_connect = js.setTimeout(
connect_to_server,
1, /* connect as soon as possible */
con_cline
);
return 1;
sock = new Socket();
sock.array_buffer = false; /* JS78, we want strings */
sock.cline = con_cline;
sock.outbound = true;
sock.connect(con_cline.host, con_port, handle_outbound_server_connect);
return true;
}
function IRCClient_do_basic_who(whomask) {
......@@ -2847,6 +2844,36 @@ function Epoch() {
return parseInt(new Date().getTime()/1000);
}
function YLine_Decrement(yline) {
if (typeof yline !== 'object')
throw "YLine_Decrement() called without yline object.";
if (yline.active < 1) {
log(LOG_DEBUG, "Y:Line trying to decrement below zero");
yline.active = 0;
return false;
}
yline.active--;
log(LOG_DEBUG, format("Class down to %u active out of %u",
yline.active,
yline.maxlinks
));
return true;
}
function YLine_Increment(yline) {
if (typeof yline !== 'object')
throw "YLine_Increment() called without yline object.";
yline.active++;
log(LOG_DEBUG, format("Class up to %u active out of %u",
yline.active,
yline.maxlinks
));
return true;
}
/** Global object prototypes **/
function CLine(host,password,servername,port,ircclass) {
......@@ -2857,7 +2884,7 @@ function CLine(host,password,servername,port,ircclass) {
this.ircclass = ircclass;
this.lastconnect = 0;
if (YLines[ircclass].connfreq > 0)
js.setImmediate(connect_to_server, this);
Reset_Autoconnect(this, 1 /* connect immediately */);
}
function HLine(allowedmask,servername) {
......
......@@ -1271,6 +1271,25 @@ function IRCClient_bcast_to_servers_raw(str) {
}
}
function Reset_Autoconnect(cline, freq) {
if (typeof cline !== 'object')
throw "Reset_Autoconnect() called without cline object.";
if (cline.next_connect)
js.clearTimeout(cline.next_connect);
if (!cline.port)
return false;
cline.next_connect = js.setTimeout(
Automatic_Server_Connect,
freq,
cline
);
return true;
}
function Server_Quit(str,suppress_bcast,is_netsplit,origin) {
var cline;
......@@ -1310,27 +1329,12 @@ function Server_Quit(str,suppress_bcast,is_netsplit,origin) {
if (this.local) {
if (YLines[this.ircclass].connfreq) {
cline = Find_CLine_by_Server(this.nick);
if (cline) {
if (cline.next_connect)
js.clearTimeout(cline.next_connect);
cline.next_connect = js.setTimeout(
connect_to_server,
YLines[this.ircclass].connfreq * 1000,
cline
);
}
if (cline)
Reset_Autoconnect(cline, YLines[this.ircclass].connfreq * 1000);
}
if (YLines[this.ircclass].active > 0) {
YLines[this.ircclass].active--;
log(LOG_DEBUG, format("Class %s down to %d active out of %d",
this.ircclass,
YLines[this.ircclass].active,
YLines[this.ircclass].maxlinks
));
} else {
log(LOG_ERR, format("Class %d YLine going negative", this.ircclass));
}
if (YLines[this.ircclass].active > 0)
YLine_Decrement(YLines[this.ircclass]);
this.recvq.purge();
this.sendq.purge();
......
......@@ -485,12 +485,7 @@ function Register_Unregistered_Local_Server(unreg, p, nline) {
YLines[s.ircclass].pingfreq * 1000,
s
);
YLines[s.ircclass].active++;
log(LOG_DEBUG,format("Class %s up to %d active out of %d",
s.ircclass,
YLines[s.ircclass].active,
YLines[s.ircclass].maxlinks
));
YLine_Increment(YLines[s.ircclass]);
s.finalize_server_connect("TS");
delete Unregistered[unreg.id];
delete Assigned_IDs[unreg.id];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment