Raised This Month: $ Target: $400
 0% 

Solved get_user_authid bug?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 08-01-2021 , 06:36   get_user_authid bug?
Reply With Quote #1

PHP Code:
new g_szAuthID[MAX_PLAYERS+1];



public 
client_putinserver(id){
get_user_authididg_szAuthID[id], sizeof(g_szAuthID) )
server_print("STEAMID :) %s :)"g_szAuthID[id]);

OUTPUT: steamid ?TEAM_0:0:8932699
OUTPUT WITH CHARSMAX INSTEAD OF SIZEOF: XTEAM_0:0:8932699
Code:
AMX Mod X 1.10.0.5418 (http://www.amxmodx.org)
Authors:
        David "BAILOPAN" Anderson, Pavol "PM OnoTo" Marko
        Felix "SniperBeamer" Geyer, Jonny "Got His Gun" Bergstrom
        Lukasz "SidLuke" Wlasinski, Christian "Basic-Master" Hammacher
        Borja "faluco" Ferrer, Scott "DS" Ehlert
Compiled: May  7 2021 03:40:55
Built from: https://github.com/alliedmodders/amxmodx/commit/3c1856f7
Build ID: 5418:3c1856f7
Core mode: JIT+ASM32

Core mode: JIT+ASM32
meta list
Currently loaded plugins:
      description      stat pend  file              vers      src  load  unlod
 [ 1] AMX Mod X        RUN   -    amxmodx_mm.dll    v1.10.0.  ini  Start ANY
 [ 2] POD-Bot mm       RUN   -    podbot_mm.dll     v3.0B15c  ini  Chlvl ANY
 [ 3] CStrike          RUN   -    cstrike_amxx.dll  v1.10.0.  pl1  ANY   ANY
 [ 4] FakeMeta         RUN   -    fakemeta_amxx.dl  v1.10.0.  pl1  ANY   ANY
 [ 5] Fun              RUN   -    fun_amxx.dll      v1.10.0.  pl1  ANY   ANY
 [ 6] Engine           RUN   -    engine_amxx.dll   v1.10.0.  pl1  ANY   ANY
 [ 7] Ham Sandwich     RUN   -    hamsandwich_amxx  v1.10.0.  pl1  ANY   ANY
7 plugins, 7 running
__________________

Last edited by deprale; 08-01-2021 at 09:10.
deprale is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-01-2021 , 06:40   Re: get_user_authid bug?
Reply With Quote #2

PHP Code:
new g_szAuthID[MAX_PLAYERS+1]; 


PHP Code:
new g_szAuthID[MAX_PLAYERS+1][32]; 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-01-2021 at 06:41.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 06:47   Re: get_user_authid bug?
Reply With Quote #3

In addition to Natsheh's post, you need to change sizeof(g_szAuthID) to charsmax(g_szAuthID[]).

You might consider reading some basic scripting tutorials to get a better idea how strings and other basics work in plugin scripting.


Also, you should get the authid only in client_authorized(), it's the only time when it is guaranteed to exist.
__________________
fysiks is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 08-01-2021 , 06:48   Re: get_user_authid bug?
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
PHP Code:
new g_szAuthID[MAX_PLAYERS+1]; 


PHP Code:
new g_szAuthID[MAX_PLAYERS+1][32]; 
I'm not sure how that would work :-?
I just recompiled it and it apparently works sometimes, sometimes it doesn't. What I'm trying to do with it, is making an enum with 3 variables, kills frags and money, and when I reconnect I always get 83 money back no matter what, but frags/kills are restored properly. Output sometimes varies from ?TEAM to XTEAM to normal STEAM, say I wanted to make something like.. uhhh

PHP Code:
enum PlayerData{
g_UserFrags;
g_UserDeaths;
g_UserMoney;
};

new 
g_szAuthID[MAX_PLAYERS+1][32][PlayerData// ??? is this how I would do it? But how do I call it to assign a value? Sorry for being dumb. 
Quote:
Originally Posted by fysiks View Post
In addition to Natsheh's post, you need to change sizeof(g_szAuthID) to charsmax(g_szAuthID[]).

You might consider reading some basic scripting tutorials to get a better idea how strings and other basics work in plugin scripting.


Also, you should get the authid only in client_authorized(), it's the only time when it is guaranteed to exist.


@fysiks totally agree, I was following OciCromX's Trie way of implementing whatever I just wrote up here and I saw he was collecting ip's instead of STEAMID's and I thought that might be a little bit too "arrr" for me, so I tried to use steamids instead, but good to know you can't reliably have steamid's on client_putinserver, i'll try to do it in client_authorized thanks!

I'm just trying to "pick" as I go, that might be a little bit too much I agree, I'll have to read up something... instead of relying on docs every time something goes awry!
__________________

Last edited by deprale; 08-01-2021 at 06:52.
deprale is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 06:53   Re: get_user_authid bug?
Reply With Quote #5

Quote:
Originally Posted by deprale View Post
I'm not sure how that would work :-?
I just recompiled it and it apparently works sometimes, sometimes it doesn't. What I'm trying to do with it, is making an enum with 3 variables, kills frags and money, and when I reconnect I always get 83 money back no matter what, but frags/kills are restored properly. Output sometimes varies from ?TEAM to XTEAM to normal STEAM, say I wanted to make something like.. uhhh
See my post above just before you posted this.


Quote:
Originally Posted by deprale View Post
PHP Code:
enum PlayerData{
g_UserFrags;
g_UserDeaths;
g_UserMoney;
};

new 
g_szAuthID[MAX_PLAYERS+1][32][PlayerData// ??? is this how I would do it? But how do I call it to assign a value? Sorry for being dumb. 
No, that is not how you would do it. For a beginner, I would recommend just creating an array for each piece of data that you're trying to store instead of trying to use pseudo-structs. Once you have the rest of your code working, it can easily be converted later.

Also, how often are you going to use the SteamID? I find it unlikely that it would be worth storing that at all, typically you would just get it when you need to use it.
__________________
fysiks is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 08-01-2021 , 07:00   Re: get_user_authid bug?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
See my post above just before you posted this.




No, that is not how you would do it. For a beginner, I would recommend just creating an array for each piece of data that you're trying to store instead of trying to use pseudo-structs. Once you have the rest of your code working, it can easily be converted later.

Also, how often are you going to use the SteamID? I find it unlikely that it would be worth storing that at all, typically you would just get it when you need to use it.
Each player reconnect and for about as many times needed whenever I swap teams or sides, I can create an array for each piece of data that I'm trying to store, but I really need the steamid to understand who is who, because I don't know any dynamic way of retrieving who was who before reconnecting, because they'd have a new id if somebody connected after them, and probably somebody else would get their frags/money/deaths.

EDIT: Also I just used client_authorized and its even worse, now its showing up as "?" in output.
__________________

Last edited by deprale; 08-01-2021 at 07:01.
deprale is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 07:06   Re: get_user_authid bug?
Reply With Quote #7

Quote:
Originally Posted by deprale View Post
Each player reconnect and for about as many times needed whenever I swap teams or sides, I can create an array for each piece of data that I'm trying to store, but I really need the steamid to understand who is who, because I don't know any dynamic way of retrieving who was who before reconnecting, because they'd have a new id if somebody connected after them, and probably somebody else would get their frags/money/deaths.
I'll not reply to this now since it would be a bit off topic. Best to this in another thread if you want more advice about it.


Quote:
Originally Posted by deprale View Post
EDIT: Also I just used client_authorized and its even worse, now its showing up as "?" in output.

Then you are doing something wrong. Please post your code. When having issues with something, it is often a good idea to make a test plugin to test just the small section of code to make sure that you are doing it correctly. This also allows you to post a full plugin so that we can see exactly how you are doing your code.
__________________

Last edited by fysiks; 08-01-2021 at 07:06.
fysiks is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-01-2021 , 07:08   Re: get_user_authid bug?
Reply With Quote #8

If I understand correctly you want to assign data to a certain steam id. If so, you should look into tries, use the steam id as the key and your enum struct as the value.
There is no need to use "id" in this case.
__________________

Last edited by HamletEagle; 08-01-2021 at 07:08.
HamletEagle is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 08-01-2021 , 07:17   Re: get_user_authid bug?
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
If I understand correctly you want to assign data to a certain steam id. If so, you should look into tries, use the steam id as the key and your enum struct as the value.
There is no need to use "id" in this case.
PHP Code:
#define PLUGIN    "TEST PLUGIN"
#define AUTHOR    "deprale"
#define VERSION "1.0"

enum PlayerDatag_UserMoney[MAX_PLAYERS+1], g_UserFrags[MAX_PLAYERS+1], g_UserDeaths[MAX_PLAYERS+1]};
new 
g_szAuthID[MAX_PLAYERS+1][PlayerData];

public 
plugin_init()
{
register_pluginPLUGINVERSIONAUTHOR );
}
public 
SaveStuff(id){
    
g_szAuthID[id][g_UserMoney] = cs_get_user_money(id);
    
g_szAuthID[id][g_UserDeaths] = cs_get_user_deaths(id);
    
g_szAuthID[id][g_UserFrags] = get_user_frags(id);
    
server_print("money %i deaths %i frags %i steamid %s"g_szAuthID[id][g_UserMoney], g_szAuthID[id][g_UserDeaths], g_szAuthID[id][g_UserFrags], g_szAuthID[id]);
}

public 
SetStuff(id){
    
cs_set_user_money(idg_szAuthID[id][g_UserMoney], 1);
    
cs_set_user_deaths(idg_szAuthID[id][g_UserDeaths]);
    
set_user_frags(idg_szAuthID[id][g_UserFrags]);
    
server_print("money %i deaths %i frags %i steamid %d"g_szAuthID[id][g_UserMoney], g_szAuthID[id][g_UserDeaths], g_szAuthID[id][g_UserFrags], g_szAuthID[id]);

}

public 
client_authorized(id)
{
    if(
is_user_connected(id) && !is_user_bot(id)){ // had to add this check, was heavily freezing my server with podbots trying to connect, also spamming error messages.
    
get_user_authididg_szAuthID[id], charsmax(g_szAuthID) );
    
SetStuff(id);
    }
}


public 
client_disconnectedidbool:dropmessage[], maxlen )
{
    
get_user_authididg_szAuthID[id], charsmax(g_szAuthID) );
    
SaveStuff(id);


My first try was with a trie, sadly, I'm far too unexperienced, because while it does a good job (I tried to use https://github.com/OciXCrom/SaveStuf...save_stuff.sma as a reference, by the way) but sadly It's not always good because in the future I want to be able to only restore frags and deaths and not always money too, which is why I chose to use an enum array instead.

Code:
money 16000 deaths 0 frags 0 steamid ?TEAM_0:0:8932699
money 800 deaths 0 frags 0 steamid  TEAM_0:0:8932699
__________________

Last edited by deprale; 08-01-2021 at 07:19.
deprale is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-01-2021 , 07:35   Re: get_user_authid bug?
Reply With Quote #10

You can use a trie for this. Take a step back and try to understand what you are doing because it's a complete mess right now. You have no space reserved to hold the steam id, g_UserMoney, g_UserFrags, g_UserDeaths are arrays when they should be integers. money, frags, deaths are numbers and they are already associated with a player when you do "g_szAuthID[id]" so there is no reason to have them be arrays, which would essentially translate to g_szAuthID[id][g_UserMoney][id].

Try to picture the layout of your arrays in memory. But in the meantime, here's an example template using tries:

PHP Code:
#include <amxmodx>

enum _:playerData
{
    
money,
    
frags,
    
deaths
}

new 
Trie:playerDataTrie

public plugin_init()
{
    
playerDataTrie TrieCreate()
}

public 
plugin_end()
{
    
TrieDestroy(playerDataTrie)
}

saveUserData(id)
{
    new 
data[playerData]
    
data[money]  = //retrieve money
    
data[frags]  = //retrieve frags
    
data[deaths] = //retrieve deaths

    
new steamId[35]
    
get_user_authid(idsteamIdcharsmax(steamId))

    
TrieSetArray(playerDataTriesteamIddatasizeof data)
}

loadUserData(id)
{
    new 
steamId[35]
    
get_user_authid(idsteamIdcharsmax(steamId))

    if(
TrieKeyExists(playerDataTriesteamId))
    {
        new 
data[playerData]
        
TrieGetArray(playerDataTriesteamIddatasizeof data)

        
//set money to data[money]
        //set frags to data[frags]
        //set deaths to data[deaths]
    
}

The beauty of a trie is that it allows you to store (key, value) pairs where the key is a string. Intuitively, it is as if you were able to do g_szAuthID["STEAM_:...."], which is to index an array by using a string instead of an integer("id").
__________________

Last edited by HamletEagle; 08-01-2021 at 07:38.
HamletEagle 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 16:44.


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