Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Name Lock Command #45

Merged
merged 3 commits into from

2 participants

@patrickroberts

There we go. Hopefully this is correctly formatted and abides by the rules of the permissions interface that kota added.

@Zarel
Owner

This sorta just made me realize how much of a hack mutedIps is... bannedIps and mutedIps were always sort of a hack...

@Zarel
Owner

This patch is definitely clean enough to work as an interim solution, though. Can someone test to make sure this works, and then merge it?

@patrickroberts

The only additional thing that needs to be made is the line "namelock: true" under either mods or admins on the config file. Other than that, this should work just fine. I've tested it broadly, including with every mute evade scenario I could think of.

@Zarel
Owner

Is there any reason you didn't make this change yourself?

@patrickroberts

I did, but it won't show up in the diff since your server only has the config-example.

@Zarel
Owner

Is there any reason you didn't change config-example?

I mean, being an example of what your config file should look like is pretty much its entire purpose of existence.

@patrickroberts

Done. Sorry, I misunderstood. Originally I thought we were supposed to just rename it to config instead of actually keeping it.

@patrickroberts

I'm gonna go ahead and pull it off since SOMEONE just proved its now buggy again... I don't know why, since I did the exact same thing...

@patrickroberts

Apparently I pulled some of Immortal's changes, but I have reopened this because I have finally fixed NameLock, and in fact, have improved it to prune people who have just logged in rather than only applying it when users are changing their name from Guest to join the chat. I have tested it and there are no bugs to report.

@Zarel Zarel commented on the diff
@@ -364,6 +386,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;
@Zarel Owner
Zarel added a note

lol, sneaking yourself into the avatar table. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@patrickroberts

Err, where is that exactly?

@Zarel
Owner

Hmm... I think this is good enough.

@Zarel Zarel merged commit 22564db into Zarel:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 27, 2012
  1. @patrickroberts
  2. @patrickroberts
Commits on Apr 28, 2012
  1. @patrickroberts

    Updated Name Lock

    patrickroberts authored
This page is out of date. Refresh to see the latest.
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;
@Zarel Owner
Zarel added a note

lol, sneaking yourself into the avatar table. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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;
Something went wrong with that request. Please try again.