|
@@ -37,8 +37,126 @@ var protocol = {
|
|
|
},
|
|
|
setSettings: function(newSettings){
|
|
|
settings = newSettings;
|
|
|
+ },
|
|
|
+ setEvents: function(newEvents){
|
|
|
+ events = newEvents;
|
|
|
+ },
|
|
|
+ // IRC actions
|
|
|
+ introduceUser: function(user){
|
|
|
+ var nick = user.name;
|
|
|
+ var distance = user.distance.toString();
|
|
|
+ var TS = user.TS.toString();
|
|
|
+ var ident = user.ident;
|
|
|
+ var host = user.host;
|
|
|
+ var uid = user.uid;
|
|
|
+ var account = '0';
|
|
|
+ if(user.account){
|
|
|
+ account = user.account;
|
|
|
+ }
|
|
|
+ var umodes = '+oSB'; // TODO
|
|
|
+ var vhost = '*';
|
|
|
+ if(user.vhost){
|
|
|
+ vhost = user.vhost;
|
|
|
+ }
|
|
|
+ var cloakedHost = '*';
|
|
|
+ if(user.cloakedHost){
|
|
|
+ cloakedHost = user.cloakedHost;
|
|
|
+ }
|
|
|
+ var ip = '*';
|
|
|
+ if(user.ip){
|
|
|
+ ip = user.ip;
|
|
|
+ }
|
|
|
+ var realname = user.realname;
|
|
|
+ var args = [nick, distance, TS, ident, host, uid, account, umodes, vhost, cloakedHost, ip, realname];
|
|
|
+ console.log(args);
|
|
|
+ ircSend(null, settings.ID, 'UID', args);
|
|
|
+ },
|
|
|
+ syncChannel: function(channel){
|
|
|
+ var modes = null;
|
|
|
+ var modeArgs = null;
|
|
|
+ // prepare list modes
|
|
|
+ var listModes = [];
|
|
|
+ for(m in channel.listModes){
|
|
|
+ var mode = channel.listModes[m];
|
|
|
+ for(var i=0; i<mode.length; i++){
|
|
|
+ switch(m){
|
|
|
+ case 'BAN': listModes.push('&' + mode[i]); break;
|
|
|
+ case 'EXCEPT': listModes.push('"' + mode[i]); break;
|
|
|
+ case 'INVEX': listModes.push('\'' + mode[i]); break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // prepare users
|
|
|
+ var users = [];
|
|
|
+ for(var i=0; i<channel.users.length; i++){
|
|
|
+ var user = channel.users[i];
|
|
|
+ if(user.uplink != settings.me) continue;
|
|
|
+ var status = '';
|
|
|
+ if(user.uid in channel.statusModes){
|
|
|
+ var statusModes = channel.statusModes[user.uid];
|
|
|
+ for(var j=0; j<statusModes.length; j++){
|
|
|
+ var statusMode = statusModes[j];
|
|
|
+ for(c in chmodeMap){
|
|
|
+ if(chmodeMap[c].name == statusMode){
|
|
|
+ for(sm in connection.statusmodes){
|
|
|
+ if(connection.statusmodes[sm] == c){
|
|
|
+ status += sm;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ users.push(status + user.uid);
|
|
|
+ }
|
|
|
+ var done = false;
|
|
|
+ var listCount = 0;
|
|
|
+ var userCount = 0;
|
|
|
+ do {
|
|
|
+ var text = '';
|
|
|
+ var count = 0;
|
|
|
+ for(; listCount < listModes.length; listCount++){
|
|
|
+ if(++count > 10) break;
|
|
|
+ if(text.length > 0) text += ' ';
|
|
|
+ text += listModes[listCount];
|
|
|
+ }
|
|
|
+
|
|
|
+ for(; userCount < users.length; userCount++){
|
|
|
+ if(++count > 10) break;
|
|
|
+ if(text.length > 0) text += ' ';
|
|
|
+ text += users[userCount];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(text.length == 0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ var args = [Math.floor(new Date() / 1000).toString(10), channel.name];
|
|
|
+ if(modes) args.push(modes); else args.push('+');
|
|
|
+ if(modeArgs) args.push(modeArgs);
|
|
|
+ args.push(text);
|
|
|
+ console.log(args);
|
|
|
+ ircSend(null, settings.ID, 'SJOIN', args);
|
|
|
+
|
|
|
+ } while(true);
|
|
|
+ },
|
|
|
+ 'makeUid': function(){
|
|
|
+ return settings.me.sid + randomID();
|
|
|
}
|
|
|
}
|
|
|
+//>>> @time=2020-03-15T12:17:07.355Z;msgid=FhjgUp20YBKQ32TGPM28tS :143 SJOIN 1580651090 #help +nt :0931Y7O8W 093375CFR 123VTY20R
|
|
|
+
|
|
|
+function randomID(){
|
|
|
+ var result = '';
|
|
|
+ var length = 6;
|
|
|
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
|
+ var charactersLength = characters.length;
|
|
|
+ for(var i=0; i<length; i++ ) {
|
|
|
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
module.exports = protocol;
|
|
|
|
|
@@ -65,6 +183,8 @@ var settings = {
|
|
|
maxUsers: null
|
|
|
};
|
|
|
|
|
|
+var events = {};
|
|
|
+
|
|
|
var connection = {
|
|
|
'protoctl': {},
|
|
|
'prefixes': {},
|
|
@@ -281,10 +401,12 @@ var cmdBinds = {
|
|
|
var expr = /^([^-]+)-([^-]+)-([^ ]+) (.*)$/;
|
|
|
var match = expr.exec(msg.args[2]);
|
|
|
if(match){
|
|
|
- handlers.newServer(msg.args[0], match[3], match[4], msg.args[1], settings.me);
|
|
|
+ settings.me.uplink = handlers.newServer(msg.args[0], match[3], match[4], msg.args[1], settings.me);
|
|
|
} else {
|
|
|
throw 'Unknown SERVER message';
|
|
|
}
|
|
|
+ events.doEvent('netSynced');
|
|
|
+ ircSend(null, settings.ID, 'EOS');
|
|
|
},
|
|
|
|
|
|
'MD': function(msg){
|
|
@@ -546,6 +668,67 @@ messagedata {
|
|
|
var server = handlers.findServer(msg.args[0]);
|
|
|
if(!server) return;
|
|
|
handlers.removeServer(server);
|
|
|
+ },
|
|
|
+/*messagedata {
|
|
|
+ text: 'TestServ',
|
|
|
+ args: [ '11K3R1VLH', 'TestServ' ],
|
|
|
+ tags: [],
|
|
|
+ command: 'WHOIS',
|
|
|
+ sender: {
|
|
|
+ nick: 'k4be',
|
|
|
+ ident: 'testowy',
|
|
|
+ host: 'localhost',
|
|
|
+ server: false,
|
|
|
+ user: user {
|
|
|
+ name: 'k4be',
|
|
|
+ TS: '1583056052',
|
|
|
+ ident: 'testowy',
|
|
|
+ host: 'localhost',
|
|
|
+ account: null,
|
|
|
+ umodes: [Object],
|
|
|
+ vhost: 'staff:netadmin',
|
|
|
+ cloakedHost: 'ukryty-18D8A42D',
|
|
|
+ ip: '0000:0000:0000:0000:0000:0000:0000:0001',
|
|
|
+ realname: 'realname',
|
|
|
+ uid: '143ZQ0B02',
|
|
|
+ distance: '0',
|
|
|
+ uplink: [server],
|
|
|
+ secure: false,
|
|
|
+ certfp: null,
|
|
|
+ vident: null,
|
|
|
+ metadata: {},
|
|
|
+ introduce: [Function],
|
|
|
+ setSecure: [Function],
|
|
|
+ setFingerprint: [Function],
|
|
|
+ changeVHost: [Function],
|
|
|
+ changeVIdent: [Function],
|
|
|
+ setRealname: [Function],
|
|
|
+ changeNick: [Function],
|
|
|
+ changeUmodes: [Function],
|
|
|
+ setMetadata: [Function]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ time: 2020-03-16T14:02:45.252Z,
|
|
|
+ reply: [Function],
|
|
|
+ originalString: ':143ZQ0B02 WHOIS 11K3R1VLH :TestServ'
|
|
|
+}*/
|
|
|
+ 'WHOIS': function(msg){
|
|
|
+ },
|
|
|
+
|
|
|
+ 'PRIVMSG': function(msg){
|
|
|
+ if(msg.args[0].charAt(0) == '#'){
|
|
|
+ events.doEvent('channelMessage', msg);
|
|
|
+ } else {
|
|
|
+ events.doEvent('botMessage', msg);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 'NOTICE': function(msg){
|
|
|
+ if(msg.args[0].charAt(0) == '#'){
|
|
|
+ events.doEvent('channelNotice', msg);
|
|
|
+ } else {
|
|
|
+ events.doEvent('botNotice', msg);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|