AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Rename players to prevent taking CLAN tag (https://forums.alliedmods.net/showthread.php?t=336495)

finishlast 02-24-2022 01:42

Rename players to prevent taking CLAN tag
 
Hi,

I use this easy script below to give admins a clantag.

How can I modify this to prevent other players from using

setinfo name CLANTAG playername

The innitial idea was to hook playerrename, then string replace name and then rename player.
After that rename the admins.

That would cause the hook again and ends in a loop bc I set playername and fire rename player hook again.

Another problem I had was when I hook playerrename I only see the oldplayer name with
Format(strNickname, sizeof(strNickname), "%N", client);
But you would need the new player name to do the string replace.

Below is the old script with the attempt, below below is the new attempt that ends in mess.

I guess it is the wrong approach...

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME "[INS] Admin TAG"
#define PLUGIN_VERSION "0.02"

public Plugin myinfo = {
    
name PLUGIN_NAME,
    
author "Linothorax",
    
description "Add [♛] infront of Playername",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart() {
    
PrintToServer("Loaded %s v%s"PLUGIN_NAMEPLUGIN_VERSION);
}

public 
void OnClientPostAdminCheck(int client) {
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
char strNickname[156];
        
Format(strNicknamesizeof(strNickname), "CLANTAG %N"client);
        
SetClientName(clientstrNickname);
    }



PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME "TAG"
#define PLUGIN_VERSION "0.0.1"

public Plugin myinfo = {
    
name PLUGIN_NAME,
    
author "TAG",
    
description "TAG",
    
version PLUGIN_VERSION,
    
url ""
};


public 
void OnPluginStart()
{
        
HookEvent("player_changename"_renameifneeded);
        
HookEvent("player_connect_full"_renameifneeded);
}


public 
void _renameifneeded(Event event, const char[] namebool dontBroadcast)
{
        
int client GetClientOfUserId(GetEventInt(event"userid"));
        
char strNickname[256];
        
Format(strNicknamesizeof(strNickname), "%N"client);
        
PrintToChat(client"Name atm %s",strNickname);
        
ReplaceString(strNickname256"CLANTAG" "");
        
PrintToChat(client"Name after stringreplace %s",strNickname);
        
Format(strNickname256"%s"strNickname);
        
SetClientName(clientstrNickname);
        if (
GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
Format(strNickname256"CLANTAG %N"client);
        
SetClientName(clientstrNickname);
    }




sorallll 02-24-2022 02:50

Re: Rename players to prevent taking CLAN tag
 
PHP Code:

player_changename
Note
Player changed name
Name
:    player_changename
Structure
:    
short    userid    user ID on server
string    oldname    players old 
(currentname
string    newname    players 
new name 


azalty 02-24-2022 18:08

Re: Rename players to prevent taking CLAN tag
 
PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME "[INS] Admin TAG"
#define PLUGIN_VERSION "0.02"

#define TAG "[♛]" // The admin tag you want to use. Don't include a space at the end.
#define TAG_SPACE " " // Defines what should be between the tag and the username. Set it to be an empty string "" to have no spacer.

bool g_bNameChanged[MAXPLAYERS 1];

public 
Plugin myinfo = {
    
name PLUGIN_NAME,
    
author "Linothorax",
    
description "Add [♛] infront of Playername",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart() {
    
HookEvent("player_changename"OnPlayerChangedNameEventHookMode_Pre);
    
PrintToServer("Loaded %s v%s"PLUGIN_NAMEPLUGIN_VERSION);
}

public 
void OnClientPostAdminCheck(int client) {
    
g_bNameChanged[client] = false;
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(client);
    }
}

void GiveAdminTag(int client) {
    
char strNickname[156];
    
Format(strNicknamesizeof(strNickname), TAG ... TAG_SPACE ... "%N"client);
    
g_bNameChanged[client] = true;
    
SetClientName(clientstrNickname);
}

Action OnPlayerChangedName(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
// Prevents infinite loops
    
if (g_bNameChanged[client]) {
        
g_bNameChanged[client] = false;
        return 
Plugin_Continue;
    }
    
    
// Adds back the admin tag
    
if (GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(client);
        return 
Plugin_Continue;
    }
    
    
char oldname[156];
    
char newname[156];
    
event.GetString("oldname"oldnamesizeof(oldname));
    
event.GetString("newname"newnamesizeof(newname));
    
    if (
ReplaceString(newnamesizeof(newname), TAG"") == 0) { // they don't have the admin tag
        
return Plugin_Continue;
    }
    
// else, we already removed any admin tag in their username
    
TrimString(newname); // Removes any spaces before and after the username
    
    
g_bNameChanged[client] = true// prevents infinite loops
    
SetClientName(clientnewname);
    return 
Plugin_Continue;



finishlast 02-25-2022 09:22

Re: Rename players to prevent taking CLAN tag
 
Oh that is almost the thing I need.

For some reason it is bugging out if an admin tries to rename himself.

It adds the tag again, if you use utf8 character and rename 3 time LILAC kicks you bc of characters in name :D

I guess you have to strip the TAG no matter what innitially to make sure its not already set.

PHP Code:

void GiveAdminTag(int client) {
    
char strNickname[156];
// get the name here somehow
//strip tag
//format that with TAG
    
Format(strNicknamesizeof(strNickname), TAG ... TAG_SPACE ... "%N"client);
    
g_bNameChanged[client] = true;
    
SetClientName(clientstrNickname);


That readds the tag every time an admin tries to rename himself, would need the stripping inside it somehow.

azalty 02-25-2022 19:54

Re: Rename players to prevent taking CLAN tag
 
I didn't really understand what was the problem, but here it is:

PHP Code:

void GiveAdminTag(int client) {
    
char strNickname[156];
    
GetClientName(clientstrNicknamesizeof(strNickname));
    
ReplaceString(strNicknamesizeof(strNickname), TAG"");
    
TrimString(strNickname);
    
Format(strNicknamesizeof(strNickname), TAG ... TAG_SPACE ... "%s"strNickname); // refering to strNickname is allowed because we use Format(). It won't work with FormatEx().
    
g_bNameChanged[client] = true;
    
SetClientName(clientstrNickname);



finishlast 02-26-2022 05:05

Re: Rename players to prevent taking CLAN tag
 
So it looks like this now:

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME "[INS] Admin TAG"
#define PLUGIN_VERSION "0.02"

#define TAG "[♛]" // The admin tag you want to use. Don't include a space at the end.
#define TAG_SPACE " " // Defines what should be between the tag and the username. Set it to be an empty string "" to have no spacer.

bool g_bNameChanged[MAXPLAYERS 1];

public 
Plugin myinfo = {
    
name PLUGIN_NAME,
    
author "Linothorax",
    
description "Add [♛] infront of Playername",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart() {
    
HookEvent("player_changename"OnPlayerChangedNameEventHookMode_Pre);
    
PrintToServer("Loaded %s v%s"PLUGIN_NAMEPLUGIN_VERSION);
}

public 
void OnClientPostAdminCheck(int client) {
    
g_bNameChanged[client] = false;
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(client);
    }
}

void GiveAdminTag(int client) {
    
char strNickname[156];
    
GetClientName(clientstrNicknamesizeof(strNickname));
    
ReplaceString(strNicknamesizeof(strNickname), TAG"");
    
TrimString(strNickname);
    
Format(strNicknamesizeof(strNickname), TAG ... TAG_SPACE ... "%s"strNickname); // refering to strNickname is allowed because we use Format(). It won't work with FormatEx().
    
g_bNameChanged[client] = true;
    
SetClientName(clientstrNickname);


Action OnPlayerChangedName(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
// Prevents infinite loops
    
if (g_bNameChanged[client]) {
        
g_bNameChanged[client] = false;
        return 
Plugin_Continue;
    }
    
    
// Adds back the admin tag
    
if (GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(client);
        return 
Plugin_Continue;
    }
    
    
char oldname[156];
    
char newname[156];
    
event.GetString("oldname"oldnamesizeof(oldname));
    
event.GetString("newname"newnamesizeof(newname));
    
    if (
ReplaceString(newnamesizeof(newname), TAG"") == 0) { // they don't have the admin tag
        
return Plugin_Continue;
    }
    
// else, we already removed any admin tag in their username
    
TrimString(newname); // Removes any spaces before and after the username
    
    
g_bNameChanged[client] = true// prevents infinite loops
    
SetClientName(clientnewname);
    return 
Plugin_Continue;


When I connect as admin and change name, then I have the ♛ in front of name, when I do

setinfo name "test"

the name stays old with ♛ in front

if I do it a second time, I get the new name without ♛


Connect to server
Name= [♛] Originalname
setinfo name "TEST"
Name= [♛] Originalname
setinfo name "TEST"
Name= TEST
setinfo name "TEST"
Name= TEST

I would think it would strip the crown on player_changename and then readds it for admins but this does not happen.
Thank you for your patience and work btw

azalty 02-26-2022 10:44

Re: Rename players to prevent taking CLAN tag
 
I wasn't even aware setinfo name "something" existed

Try changing your name the "normal" way: through Steam or sm_rename

I'll investigate a bit further about that setinfo name thing

azalty 02-26-2022 11:07

Re: Rename players to prevent taking CLAN tag
 
After some testing, setinfo name is highly buggy and doesn't even properly change your username by default. It seems to enforce your current steam name when changed, even when I set it to something else.

The plugins is working fine when using sm_rename

I will upload a quick fix for something I noticed

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_NAME "[INS] Admin TAG"
#define PLUGIN_VERSION "0.02"

#define TAG "[♛]" // The admin tag you want to use. Don't include a space at the end.
#define TAG_SPACE " " // Defines what should be between the tag and the username. Set it to be an empty string "" to have no spacer.

bool g_bNameChanged[MAXPLAYERS 1];

public 
Plugin myinfo = {
    
name PLUGIN_NAME,
    
author "Linothorax",
    
description "Add [♛] infront of Playername",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart() {
    
HookEvent("player_changename"OnPlayerChangedName);
    
PrintToServer("Loaded %s v%s"PLUGIN_NAMEPLUGIN_VERSION);
}

public 
void OnClientPostAdminCheck(int client) {
    
g_bNameChanged[client] = false;
    if (
GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(client"");
    }
}

void GiveAdminTag(int client, const char[] name) {
    
char strNickname[156];
    if (
name[0] == '\0'// is string empty?
        
GetClientName(clientstrNicknamesizeof(strNickname));
    else
        
strcopy(strNicknamesizeof(strNickname), name);
    
    
//LogMessage("GiveAdminTag called. ClientName: %s", strNickname);
    
ReplaceString(strNicknamesizeof(strNickname), TAG"");
    
TrimString(strNickname);
    
Format(strNicknamesizeof(strNickname), TAG ... TAG_SPACE ... "%s"strNickname); // refering to strNickname is allowed because we use Format(). It won't work with FormatEx().
    
g_bNameChanged[client] = true;
    
SetClientName(clientstrNickname);
}

Action OnPlayerChangedName(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
    
// Prevents infinite loops
    
if (g_bNameChanged[client]) {
        
g_bNameChanged[client] = false;
        return 
Plugin_Continue;
    }
    
    
char oldname[156];
    
char newname[156];
    
event.GetString("oldname"oldnamesizeof(oldname));
    
event.GetString("newname"newnamesizeof(newname));
    
//LogMessage("OnPlayerChangedName called");
    //LogMessage("oldname: %s - newname: %s", oldname, newname);
    
    // Adds back the admin tag
    
if (GetUserAdmin(client) != INVALID_ADMIN_ID) {
        
GiveAdminTag(clientnewname); // grab the newname from here because the client name from GetClientName isn't updated fast enough
        
return Plugin_Continue;
    }
    
    if (
ReplaceString(newnamesizeof(newname), TAG"") == 0) { // they don't have the admin tag
        
return Plugin_Continue;
    }
    
// else, we already removed any admin tag in their username
    
TrimString(newname); // Removes any spaces before and after the username
    
    
g_bNameChanged[client] = true// prevents infinite loops
    
SetClientName(clientnewname);
    return 
Plugin_Continue;



finishlast 02-27-2022 05:25

Re: Rename players to prevent taking CLAN tag
 
It seems to work now, normally admins don't tend to change their name anyways.
Thanks a lot for that!

Btw the setinfo name "" is widely used by lots of trolls to impersonate people by copying their name and add a blank after the name.

Lets say you have "player1" and then someone does setinfo name "player1 " it seems like you have two player1.

Mostly done to avoid !kick player1 which may result in "multiple target error" output.

Or it is just used to - well - change your name midgame to someting funny.

Bacardi 02-27-2022 07:08

Re: Rename players to prevent taking CLAN tag
 
Use players #userid for targeting, not names. (Look from console status).
!kick #59


All times are GMT -4. The time now is 16:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.