sasl
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
const net = require("net")
|
||||
, tls = require("tls")
|
||||
, EventEmitter = require("events").EventEmitter
|
||||
,util = require("util");
|
||||
, util = require("util")
|
||||
, parser = require("parse-irc");
|
||||
|
||||
class irc {
|
||||
constructor(options) {
|
||||
@ -19,8 +20,10 @@ class irc {
|
||||
this.realname = this.options.realname || "test";
|
||||
this.channels = this.options.channels || [];
|
||||
this._recachetime = 60 * 5; // 10 minutes
|
||||
this.stream = parser();
|
||||
this.server = {
|
||||
motd: "",
|
||||
sasl: {},
|
||||
me: {},
|
||||
channel: [],
|
||||
user: new Map()
|
||||
@ -32,14 +35,20 @@ class irc {
|
||||
}, () => {
|
||||
this.send(`NICK ${this.nickname}`);
|
||||
this.send(`USER ${this.username} 0 * : ${this.realname}`);
|
||||
});
|
||||
if(this.options.sasl) {
|
||||
this.send("CAP LS");
|
||||
//this.send("CAP REQ sasl");
|
||||
}
|
||||
}).pipe(this.stream);
|
||||
this.socket.setEncoding("utf-8");
|
||||
this.socket.on("data", msg => {
|
||||
msg = this.parse(msg);
|
||||
this.stream.on("data", msg => {
|
||||
//msg = this.parse(msg);
|
||||
let tmpuser = {};
|
||||
let tmpchan = {};
|
||||
let chans = [];
|
||||
let prefix = "";
|
||||
if(msg.command != "372")
|
||||
console.log(msg);
|
||||
switch (msg.command) { // auslagern!
|
||||
// WHOIS BEGIN
|
||||
case "307": // Rizon Account
|
||||
@ -127,7 +136,7 @@ class irc {
|
||||
this.whois(msg.params[5]);
|
||||
break;
|
||||
case "315": // who_end
|
||||
console.log(this.server.channel);
|
||||
//console.log(this.server.channel);
|
||||
break;
|
||||
case "372": // motd
|
||||
this.server.motd += `${msg.params[1]}\n`;
|
||||
@ -140,18 +149,16 @@ class irc {
|
||||
this.emit("data", ["motd", this.server.motd]);
|
||||
break;
|
||||
case "464": // Password required
|
||||
if (this.options.password.length > 0)
|
||||
if (this.options.password.length > 0 && !this.options.sasl)
|
||||
this.send(`PASS ${this.options.password}`); // pwd
|
||||
break;
|
||||
case "PING":
|
||||
this.send(`PONG ${msg.params.join``}`);
|
||||
break;
|
||||
case "JOIN":
|
||||
console.log("join", msg);
|
||||
this.send(`WHO ${msg.params[0]}`);
|
||||
break;
|
||||
case "PART":
|
||||
console.log("part", msg);
|
||||
delete this.server.user[msg.params[0]];
|
||||
//this.whois(msg.params[0], true); // force whois
|
||||
break;
|
||||
@ -170,15 +177,40 @@ class irc {
|
||||
this.server.user.deli(prefix.nick);
|
||||
this.whois(msg.params[0], true); // force
|
||||
break;
|
||||
/* CAPKACKE */
|
||||
case "CAP":
|
||||
console.log("CAP", msg);
|
||||
switch(msg.params[1]) {
|
||||
case "LS":
|
||||
this.server.sasl.ls = msg.params[2].split(" ");
|
||||
this.send(`CAP REQ :${this.server.sasl.ls.join(" ")}`);
|
||||
break;
|
||||
case "ACK": // success
|
||||
this.send("AUTHENTICATE PLAIN");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "AUTHENTICATE":
|
||||
if(msg.params[0].match(/\+/))
|
||||
this.send(`AUTHENTICATE ${new Buffer(this.username+"\u0000"+this.username+"\u0000"+this.options.password).toString("base64")}`);
|
||||
break;
|
||||
case "900":
|
||||
this.send("CAP END");
|
||||
this.join(this.options.channels); // tmp
|
||||
break;
|
||||
default:
|
||||
console.log(msg);
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
send() {
|
||||
for (let i = 0; i < arguments.length; i++)
|
||||
let args = "";
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
this.socket.write(arguments[i]);
|
||||
args += arguments[i];
|
||||
}
|
||||
console.log(this.options.network, "sending", args);
|
||||
this.socket.write("\n");
|
||||
}
|
||||
parse(data) {
|
||||
@ -235,6 +267,7 @@ class irc {
|
||||
// act chan
|
||||
_chan: this.server.channel[tmp.params[0]],
|
||||
_user: this.server.user,
|
||||
sasl: this.server.sasl,
|
||||
// commands
|
||||
join: chan => this.join(chan),
|
||||
part: (chan, msg) => this.part(chan, msg),
|
||||
@ -252,12 +285,12 @@ class irc {
|
||||
user = user.toLowerCase();
|
||||
if(this.server.user.hasi(user) && !force) {
|
||||
if(this.server.user.geti(user).cached >= ~~(Date.now() / 1000) - this._recachetime) {
|
||||
console.log(this.server.user.geti(user).cached, ~~(Date.now() / 1000) - this._recachetime);
|
||||
console.log(user, "already cached");
|
||||
//console.log(this.server.user.geti(user).cached, ~~(Date.now() / 1000) - this._recachetime);
|
||||
//console.log(user, "already cached");
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log("get whois for", user);
|
||||
//console.log("get whois for", user);
|
||||
this.send(`WHOIS ${user}`);
|
||||
}
|
||||
}
|
||||
|
@ -9,21 +9,23 @@ const clients = [];
|
||||
|
||||
const wrapper = function () {
|
||||
for (let srv in cfg.client) {
|
||||
switch (cfg.client[srv].type) {
|
||||
case "irc":
|
||||
clients.push({
|
||||
name: cfg.client[srv].network,
|
||||
type: "irc",
|
||||
client: new irclib(cfg.client[srv])
|
||||
});
|
||||
break;
|
||||
case "tg":
|
||||
clients.push({
|
||||
name: "tg",
|
||||
type: "tg",
|
||||
client: new tglib(cfg.client[srv])
|
||||
});
|
||||
break;
|
||||
if(cfg.client[srv].enabled) {
|
||||
switch (cfg.client[srv].type) {
|
||||
case "irc":
|
||||
clients.push({
|
||||
name: cfg.client[srv].network,
|
||||
type: "irc",
|
||||
client: new irclib(cfg.client[srv])
|
||||
});
|
||||
break;
|
||||
case "tg":
|
||||
clients.push({
|
||||
name: "tg",
|
||||
type: "tg",
|
||||
client: new tglib(cfg.client[srv])
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user