2009-06-21 21:24:24 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-06-21 21:24:24 +02:00
|
|
|
*
|
|
|
|
* File: steamidcache.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: A SteamID caching API.
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-06-21 21:24:24 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a steamid cache.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-21 21:24:24 +02:00
|
|
|
* @return Handle to SteamID cache.
|
|
|
|
*/
|
|
|
|
stock Handle:SteamidCacheCreate()
|
|
|
|
{
|
|
|
|
// Return steamid cache handle.
|
2017-01-22 15:09:22 +01:00
|
|
|
return CreateArray(1);
|
2009-06-21 21:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add client serial number to the SteamID cache.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-21 21:24:24 +02:00
|
|
|
* @param steamidcache The SteamID cache to add client to.
|
|
|
|
* @param client The client index.
|
|
|
|
* @return True if the client was added successfully, false if the client already exists.
|
|
|
|
*/
|
|
|
|
stock bool:SteamidCacheAddClient(Handle:steamidcache, client)
|
|
|
|
{
|
|
|
|
// Check if client is in the cache.
|
|
|
|
if (SteamidCacheClientExists(steamidcache, client))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Get client's SteamID.
|
2017-01-22 15:09:22 +01:00
|
|
|
new steamid = GetSteamAccountID(client);
|
|
|
|
if (!steamid)
|
|
|
|
return false;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Push SteamID into the SteamID cache.
|
2017-01-22 15:09:22 +01:00
|
|
|
PushArrayCell(steamidcache, steamid);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Client added successfully.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a client is in the SteamID cache.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-21 21:24:24 +02:00
|
|
|
* @param steamidcache The SteamID cache to check in.
|
|
|
|
* @param client The client index.
|
|
|
|
* @return True if the client exists, false otherwise.
|
|
|
|
*/
|
|
|
|
stock bool:SteamidCacheClientExists(Handle:steamidcache, client)
|
|
|
|
{
|
|
|
|
// Get client's SteamID.
|
2017-01-22 15:09:22 +01:00
|
|
|
new steamid = GetSteamAccountID(client);
|
|
|
|
if (!steamid)
|
|
|
|
return false;
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Return true if client was found, false otherwise.
|
2017-01-22 15:09:22 +01:00
|
|
|
return (FindValueInArray(steamidcache, steamid) != -1);
|
2009-06-21 21:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset SteamID cache.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-21 21:24:24 +02:00
|
|
|
* @param steamidcache The SteamID cache to reset.
|
|
|
|
*/
|
|
|
|
stock SteamidCacheReset(Handle:steamidcache)
|
|
|
|
{
|
|
|
|
// Clear array.
|
|
|
|
ClearArray(steamidcache);
|
|
|
|
}
|