Ip via username rather than realname
authorDarren <darren@darrenwhitlen.com>
Sun, 21 Oct 2012 20:39:51 +0000 (21:39 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 21 Oct 2012 20:39:51 +0000 (21:39 +0100)
server/app.js
server/config.json

index 7668bfcc723a1ccb144685688e921fc17fff3378..d6af26912a0ac8b124b3eff7529146bfdb90fef6 100644 (file)
@@ -823,7 +823,10 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb
     events.EventEmitter.call(this);
 
     onConnectHandler = function () {
-        var realname = nick;
+        // Inspired by:
+        // <dux0r> y4ry65yer56ytr
+        var realname = '[www.kiwiirc.com] ' + nick;
+        var username = nick.replace(/[^0-9a-zA-Z\-_.]/, '');
 
         that.IRC.nick = nick;
         // Send the login data
@@ -831,8 +834,11 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb
             websocket.kiwi.hostname = (err) ? websocket.kiwi.address : _.first(domains);
 
             // Check if we need to pass the users IP as its realname
-            if (kiwi.config.ip_as_realname && kiwi.config.ip_as_realname.indexOf(host) > -1) {
-                realname = websocket.kiwi.address;
+            if (kiwi.config.ip_as_username && kiwi.config.ip_as_username.indexOf(host) > -1) {
+                // Get a hex value of the clients IP
+                username = websocket.kiwi.address.split('.').map(function(i, idx){
+                    return parseInt(i, 10).toString(16);
+                }).join('');
             }
 
             // Do we have a WEBIRC password for this?
@@ -847,7 +853,8 @@ this.IRCConnection = function (websocket, nick, host, port, ssl, password, callb
 
             websocket.sendServerLine('CAP LS');
             websocket.sendServerLine('NICK ' + nick);
-            websocket.sendServerLine('USER kiwi_' + nick.replace(/[^0-9a-zA-Z\-_.]/, '') + ' 0 0 :' + realname);
+            websocket.sendServerLine('USER ' + username + ' 0 0 :' + realname);
+        console.log('Username:', username, 'Realname:', realname);
 
             that.connected = true;
             that.emit('connect');
index 6477b1e0a606753bc8a7381dfb716ea7264a80f6..4dfc684baa14d2635dd65adfb55e96b3e843e99c 100755 (executable)
@@ -37,7 +37,7 @@
                             "irc.example.com":  "examplepassword",
                             "127.0.0.1":        "foobar"
                         },
-    "ip_as_realname": [],
+    "ip_as_username": [],
 
     "transports":       [
                             "websocket",