MODE fix, hourly status report in console

This commit is contained in:
Evert Prants 2016-09-28 21:51:25 +03:00
parent 4127533f8b
commit 10abaa5706
2 changed files with 46 additions and 4 deletions

View File

@ -212,11 +212,13 @@ class IRCConnectionHandler {
case "251":
case "290":
case "292":
case "381":
case "255":
this.conn.emit('pass_to_client', {type: "server_message", messageType: "regular", message: line.trailing, server: serverName, from: realServerName});
break;
case "252":
case "254":
case "396":
case "042":
this.conn.emit('pass_to_client', {type: "server_message", messageType: "regular", message: line.arguments[1] +" "+ line.trailing, server: serverName, from: realServerName});
break;
@ -237,6 +239,14 @@ class IRCConnectionHandler {
isChannelMode = true;
let modes = line.arguments[1];
if(!modes && line.trailing != '')
modes = line.trailing;
let sender = line.user.nickname;
if(sender == '')
sender = line.user.hostname;
method = modes.substring(0, 1);
modes = modes.substring(1).split('');
let pass = [];
@ -246,7 +256,7 @@ class IRCConnectionHandler {
let mode = modes[i];
if(this.conn.data.supportedModes[mode])
this.conn.emit('pass_to_client', {type: "mode_"+(method=='+'?'add':'del'), target: line.arguments[0], mode: mode,
modeTarget: line.arguments[2+parseInt(i)], server: serverName, user: line.user});
modeTarget: line.arguments[2+parseInt(i)], server: serverName, user: {nickname: sender}});
else
pass.push(mode);
}
@ -255,8 +265,8 @@ class IRCConnectionHandler {
}
if(pass.length > 0)
this.conn.emit('pass_to_client', {type: "mode", target: line.arguments[0], message: line.arguments.slice(1).join(" "),
server: serverName, user: line.user});
this.conn.emit('pass_to_client', {type: "mode", target: line.arguments[0], message: method+pass.join(''),
server: serverName, user: {nickname: sender}});
break;
case "433":
let newNick = this.conn.config.nickname + "_";

View File

@ -13,6 +13,10 @@ let ircclient = require(__dirname+'/server/irc');
let port = config.server.port || 8080;
let runtime_stats = {
connectionsMade: 0
};
let connections = {};
process.stdin.resume();
@ -29,8 +33,31 @@ app.use('/', express.static(pubdir, { maxAge: 365*24*60*60*1000 }));
app.use('/:server', express.static(pubdir, { maxAge: 365*24*60*60*1000 }));
app.use('/', router);
function printRuntimeStats() {
let date = new Date();
let users = 0;
let servers = 0;
let serversPerUser = 0;
for(let uid in connections) {
let c = connections[uid];
users += 1;
for(let snam in c) {
if(snam == "host") continue;
let snam = c[snam];
servers += 1;
}
}
if(servers != 0)
serversPerUser = users/servers;
console.log(""+date+": Currently connected users: "+users+"; IRC server connections: "+servers+"; Average servers per user: "+serversPerUser);
}
let io = sockio.listen(app.listen(port, function() {
console.log("*** Listening on http://localhost:" + port + "/");
setInterval(printRuntimeStats, 3600000);
}));
function resolveHostname(ipaddr) {
@ -66,7 +93,10 @@ io.sockets.on('connection', function (socket) {
hostQuery.then((arr) => {
if(arr.length > 0)
connections[socket.id].host.hostname = arr[0];
}).catch((err) => { console.log("Host resolve for "+socket.id+" failed: ", err); });
}).catch((err) => {
if(config.server.debug)
console.log("Host resolve for "+socket.id+" failed: ", err);
});
if(config.server.debug)
console.log("Hostname of "+socket.id+" was determined to be "+connections[socket.id].host.hostname);
@ -114,6 +144,8 @@ io.sockets.on('connection', function (socket) {
socket.emit('act_client', {type: "event_connect", address: connectiondata.server, network: newConnection.data.network,
supportedModes: newConnection.data.supportedModes, nickname: newConnection.config.nickname,
max_channel_length: newConnection.data.max_channel_length});
runtime_stats.connectionsMade += 1;
});
if(config.server.debug) {