sm-zombiereloaded-3/src/zr/steamidcache.inc

94 lines
2.6 KiB
PHP
Raw Normal View History

/*
* ============================================================================
*
* Zombie:Reloaded
*
* 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
*
* 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.
*
* @return Handle to SteamID cache.
*/
stock Handle:SteamidCacheCreate()
{
// Return steamid cache handle.
return CreateArray(1);
}
/**
* Add client serial number to the SteamID cache.
*
* @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;
}
// Get client's SteamID.
new steamid = GetSteamAccountID(client);
if (!steamid)
return false;
// Push SteamID into the SteamID cache.
PushArrayCell(steamidcache, steamid);
// Client added successfully.
return true;
}
/**
* Check if a client is in the SteamID cache.
*
* @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.
new steamid = GetSteamAccountID(client);
if (!steamid)
return false;
// Return true if client was found, false otherwise.
return (FindValueInArray(steamidcache, steamid) != -1);
}
/**
* Reset SteamID cache.
*
* @param steamidcache The SteamID cache to reset.
*/
stock SteamidCacheReset(Handle:steamidcache)
{
// Clear array.
ClearArray(steamidcache);
}