extensions/clientprefs/extension.h
author Nicholas Hastings <skamonkey@gmail.com>
Tue Jul 03 07:51:12 2012 -0400 (2012-07-03)
changeset 3573 440c51204096
parent 3500 87231551b8e6
child 3804 90159516acd3
permissions -rw-r--r--
Fixed clientprefs prefab menu double free crash (bug 5374, r=asherkin).
pred@2009
     1
/**
pred@2009
     2
 * vim: set ts=4 :
pred@2009
     3
 * =============================================================================
pred@2009
     4
 * SourceMod Client Preferences Extension
pred@2009
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2009
     6
 * =============================================================================
pred@2009
     7
 *
pred@2009
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2009
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009
    10
 * Free Software Foundation.
pred@2009
    11
 * 
pred@2009
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2009
    15
 * details.
pred@2009
    16
 *
pred@2009
    17
 * You should have received a copy of the GNU General Public License along with
pred@2009
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2009
    19
 *
pred@2009
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2009
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2009
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2009
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2009
    28
 *
pred@2009
    29
 * Version: $Id$
pred@2009
    30
 */
pred@2009
    31
pred@2009
    32
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
pred@2009
    33
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
pred@2009
    34
skamonkey@3188
    35
#define MAXCLIENTS 65
pred@2009
    36
ds@2051
    37
#include <stdlib.h>
ds@2051
    38
#include <stdarg.h>
pred@2009
    39
#include "smsdk_ext.h"
pred@2048
    40
#include "sh_list.h"
pred@2009
    41
#include "cookie.h"
pred@2048
    42
#include "menus.h"
pred@2087
    43
#include "query.h"
pred@2009
    44
dvander@2373
    45
enum DbDriver
dvander@2373
    46
{
dvander@2373
    47
	Driver_MySQL,
dvander@2373
    48
	Driver_SQLite
dvander@2373
    49
};
pred@2009
    50
pred@2048
    51
#define MAX_TRANSLATE_PARAMS		32
pred@2048
    52
pred@2207
    53
class TQueryOp;
pred@2207
    54
pred@2009
    55
/**
pred@2009
    56
 * @brief Sample implementation of the SDK Extension.
pred@2009
    57
 * Note: Uncomment one of the pre-defined virtual functions in order to use it.
pred@2009
    58
 */
pred@2009
    59
class ClientPrefs : public SDKExtension
pred@2009
    60
{
pred@2009
    61
public:
pred@2009
    62
	/**
pred@2009
    63
	 * @brief This is called after the initial loading sequence has been processed.
pred@2009
    64
	 *
pred@2009
    65
	 * @param error		Error message buffer.
pred@2009
    66
	 * @param maxlength	Size of error message buffer.
pred@2009
    67
	 * @param late		Whether or not the module was loaded after map load.
pred@2009
    68
	 * @return			True to succeed loading, false to fail.
pred@2009
    69
	 */
pred@2009
    70
	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
pred@2009
    71
	
pred@2009
    72
	/**
pred@2009
    73
	 * @brief This is called right before the extension is unloaded.
pred@2009
    74
	 */
pred@2009
    75
	virtual void SDK_OnUnload();
pred@2009
    76
pred@2009
    77
	/**
pred@2009
    78
	 * @brief This is called once all known extensions have been loaded.
pred@2009
    79
	 * Note: It is is a good idea to add natives here, if any are provided.
pred@2009
    80
	 */
pred@2009
    81
	virtual void SDK_OnAllLoaded();
pred@2009
    82
dvander@2135
    83
	virtual bool QueryInterfaceDrop(SMInterface *pInterface);
dvander@2135
    84
dvander@2135
    85
	virtual void NotifyInterfaceDrop(SMInterface *pInterface);
dvander@2135
    86
dvander@2790
    87
	const char *GetExtensionVerString();
dvander@2790
    88
	const char *GetExtensionDateString();
dvander@2783
    89
asherkin@3500
    90
	virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
asherkin@3500
    91
	
pred@2207
    92
	void DatabaseConnect();
pred@2207
    93
pred@2207
    94
	bool AddQueryToQueue(TQueryOp *query);
pred@2207
    95
	void ProcessQueryCache();
pred@2207
    96
pred@2009
    97
	/**
pred@2009
    98
	 * @brief Called when the pause state is changed.
pred@2009
    99
	 */
pred@2009
   100
	//virtual void SDK_OnPauseChange(bool paused);
pred@2009
   101
pred@2009
   102
	/**
pred@2009
   103
	 * @brief this is called when Core wants to know if your extension is working.
pred@2009
   104
	 *
pred@2009
   105
	 * @param error		Error message buffer.
pred@2009
   106
	 * @param maxlength	Size of error message buffer.
pred@2009
   107
	 * @return			True if working, false otherwise.
pred@2009
   108
	 */
pred@2009
   109
	//virtual bool QueryRunning(char *error, size_t maxlength);
pred@2009
   110
public:
pred@2009
   111
#if defined SMEXT_CONF_METAMOD
pred@2009
   112
	/**
pred@2009
   113
	 * @brief Called when Metamod is attached, before the extension version is called.
pred@2009
   114
	 *
pred@2009
   115
	 * @param error			Error buffer.
pred@2009
   116
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   117
	 * @param late			Whether or not Metamod considers this a late load.
pred@2009
   118
	 * @return				True to succeed, false to fail.
pred@2009
   119
	 */
pred@2009
   120
	//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
pred@2009
   121
pred@2009
   122
	/**
pred@2009
   123
	 * @brief Called when Metamod is detaching, after the extension version is called.
pred@2009
   124
	 * NOTE: By default this is blocked unless sent from SourceMod.
pred@2009
   125
	 *
pred@2009
   126
	 * @param error			Error buffer.
pred@2009
   127
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   128
	 * @return				True to succeed, false to fail.
pred@2009
   129
	 */
pred@2009
   130
	//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
pred@2009
   131
pred@2009
   132
	/**
pred@2009
   133
	 * @brief Called when Metamod's pause state is changing.
pred@2009
   134
	 * NOTE: By default this is blocked unless sent from SourceMod.
pred@2009
   135
	 *
pred@2009
   136
	 * @param paused		Pause state being set.
pred@2009
   137
	 * @param error			Error buffer.
pred@2009
   138
	 * @param maxlength		Maximum size of error buffer.
pred@2009
   139
	 * @return				True to succeed, false to fail.
pred@2009
   140
	 */
pred@2009
   141
	//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
pred@2009
   142
#endif
pred@2009
   143
public:
skamonkey@3573
   144
	IdentityToken_t *GetIdentity() const;
skamonkey@3573
   145
public:
pred@2009
   146
	IDBDriver *Driver;
pred@2009
   147
	IDatabase *Database;
pred@2207
   148
	bool databaseLoading;
pred@2048
   149
	IPhraseCollection *phrases;
pred@2207
   150
	const DatabaseInfo *DBInfo;
pred@2207
   151
pred@2207
   152
	IMutex *cookieMutex;
pred@2207
   153
pred@2207
   154
private:
pred@2207
   155
	SourceHook::List<TQueryOp *> cachedQueries;
pred@2207
   156
	IMutex *queryMutex;
skamonkey@3573
   157
	IdentityToken_t *identity;
pred@2009
   158
};
pred@2009
   159
pred@2009
   160
class CookieTypeHandler : public IHandleTypeDispatch
pred@2009
   161
{
pred@2009
   162
public:
pred@2009
   163
	void OnHandleDestroy(HandleType_t type, void *object)
pred@2009
   164
	{
pred@2207
   165
		/* No delete needed since Cookies are persistent */
pred@2009
   166
	}
pred@2009
   167
};
pred@2009
   168
pred@2048
   169
class CookieIteratorHandler : public IHandleTypeDispatch
pred@2048
   170
{
pred@2048
   171
public:
pred@2048
   172
	void OnHandleDestroy(HandleType_t type, void *object)
pred@2048
   173
	{
pred@2048
   174
		delete (SourceHook::List<Cookie *>::iterator *)object;
pred@2048
   175
	}
pred@2048
   176
};
pred@2048
   177
datal30mb@3411
   178
size_t IsAuthIdConnected(char *authID);
datal30mb@3411
   179
pred@2048
   180
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
pred@2048
   181
pred@2009
   182
extern sp_nativeinfo_t g_ClientPrefNatives[];
pred@2009
   183
pred@2009
   184
extern ClientPrefs g_ClientPrefs;
pred@2009
   185
extern HandleType_t g_CookieType;
pred@2009
   186
extern CookieTypeHandler g_CookieTypeHandler;
pred@2009
   187
pred@2048
   188
extern HandleType_t g_CookieIterator;
pred@2048
   189
extern CookieIteratorHandler g_CookieIteratorHandler;
pred@2048
   190
pred@2048
   191
bool Translate(char *buffer, 
pred@2048
   192
				   size_t maxlength,
pred@2048
   193
				   const char *format,
pred@2048
   194
				   unsigned int numparams,
pred@2048
   195
				   size_t *pOutLength,
pred@2048
   196
				   ...);
pred@2048
   197
dvander@2373
   198
extern DbDriver g_DriverType;
pred@2009
   199
pred@2009
   200
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
dvander@2373
   201