extending buffers a bit. some extra checks. not reseting players that disconnected. initializing all indexes as -1 on loading
This commit is contained in:
		
							parent
							
								
									950fba2f5c
								
							
						
					
					
						commit
						e8b7eeef56
					
				| @ -10,9 +10,9 @@ | ||||
| class CBaseEntity; | ||||
| //class CBasePlayer;
 | ||||
| 
 | ||||
| uint8_t g_ClientGiveNamedCounter[SM_MAXPLAYERS + 1]; | ||||
| char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][32]; | ||||
| char g_ClientNameMap[SM_MAXPLAYERS + 1][32]; | ||||
| uint32_t g_ClientGiveNamedCounter[SM_MAXPLAYERS + 1]; | ||||
| char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][64]; | ||||
| char g_ClientNameMap[SM_MAXPLAYERS + 1][128]; | ||||
| int g_Capacity = 20; | ||||
| 
 | ||||
| //https://sm.alliedmods.net/doxygen/index.html
 | ||||
| @ -144,6 +144,12 @@ bool GiveNamedItemTracker::SDK_OnLoad(char *error, size_t maxlength, bool late) | ||||
| 
 | ||||
|     //set up timer for reseting GiveNamedItemTracker counts.
 | ||||
|     g_pGiveNamedItemTimer = timersys->CreateTimer(&g_GiveNamedItemTracker, 2.0, NULL, TIMER_FLAG_REPEAT); | ||||
| 
 | ||||
|     for (int idx = 0; idx <= 65; idx++) | ||||
|     { | ||||
|         g_ClientGiveNamedCounter[idx] = -1; | ||||
|     } | ||||
| 
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| @ -157,7 +163,7 @@ void GiveNamedItemTracker::OnClientPostAdminCheck(int client) | ||||
| 
 | ||||
| void GiveNamedItemTracker::OnClientDisconnected(int client) | ||||
| { | ||||
|     g_ClientGiveNamedCounter[client] = 0; | ||||
|     g_ClientGiveNamedCounter[client] = -1; | ||||
|     strlcpy(g_ClientSteamIDMap[client], "", sizeof(*g_ClientSteamIDMap)); | ||||
|     strlcpy(g_ClientNameMap[client], "", sizeof(*g_ClientNameMap)); | ||||
| } | ||||
| @ -166,6 +172,11 @@ void GiveNamedItemTracker::OnTimer() | ||||
| { | ||||
|     for (int idx = 0; idx <= playerhelpers->GetMaxClients(); idx++) | ||||
|     { | ||||
|         if (g_ClientGiveNamedCounter[idx] == -1) | ||||
|         { | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
|         if (strcmp(g_ClientSteamIDMap[idx], "") == 0) | ||||
|         { | ||||
|             //empty steamid. (null). idx: 2. name: mituju
 | ||||
| @ -174,8 +185,17 @@ void GiveNamedItemTracker::OnTimer() | ||||
|             IGamePlayer* gp = playerhelpers->GetGamePlayer(idx); | ||||
|             if (gp && gp->IsConnected() && gp->IsInGame()) | ||||
|             { | ||||
|                 strlcpy(g_ClientSteamIDMap[idx], gp->GetAuthString(), sizeof(*g_ClientSteamIDMap)); | ||||
|                 strlcpy(g_ClientNameMap[idx], gp->GetName(), sizeof(*g_ClientNameMap)); | ||||
|                 const char *steamID = gp->GetAuthString(); | ||||
|                 const char *name = gp->GetName(); | ||||
|                 if (steamID) | ||||
|                 { | ||||
|                     strlcpy(g_ClientSteamIDMap[idx], steamID, sizeof(*g_ClientSteamIDMap)); | ||||
|                 } | ||||
|                 //not too bad if we miss the name, just steam id is important
 | ||||
|                 if (name) | ||||
|                 { | ||||
|                     strlcpy(g_ClientNameMap[idx], name, sizeof(*g_ClientNameMap)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         g_ClientGiveNamedCounter[idx] = 0; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user