2008-04-17 06:58:09 +02:00
|
|
|
/**
|
2013-08-25 21:19:10 +02:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-04-17 06:58:09 +02:00
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Client Preferences Extension
|
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_SOURCEMOD_CLIENTPREFS_COOKIE_H_
|
|
|
|
#define _INCLUDE_SOURCEMOD_CLIENTPREFS_COOKIE_H_
|
|
|
|
|
|
|
|
#include "extension.h"
|
2014-06-05 06:49:48 +02:00
|
|
|
#include "am-vector.h"
|
2013-08-25 21:19:10 +02:00
|
|
|
#include <sm_namehashset.h>
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
#define MAX_NAME_LENGTH 30
|
|
|
|
#define MAX_DESC_LENGTH 255
|
|
|
|
#define MAX_VALUE_LENGTH 100
|
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
enum CookieAccess
|
|
|
|
{
|
|
|
|
CookieAccess_Public, /**< Visible and Changeable by users */
|
|
|
|
CookieAccess_Protected, /**< Read only to users */
|
|
|
|
CookieAccess_Private, /**< Completely hidden cookie */
|
|
|
|
};
|
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
struct Cookie;
|
|
|
|
|
|
|
|
struct CookieData
|
|
|
|
{
|
|
|
|
CookieData(const char *value)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
UTIL_strncpy(this->value, value, MAX_VALUE_LENGTH);
|
2008-04-17 06:58:09 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 22:51:49 +01:00
|
|
|
char value[MAX_VALUE_LENGTH+1];
|
2008-04-17 06:58:09 +02:00
|
|
|
bool changed;
|
2009-03-17 00:30:21 +01:00
|
|
|
time_t timestamp;
|
2008-04-17 06:58:09 +02:00
|
|
|
Cookie *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Cookie
|
|
|
|
{
|
2008-05-12 10:06:47 +02:00
|
|
|
Cookie(const char *name, const char *description, CookieAccess access)
|
2008-04-17 06:58:09 +02:00
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
UTIL_strncpy(this->name, name, MAX_NAME_LENGTH);
|
|
|
|
UTIL_strncpy(this->description, description, MAX_DESC_LENGTH);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
this->access = access;
|
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
dbid = -1;
|
|
|
|
|
2014-05-07 03:40:35 +02:00
|
|
|
for (int i=0; i<=SM_MAXPLAYERS; i++)
|
2008-04-17 06:58:09 +02:00
|
|
|
data[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Cookie()
|
|
|
|
{
|
2014-05-07 03:40:35 +02:00
|
|
|
for (int i=0; i<=SM_MAXPLAYERS; i++)
|
2008-04-17 06:58:09 +02:00
|
|
|
{
|
|
|
|
if (data[i] != NULL)
|
|
|
|
delete data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-28 22:51:49 +01:00
|
|
|
char name[MAX_NAME_LENGTH+1];
|
|
|
|
char description[MAX_DESC_LENGTH+1];
|
2008-04-17 06:58:09 +02:00
|
|
|
int dbid;
|
2014-05-07 03:40:35 +02:00
|
|
|
CookieData *data[SM_MAXPLAYERS+1];
|
2008-05-12 10:06:47 +02:00
|
|
|
CookieAccess access;
|
2013-08-25 21:19:10 +02:00
|
|
|
|
|
|
|
static inline bool matches(const char *name, const Cookie *cookie)
|
|
|
|
{
|
|
|
|
return strcmp(name, cookie->name) == 0;
|
|
|
|
}
|
2018-07-10 23:38:40 +02:00
|
|
|
static inline uint32_t hash(const detail::CharsAndLength &key)
|
|
|
|
{
|
|
|
|
return key.hash();
|
|
|
|
}
|
2008-04-17 06:58:09 +02:00
|
|
|
};
|
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
class CookieManager : public IClientListener, public IPluginsListener
|
2008-04-17 06:58:09 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CookieManager();
|
|
|
|
~CookieManager();
|
|
|
|
|
|
|
|
void OnClientAuthorized(int client, const char *authstring);
|
|
|
|
void OnClientDisconnecting(int client);
|
|
|
|
|
|
|
|
bool GetCookieValue(Cookie *pCookie, int client, char **value);
|
2010-05-11 10:46:54 +02:00
|
|
|
bool SetCookieValue(Cookie *pCookie, int client, const char *value);
|
2009-03-17 00:30:21 +01:00
|
|
|
bool GetCookieTime(Cookie *pCookie, int client, time_t *value);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
void Unload();
|
|
|
|
|
2009-02-19 07:28:50 +01:00
|
|
|
void ClientConnectCallback(int serial, IQuery *data);
|
2008-04-17 06:58:09 +02:00
|
|
|
void InsertCookieCallback(Cookie *pCookie, int dbId);
|
2008-05-12 10:06:47 +02:00
|
|
|
void SelectIdCallback(Cookie *pCookie, IQuery *data);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
Cookie *FindCookie(const char *name);
|
2008-05-12 10:06:47 +02:00
|
|
|
Cookie *CreateCookie(const char *name, const char *description, CookieAccess access);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
bool AreClientCookiesCached(int client);
|
|
|
|
|
2008-07-15 02:24:08 +02:00
|
|
|
void OnPluginDestroyed(IPlugin *plugin);
|
2013-02-28 22:51:49 +01:00
|
|
|
|
2014-05-09 18:34:29 +02:00
|
|
|
bool AreClientCookiesPending(int client);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
2008-07-15 02:24:08 +02:00
|
|
|
public:
|
|
|
|
IForward *cookieDataLoadedForward;
|
2014-06-05 06:49:48 +02:00
|
|
|
ke::Vector<Cookie *> cookieList;
|
2008-05-12 10:06:47 +02:00
|
|
|
IBaseMenu *clientMenu;
|
|
|
|
|
|
|
|
private:
|
2013-08-25 21:19:10 +02:00
|
|
|
NameHashSet<Cookie *> cookieFinder;
|
2014-06-05 06:49:48 +02:00
|
|
|
ke::Vector<CookieData *> clientData[SM_MAXPLAYERS+1];
|
2008-04-17 06:58:09 +02:00
|
|
|
|
2014-05-07 03:40:35 +02:00
|
|
|
bool connected[SM_MAXPLAYERS+1];
|
|
|
|
bool statsLoaded[SM_MAXPLAYERS+1];
|
|
|
|
bool statsPending[SM_MAXPLAYERS+1];
|
2008-04-17 06:58:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CookieManager g_CookieManager;
|
|
|
|
|
|
|
|
#endif // _INCLUDE_SOURCEMOD_CLIENTPREFS_COOKIE_H_
|