Permalink
Browse files

Merge pull request #45 from patrickroberts/nameLock

Name Lock Command
  • Loading branch information...
2 parents b243866 + 0e83300 commit 22564db52b749d22ec62f34ba3865b47679fe970 @Zarel committed Apr 28, 2012
Showing with 125 additions and 1 deletion.
  1. +2 −0 app.js
  2. +68 −0 chat-commands.js
  3. +2 −1 config/config-example.js
  4. +53 −0 users.js
View
2 app.js
@@ -1134,6 +1134,8 @@ mutedIps = {
};
bannedIps = {
};
+nameLockedIps = {
+};
function resolveUser(you, socket) {
if (!you) {
View
68 chat-commands.js
@@ -46,7 +46,75 @@ function parseCommandLocal(user, cmd, target, room, socket, message) {
switch (cmd) {
case 'me':
return '/me '+target;
+ break;
+ case 'namelock':
+ case 'nl':
+ if(!target) {
+ return false;
+ }
+ var targets = splitTarget(target);
+ var targetUser = getUser(targets[0]);
+ var targetName = targets[1]||targetUser.name;
+ if(!user.can('namelock',targetUser)) {
+ socket.emit('console','/namelock - access denied.');
+ return false;
+ } else if(targetUser && targetName) {
+ var oldname = targetUser.name;
+ var targetId = toUserid(targetName);
+ var userOfName = Users.users[targetId];
+ var isAlt = false;
+ if(userOfName) {
+ for(var altName in userOfName.getAlts()) {
+ var altUser = Users.users[toUserid(alt)];
+ if(targetId == altUser.userid) {
+ isAlt = true;
+ break;
+ }
+ for(var prevName in altUser.prevNames) {
+ if(targetId == toUserid(prevName)) {
+ isAlt = true;
+ break;
+ }
+ }
+ if(isAlt) break;
+ }
+ }
+ if(!userOfName || oldname == targetName || isAlt)
+ targetUser.nameLock(targetName,true);
+ if (targetUser.nameLocked()) {
+ room.add(user.name+" name-locked "+oldname+" to "+targetName+".");
+ return false;
+ }
+ socket.emit('console',oldname+" can't be name-locked to "+targetName+".");
+ } else {
+ socket.emit('console',(target.split(",")[0].trim())+" not found.");
+ }
+ return false;
+ break;
+ case 'nameunlock':
+ case 'unnamelock':
+ case 'nul':
+ case 'unl':
+ if(!user.can('namelock') || !target) {
+ return false;
+ }
+ var removed = false;
+ for (var i in nameLockedIps) {
+ if(nameLockedIps[i]==target) {
+ delete nameLockedIps[i];
+ removed = true;
+ }
+ } if(removed) {
+ if(getUser(target)) {
+ rooms.lobby.usersChanged = true;
+ }
+ room.add(user.name+" unlocked the name of "+target+".");
+ } else {
+ socket.emit('console',target+" not found.");
+ }
+ return false;
+ break;
case 'command':
if (target.command === 'userdetails') {
target.userid = ''+target.userid;
View
3 config/config-example.js
@@ -115,7 +115,8 @@ exports.groups = {
mute: 'u',
forcerename: 'u',
redirect: true,
- receivemutedpms: true
+ receivemutedpms: true,
+ namelock: 'u'
},
'+': {
id: "voice",
View
53 users.js
@@ -35,6 +35,19 @@ function searchUser(name) {
}
return users[userid];
}
+function nameLock(user,name,ip) {
+ ip = ip||user.ip;
+ var userid = toUserid(name);
+ if(nameLockedIps[ip]) {
+ return user.nameLock(nameLockedIps[ip]);
+ } for(var i in nameLockedIps) {
+ if((userid && toUserid(nameLockedIps[i])==userid)||user.userid==toUserid(nameLockedIps[i])) {
+ nameLockedIps[ip] = nameLockedIps[i];
+ return user.nameLock(nameLockedIps[ip]);
+ }
+ }
+ return name||user.name;
+}
function connectUser(name, socket, token, room) {
var userid = toUserid(name);
var user;
@@ -51,6 +64,10 @@ function connectUser(name, socket, token, room) {
} else {
console.log("NEW USER: [guest] "+name);
user = new User(name, person, token);
+ var nameSuggestion = nameLock(user);
+ if(nameSuggestion!=user.name) {
+ user.rename(nameSuggestion);
+ }
}
if (room) {
user.joinRoom(room, person);
@@ -125,6 +142,8 @@ function User(name, person, token) {
this.getIdentity = function() {
if (selfP.muted) {
return '!'+selfP.name;
+ } if(selfP.nameLocked()) {
+ return '#'+selfP.name;
}
return selfP.group+selfP.name;
};
@@ -244,6 +263,7 @@ function User(name, person, token) {
for (var i in selfP.roomCount) {
getRoom(i).rename(selfP, oldid, joining);
}
+ rooms.lobby.usersChanged = true;
return true;
};
this.resetName = function() {
@@ -302,6 +322,9 @@ function User(name, person, token) {
}
if (!name) name = '';
name = sanitizeName(name);
+ console.log("checking name lock for: "+selfP.name+" renaming to "+name);
+ name = nameLock(selfP,name);
+ console.log("returned "+name);
var userid = toUserid(name);
if (selfP.authenticated) auth = false;
@@ -364,6 +387,7 @@ function User(name, person, token) {
else if (userid === "aeo2") avatar = 166;
else if (userid === "sharktamer") avatar = 7;
else if (userid === "bmelts") avatar = 1004;
+ else if (userid === "n") avatar = 209;
try {
var data = JSON.parse(body);
@@ -563,6 +587,34 @@ function User(name, person, token) {
}
return result;
};
+ this.nameLock = function(targetName,recurse) {
+ var targetUser = getUser(targetName);
+ if(nameLockedIps[selfP.ip]==targetName||!targetUser||targetUser.ip == selfP.ip) {
+ nameLockedIps[selfP.ip] = targetName;
+ if(recurse) {
+ for(var i in users) {
+ if(users[i].ip == selfP.ip && users[i] != selfP) {
+ users[i].destroy();
+ }
+ }
+ selfP.forceRename(targetName,selfP.authenticated);
+ }
+ }
+ return targetName;
+ };
+ this.nameLocked = function() {
+ if(nameLockedIps[selfP.ip]) {
+ selfP.nameLock(nameLockedIps[selfP.ip]);
+ return true;
+ } for(var i in nameLockedIps) {
+ if(nameLockedIps[i]==selfP.name) {
+ nameLockedIps[selfP.ip] = nameLockedIps[i];
+ selfP.nameLock(nameLockedIps[selfP.ip]);
+ return true;
+ }
+ }
+ return false;
+ };
this.ban = function(noRecurse) {
// no need to recurse, since the root for-loop already bans everything with your IP
if (!noRecurse) for (var i in users) {
@@ -796,3 +848,4 @@ exports.searchUser = searchUser;
exports.connectUser = connectUser;
exports.users = users;
exports.prevUsers = prevUsers;
+exports.importUsergroups = importUsergroups;

1 comment on commit 22564db

Please sign in to comment.