Code to kick user


#1

Hi,
I am writing a function to kick a user. Not exactly sure how to implement. The API shows:

kick(nodeID)
Kick/ban another user. Removes them from the server and prevents them from returning. Bans by either user name (if available) or machine fingerprint otherwise. This will only do anything if you’re an admin of the domain you’re in.
Parameters:
Name Type Description
nodeID Uuid The node or session ID of the user you want to kick.

First, how do I get the UUID of the user I want to kick.
Then, do I just do - kick(uuid)?


#2

Heya!

To get a list of users in general, you would want to use Avatar.getAvatarIdentifiers() like so:
var identifiers = AvatarList.getAvatarIdentifiers();

Now we can begin a loop and grab their ID (sessionID):

for(var iPos = 0; iPos < identifiers.length; ++iPos) {
	var sessionID = identifiers[ iPos ];
}

Or you could also just do this:

identifiers.foreach(function(sessionID) {

});

From there, you can use things like AvatarList.getAvatar to have their information in a MyAvatar like system and for using said information for Users.kick. Of course, make sure to check Users.getCanKick to ensure you do have permissions to do so.

EDIT: Note, kick isn’t the same kind of kick you are used to: it’s really BAN.
Source: https://docs.highfidelity.com/api-reference/namespaces/users#.kick

Kick/ban another user. Removes them from the server and prevents them from returning. Bans by either user name (if available) or machine fingerprint otherwise. This will only do anything if you’re an admin of the domain you’re in.


#3

Hi! thanks for the response. That’s working so far…
I want to get the user name from the loop. I did this but get an error:

for (var iPos = 0; iPos < identifiers.length; ++iPos) {
        var sessionID = identifiers[iPos];
        print("sessionID: " + sessionID);

        var userName = Users.getUsernameFromID(sessionID);
        print("userName: " + userName);
}

The error I get is: Error: getUsernameFromID is not a function

Here’s the entire script: http://spinteractive.net/3D/kickUsers.js