2008-04-17 06:58:09 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* 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"
|
|
|
|
#include "sh_list.h"
|
|
|
|
#include "sm_trie_tpl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
strncpy(this->value, value, MAX_VALUE_LENGTH);
|
|
|
|
this->value[MAX_VALUE_LENGTH-1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
char value[MAX_VALUE_LENGTH];
|
|
|
|
bool changed;
|
|
|
|
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
|
|
|
{
|
|
|
|
strncpy(this->name, name, MAX_NAME_LENGTH);
|
|
|
|
this->name[MAX_NAME_LENGTH-1] = '\0';
|
|
|
|
strncpy(this->description, description, MAX_DESC_LENGTH);
|
|
|
|
this->description[MAX_DESC_LENGTH-1] = '\0';
|
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
this->access = access;
|
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
dbid = -1;
|
|
|
|
|
|
|
|
for (int i=0; i<=MAXCLIENTS; i++)
|
|
|
|
{
|
|
|
|
data[i] = NULL;
|
|
|
|
}
|
2008-07-15 02:24:08 +02:00
|
|
|
|
|
|
|
shouldDelete = false;
|
|
|
|
usedInQuery = 0;
|
2008-04-17 06:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~Cookie()
|
|
|
|
{
|
|
|
|
for (int i=0; i<=MAXCLIENTS; i++)
|
|
|
|
{
|
|
|
|
if (data[i] != NULL)
|
|
|
|
{
|
|
|
|
delete data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
char description[MAX_DESC_LENGTH];
|
|
|
|
int dbid;
|
|
|
|
CookieData *data[MAXCLIENTS+1];
|
2008-05-12 10:06:47 +02:00
|
|
|
CookieAccess access;
|
2008-07-15 02:24:08 +02:00
|
|
|
|
|
|
|
/* Reference counting stuff */
|
|
|
|
bool shouldDelete;
|
|
|
|
int usedInQuery;
|
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);
|
|
|
|
bool SetCookieValue(Cookie *pCookie, int client, char *value);
|
|
|
|
|
|
|
|
void Unload();
|
|
|
|
|
2008-10-31 14:28:08 +01:00
|
|
|
void ClientConnectCallback(int userid, 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);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
2008-07-15 02:24:08 +02:00
|
|
|
public:
|
|
|
|
IForward *cookieDataLoadedForward;
|
2008-04-17 06:58:09 +02:00
|
|
|
SourceHook::List<Cookie *> cookieList;
|
2008-05-12 10:06:47 +02:00
|
|
|
IBaseMenu *clientMenu;
|
|
|
|
|
|
|
|
private:
|
2008-04-17 06:58:09 +02:00
|
|
|
KTrie<Cookie *> cookieTrie;
|
|
|
|
SourceHook::List<CookieData *> clientData[MAXCLIENTS];
|
|
|
|
|
|
|
|
bool connected[MAXCLIENTS+1];
|
|
|
|
bool statsLoaded[MAXCLIENTS+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CookieManager g_CookieManager;
|
|
|
|
|
|
|
|
#endif // _INCLUDE_SOURCEMOD_CLIENTPREFS_COOKIE_H_
|