Results 1 to 7 of 7

Thread: Sharing Dynamic objects with multiple plugins

  1. #1
    Junior Member klin34970's Avatar
    Join Date
    May 2018
    Posts
    5

    Red face Sharing Dynamic objects with multiple plugins

    Hi

    I try lot of ways to share object attached to a client. The goal its to take one time the steamidID64, WebID, Language, IP, etc.. after a OnClientPostAdminCheck

    #First

    Here I got for all players 1 to 64 the same steamid64 (mine)

    player.inc
    PHP Code:
    methodmap Player Dynamic
        
    {
        public 
    Player(){
            
    Dynamic myclass Dynamic(640);
            
    myclass.SetString("SteamID64"""64);
            return 
    view_as<MyClass>(myclass);
        }

    drapi_users.sp
    PHP Code:
    Player player[MAXPLAYERS 1];

    public 
    void OnClientPostAdminCheck(int client){
        
    Player player[client] = Player();
        
    char sSetName[32];
        
    Format(sSetNamesizeof(sSetName), "drapi_users_%d"client);
        
    player[player].SetName(sSetName);
        
    //MY FUNCTION TO TAKE ALL DATA

    drapi_users_bans.sp

    I tried two syntax.
    1 - Player player[i]= view_as<Player>(Dynamic.FindByName(sGetName));
    2 - Dynamic player[i] = Dynamic.FindByName(sGetName);

    PHP Code:
    //when I Type test in console
    public Action TimerCheckBans(Handle timer){
            for(
    int i <= MaxClientsi++){
            
    Player player[MAXPLAYERS 1];
            
    char sGetName[32];
            
    Format(sGetNamesizeof(sGetName), "drapi_users_%d"i);
            
    Dynamic player[i] = Dynamic.FindByName(sGetName);
            if (!
    player[i].IsValid){
            }else{
                
    char steamid[64];
                
    player[i].GetSteamID64(steamidsizeof(steamid));
                
    PrintToServer("%s client %d GetSteamID64 %s"TAGisteamid);
            }
        }

    #Second

    Here I got the default value for all

    player.inc

    [/php]
    #if defined _dynamic_class_player_
    #endinput
    #endif
    #define _dynamic_class_player_

    Dynamic myclass[MAXPLAYERS + 1];

    methodmap Player < Dynamic
    {
    public Player(int client){
    return view_as<Player>(myclass[client]);
    }

    public void init(int client){
    //PrintToServer("%d init %d", client, myclass[client].IsValid);
    myclass[client] = Dynamic(64, 0);
    char sSetName[32];
    Format(sSetName, sizeof(sSetName), "drapi_users_%d", client);
    myclass[client].SetName(sSetName);
    PrintToServer("%s SetName %d %s", TAG, client, sSetName);
    //PrintToServer("%d init %d", client, myclass[client].IsValid);
    }

    public void clear(int client){
    myclass[client].SetBool("isBan", false);
    myclass[client].SetString("WebID", "none", 64);
    myclass[client].SetString("SteamID64", "none", 64);
    myclass[client].SetString("lastConnect", "", 64);
    //PrintToServer("%d clear", client);
    }
    public void dispose(int client){
    myclass[client].Dispose();
    myclass[client] = INVALID_DYNAMIC_OBJECT;
    //PrintToServer("%d Dispose", client);
    }


    }
    [/php]


    drapi_users.sp
    PHP Code:
    public void OnPluginStart() {
        
    RegConsoleCmd("test"checkResponse"");
        for(
    int i <= MaxClientsi++){
            
    Player player Player(i);
            
    player.init(i);
            
    player.clear(i);
        }
    }

    public 
    void OnPluginEnd() {
        for(
    int i <= MaxClientsi++){
            
    //PrintToServer("%s OnPluginEnd %d %d", TAG, i, MaxClients);
            
    Player player Player(i);
            
    player.dispose(i);
        }
    }

    public 
    Action checkResponse(int clientint args){
        for(
    int i <= MaxClientsi++){
            
    Player player Player(i);
            if (!
    player.IsValid){
                
    //PrintToServer("%s IsValid client %d", TAG, i);
            
    }else{
                
    char sSteamID64[32];
                
    player.GetSteamID64(sSteamID64sizeof(sSteamID64));
                
    PrintToServer("%s client %d GetSteamID64 %s"TAGisSteamID64);

                
    char sWebID[32];
                
    player.GetWebID(sWebIDsizeof(sWebID));
                
    PrintToServer("%s client %d GetWebID %s"TAGisWebID);
            }
        }
        return 
    Plugin_Handled;
    }

    public 
    void OnClientPostAdminCheck(int client){
        
    Player player Player(client);
        
    player.clear(client);

        if(
    IsFakeClient(client)){
            
    char webid[64];
            
    Format(webidsizeof(webid), "bot_%d"client);
            
    player.SetWebID(webid);
            
    char steamid[64];
            
    Format(steamidsizeof(steamid), "bot_%d"client);
            
    player.SetSteamID64(steamid);
            
    //PrintToServer("%s IsFakeClient %d SetWebID %s", TAG, client, webid);
        
    }
        if(!
    IsFakeClient(client)){
            
    CreateTimer(5.0Timer_PrepareRequestclientTIMER_FLAG_NO_MAPCHANGE);
        }
    }

    public 
    void OnClientDisconnect(int client){
        
    Player player Player(client);
        
    player.clear(client);
    }

    public 
    Action Timer_PrepareRequest(Handle timerint client){
        if(!
    IsFakeClient(client)){
            
    httpClient(client).Get("*****"OnReceivedclient);
        }

    drapi_users_bans.sp
    PHP Code:

    bool drapi_users 
    false;

    public 
    Plugin myinfo ={
        
    name "drapi_users_bans",
        
    author "Dr. Api",
        
    description "",
        
    version PLUGIN_VERSION,
        
    url "https://csgo.devsapps.com"
    }

    public 
    void OnMapStart(){
        if(
    drapi_users){
            
    CreateTimer(10.0TimerCheckBans_TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
        }
    }

    public 
    Action TimerCheckBans(Handle timer){
            for(
    int i <= MaxClientsi++){
                
    char sGetName[32];
                
    Format(sGetNamesizeof(sGetName), "drapi_users_%d"i);
                
    Dynamic player Dynamic.FindByName(sGetName);
                
    //Player player = view_as<Player>(Dynamic.FindByName(sGetName));
                
    PrintToServer("%s sGetName %d %s"TAGisGetName);
                if (!
    player.IsValid){
                    
    //PrintToServer("%s IsValid client %d", TAG, i);
                
    }else{
                    
    //PrintToServer("%s client %d", TAG, i);
                    
    char steamid[64];
                    
    player.GetString("SteamID64"steamidsizeof(steamid));
                    
    PrintToServer("%s client %d GetSteamID64 %s"TAGisteamid);
                }
            }


    when I type test (drapi_users)

    [USERS] - client 1 GetSteamID64 76561197969245555
    [USERS] - client 1 GetWebID 1
    [USERS] - client 2 GetSteamID64 bot_2
    [USERS] - client 2 GetWebID bot_2
    [USERS] - client 3 GetSteamID64 bot_3
    [USERS] - client 3 GetWebID bot_3
    [USERS] - client 4 GetSteamID64 bot_4
    [USERS] - client 4 GetWebID bot_4
    [USERS] - client 5 GetSteamID64 bot_5
    [USERS] - client 5 GetWebID bot_5
    [USERS] - client 6 GetSteamID64 bot_6
    [USERS] - client 6 GetWebID bot_6
    [USERS] - client 7 GetSteamID64 bot_7
    [USERS] - client 7 GetWebID bot_7
    [USERS] - client 8 GetSteamID64 bot_8
    [USERS] - client 8 GetWebID bot_8
    [USERS] - client 9 GetSteamID64 bot_9
    [USERS] - client 9 GetWebID bot_9
    [USERS] - client 10 GetSteamID64 bot_10
    [USERS] - client 10 GetWebID bot_10

    when the TimerCheckBans from drapi_users_bans

    [BANS] - sGetName 1 drapi_users_1
    [BANS] - client 1 GetSteamID64 none
    [BANS] - sGetName 2 drapi_users_2
    [BANS] - client 2 GetSteamID64 none
    [BANS] - sGetName 3 drapi_users_3
    [BANS] - client 3 GetSteamID64 none
    [BANS] - sGetName 4 drapi_users_4
    [BANS] - client 4 GetSteamID64 none
    [BANS] - sGetName 5 drapi_users_5
    [BANS] - client 5 GetSteamID64 none
    [BANS] - sGetName 6 drapi_users_6
    [BANS] - client 6 GetSteamID64 none
    [BANS] - sGetName 7 drapi_users_7
    [BANS] - client 7 GetSteamID64 none
    [BANS] - sGetName 8 drapi_users_8
    [BANS] - client 8 GetSteamID64 none
    [BANS] - sGetName 9 drapi_users_9
    [BANS] - client 9 GetSteamID64 none
    [BANS] - sGetName 10 drapi_users_10

    I tried others ways but still not working.
    I don't want to create native to share data between plugin since dynamic is awesome.
    How you would do a methodmap attache to a client and share between plugins?

    Thx for your help

  2. #2
    Junior Member klin34970's Avatar
    Join Date
    May 2018
    Posts
    5

    Another test

    PHP Code:
    #if defined _dynamic_class_player_
      #endinput
    #endif
    #define _dynamic_class_player_

    methodmap Player Dynamic
    {
        public 
    Player()
        {
            
    Dynamic myclass Dynamic(640);
            return 
    view_as<Player>(myclass);
        }

        public 
    void clear(){
            
    this.SetInt("testID"0);
        }

        
    property int testID
        
    {
            public 
    get()
            {
                static 
    DynamicOffset offset INVALID_DYNAMIC_OFFSET;
                if (
    offset == INVALID_DYNAMIC_OFFSET)
                {
                    
    offset this.GetMemberOffset("testID");
                    if (
    offset == INVALID_DYNAMIC_OFFSET)
                        
    SetFailState("A serious error occured in Dynamic!");
                }
                return 
    this.GetIntByOffset(offset);
            }
            public 
    set(int value)
            {
                static 
    DynamicOffset offset INVALID_DYNAMIC_OFFSET;
                if (
    offset == INVALID_DYNAMIC_OFFSET)
                {
                    
    offset this.GetMemberOffset("testID");
                    if (
    offset == INVALID_DYNAMIC_OFFSET)
                    {
                        
    offset this.SetInt("testID"value);
                        return;
                    }
                }
                
    this.SetIntByOffset(offsetvalue);
            }
        }

    PHP Code:
    #pragma semicolon 1

    #define TAG "[TEST_SEND] -"
    #define PLUGIN_VERSION "1.0.0"
    #define CVARS FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY
    #define DEFAULT_FLAGS FCVAR_NOTIFY

    #undef REQUIRE_PLUGIN
    #include <dynamic>
    #include <drapi/test>

    #pragma newdecls required


    Player player[MAXPLAYERS 1];

    public 
    Plugin myinfo ={
        
    name "test_send",
        
    author "Dr. Api",
        
    description "",
        
    version PLUGIN_VERSION,
        
    url "https://csgo.devsapps.com"
    }

    public 
    void OnPluginStart() {
        
    RegConsoleCmd("test"checkResponse"");
        for(
    int i <= MaxClientsi++){
            
    player[i] = Player();
            
    player[i].clear();
            
    char sSetName[32];
            
    Format(sSetNamesizeof(sSetName), "drapi_users_%d"i);
            
    player[i].SetName(sSetName);
            
    PrintToServer("%s OnPluginStart client %d TestID %d"TAGiplayer[i].testID);
            
    PrintToServer("%s OnPluginStart client %d sSetName %s"TAGisSetName);
        }
    }

    public 
    void OnPluginEnd() {
        for(
    int i <= MaxClientsi++){
            
    player[i].Dispose();
            
    PrintToServer("%s OnPluginEnd client %d Dispose"TAGi);
        }
    }

    public 
    Action checkResponse(int clientint args){
        for(
    int i <= MaxClientsi++){
            if (!
    player[i].IsValid){
            }else{
                
    PrintToServer("%s client %d TestID %d"TAGiplayer[i].testID);
            }
        }
        return 
    Plugin_Handled;
    }

    public 
    void OnClientPostAdminCheck(int client){
        
    player[client].testID client;
        
    PrintToServer("%s OnClientPostAdminCheck client %d TestID %d"TAGclientplayer[client].testID);
    }

    public 
    void OnClientDisconnect(int client){
        
    player[client].clear();

    PHP Code:
    #pragma semicolon 1

    #define TAG "[TEST_RECEIVE] -"
    #define PLUGIN_VERSION "1.0.0"
    #define CVARS FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY
    #define DEFAULT_FLAGS FCVAR_NOTIFY

    #undef REQUIRE_PLUGIN
    #include <dynamic>

    #pragma newdecls required

    public Plugin myinfo ={
        
    name "test_receive",
        
    author "Dr. Api",
        
    description "",
        
    version PLUGIN_VERSION,
        
    url "https://csgo.devsapps.com"
    }

    public 
    void OnPluginStart() {
        
    RegConsoleCmd("r"checkResponse"");
    }

    public 
    Action checkResponse(int clientint args){
        for(
    int i <= MaxClientsi++){
            
    char sSetName[32];
            
    int testID;
            
    Format(sSetNamesizeof(sSetName), "drapi_users_%d"i);
            
    Dynamic player Dynamic.FindByName(sSetName);
            if (!
    player.IsValid){
            }else{
                
    player.GetInt("testID"testID);
                
    PrintToServer("%s client %d TestID %d"TAGitestID);
            }
        }
        return 
    Plugin_Handled;

    [TEST_SEND] - client 1 TestID 1
    [TEST_SEND] - client 2 TestID 2
    [TEST_SEND] - client 3 TestID 3
    [TEST_SEND] - client 4 TestID 4
    [TEST_SEND] - client 5 TestID 5
    [TEST_SEND] - client 6 TestID 6
    [TEST_SEND] - client 7 TestID 7
    [TEST_SEND] - client 8 TestID 8
    [TEST_SEND] - client 9 TestID 9
    [TEST_SEND] - client 10 TestID 10

    [TEST_RECEIVE] - client 1 TestID 0
    [TEST_RECEIVE] - client 2 TestID 0
    [TEST_RECEIVE] - client 3 TestID 0
    [TEST_RECEIVE] - client 4 TestID 0
    [TEST_RECEIVE] - client 5 TestID 0
    [TEST_RECEIVE] - client 6 TestID 0
    [TEST_RECEIVE] - client 7 TestID 0
    [TEST_RECEIVE] - client 8 TestID 0
    [TEST_RECEIVE] - client 9 TestID 0
    [TEST_RECEIVE] - client 10 TestID 0

  3. #3
    Junior Member klin34970's Avatar
    Join Date
    May 2018
    Posts
    5

    Works

    This is working, I'm posting for people who need

    PHP Code:
    #pragma semicolon 1

    #define TAG "[TEST_SEND] -"
    #define PLUGIN_VERSION "1.0.0"
    #define CVARS FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY
    #define DEFAULT_FLAGS FCVAR_NOTIFY

    #undef REQUIRE_PLUGIN
    #include <dynamic>

    #pragma newdecls required


    public Plugin myinfo ={
        
    name "test_send",
        
    author "Dr. Api",
        
    description "",
        
    version PLUGIN_VERSION,
        
    url "https://csgo.devsapps.com"
    }

    public 
    void OnPluginStart() {
        
    RegConsoleCmd("test"checkResponse"");
        for(
    int i <= MaxClientsi++){
            
    Dynamic playersettings Dynamic.GetPlayerSettings(i);
            
    playersettings.Dispose();
            
    Dynamic dynamic Dynamic();
            
    dynamic.SetInt("ID"0);
            
    playersettings.SetDynamic("infos"dynamic);
        }
    }

    public 
    void OnPluginEnd() {
        for(
    int i <= MaxClientsi++){
            
    Dynamic playersettings Dynamic.GetPlayerSettings(i);
            
    playersettings.Dispose();
        }
    }

    public 
    Action checkResponse(int clientint args){
        for(
    int i <= MaxClientsi++){
            
    Dynamic playersettings Dynamic.GetPlayerSettings(i).GetDynamic("infos");
            if(
    playersettings.IsValid){
                
    PrintToServer("%s client %d TestID %d"TAGiplayersettings.GetInt("ID"));
            }else{
                
    PrintToServer("%s client %d !IsValid %d"TAGiplayersettings);
            }
        }
        return 
    Plugin_Handled;
    }


    public 
    void OnClientPostAdminCheck(int client){
        
    Dynamic playersettings Dynamic.GetPlayerSettings(client).GetDynamic("infos");
        
    playersettings.SetInt("ID"client);
    }

    public 
    void OnClientDisconnect(int client){
        
    Dynamic playersettings Dynamic.GetPlayerSettings(client).GetDynamic("infos");
        
    playersettings.SetInt("ID"0);

    PHP Code:
    #pragma semicolon 1

    #define TAG "[TEST_RECEIVE] -"
    #define PLUGIN_VERSION "1.0.0"
    #define CVARS FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY
    #define DEFAULT_FLAGS FCVAR_NOTIFY

    #undef REQUIRE_PLUGIN
    #include <dynamic>

    #pragma newdecls required

    public Plugin myinfo ={
        
    name "test_receive",
        
    author "Dr. Api",
        
    description "",
        
    version PLUGIN_VERSION,
        
    url "https://csgo.devsapps.com"
    }

    public 
    void OnPluginStart() {
        
    RegConsoleCmd("r"checkResponse"");
    }

    public 
    Action checkResponse(int clientint args){
        for(
    int i <= MaxClientsi++){
            
    Dynamic playersettings Dynamic.GetPlayerSettings(i).GetDynamic("infos");
            if(
    playersettings.IsValid){
                
    PrintToServer("%s client %d TestID %d"TAGiplayersettings.GetInt("ID"));
            }else{
                
    PrintToServer("%s client %d !IsValid %d"TAGiplayersettings);
            }
        }
        return 
    Plugin_Handled;

    [TEST_SEND] - client 1 TestID 1
    [TEST_SEND] - client 2 TestID 2
    [TEST_SEND] - client 3 TestID 3
    [TEST_SEND] - client 4 TestID 4
    [TEST_SEND] - client 5 TestID 5
    [TEST_SEND] - client 6 TestID 6
    [TEST_SEND] - client 7 TestID 7
    [TEST_SEND] - client 8 TestID 8
    [TEST_SEND] - client 9 TestID 9
    [TEST_SEND] - client 10 TestID 10
    [TEST_SEND] - client 11 TestID 11

    [TEST_RECEIVE] - client 1 TestID 1
    [TEST_RECEIVE] - client 2 TestID 2
    [TEST_RECEIVE] - client 3 TestID 3
    [TEST_RECEIVE] - client 4 TestID 4
    [TEST_RECEIVE] - client 5 TestID 5
    [TEST_RECEIVE] - client 6 TestID 6
    [TEST_RECEIVE] - client 7 TestID 7
    [TEST_RECEIVE] - client 8 TestID 8
    [TEST_RECEIVE] - client 9 TestID 9
    [TEST_RECEIVE] - client 10 TestID 10

  4. #4
    Closing the void Neuro Toxin's Avatar
    Join Date
    Aug 2014
    Location
    Melbourne
    Posts
    1,818
    Hi DR API,

    First I would like to make sure you are aware of the Wiki for Dynamic on GitHub.

    This page contains information around sharing objects using the .SetName and .FindByName natives.

    I suggest using Static Objects to access Server and Players settings.

    Quote Originally Posted by Static Objects
    These objects are stored in such a way that Natives are not required to access pointers to these dynamic objects
    Any plugin can access player objects like so:

    PHP Code:
    public void OnClientConnected(int client)
    {
        
    Dynamic playersettings Dynamic.GetPlayerSettings(client);

    This way you can access client settings via Dynamic.GetPlayerSettings(int client) in your OnClientPostAdminCheck forward.
    http://www.aus-tg.com

    Quote Originally Posted by Batman View Post
    oh ye i scammed luvchopz

  5. #5
    Junior Member klin34970's Avatar
    Join Date
    May 2018
    Posts
    5
    Got
    -> Total Handles: 19 (0 persistant handles)
    --> `drapi_users`: 19 Handles (0 persistant handles)

    but in console I got 20
    [USERS] - client 1 steamID64 7656119796924555
    [USERS] - client 2 steamID64 bot_2
    [USERS] - client 3 steamID64 bot_3
    [USERS] - client 4 steamID64 bot_4
    [USERS] - client 5 steamID64 bot_5
    [USERS] - client 6 steamID64 bot_6
    [USERS] - client 7 steamID64 bot_7
    [USERS] - client 8 steamID64 bot_8
    [USERS] - client 9 steamID64 bot_9
    [USERS] - client 10 steamID64 bot_10
    [USERS] - client 11 steamID64 bot_11
    [USERS] - client 12 steamID64 bot_12
    [USERS] - client 13 steamID64 bot_13
    [USERS] - client 14 steamID64 bot_14
    [USERS] - client 15 steamID64 bot_15
    [USERS] - client 16 steamID64 bot_16
    [USERS] - client 17 steamID64 bot_17
    [USERS] - client 18 steamID64 bot_18
    [USERS] - client 19 steamID64 bot_19
    [USERS] - client 20 steamID64 bot_20

    When I'm doing sm plugins unload_all and restart the map

    I got
    Dynamic is running a HandleUsage report...
    -> Total Handles: 20 (0 persistant handles)
    --> `drapi_users`: 20 Handles (0 persistant handles)
    console
    [USERS] - client 1 steamID64 7656119796924555
    [USERS] - client 2 steamID64 bot_2
    [USERS] - client 3 steamID64 bot_3
    [USERS] - client 4 steamID64 bot_4
    [USERS] - client 5 steamID64 bot_5
    [USERS] - client 6 steamID64 bot_6
    [USERS] - client 7 steamID64 bot_7
    [USERS] - client 8 steamID64 bot_8
    [USERS] - client 9 steamID64 bot_9
    [USERS] - client 10 steamID64 bot_10
    [USERS] - client 11 steamID64 bot_11
    [USERS] - client 12 steamID64 bot_12
    [USERS] - client 13 steamID64 bot_13
    [USERS] - client 14 steamID64 bot_14
    [USERS] - client 15 steamID64 bot_15
    [USERS] - client 16 steamID64 bot_16
    [USERS] - client 17 steamID64 bot_17
    [USERS] - client 18 steamID64 bot_18
    [USERS] - client 19 steamID64 bot_19
    [USERS] - client 20 steamID64 bot_20

    Weird ?
    bot_add
    [USERS] - OnClientPostAdminCheck 2
    [USERS] - OnClientDisconnect 2
    Game will not start until both teams have players.

    Maybe fast connect/disconnect bug

  6. #6
    Closing the void Neuro Toxin's Avatar
    Join Date
    Aug 2014
    Location
    Melbourne
    Posts
    1,818
    That does seem really strange!

    When you get one less handle than what you expect, are all player setting objects accessible and working?

    Note: Checking the code, there is no variance on how the player setting objects are created, its the same code executed in AskPluginLoad2.
    http://www.aus-tg.com

    Quote Originally Posted by Batman View Post
    oh ye i scammed luvchopz

  7. #7
    Junior Member klin34970's Avatar
    Join Date
    May 2018
    Posts
    5
    if I kick bot, not more accessible.

    PHP Code:
    public void OnClientPostAdminCheck(int client){
        
    PrintToServer("%s OnClientPostAdminCheck %d"TAGclient);

        
    Dynamic playersettings Dynamic.GetPlayerSettings(client);

       
    //I have to do this otherwise handle a created on and on
        
    if(!playersettings.GetDynamic("infos").IsValid){
            
    PlayerInfo playerinfo PlayerInfo();
            
    playersettings.SetDynamic("infos"playerinfo);
            
    PrintToServer("%s SetDynamic %d %d"TAGclientplayerinfo);
        }
    }

    public 
    void OnClientDisconnect(int client){
        
    PrintToServer("%s OnClientDisconnect %d"TAGclient);
        
    Dynamic playersettings Dynamic.GetPlayerSettings(client).GetDynamic("infos");

        
    //Works well when i have 20 handles for 20 players
        
    if(playersettings.IsValid){
            
    playersettings.Dispose();
            
    playersettings INVALID_DYNAMIC_OBJECT;
        }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •