AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] Change your name ( sm_name ) (https://forums.alliedmods.net/showthread.php?t=308179)

eyal282 06-09-2018 11:05

[ANY] Change your name ( sm_name )
 
1 Attachment(s)
NOTE: The plugin will malfunction on ANY game that doesn't enforce the console command "name" to be equal to your steam name ( Works in CS:GO and L4D2 ). Doesn't break the plugin though.

Commands:

!name <new name> - Changes your name to the name you write after !name. For example: "!name Epic Guy" will change your name to Epic Guy. If you only write !name without anything after your name will change to your steam name.

!oname <name/#userid> - Finds a target's steam name.

setinfo secretname "New Name" - Next time you connect to the server, your name will be "New Name". This console command works on any server and even if you aren't inside a server.

Bugs:

Cheaters can give a wrong name on !oname. If a player sends a wrong name on !oname, he'll likely be VAC banned for doing so.

mug1wara 06-09-2018 11:40

Re: [ANY] Change your name
 
Nice, but might wanna check out the new syntax since it's becoming more current.

eyal282 06-09-2018 12:28

Re: [ANY] Change your name
 
Quote:

Originally Posted by mug1wara (Post 2596054)
Nice, but might wanna check out the new syntax since it's becoming more current.

I'm from AmxModX so I'm keeping my syntax and I know both if I need to edit a code.

mug1wara 06-09-2018 12:47

Re: [ANY] Change your name
 
That's fine ^_^

speedvoltage 06-09-2018 13:35

Re: [ANY] Change your name
 
I went ahead and edited the plugin to have the new style declarations (sorry for the leftover of the old code):
Code:

/**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
******************************************************************!AND HERE BEGINS A DREAM!*******************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************/

/******************************
INCLUDE ALL THE NECESSARY FILES
******************************/

#include <sourcemod>
#include <sdktools>

/******************************
COMPILE OPTIONS
******************************/

#pragma semicolon 1
#pragma newdecls required

/******************************
PLUGIN DEFINES
******************************/

/*Plugin Info*/
#define PLUGIN_NAME                                                                "Set My Name"
#define PLUGIN_AUTHOR                                                        "Eyal282 ( FuckTheSchool ) [Modified by Peter Brev with new style declarations]"
#define PLUGIN_VERSION                                                        "1.1.0.0"
#define PLUGIN_DESCRIPTION                                                "Allows players to use a new name"
#define PLUGIN_URL                                                                "https://forums.alliedmods.net/showthread.php?t=308179"

/*Plugin defines for messages*/
#define TAG                                                                        "[NAME]"
#define TAG_COLOR                                                        "\x07cc3300"
#define COLOR_AZURE                                                        "\x0700ace6"
#define COLOR_LIME                                                        "\x073ff206"
#define COLOR_PLAYER                                                        "\x07daaf0c"
#define COLOR_ERROR                                                        "\x07ff0000"

/******************************
PLUGIN INFO BASED ON PREVIOUS DEFINES
******************************/

public Plugin myinfo =
{
        name = PLUGIN_NAME,
        author = PLUGIN_AUTHOR,
        description = PLUGIN_DESCRIPTION,
        version = PLUGIN_VERSION,
        url = PLUGIN_URL,
};

/******************************
INITIATE THE PLUGIN
******************************/
public void OnPluginStart()
{       
        //We want to hook player_changename in order to block the default message from showing
       
        HookEvent("player_changename", namechange_callback, EventHookMode_Pre);

        /***COMMANDS SETUP***/
       
        //Create a convar for plugin version
       
        CreateConVar("sm_name_version", PLUGIN_VERSION, "Plugin Version", FCVAR_NOTIFY|FCVAR_SPONLY);
       
        //Create the public command
       
        RegConsoleCmd("sm_name", Command_Name, "sm_name <new name>");
        RegConsoleCmd("sm_oname", Command_Oname, "sm_oname <#userid|name> - Find the original Steam name of a player");
       
        //Are we done here? Can we move to coding the real thing?
}

/******************************
PUBLIC CALLBACKS
******************************/

public Action namechange_callback(Event event, const char[] name, bool dontBroadcast)
{
        SetEventBroadcast(event, true);
        return Plugin_Continue;
}

public void OnClientAuthorized(int client)
{
        char pname[50];
       
        if (!GetClientInfo(client, "secretname", pname, sizeof(pname)))
                return;
       
        if (pname[0] == EOS)
        return;
       
        for (int i=0; i <= MaxClients; i++)
        {
                if (!IsClientInGame(i))
                        continue;
               
                else if (IsFakeClient(i))
                        continue;
                       
                else if(!CheckCommandAccess(i, "sm_kick", ADMFLAG_KICK))
                        continue;
                       
                PrintToServer("Client %N has joined with the name %s.", client, pname);
        }
       
        SetClientInfo(client, "name", pname);
}

public Action Command_Name(int client, int args)
{
        if (args < 1)
        {
                ReplyToCommand(client, "%s%s %sUsage: %ssm_name <new name>", TAG_COLOR, TAG, COLOR_AZURE, COLOR_LIME);
                return Plugin_Handled;
        }
        char NewName[MAX_NAME_LENGTH];
        GetCmdArgString(NewName, sizeof(NewName));
       
        Handle DP = CreateDataPack();
       
        RequestFrame(TwoTotalFrames, DP);
       
        WritePackCell(DP, GetClientUserId(client));
        WritePackString(DP, NewName);
       
        return Plugin_Handled;
}

public void TwoTotalFrames(Handle DP)
{
        RequestFrame(ChangeName, DP);
}
public void ChangeName(Handle DP)
{
        ResetPack(DP);
       
        int client = GetClientOfUserId(ReadPackCell(DP));
       
        if (client <= 0 || client > MaxClients)
                return;
               
        else if(!IsClientInGame(client))
                return;       
       
        char NewName[MAX_NAME_LENGTH];
        ReadPackString(DP, NewName, sizeof(NewName));
       
        CloseHandle(DP);
       
        SetClientInfo(client, "name", NewName);
        PrintToChatAll("%s%s %s%N %shas changed their name to %s%s.", TAG_COLOR, TAG, COLOR_PLAYER, client, COLOR_AZURE, COLOR_PLAYER, NewName);
}

public Action Command_Oname(int client, int args)
{
        char targetarg[MAX_NAME_LENGTH];
        GetCmdArgString(targetarg, sizeof(targetarg));
       
        char target_name[MAX_TARGET_LENGTH];
        int target_list[MAXPLAYERS], target_count;
        bool tn_is_ml;
       
        int targetclient;
       
        if ((target_count = ProcessTargetString(
                        targetarg,
                        client,
                        target_list,
                        MAXPLAYERS,
                        COMMAND_FILTER_NO_MULTI,
                        target_name,
                        sizeof(target_name),
                        tn_is_ml)) > 0)
        {               
                for (int i = 0; i < target_count; i++)
                {
                        targetclient = target_list[i];
                                               
                        QueryClientConVar(targetclient, "name", OnSteamNameQueried, GetClientUserId(client));       
                }
        }
        else
        {
                ReplyToTargetError(client, target_count);
        }
        return Plugin_Handled;
}

public void OnSteamNameQueried(QueryCookie cookie, int targetclient, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, any UserId)
{
        int client = GetClientOfUserId(UserId);
        if (result != ConVarQuery_Okay)
        {
                PrintToChat(client, "%s%s %sError: Couldn't retrieve %s%N%s's Steam name.", TAG_COLOR, TAG, COLOR_ERROR, COLOR_PLAYER, targetclient, COLOR_ERROR);
                return;
        }       
       
        if (client <= 0 || client > MaxClients)
                return;
               
        else if (!IsClientInGame(client))
                return;
       
        PrintToChat(client, "%s%s %s%N%s's Steam name is %s%s.", TAG_COLOR, TAG, COLOR_PLAYER, targetclient, COLOR_AZURE, COLOR_PLAYER, cvarValue);
}

/**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
*****************************************************************!AND THE DREAM ENDS HERE!********************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************
**************************************************************************************************************************************************************/


Zyten 06-09-2018 14:40

Re: [ANY] Change your name
 
https://forums.alliedmods.net/showthread.php?t=307637

whats the diffrence?

eyal282 06-09-2018 15:23

Re: [ANY] Change your name
 
Quote:

Originally Posted by Zyten (Post 2596108)

1. Less colors therefore no need to waste time for includes.

2. His !oname is capable of being false if you change your steam name while playing since it saves the steam name on login, and even then setinfo name "New Name" can fool his plugin. Mine uses a smarter method.

3. setinfo secretname "New Name" which allows you to bypass any connect announce but ONLY if connect announce appears on "OnClientAuthorized" where it always should anyways.

Psyk0tik 06-09-2018 16:13

Re: [ANY] Change your name
 
Simple but useful. Thanks for this.

DarkDeviL 06-09-2018 16:24

Re: [ANY] Change your name
 
As posted in your thread Get steam name:

Quote:

Originally Posted by arne1288 (Post 2596123)
Quote:

Originally Posted by eyal282 (Post 2596024)
Quote:

Originally Posted by arne1288 (Post 2595999)
You can call the Steam API using some HTTP framework, e.g. SteamWorks.

Too much work... Is there a way to hook setinfo command? The only way to change your name is setinfo and steam name change. Oh, the console variable name cannot be changed, and is always equal to your steam name.

Not sure if that "name" always 100% identical to the Steam name though.

But the "name" command comes from the client, and as such, I wouldn't trust it blindly.

Just like there are some cheats that allows you to set r_drawothermodels (walhack) even if sv_cheats is 0, you can most likely use the same sort of cheats to fool your server into believing that the faked "name" is the real one.

Too much work? It's maybe a little bit more with the HTTP calls, but isn't it worth it doing it that way, if you get a 100% accurate response, rather than having a 50-50 chance of some fake value?

"Safety" before "cutting corners" would be my personal call.

eyal282 06-09-2018 16:43

Re: [ANY] Change your name
 
Quote:

Originally Posted by arne1288 (Post 2596127)
As posted in your thread Get steam name:



"Safety" before "cutting corners" would be my personal call.

Yeah, I'll just get me enough games to confirm it is impossible to change "name" and that it always automatically changes back to your steam name. Also sometimes the API might break ( it happens on Discord ) so it MAY be safer ( maybe steam API never breaks )

If someone is willing to get himself VAC banned to bypass the !oname, I'll list it as a bug LMAO.


All times are GMT -4. The time now is 09:53.

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