diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 1f6b2b6..604ed0a 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -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(); diff --git a/src/zr/cookies.inc b/src/zr/cookies.inc index cfc40dd..7997b0b 100644 --- a/src/zr/cookies.inc +++ b/src/zr/cookies.inc @@ -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); } /** diff --git a/src/zr/serial.inc b/src/zr/serial.inc deleted file mode 100644 index f2f8d8c..0000000 --- a/src/zr/serial.inc +++ /dev/null @@ -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 . - * - * ============================================================================ - */ - -/** - * 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); -} diff --git a/src/zr/steamidcache.inc b/src/zr/steamidcache.inc new file mode 100644 index 0000000..aa2700d --- /dev/null +++ b/src/zr/steamidcache.inc @@ -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 . + * + * ============================================================================ + */ + +/** + * 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); +} diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index 029f46c..f746588 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -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");