Fixed stupid compiler error in cookies (oops) and recoded serial module to use steamids (serial's weren't workin' out) + the API was very confined, added ability to create SteamID cache's instead of one global cache. ZSpawn uses this new cache system.

This commit is contained in:
Greyscale 2009-06-20 22:24:31 -07:00
parent bb75f1955c
commit 6426bf169c
5 changed files with 119 additions and 110 deletions

View File

@ -43,7 +43,7 @@
#include "zr/cvars"
#include "zr/log"
#include "zr/config"
#include "zr/serial"
#include "zr/steamidcache"
#include "zr/sayhooks"
#include "zr/tools"
#include "zr/cookies"
@ -130,7 +130,6 @@ public OnPluginStart()
public OnMapStart()
{
// Forward event to modules.
SerialOnMapStart();
OverlaysOnMapStart();
RoundEndOnMapStart();
InfectOnMapStart();

View File

@ -48,7 +48,7 @@ CookiesSetClientCookieBool(client, Handle:cookie, bool:cookievalue)
ZRBoolToString(cookievalue, strCookievalue, sizeof(strCookievalue));
// Set the converted string to the cookie.
SetClientCookie(client, cookie, cookievalue);
SetClientCookie(client, cookie, strCookievalue);
}
/**

View File

@ -1,100 +0,0 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: serial.inc
* Type: Core
* Description: Client serial number tracking API.
*
* Copyright (C) 2009 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/>.
*
* ============================================================================
*/
/**
* Maximum length of a client's serial number.
*/
#define SERIAL_MAX_LENGTH 8
/**
* Array to store client serial numbers.
*/
new Handle:arraySerial = INVALID_HANDLE;
/**
* Map is starting.
*/
SerialOnMapStart()
{
// If array exists, destroy before recreating.
if (arraySerial != INVALID_HANDLE)
{
CloseHandle(arraySerial);
}
// Create array.
arraySerial = CreateArray();
}
/**
* Add client serial number to global array.
*
* @param client The client index.
* @return True if the client was added successfully, false if the client already exists.
*/
bool:SerialAddClient(client)
{
// Check if client is already added.
new bool:exists = SerialClientExists(client);
if (exists)
{
return false;
}
// Get client's serial number.
new serial = GetClientSerial(client);
// Push serial number into the global array.
PushArrayCell(arraySerial, serial);
// Client added successfully.
return true;
}
/**
* Check if a client has been added to the global array.
*
* @param client The client index.
* @return True if the client exists, false otherwise.
*/
bool:SerialClientExists(client)
{
// Get client's serial number.
new serial = GetClientSerial(client);
// Return true if value was found, false otherwise.
return (FindValueInArray(arraySerial, serial) != -1);
}
/**
* Reset serial number array.
*/
SerialReset()
{
// Clear array.
ClearArray(arraySerial);
}

96
src/zr/steamidcache.inc Normal file
View File

@ -0,0 +1,96 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: steamidcache.inc
* Type: Core
* Description: A SteamID caching API.
*
* Copyright (C) 2009 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/>.
*
* ============================================================================
*/
/**
* The maximum length of a SteamID
*/
#define STEAMIDCACHE_MAX_LENGTH 16
/**
* Creates a steamid cache.
*
* @return Handle to SteamID cache.
*/
stock Handle:SteamidCacheCreate()
{
// Return steamid cache handle.
return CreateArray(STEAMIDCACHE_MAX_LENGTH);
}
/**
* 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.
decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
GetClientAuthString(client, steamid, sizeof(steamid));
// Push SteamID into the SteamID cache.
PushArrayString(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.
decl String:steamid[STEAMIDCACHE_MAX_LENGTH];
GetClientAuthString(client, steamid, sizeof(steamid));
// Return true if client was found, false otherwise.
return (FindStringInArray(steamidcache, steamid) != -1);
}
/**
* Reset SteamID cache.
*
* @param steamidcache The SteamID cache to reset.
*/
stock SteamidCacheReset(Handle:steamidcache)
{
// Clear array.
ClearArray(steamidcache);
}

View File

@ -30,6 +30,11 @@
*/
new Handle:tZSpawn = INVALID_HANDLE;
/**
* Global variable to store SteamID cache handle.
*/
new Handle:g_hZSpawnSteamIDCache = INVALID_HANDLE;
/**
* Create commands specific to ZSpawn.
*/
@ -46,6 +51,15 @@ ZSpawnOnMapStart()
{
// Reset timer handle.
tZSpawn = INVALID_HANDLE;
// If SteamID cache hasn't been created yet, then create.
if (g_hZSpawnSteamIDCache == INVALID_HANDLE)
{
g_hZSpawnSteamIDCache = SteamidCacheCreate();
}
// Reset the SteamID cache.
SteamidCacheReset(g_hZSpawnSteamIDCache);
}
/**
@ -61,8 +75,8 @@ ZSpawnOnClientDisconnect(client)
return;
}
// Add client serial to global array.
SerialAddClient(client);
// Add client to the SteamID cache.
SteamidCacheAddClient(g_hZSpawnSteamIDCache, client);
}
/**
@ -72,8 +86,8 @@ ZSpawnOnClientDisconnect(client)
*/
ZSpawnOnClientDeath(client)
{
// Add client serial to global array.
SerialAddClient(client);
// Add client to the SteamID cache.
SteamidCacheAddClient(g_hZSpawnSteamIDCache, client);
}
/**
@ -81,8 +95,8 @@ ZSpawnOnClientDeath(client)
*/
ZSpawnOnRoundStart()
{
// Reset serial number array.
SerialReset();
// Reset the SteamID cache.
SteamidCacheReset(g_hZSpawnSteamIDCache);
// If zspawn timer is running, then kill it.
if (tZSpawn != INVALID_HANDLE)
@ -177,7 +191,7 @@ bool:ZSpawnClient(client)
}
// Block if client has already played during this round.
if (SerialClientExists(client))
if (SteamidCacheClientExists(g_hZSpawnSteamIDCache, client))
{
// Tell client the command may only be used when joining late.
TranslationPrintToChat(client, "ZSpawn double spawn");