|
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 |
|
|
pred@2009
|
35 |
#define MAXCLIENTS 64 |
|
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 |
|
|
pred@2207
|
90 |
void DatabaseConnect(); |
|
pred@2207
|
91 |
|
|
pred@2207
|
92 |
bool AddQueryToQueue(TQueryOp *query); |
|
pred@2207
|
93 |
void ProcessQueryCache(); |
|
pred@2207
|
94 |
|
|
pred@2009
|
95 |
/** |
|
pred@2009
|
96 |
* @brief Called when the pause state is changed. |
|
pred@2009
|
97 |
*/ |
|
pred@2009
|
98 |
//virtual void SDK_OnPauseChange(bool paused); |
|
pred@2009
|
99 |
|
|
pred@2009
|
100 |
/** |
|
pred@2009
|
101 |
* @brief this is called when Core wants to know if your extension is working. |
|
pred@2009
|
102 |
* |
|
pred@2009
|
103 |
* @param error Error message buffer. |
|
pred@2009
|
104 |
* @param maxlength Size of error message buffer. |
|
pred@2009
|
105 |
* @return True if working, false otherwise. |
|
pred@2009
|
106 |
*/ |
|
pred@2009
|
107 |
//virtual bool QueryRunning(char *error, size_t maxlength); |
|
pred@2009
|
108 |
public: |
|
pred@2009
|
109 |
#if defined SMEXT_CONF_METAMOD |
|
pred@2009
|
110 |
/** |
|
pred@2009
|
111 |
* @brief Called when Metamod is attached, before the extension version is called. |
|
pred@2009
|
112 |
* |
|
pred@2009
|
113 |
* @param error Error buffer. |
|
pred@2009
|
114 |
* @param maxlength Maximum size of error buffer. |
|
pred@2009
|
115 |
* @param late Whether or not Metamod considers this a late load. |
|
pred@2009
|
116 |
* @return True to succeed, false to fail. |
|
pred@2009
|
117 |
*/ |
|
pred@2009
|
118 |
//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); |
|
pred@2009
|
119 |
|
|
pred@2009
|
120 |
/** |
|
pred@2009
|
121 |
* @brief Called when Metamod is detaching, after the extension version is called. |
|
pred@2009
|
122 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
pred@2009
|
123 |
* |
|
pred@2009
|
124 |
* @param error Error buffer. |
|
pred@2009
|
125 |
* @param maxlength Maximum size of error buffer. |
|
pred@2009
|
126 |
* @return True to succeed, false to fail. |
|
pred@2009
|
127 |
*/ |
|
pred@2009
|
128 |
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); |
|
pred@2009
|
129 |
|
|
pred@2009
|
130 |
/** |
|
pred@2009
|
131 |
* @brief Called when Metamod's pause state is changing. |
|
pred@2009
|
132 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
pred@2009
|
133 |
* |
|
pred@2009
|
134 |
* @param paused Pause state being set. |
|
pred@2009
|
135 |
* @param error Error buffer. |
|
pred@2009
|
136 |
* @param maxlength Maximum size of error buffer. |
|
pred@2009
|
137 |
* @return True to succeed, false to fail. |
|
pred@2009
|
138 |
*/ |
|
pred@2009
|
139 |
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); |
|
pred@2009
|
140 |
#endif |
|
pred@2009
|
141 |
public: |
|
pred@2009
|
142 |
IDBDriver *Driver; |
|
pred@2009
|
143 |
IDatabase *Database; |
|
pred@2207
|
144 |
bool databaseLoading; |
|
pred@2048
|
145 |
IPhraseCollection *phrases; |
|
pred@2207
|
146 |
const DatabaseInfo *DBInfo; |
|
pred@2207
|
147 |
|
|
pred@2207
|
148 |
IMutex *cookieMutex; |
|
pred@2207
|
149 |
|
|
pred@2207
|
150 |
private: |
|
pred@2207
|
151 |
SourceHook::List<TQueryOp *> cachedQueries; |
|
pred@2207
|
152 |
IMutex *queryMutex; |
|
pred@2009
|
153 |
}; |
|
pred@2009
|
154 |
|
|
pred@2009
|
155 |
class CookieTypeHandler : public IHandleTypeDispatch |
|
pred@2009
|
156 |
{ |
|
pred@2009
|
157 |
public: |
|
pred@2009
|
158 |
void OnHandleDestroy(HandleType_t type, void *object) |
|
pred@2009
|
159 |
{ |
|
pred@2207
|
160 |
/* No delete needed since Cookies are persistent */ |
|
pred@2009
|
161 |
} |
|
pred@2009
|
162 |
}; |
|
pred@2009
|
163 |
|
|
pred@2048
|
164 |
class CookieIteratorHandler : public IHandleTypeDispatch |
|
pred@2048
|
165 |
{ |
|
pred@2048
|
166 |
public: |
|
pred@2048
|
167 |
void OnHandleDestroy(HandleType_t type, void *object) |
|
pred@2048
|
168 |
{ |
|
pred@2048
|
169 |
delete (SourceHook::List<Cookie *>::iterator *)object; |
|
pred@2048
|
170 |
} |
|
pred@2048
|
171 |
}; |
|
pred@2048
|
172 |
|
|
pred@2048
|
173 |
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); |
|
pred@2048
|
174 |
|
|
pred@2009
|
175 |
extern sp_nativeinfo_t g_ClientPrefNatives[]; |
|
pred@2009
|
176 |
|
|
pred@2009
|
177 |
extern ClientPrefs g_ClientPrefs; |
|
pred@2009
|
178 |
extern HandleType_t g_CookieType; |
|
pred@2009
|
179 |
extern CookieTypeHandler g_CookieTypeHandler; |
|
pred@2009
|
180 |
|
|
pred@2048
|
181 |
extern HandleType_t g_CookieIterator; |
|
pred@2048
|
182 |
extern CookieIteratorHandler g_CookieIteratorHandler; |
|
pred@2048
|
183 |
|
|
pred@2048
|
184 |
bool Translate(char *buffer, |
|
pred@2048
|
185 |
size_t maxlength, |
|
pred@2048
|
186 |
const char *format, |
|
pred@2048
|
187 |
unsigned int numparams, |
|
pred@2048
|
188 |
size_t *pOutLength, |
|
pred@2048
|
189 |
...); |
|
pred@2048
|
190 |
|
|
dvander@2373
|
191 |
extern DbDriver g_DriverType; |
|
pred@2009
|
192 |
|
|
pred@2009
|
193 |
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ |
|
dvander@2373
|
194 |
|