PDA

View Full Version : Sharing Dynamic objects with multiple plugins



klin34970
20-05-2018, 07:18 PM
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


methodmap Player < Dynamic
{
public Player(){
Dynamic myclass = Dynamic(64, 0);
myclass.SetString("SteamID64", "", 64);
return view_as<MyClass>(myclass);
}
}


drapi_users.sp


Player player[MAXPLAYERS + 1];

public void OnClientPostAdminCheck(int client){
Player player[client] = Player();
char sSetName[32];
Format(sSetName, sizeof(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);



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


#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


public void OnPluginStart() {
RegConsoleCmd("test", checkResponse, "");
for(int i = 1 ; i <= MaxClients; i++){
Player player = Player(i);
player.init(i);
player.clear(i);
}
}

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

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

char sWebID[32];
player.GetWebID(sWebID, sizeof(sWebID));
PrintToServer("%s client %d GetWebID %s", TAG, i, sWebID);
}
}
return Plugin_Handled;
}

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

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

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

public Action Timer_PrepareRequest(Handle timer, int client){
if(!IsFakeClient(client)){
httpClient(client).Get("*****", OnReceived, client);
}
}


drapi_users_bans.sp



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.0, TimerCheckBans, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}

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



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

klin34970
20-05-2018, 08:18 PM
#if defined _dynamic_class_player_
#endinput
#endif
#define _dynamic_class_player_

methodmap Player < Dynamic
{
public Player()
{
Dynamic myclass = Dynamic(64, 0);
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(offset, value);
}
}
}




#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 = 1 ; i <= MaxClients; i++){
player[i] = Player();
player[i].clear();
char sSetName[32];
Format(sSetName, sizeof(sSetName), "drapi_users_%d", i);
player[i].SetName(sSetName);
PrintToServer("%s OnPluginStart client %d TestID %d", TAG, i, player[i].testID);
PrintToServer("%s OnPluginStart client %d sSetName %s", TAG, i, sSetName);
}
}

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

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

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

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




#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 client, int args){
for(int i = 1 ; i <= MaxClients; i++){
char sSetName[32];
int testID;
Format(sSetName, sizeof(sSetName), "drapi_users_%d", i);
Dynamic player = Dynamic.FindByName(sSetName);
if (!player.IsValid){
}else{
player.GetInt("testID", testID);
PrintToServer("%s client %d TestID %d", TAG, i, testID);
}
}
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

klin34970
20-05-2018, 09:31 PM
This is working, I'm posting for people who need



#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 = 1 ; i <= MaxClients; i++){
Dynamic playersettings = Dynamic.GetPlayerSettings(i);
playersettings.Dispose();
Dynamic dynamic = Dynamic();
dynamic.SetInt("ID", 0);
playersettings.SetDynamic("infos", dynamic);
}
}

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

public Action checkResponse(int client, int args){
for(int i = 1 ; i <= MaxClients; i++){
Dynamic playersettings = Dynamic.GetPlayerSettings(i).GetDynamic("infos");
if(playersettings.IsValid){
PrintToServer("%s client %d TestID %d", TAG, i, playersettings.GetInt("ID"));
}else{
PrintToServer("%s client %d !IsValid %d", TAG, i, playersettings);
}
}
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);
}




#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 client, int args){
for(int i = 1 ; i <= MaxClients; i++){
Dynamic playersettings = Dynamic.GetPlayerSettings(i).GetDynamic("infos");
if(playersettings.IsValid){
PrintToServer("%s client %d TestID %d", TAG, i, playersettings.GetInt("ID"));
}else{
PrintToServer("%s client %d !IsValid %d", TAG, i, playersettings);
}
}
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

Neuro Toxin
20-05-2018, 10:10 PM
Hi DR API,

First I would like to make sure you are aware of the Wiki (https://github.com/ntoxin66/Dynamic/wiki) for Dynamic on GitHub.

This (https://github.com/ntoxin66/Dynamic/wiki/%5B1.0.4%5D-Sharing-Dynamic-objects-with-multiple-plugins) page contains information around sharing objects using the .SetName and .FindByName natives.

I suggest using Static Objects (https://github.com/ntoxin66/Dynamic/wiki/%5B1.0.5%5D-Static-Setting-Objects) to access Server and Players settings.
(https://github.com/ntoxin66/Dynamic/wiki/%5B1.0.5%5D-Static-Setting-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:


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.

klin34970
21-05-2018, 07:17 AM
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

Neuro Toxin
21-05-2018, 11:55 AM
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 (https://github.com/ntoxin66/Dynamic/blob/master/scripting/dynamic.sp#L86).

klin34970
21-05-2018, 07:10 PM
if I kick bot, not more accessible.



public void OnClientPostAdminCheck(int client){
PrintToServer("%s OnClientPostAdminCheck %d", TAG, client);

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", TAG, client, playerinfo);
}
}

public void OnClientDisconnect(int client){
PrintToServer("%s OnClientDisconnect %d", TAG, client);
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;
}
}