create initializeSocket(socket), add git commit to version
This commit is contained in:
@@ -10,8 +10,8 @@ class WTVIRC {
|
|||||||
/*
|
/*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @class WTVIRC
|
* @class WTVIRC
|
||||||
* WTVIRC - A small IRC server implementation for WebTV
|
* zefIRCd - A node.js IRC server implementation
|
||||||
* Tested with WebT, KvIRC and mIRC.
|
* Tested with WebTV, KvIRC and mIRC.
|
||||||
* Supports unencrypted and encrypted (SSL) connections on the same port.
|
* Supports unencrypted and encrypted (SSL) connections on the same port.
|
||||||
* It supports basic commands like NICK, USER, JOIN, PART, PRIVMSG, NOTICE, TOPIC, AWAY, MODE, KICK, and PING.
|
* It supports basic commands like NICK, USER, JOIN, PART, PRIVMSG, NOTICE, TOPIC, AWAY, MODE, KICK, and PING.
|
||||||
* Basic IRCOp functionality is included.
|
* Basic IRCOp functionality is included.
|
||||||
@@ -30,7 +30,12 @@ class WTVIRC {
|
|||||||
constructor(minisrv_config, host = 'localhost', port = 6667, debug = false) {
|
constructor(minisrv_config, host = 'localhost', port = 6667, debug = false) {
|
||||||
this.minisrv_config = minisrv_config;
|
this.minisrv_config = minisrv_config;
|
||||||
this.wtvshared = new WTVShared(minisrv_config);
|
this.wtvshared = new WTVShared(minisrv_config);
|
||||||
this.version = '0.2.6';
|
this.version = '0.2.7';
|
||||||
|
// Try to get git commit from environment variable or file, fallback to null if not available
|
||||||
|
this.git_commit = this.getGitRevision();
|
||||||
|
if (this.git_commit) {
|
||||||
|
this.version += `-${this.git_commit}`;
|
||||||
|
}
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.debug = debug;
|
this.debug = debug;
|
||||||
@@ -78,6 +83,7 @@ class WTVIRC {
|
|||||||
this.irc_motd = this.irc_config.motd || [
|
this.irc_motd = this.irc_config.motd || [
|
||||||
'Welcome to the zefIRCd IRC server, powered by minisrv.',
|
'Welcome to the zefIRCd IRC server, powered by minisrv.',
|
||||||
'This server is powered by Node.js, and the minisrv project.',
|
'This server is powered by Node.js, and the minisrv project.',
|
||||||
|
'',
|
||||||
'For more information, visit:',
|
'For more information, visit:',
|
||||||
'https://github.com/zefie/zefie_wtvp_minisrv'
|
'https://github.com/zefie/zefie_wtvp_minisrv'
|
||||||
];
|
];
|
||||||
@@ -119,6 +125,7 @@ class WTVIRC {
|
|||||||
|
|
||||||
start() {
|
start() {
|
||||||
this.loadKLinesFromFile();
|
this.loadKLinesFromFile();
|
||||||
|
|
||||||
if (this.enable_tls) {
|
if (this.enable_tls) {
|
||||||
this.supported_client_caps.push('tls');
|
this.supported_client_caps.push('tls');
|
||||||
}
|
}
|
||||||
@@ -184,52 +191,34 @@ class WTVIRC {
|
|||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log('Secure connection established');
|
console.log('Secure connection established');
|
||||||
}
|
}
|
||||||
if (this.debug) {
|
|
||||||
const originalWrite = secureSocket.write;
|
socket.removeAllListeners();
|
||||||
secureSocket.write = function (...args) {
|
await this.initializeSocket(secureSocket);
|
||||||
var log_args = args.map(arg => {
|
|
||||||
if (typeof arg === 'string') {
|
|
||||||
return arg.replace(/\r\n/g, '').replace(/\n/g, '');
|
|
||||||
}
|
|
||||||
return arg;
|
|
||||||
});
|
|
||||||
console.log('<', ...log_args);
|
|
||||||
return originalWrite.apply(secureSocket, args);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
socket.removeAllListeners('error');
|
|
||||||
secureSocket.registered = false;
|
|
||||||
secureSocket.nickname = '';
|
|
||||||
secureSocket.username = '';
|
|
||||||
secureSocket.isserver = false;
|
|
||||||
secureSocket.is_srv_authorized = false;
|
|
||||||
secureSocket.signedoff = false;
|
|
||||||
secureSocket.client_version = '';
|
|
||||||
secureSocket.client_caps = [];
|
|
||||||
secureSocket.hostname_resolved = false;
|
|
||||||
secureSocket.realhost = socket.remoteAddress
|
|
||||||
secureSocket.upgrading_to_tls = false;
|
|
||||||
secureSocket.host = this.filterHostname(secureSocket, socket.remoteAddress);
|
|
||||||
secureSocket.timestamp = this.getDate();
|
|
||||||
secureSocket.secure = true;
|
|
||||||
secureSocket.uniqueId = `${this.serverId}${this.generateUniqueId(secureSocket)}`;
|
|
||||||
await this.doInitialHandshake(secureSocket);
|
|
||||||
// Push the secure socket to clients
|
|
||||||
this.clients.push(secureSocket);
|
|
||||||
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
|
||||||
secureSocket.on('data', async data => {
|
|
||||||
await this.processSocketData(secureSocket, data);
|
|
||||||
});
|
|
||||||
secureSocket.on('end', () => {
|
|
||||||
this.terminateSession(secureSocket, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
secureSocket.resume();
|
secureSocket.resume();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// Not SSL, re-emit the data event for normal processing
|
// Not SSL, re-emit the data event for normal processing
|
||||||
|
await this.initializeSocket(socket);
|
||||||
|
socket.emit('data', firstChunk.toString('ascii'));
|
||||||
|
socket.resume();
|
||||||
|
this.clients.push(socket);
|
||||||
|
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.server.listen(this.port, this.host, () => {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
|
console.log(`zefIRCd ${this.version} server started on port ${this.host}:${this.port}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async initializeSocket(socket) {
|
||||||
|
if (this.debug) {
|
||||||
|
// debug output for socket data
|
||||||
const originalWrite = socket.write;
|
const originalWrite = socket.write;
|
||||||
socket.write = function (...args) {
|
socket.write = function (...args) {
|
||||||
var log_args = args.map(arg => {
|
var log_args = args.map(arg => {
|
||||||
@@ -242,6 +231,7 @@ class WTVIRC {
|
|||||||
return originalWrite.apply(socket, args);
|
return originalWrite.apply(socket, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.registered = false;
|
socket.registered = false;
|
||||||
socket.nickname = '';
|
socket.nickname = '';
|
||||||
socket.username = '';
|
socket.username = '';
|
||||||
@@ -270,19 +260,12 @@ class WTVIRC {
|
|||||||
socket.on('error', () => {
|
socket.on('error', () => {
|
||||||
this.terminateSession(socket, true);
|
this.terminateSession(socket, true);
|
||||||
});
|
});
|
||||||
socket.emit('data', firstChunk.toString('ascii'));
|
|
||||||
socket.resume();
|
socket.on('close', () => {
|
||||||
|
this.terminateSession(socket, false);
|
||||||
|
});
|
||||||
this.clients.push(socket);
|
this.clients.push(socket);
|
||||||
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
this.clientpeak = Math.max(this.clientpeak, this.clients.length);
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.server.listen(this.port, this.host, () => {
|
|
||||||
if (this.debug) {
|
|
||||||
console.log(`IRC server started on port ${this.host}:${this.port}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async processServerData(socket, line) {
|
async processServerData(socket, line) {
|
||||||
@@ -1016,8 +999,6 @@ class WTVIRC {
|
|||||||
}
|
}
|
||||||
this.channelinvites.set(targetChannel, channelInvites);
|
this.channelinvites.set(targetChannel, channelInvites);
|
||||||
} else if (flags[i] === '+l' || flags[i] === '-l') {
|
} else if (flags[i] === '+l' || flags[i] === '-l') {
|
||||||
// Check if 'l' mode is already present, if not, add it with the limit
|
|
||||||
// Check if 'l' mode is already present
|
|
||||||
if (flags[i] === '+l') {
|
if (flags[i] === '+l') {
|
||||||
this.setChannelMode(targetChannel, 'l', true);
|
this.setChannelMode(targetChannel, 'l', true);
|
||||||
this.channellimits.set(targetChannel, parseInt(target));
|
this.channellimits.set(targetChannel, parseInt(target));
|
||||||
@@ -4590,6 +4571,21 @@ class WTVIRC {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getGitRevision() {
|
||||||
|
console.log(__dirname)
|
||||||
|
try {
|
||||||
|
var gitPath = __dirname + path.sep + ".." + path.sep + ".." + path.sep + ".." + path.sep + ".git" + path.sep
|
||||||
|
const rev = fs.readFileSync(gitPath + "HEAD").toString().trim();
|
||||||
|
if (rev.indexOf(':') === -1) {
|
||||||
|
return rev;
|
||||||
|
} else {
|
||||||
|
return fs.readFileSync(gitPath + rev.substring(5)).toString().trim().substring(0, 8) + "-" + rev.split('/').pop();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async doLogin(nickname, socket) {
|
async doLogin(nickname, socket) {
|
||||||
if (await this.scanSocketForKLine(socket)) {
|
if (await this.scanSocketForKLine(socket)) {
|
||||||
return; // If the socket is K-lined, exit early
|
return; // If the socket is K-lined, exit early
|
||||||
|
|||||||
Reference in New Issue
Block a user