Raised This Month: $32 Target: $400
 8% 

Rename players to prevent taking CLAN tag


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 02-24-2022 , 01:42   Rename players to prevent taking CLAN tag
Reply With Quote #1

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);
    }


__________________

Last edited by finishlast; 02-24-2022 at 01:50.
finishlast is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 02-24-2022 , 02:50   Re: Rename players to prevent taking CLAN tag
Reply With Quote #2

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 
sorallll is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 02-24-2022 , 18:08   Re: Rename players to prevent taking CLAN tag
Reply With Quote #3

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;

__________________
GitHub | Discord: @azalty | Steam
azalty is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 02-25-2022 , 09:22   Re: Rename players to prevent taking CLAN tag
Reply With Quote #4

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

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.
__________________

Last edited by finishlast; 02-25-2022 at 09:25.
finishlast is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 02-25-2022 , 19:54   Re: Rename players to prevent taking CLAN tag
Reply With Quote #5

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);

__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 02-25-2022 at 19:55.
azalty is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 02-26-2022 , 05:05   Re: Rename players to prevent taking CLAN tag
Reply With Quote #6

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
__________________

Last edited by finishlast; 02-26-2022 at 05:06.
finishlast is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 02-26-2022 , 10:44   Re: Rename players to prevent taking CLAN tag
Reply With Quote #7

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
__________________
GitHub | Discord: @azalty | Steam
azalty is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 02-26-2022 , 11:07   Re: Rename players to prevent taking CLAN tag
Reply With Quote #8

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;

__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 02-26-2022 at 11:17.
azalty is offline
finishlast
Senior Member
Join Date: Nov 2018
Location: In Reno with the vitamin
Old 02-27-2022 , 05:25   Re: Rename players to prevent taking CLAN tag
Reply With Quote #9

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.
__________________
finishlast is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-27-2022 , 07:08   Re: Rename players to prevent taking CLAN tag
Reply With Quote #10

Use players #userid for targeting, not names. (Look from console status).
!kick #59
Bacardi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:36.


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