2009-06-20 09:21:46 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-06-20 09:21:46 +02:00
|
|
|
*
|
|
|
|
* File: cookies.inc
|
|
|
|
* Type: Module
|
2009-06-22 06:08:26 +02:00
|
|
|
* Description: Extended client cookie API.
|
2009-06-20 09:21:46 +02:00
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-06-20 09:21:46 +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/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cookies module init function.
|
2016-02-06 00:47:47 +01:00
|
|
|
*/
|
2009-06-20 09:21:46 +02:00
|
|
|
CookiesInit()
|
|
|
|
{
|
2009-06-22 06:08:26 +02:00
|
|
|
// Forward "OnCookiesCreate" event to modules.
|
2009-06-21 21:24:24 +02:00
|
|
|
ClassOnCookiesCreate();
|
|
|
|
WeaponsOnCookiesCreate();
|
2009-06-20 09:21:46 +02:00
|
|
|
ZHPOnCookiesCreate();
|
|
|
|
}
|
|
|
|
|
2019-09-29 10:37:23 +02:00
|
|
|
/**
|
|
|
|
* Returns a cookie value as a bool.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param cookie The handle to the cookie.
|
|
|
|
*/
|
2019-11-01 16:17:50 +01:00
|
|
|
stock bool:CookiesGetClientCookieBool(client, Handle:cookie)
|
2019-09-29 10:37:23 +02:00
|
|
|
{
|
|
|
|
// Get cookie string.
|
|
|
|
decl String:cookievalue[8];
|
|
|
|
GetClientCookie(client, cookie, cookievalue, sizeof(cookievalue));
|
|
|
|
|
|
|
|
// Return string casted into an int, then to bool.
|
|
|
|
return bool:StringToInt(cookievalue);
|
|
|
|
}
|
|
|
|
|
2009-06-20 09:21:46 +02:00
|
|
|
/**
|
|
|
|
* Accepts a bools for setting client cookies.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-20 09:21:46 +02:00
|
|
|
* @param client The client index.
|
|
|
|
* @param cookie The handle to the cookie.
|
|
|
|
* @param cookievalue The bool value to set cookie as.
|
|
|
|
*/
|
2019-11-01 16:17:50 +01:00
|
|
|
stock CookiesSetClientCookieBool(client, Handle:cookie, bool:cookievalue)
|
2009-06-20 09:21:46 +02:00
|
|
|
{
|
|
|
|
// Convert bool to string.
|
|
|
|
decl String:strCookievalue[8];
|
|
|
|
ZRBoolToString(cookievalue, strCookievalue, sizeof(strCookievalue));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-06-20 09:21:46 +02:00
|
|
|
// Set the converted string to the cookie.
|
2009-06-21 07:24:31 +02:00
|
|
|
SetClientCookie(client, cookie, strCookievalue);
|
2009-06-20 09:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-29 10:37:23 +02:00
|
|
|
* Gets a integer value from a cookie.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2009-06-20 09:21:46 +02:00
|
|
|
* @param client The client index.
|
|
|
|
* @param cookie The handle to the cookie.
|
|
|
|
*/
|
2019-11-01 16:17:50 +01:00
|
|
|
stock CookiesGetInt(client, Handle:cookie)
|
2009-06-20 09:21:46 +02:00
|
|
|
{
|
2019-09-29 10:37:23 +02:00
|
|
|
decl String:strValue[16];
|
|
|
|
strValue[0] = 0;
|
|
|
|
GetClientCookie(client, cookie, strValue, sizeof(strValue));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2019-09-29 10:37:23 +02:00
|
|
|
return StringToInt(strValue);
|
2009-08-15 06:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a integer value on a cookie.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param cookie The handle to the cookie.
|
|
|
|
* @param value The value to set.
|
|
|
|
*/
|
2019-11-01 16:17:50 +01:00
|
|
|
stock CookiesSetInt(client, Handle:cookie, value)
|
2009-08-15 06:32:44 +02:00
|
|
|
{
|
|
|
|
// Convert value to string.
|
|
|
|
decl String:strValue[16];
|
|
|
|
IntToString(value, strValue, sizeof(strValue));
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2009-08-15 06:32:44 +02:00
|
|
|
// Set string value.
|
|
|
|
SetClientCookie(client, cookie, strValue);
|
|
|
|
}
|