Parcourir la source

Support umodes + more protocol updates.

k4be il y a 5 ans
Parent
commit
c21849187c
3 fichiers modifiés avec 60 ajouts et 47 suppressions
  1. 0 6
      irc.js
  2. 51 40
      protocol/unrealircd.js
  3. 9 1
      user.js

+ 0 - 6
irc.js

@@ -109,11 +109,6 @@ function newServer(name, sid, desc, distance, uplink){
 	servers.push(server);
 }
 
-function parseUmodes(text){
-	return null;
-	// TODO
-}
-
 function ircSendData(tags, from, cmd, args){
 	var data = makeTagsString(tags);
 	if(from){
@@ -214,7 +209,6 @@ var irc = {
 			killUser: killUser,
 			newServer: newServer,
 			newUser: newUser,
-			parseUmodes: parseUmodes,
 			getChannel: getChannel,
 			quitUser: quitUser,
 			removeServer: removeServer,

+ 51 - 40
protocol/unrealircd.js

@@ -49,7 +49,6 @@ var handlers = {
 	killUser: null,
 	newServer: null,
 	newUser: null,
-	parseUmodes: null,
 	getChannel: null,
 	findChannel: null,
 	quitUser: null,
@@ -114,6 +113,30 @@ var chmodeMap = {
 	'c': { 'name': 'NOCOLOR', 'user': true, 'services': true }
 };
 
+var umodeMap = {
+	'i': { 'name': 'INVISIBLE', 'user': true, 'services': true },
+	'o': { 'name': 'OPER', 'user': false, 'services': false },
+	'w': { 'name': 'WALLOP', 'user': true, 'services': true },
+	'r': { 'name': 'REGISTEREDNICK', 'user': false, 'services': true },
+	's': { 'name': 'SNOTICE', 'user': true, 'services': true },
+	'x': { 'name': 'CLOAK', 'user': true, 'services': true },
+	'z': { 'name': 'SECUREUSER', 'user': false, 'services': false },
+	'd': { 'name': 'DEAF', 'user': true, 'services': true },
+	'H': { 'name': 'HIDEIRCOP', 'user': false, 'services': false },
+	't': { 'name': 'VHOST', 'user': false, 'services': true },
+	'I': { 'name': 'HIDEIDLE', 'user': false, 'services': false },
+	'D': { 'name': 'PRIVDEAF', 'user': true, 'services': true },
+	'Z': { 'name': 'SECUREMESSAGES', 'user': true, 'services': true },
+	'R': { 'name': 'REGISTEREDMESSAGES', 'user': true, 'services': true },
+	'q': { 'name': 'UNKICKABLE', 'user': false, 'services': false },
+	'p': { 'name': 'HIDECHANNELS', 'user': true, 'services': true },
+	'W': { 'name': 'WHOISNOTICE', 'user': false, 'services': false },
+	'G': { 'name': 'CENSORMESSAGES', 'user': true, 'services': true },
+	'T': { 'name': 'NOCTCPMESSAGES', 'user': true, 'services': true },
+	'S': { 'name': 'SERVICEUSER', 'user': false, 'services': true },
+	'B': { 'name': 'BOT', 'user': true, 'services': true }
+};
+
 function parseChannelModes(modes, args){
 	var plus = true;
 	var argIndex = 0;
@@ -149,7 +172,6 @@ function parseChannelModes(modes, args){
 		} else if(connection.statusmodes.indexOf(c) >= 0){
 			var user = handlers.findUser(args[argIndex++]);
 			if(user){
-				console.log('Setting status mode for '+user.name);
 				output['status'].push({ 'name': name, 'user': user, 'status': plus });
 			} else {
 				throw 'User not found';
@@ -161,10 +183,27 @@ function parseChannelModes(modes, args){
 			output[name] = plus;
 		}
 	}
-	console.log(output);
 	return output;
 }
 
+function parseUmodes(modeString){
+	var plus = true;
+	var modes = {};
+	for(var i=0; i<modeString.length; i++){
+		var c = modeString.charAt(i);
+		switch(c){
+			case '+': plus = true; break;
+			case '-': plus = false; break;
+			default:
+				var modeName = umodeMap[c].name;
+				if(!modeName) modeName = c;
+				modes[modeName] = plus;
+				break;
+		}
+	}
+	return modes;
+}
+
 function parseModePrefix(text){
 	var modes = {'status': [], 'list': [] };
 	var isUser = false;
@@ -319,7 +358,7 @@ var cmdBinds = {
 		if(account == '0'){
 			account = null;
 		}
-		handlers.newUser(nick, distance, TS, ident, host, uid, account, handlers.parseUmodes(umodes), vhost, cloakedHost, ip, realname, msg.sender.server);
+		handlers.newUser(nick, distance, TS, ident, host, uid, account, parseUmodes(umodes), vhost, cloakedHost, ip, realname, msg.sender.server);
 	},
 
 	'SJOIN': function(msg){
@@ -348,6 +387,9 @@ var cmdBinds = {
 	'SENDUMODE': function(msg){ // ignore
 	},
 	
+	'SENDSNO': function(msg){ // ignore
+	},
+	
 	'PASS': function(msg){ // ignore
 	},
 	
@@ -355,33 +397,7 @@ var cmdBinds = {
 		console.log(msg);
 		//TODO
 	},
-/*messagedata {
-  text: '1584206946',
-  args: [ '#qwer', '+nt', '1584206946' ],
-  tags: [
-    time: '2020-03-14T17:29:07.017Z',
-    msgid: '0AnsVOjKaaFGxoaANiChIo-Uqo0dqr9WjGPgUEgGzdr3w'
-  ],
-  command: 'MODE',
-  sender: {
-    nick: 'test3.pirc.pl',
-    ident: '',
-    host: '',
-    server: server {
-      name: 'test3.pirc.pl',
-      sid: '143',
-      description: 'serwer testowy!',
-      distance: '1',
-      uplink: [server],
-      introduce: [Function]
-    },
-    user: false
-  },
-  time: 2020-03-14T17:29:07.021Z,
-  reply: [Function],
-  originalString: '@time=2020-03-14T17:29:07.017Z;msgid=0AnsVOjKaaFGxoaANiChIo-Uqo0dqr9WjGPgUEgGzdr3w :143 MODE #qwer +nt  1584206946'
-}
-*/
+
 	'MODE': function(msg){
 		var channel = handlers.findChannel(msg.args[0]);
 		if(channel){
@@ -392,8 +408,6 @@ var cmdBinds = {
 			var chmodes = parseChannelModes(msg.args[1], modeArgs);
 			channel.changeModes(chmodes);
 		}
-		console.log(msg);
-		//TODO
 	},
 	
 	'TKL': function(msg){
@@ -451,13 +465,11 @@ var cmdBinds = {
 	},
 	
 	'SETHOST': function(msg){
-		console.log(msg);
-		//TODO
+		msg.sender.user.changeVHost(msg.args[0]);
 	},
 	
 	'SETIDENT': function(msg){
-		console.log(msg);
-		//TODO
+		msg.sender.user.changeVIdent(msg.args[0]);
 	},
 	
 	'NICK': function(msg){
@@ -501,10 +513,9 @@ messagedata {
 	'REPUTATION': function(msg){
 		//TODO
 	},
-	
+
 	'UMODE2': function(msg){
-		console.log(msg);
-		//TODO
+		msg.sender.user.changeUmodes(parseUmodes(msg.args[0]));
 	},
 	
 	'KILL': function(msg){

+ 9 - 1
user.js

@@ -4,7 +4,7 @@ var user = function(){
 	this.ident = null;
 	this.host = null;
 	this.account = null;
-	this.umodes = null;
+	this.umodes = {};
 	this.vhost = null;
 	this.cloakedHost = null;
 	this.ip = null;
@@ -30,6 +30,7 @@ var user = function(){
 		this.ip = ip;
 		this.realname = realname;
 		this.uplink = uplink;
+		console.log(this.umodes);
 	}
 	
 	this.setSecure = function(secure){
@@ -55,6 +56,13 @@ var user = function(){
 	this.changeNick = function(nick){
 		this.name = nick;
 	}
+	
+	this.changeUmodes = function(umodes){
+		for(umode in umodes){
+			this.umodes[umode] = umodes[umode];
+		}
+		console.log(this.umodes);
+	}
 }
 
 module.exports = user;