2021-01-20 03:53:33 +02:00
|
|
|
/*
|
|
|
|
Software to convert the Brainlet protocol to the IRC protocol
|
|
|
|
Copyright (C) 2021 hiimgoodpack
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
const fs = require("fs");
|
2021-01-21 02:32:08 +02:00
|
|
|
const ircServer = require("./ircd.js/lib/server.js");
|
2021-01-20 03:53:33 +02:00
|
|
|
const ircClient = require("irc");
|
|
|
|
const crypto = require("crypto");
|
|
|
|
|
|
|
|
// Set up IRC server
|
2021-01-21 02:32:08 +02:00
|
|
|
const config = require(`${__dirname}/config.js`)
|
2021-01-20 03:53:33 +02:00
|
|
|
|
|
|
|
const genPass = () => {
|
|
|
|
// This should give us a reasonably secure password
|
|
|
|
return crypto.randomBytes(66).toString("base64");
|
|
|
|
}
|
|
|
|
|
|
|
|
let systemUsers = {
|
|
|
|
NickServ: {
|
|
|
|
password: genPass()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const ircConfig = {
|
|
|
|
network: "BrainletToIRC",
|
|
|
|
hostname: "localhost",
|
|
|
|
serverDescription: "A brainlet to IRC translation layer",
|
2021-01-21 02:32:08 +02:00
|
|
|
serverName: config.server,
|
2021-01-20 03:53:33 +02:00
|
|
|
port: 6667,
|
|
|
|
linkPort: 7777,
|
2021-01-21 02:32:08 +02:00
|
|
|
motd: config.motd,
|
2021-01-20 03:53:33 +02:00
|
|
|
whoWasLimit: 10000,
|
|
|
|
token: 1,
|
|
|
|
opers: systemUsers,
|
|
|
|
channels: {},
|
|
|
|
links: {
|
|
|
|
server: {
|
|
|
|
host: "127.0.0.1",
|
|
|
|
password: genPass(),
|
|
|
|
port: 7778,
|
|
|
|
token: 2
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pingTimeout: 120,
|
|
|
|
maxNickLength: 30
|
|
|
|
};
|
2021-01-21 02:32:08 +02:00
|
|
|
fs.writeFileSync(`${__dirname}/ircd.js/config/config.json`, JSON.stringify(ircConfig));
|
2021-01-20 03:53:33 +02:00
|
|
|
|
|
|
|
ircServer.Server.boot();
|
|
|
|
|
|
|
|
// Set up system users
|
|
|
|
const ircServerAddress = ircConfig.links.server.host;
|
|
|
|
const ircServerPort = ircConfig.links.server.port;
|
2021-01-21 02:32:08 +02:00
|
|
|
|
|
|
|
let NickServ = new ircClient.Client("localhost", "NickServ");
|
|
|
|
console.log(NickServ)
|
2021-01-20 03:53:33 +02:00
|
|
|
NickServ.addListener("error", console.error);
|
2021-01-21 02:32:08 +02:00
|
|
|
NickServ.addListener("message", (from, to, text, message) => {
|
|
|
|
// Make sure it's a private message to NickServ
|
|
|
|
if (to !== NickServ.opt.nick)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const args = text.split(" ");
|
|
|
|
if (args.length == 0) {
|
|
|
|
NickServ.notice(from, config.responses.NickServ.invalid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (args[0].toLowerCase()) {
|
|
|
|
case "help": {
|
|
|
|
NickServ.notice(from, config.responses.NickServ.help);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "register": {
|
|
|
|
const password = args[1];
|
|
|
|
const email = args[2];
|
|
|
|
if (!password || !email) {
|
|
|
|
NickServ.notice(from, config.responses.NickServ.invalid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NickServ.notice(from, "Account registration is currently not implemented");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "identify": {
|
|
|
|
const name = args[1];
|
|
|
|
const password = args[2];
|
|
|
|
if (!name || !password) {
|
|
|
|
NickServ.notice(from, config.responses.NickServ.invalid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NickServ.notice(from, "Account login is currently not implemented");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
NickServ.notice(from, config.responses.NickServ.invalid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|