|
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 |
#include "extension.h" |
|
pred@2009
|
33 |
#include "cookie.h" |
|
pred@2048
|
34 |
#include "menus.h" |
|
pred@2009
|
35 |
|
|
pred@2009
|
36 |
cell_t RegClientPrefCookie(IPluginContext *pContext, const cell_t *params) |
|
pred@2009
|
37 |
{ |
|
kyle@3804
|
38 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
39 |
|
|
pred@2009
|
40 |
char *name; |
|
pred@2009
|
41 |
pContext->LocalToString(params[1], &name); |
|
pred@2009
|
42 |
|
|
pred@2009
|
43 |
if (name[0] == '\0') |
|
pred@2009
|
44 |
{ |
|
pred@2009
|
45 |
return pContext->ThrowNativeError("Cannot create preference cookie with no name"); |
|
pred@2009
|
46 |
} |
|
pred@2009
|
47 |
|
|
pred@2009
|
48 |
char *desc; |
|
pred@2009
|
49 |
pContext->LocalToString(params[2], &desc); |
|
pred@2009
|
50 |
|
|
pred@2048
|
51 |
Cookie *pCookie = g_CookieManager.CreateCookie(name, desc, (CookieAccess)params[3]); |
|
pred@2009
|
52 |
|
|
pred@2009
|
53 |
if (!pCookie) |
|
pred@2009
|
54 |
{ |
|
pred@2009
|
55 |
return BAD_HANDLE; |
|
pred@2009
|
56 |
} |
|
pred@2009
|
57 |
|
|
pred@2009
|
58 |
return handlesys->CreateHandle(g_CookieType, |
|
pred@2009
|
59 |
pCookie, |
|
pred@2009
|
60 |
pContext->GetIdentity(), |
|
pred@2009
|
61 |
myself->GetIdentity(), |
|
pred@2009
|
62 |
NULL); |
|
pred@2009
|
63 |
} |
|
pred@2009
|
64 |
|
|
pred@2009
|
65 |
cell_t FindClientPrefCookie(IPluginContext *pContext, const cell_t *params) |
|
pred@2009
|
66 |
{ |
|
kyle@3804
|
67 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
68 |
|
|
pred@2009
|
69 |
char *name; |
|
pred@2009
|
70 |
pContext->LocalToString(params[1], &name); |
|
pred@2009
|
71 |
|
|
pred@2009
|
72 |
Cookie *pCookie = g_CookieManager.FindCookie(name); |
|
pred@2009
|
73 |
|
|
pred@2009
|
74 |
if (!pCookie) |
|
pred@2009
|
75 |
{ |
|
pred@2009
|
76 |
return BAD_HANDLE; |
|
pred@2009
|
77 |
} |
|
pred@2009
|
78 |
|
|
pred@2009
|
79 |
return handlesys->CreateHandle(g_CookieType, |
|
pred@2009
|
80 |
pCookie, |
|
pred@2009
|
81 |
pContext->GetIdentity(), |
|
pred@2009
|
82 |
myself->GetIdentity(), |
|
pred@2009
|
83 |
NULL); |
|
pred@2009
|
84 |
} |
|
pred@2009
|
85 |
|
|
datal30mb@3411
|
86 |
cell_t SetAuthIdCookie(IPluginContext *pContext, const cell_t *params) |
|
datal30mb@3411
|
87 |
{ |
|
kyle@3804
|
88 |
g_ClientPrefs.AttemptReconnection(); |
|
datal30mb@3411
|
89 |
|
|
datal30mb@3411
|
90 |
char *steamID; |
|
datal30mb@3411
|
91 |
pContext->LocalToString(params[1], &steamID); |
|
datal30mb@3411
|
92 |
|
|
datal30mb@3411
|
93 |
// convert cookie handle to Cookie* |
|
datal30mb@3411
|
94 |
Handle_t hndl = static_cast<Handle_t>(params[2]); |
|
datal30mb@3411
|
95 |
HandleError err; |
|
datal30mb@3411
|
96 |
HandleSecurity sec; |
|
datal30mb@3411
|
97 |
|
|
datal30mb@3411
|
98 |
sec.pOwner = NULL; |
|
datal30mb@3411
|
99 |
sec.pIdentity = myself->GetIdentity(); |
|
datal30mb@3411
|
100 |
|
|
datal30mb@3411
|
101 |
Cookie *pCookie; |
|
datal30mb@3411
|
102 |
|
|
datal30mb@3411
|
103 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
datal30mb@3411
|
104 |
!= HandleError_None) |
|
datal30mb@3411
|
105 |
{ |
|
datal30mb@3411
|
106 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
datal30mb@3411
|
107 |
} |
|
datal30mb@3411
|
108 |
|
|
datal30mb@3411
|
109 |
int i_dbId = pCookie->dbid; |
|
datal30mb@3411
|
110 |
char *value; |
|
datal30mb@3411
|
111 |
pContext->LocalToString(params[3], &value); |
|
datal30mb@3411
|
112 |
|
|
datal30mb@3411
|
113 |
// make sure the steamID isn't currently connected |
|
datal30mb@3411
|
114 |
if (int client = IsAuthIdConnected(steamID)) |
|
datal30mb@3411
|
115 |
{ |
|
datal30mb@3411
|
116 |
// use regular code for connected players |
|
datal30mb@3411
|
117 |
return g_CookieManager.SetCookieValue(pCookie, client, value); |
|
datal30mb@3411
|
118 |
} |
|
datal30mb@3411
|
119 |
|
|
datal30mb@3411
|
120 |
// constructor calls strncpy for us |
|
datal30mb@3411
|
121 |
CookieData *payload = new CookieData(value); |
|
datal30mb@3411
|
122 |
|
|
datal30mb@3411
|
123 |
// set changed so players connecting later in during the same map will have the correct value |
|
datal30mb@3411
|
124 |
payload->changed = true; |
|
datal30mb@3411
|
125 |
payload->timestamp = time(NULL); |
|
datal30mb@3411
|
126 |
|
|
datal30mb@3411
|
127 |
// edit database table |
|
datal30mb@3411
|
128 |
TQueryOp *op = new TQueryOp(Query_InsertData, pCookie); |
|
datal30mb@3411
|
129 |
// limit player auth length which doubles for cookie name length |
|
kyle@3804
|
130 |
UTIL_strncpy(op->m_params.steamId, steamID, MAX_NAME_LENGTH); |
|
datal30mb@3411
|
131 |
op->m_params.cookieId = i_dbId; |
|
datal30mb@3411
|
132 |
op->m_params.data = payload; |
|
datal30mb@3411
|
133 |
|
|
datal30mb@3411
|
134 |
g_ClientPrefs.AddQueryToQueue(op); |
|
datal30mb@3411
|
135 |
|
|
datal30mb@3411
|
136 |
return 1; |
|
datal30mb@3411
|
137 |
} |
|
datal30mb@3411
|
138 |
|
|
pred@2009
|
139 |
cell_t SetClientPrefCookie(IPluginContext *pContext, const cell_t *params) |
|
pred@2009
|
140 |
{ |
|
kyle@3804
|
141 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
142 |
|
|
pred@2009
|
143 |
int client = params[1]; |
|
pred@2009
|
144 |
|
|
pred@2009
|
145 |
if ((client < 1) || (client > playerhelpers->GetMaxClients())) |
|
pred@2009
|
146 |
{ |
|
pred@2009
|
147 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
pred@2009
|
148 |
} |
|
pred@2009
|
149 |
|
|
pred@2009
|
150 |
Handle_t hndl = static_cast<Handle_t>(params[2]); |
|
pred@2009
|
151 |
HandleError err; |
|
pred@2009
|
152 |
HandleSecurity sec; |
|
pred@2009
|
153 |
|
|
pred@2009
|
154 |
sec.pOwner = NULL; |
|
pred@2009
|
155 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2009
|
156 |
|
|
pred@2009
|
157 |
Cookie *pCookie; |
|
pred@2009
|
158 |
|
|
pred@2009
|
159 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
pred@2009
|
160 |
!= HandleError_None) |
|
pred@2009
|
161 |
{ |
|
pred@2009
|
162 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
pred@2009
|
163 |
} |
|
pred@2009
|
164 |
|
|
pred@2009
|
165 |
char *value; |
|
pred@2009
|
166 |
pContext->LocalToString(params[3], &value); |
|
pred@2009
|
167 |
|
|
pred@2009
|
168 |
return g_CookieManager.SetCookieValue(pCookie, client, value); |
|
pred@2009
|
169 |
} |
|
pred@2009
|
170 |
|
|
pred@2009
|
171 |
cell_t GetClientPrefCookie(IPluginContext *pContext, const cell_t *params) |
|
pred@2009
|
172 |
{ |
|
kyle@3804
|
173 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
174 |
|
|
pred@2009
|
175 |
int client = params[1]; |
|
pred@2009
|
176 |
|
|
pred@2009
|
177 |
if ((client < 1) || (client > playerhelpers->GetMaxClients())) |
|
pred@2009
|
178 |
{ |
|
pred@2009
|
179 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
pred@2009
|
180 |
} |
|
pred@2009
|
181 |
|
|
pred@2009
|
182 |
Handle_t hndl = static_cast<Handle_t>(params[2]); |
|
pred@2009
|
183 |
HandleError err; |
|
pred@2009
|
184 |
HandleSecurity sec; |
|
pred@2009
|
185 |
|
|
pred@2009
|
186 |
sec.pOwner = NULL; |
|
pred@2009
|
187 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2009
|
188 |
|
|
pred@2009
|
189 |
Cookie *pCookie; |
|
pred@2009
|
190 |
|
|
pred@2009
|
191 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
pred@2009
|
192 |
!= HandleError_None) |
|
pred@2009
|
193 |
{ |
|
pred@2009
|
194 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
pred@2009
|
195 |
} |
|
pred@2009
|
196 |
|
|
pred@2009
|
197 |
char *value = NULL; |
|
pred@2009
|
198 |
|
|
pred@2009
|
199 |
g_CookieManager.GetCookieValue(pCookie, client, &value); |
|
pred@2009
|
200 |
|
|
pred@2009
|
201 |
pContext->StringToLocal(params[3], params[4], value); |
|
pred@2009
|
202 |
|
|
pred@2009
|
203 |
return 1; |
|
pred@2009
|
204 |
} |
|
pred@2009
|
205 |
|
|
pred@2009
|
206 |
cell_t AreClientCookiesCached(IPluginContext *pContext, const cell_t *params) |
|
pred@2009
|
207 |
{ |
|
kyle@3804
|
208 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
209 |
|
|
pred@2009
|
210 |
int client = params[1]; |
|
pred@2009
|
211 |
|
|
pred@2009
|
212 |
if ((client < 1) || (client > playerhelpers->GetMaxClients())) |
|
pred@2009
|
213 |
{ |
|
pred@2009
|
214 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
pred@2009
|
215 |
} |
|
pred@2009
|
216 |
|
|
pred@2009
|
217 |
return g_CookieManager.AreClientCookiesCached(client); |
|
pred@2009
|
218 |
} |
|
pred@2009
|
219 |
|
|
pred@2048
|
220 |
cell_t GetCookieAccess(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
221 |
{ |
|
kyle@3804
|
222 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
223 |
|
|
pred@2048
|
224 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
pred@2048
|
225 |
HandleError err; |
|
pred@2048
|
226 |
HandleSecurity sec; |
|
pred@2048
|
227 |
|
|
pred@2048
|
228 |
sec.pOwner = NULL; |
|
pred@2048
|
229 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2048
|
230 |
|
|
pred@2048
|
231 |
Cookie *pCookie; |
|
pred@2048
|
232 |
|
|
pred@2048
|
233 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
pred@2048
|
234 |
!= HandleError_None) |
|
pred@2048
|
235 |
{ |
|
pred@2048
|
236 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
pred@2048
|
237 |
} |
|
pred@2048
|
238 |
|
|
pred@2048
|
239 |
return pCookie->access; |
|
pred@2048
|
240 |
} |
|
pred@2048
|
241 |
|
|
pred@2048
|
242 |
static cell_t GetCookieIterator(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
243 |
{ |
|
kyle@3804
|
244 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
245 |
|
|
pred@2048
|
246 |
SourceHook::List<Cookie *>::iterator *iter = new SourceHook::List<Cookie *>::iterator; |
|
pred@2048
|
247 |
*iter = g_CookieManager.cookieList.begin(); |
|
pred@2048
|
248 |
|
|
pred@2048
|
249 |
Handle_t hndl = handlesys->CreateHandle(g_CookieIterator, iter, pContext->GetIdentity(), myself->GetIdentity(), NULL); |
|
pred@2048
|
250 |
if (hndl == BAD_HANDLE) |
|
pred@2048
|
251 |
{ |
|
pred@2048
|
252 |
delete iter; |
|
pred@2048
|
253 |
} |
|
pred@2048
|
254 |
|
|
pred@2048
|
255 |
return hndl; |
|
pred@2048
|
256 |
} |
|
pred@2048
|
257 |
|
|
pred@2048
|
258 |
static cell_t ReadCookieIterator(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
259 |
{ |
|
kyle@3804
|
260 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
261 |
|
|
pred@2048
|
262 |
SourceHook::List<Cookie *>::iterator *iter; |
|
pred@2048
|
263 |
|
|
pred@2048
|
264 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
pred@2048
|
265 |
HandleError err; |
|
pred@2048
|
266 |
HandleSecurity sec; |
|
pred@2048
|
267 |
|
|
pred@2048
|
268 |
sec.pOwner = NULL; |
|
pred@2048
|
269 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2048
|
270 |
|
|
pred@2048
|
271 |
if ((err = handlesys->ReadHandle(hndl, g_CookieIterator, &sec, (void **)&iter)) |
|
pred@2048
|
272 |
!= HandleError_None) |
|
pred@2048
|
273 |
{ |
|
pred@2048
|
274 |
return pContext->ThrowNativeError("Invalid Cookie iterator handle %x (error %d)", hndl, err); |
|
pred@2048
|
275 |
} |
|
pred@2048
|
276 |
|
|
pred@2048
|
277 |
if (*iter == g_CookieManager.cookieList.end()) |
|
pred@2048
|
278 |
{ |
|
pred@2048
|
279 |
return 0; |
|
pred@2048
|
280 |
} |
|
pred@2048
|
281 |
|
|
pred@2048
|
282 |
Cookie *pCookie = (Cookie *)**iter; |
|
pred@2048
|
283 |
|
|
pred@2048
|
284 |
(*iter)++; |
|
pred@2048
|
285 |
|
|
pred@2048
|
286 |
pContext->StringToLocalUTF8(params[2], params[3], pCookie->name, NULL); |
|
pred@2048
|
287 |
pContext->StringToLocalUTF8(params[5], params[6], pCookie->description, NULL); |
|
pred@2048
|
288 |
|
|
pred@2048
|
289 |
cell_t *addr; |
|
pred@2048
|
290 |
pContext->LocalToPhysAddr(params[4], &addr); |
|
pred@2048
|
291 |
*addr = pCookie->access; |
|
pred@2048
|
292 |
|
|
pred@2048
|
293 |
return 1; |
|
pred@2048
|
294 |
} |
|
pred@2048
|
295 |
|
|
pred@2048
|
296 |
cell_t ShowSettingsMenu(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
297 |
{ |
|
kyle@3804
|
298 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
299 |
|
|
pred@2048
|
300 |
char message[256]; |
|
pred@2048
|
301 |
Translate(message, sizeof(message), "%T:", 2, NULL, "Client Settings", ¶ms[1]); |
|
pred@2048
|
302 |
|
|
pred@2048
|
303 |
g_CookieManager.clientMenu->SetDefaultTitle(message); |
|
pred@2048
|
304 |
g_CookieManager.clientMenu->Display(params[1], 0, NULL); |
|
pred@2048
|
305 |
|
|
pred@2048
|
306 |
return 0; |
|
pred@2048
|
307 |
} |
|
pred@2048
|
308 |
|
|
pred@2048
|
309 |
cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
310 |
{ |
|
kyle@3804
|
311 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
312 |
|
|
pred@2048
|
313 |
char *display; |
|
pred@2048
|
314 |
pContext->LocalToString(params[3], &display); |
|
pred@2048
|
315 |
|
|
pred@2048
|
316 |
/* Register a callback */ |
|
pred@2048
|
317 |
ItemHandler *pItem = new ItemHandler; |
|
pred@2048
|
318 |
pItem->isAutoMenu = false; |
|
pred@2048
|
319 |
pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); |
|
pred@2048
|
320 |
|
|
pred@2048
|
321 |
pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[1])); |
|
pred@2048
|
322 |
|
|
pred@2048
|
323 |
char info[20]; |
|
pred@2048
|
324 |
AutoMenuData *data = new AutoMenuData; |
|
pred@2048
|
325 |
data->datavalue = params[2]; |
|
pred@2048
|
326 |
data->handler = pItem; |
|
kyle@3804
|
327 |
g_pSM->Format(info, sizeof(info), "%x", data); |
|
pred@2048
|
328 |
|
|
pred@2048
|
329 |
ItemDrawInfo draw(display, 0); |
|
pred@2048
|
330 |
|
|
pred@2048
|
331 |
g_CookieManager.clientMenu->AppendItem(info, draw); |
|
pred@2048
|
332 |
|
|
pred@2048
|
333 |
/* Track this in case the plugin unloads */ |
|
pred@2048
|
334 |
|
|
pred@2048
|
335 |
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); |
|
pred@2048
|
336 |
SourceHook::List<char *> *pList = NULL; |
|
pred@2048
|
337 |
|
|
pred@2048
|
338 |
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) |
|
pred@2048
|
339 |
{ |
|
pred@2048
|
340 |
pList = new SourceHook::List<char *>; |
|
pred@2048
|
341 |
pPlugin->SetProperty("SettingsMenuItems", pList); |
|
pred@2048
|
342 |
} |
|
pred@2048
|
343 |
|
|
pred@2048
|
344 |
char *copyarray = new char[strlen(display)+1]; |
|
kyle@3804
|
345 |
g_pSM->Format(copyarray, strlen(display)+1, "%s", display); |
|
pred@2048
|
346 |
|
|
pred@2048
|
347 |
pList->push_back(copyarray); |
|
pred@2048
|
348 |
|
|
pred@2048
|
349 |
return 0; |
|
pred@2048
|
350 |
} |
|
pred@2048
|
351 |
|
|
pred@2048
|
352 |
cell_t AddSettingsPrefabMenuItem(IPluginContext *pContext, const cell_t *params) |
|
pred@2048
|
353 |
{ |
|
kyle@3804
|
354 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2207
|
355 |
|
|
pred@2048
|
356 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
pred@2048
|
357 |
HandleError err; |
|
pred@2048
|
358 |
HandleSecurity sec; |
|
pred@2048
|
359 |
|
|
pred@2048
|
360 |
sec.pOwner = NULL; |
|
pred@2048
|
361 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2048
|
362 |
|
|
pred@2048
|
363 |
Cookie *pCookie; |
|
pred@2048
|
364 |
|
|
pred@2048
|
365 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
pred@2048
|
366 |
!= HandleError_None) |
|
pred@2048
|
367 |
{ |
|
pred@2048
|
368 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
pred@2048
|
369 |
} |
|
pred@2048
|
370 |
|
|
pred@2048
|
371 |
/* Register a callback */ |
|
pred@2048
|
372 |
ItemHandler *pItem = new ItemHandler; |
|
pred@2048
|
373 |
pItem->isAutoMenu = true; |
|
pred@2048
|
374 |
pItem->autoMenuType = (CookieMenu)params[2]; |
|
pred@2048
|
375 |
|
|
pred@2048
|
376 |
|
|
pred@2048
|
377 |
/* User passed a function id for a callback */ |
|
pred@2048
|
378 |
if (params[4] != -1) |
|
pred@2048
|
379 |
{ |
|
pred@2048
|
380 |
pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); |
|
pred@2048
|
381 |
pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[4])); |
|
pred@2048
|
382 |
} |
|
pred@2048
|
383 |
else |
|
pred@2048
|
384 |
{ |
|
pred@2048
|
385 |
pItem->forward = NULL; |
|
pred@2048
|
386 |
} |
|
pred@2048
|
387 |
|
|
pred@2048
|
388 |
char *display; |
|
pred@2048
|
389 |
pContext->LocalToString(params[3], &display); |
|
pred@2048
|
390 |
|
|
pred@2048
|
391 |
ItemDrawInfo draw(display, 0); |
|
pred@2048
|
392 |
|
|
pred@2048
|
393 |
char info[20]; |
|
pred@2048
|
394 |
AutoMenuData *data = new AutoMenuData; |
|
pred@2048
|
395 |
data->datavalue = params[5]; |
|
pred@2048
|
396 |
data->pCookie = pCookie; |
|
pred@2048
|
397 |
data->type = (CookieMenu)params[2]; |
|
pred@2048
|
398 |
data->handler = pItem; |
|
kyle@3804
|
399 |
g_pSM->Format(info, sizeof(info), "%x", data); |
|
pred@2048
|
400 |
|
|
pred@2048
|
401 |
g_CookieManager.clientMenu->AppendItem(info, draw); |
|
pred@2048
|
402 |
|
|
pred@2048
|
403 |
/* Track this in case the plugin unloads */ |
|
pred@2048
|
404 |
|
|
pred@2048
|
405 |
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); |
|
pred@2048
|
406 |
SourceHook::List<char *> *pList = NULL; |
|
pred@2048
|
407 |
|
|
pred@2048
|
408 |
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) |
|
pred@2048
|
409 |
{ |
|
pred@2048
|
410 |
pList = new SourceHook::List<char *>; |
|
pred@2048
|
411 |
pPlugin->SetProperty("SettingsMenuItems", pList); |
|
pred@2048
|
412 |
} |
|
pred@2048
|
413 |
|
|
pred@2048
|
414 |
char *copyarray = new char[strlen(display)+1]; |
|
kyle@3804
|
415 |
g_pSM->Format(copyarray, strlen(display)+1, "%s", display); |
|
pred@2048
|
416 |
|
|
pred@2048
|
417 |
pList->push_back(copyarray); |
|
pred@2048
|
418 |
|
|
pred@2048
|
419 |
return 0; |
|
pred@2048
|
420 |
} |
|
pred@2048
|
421 |
|
|
pred@2668
|
422 |
cell_t GetClientCookieTime(IPluginContext *pContext, const cell_t *params) |
|
pred@2668
|
423 |
{ |
|
kyle@3804
|
424 |
g_ClientPrefs.AttemptReconnection(); |
|
pred@2668
|
425 |
|
|
pred@2668
|
426 |
Handle_t hndl = static_cast<Handle_t>(params[2]); |
|
pred@2668
|
427 |
HandleError err; |
|
pred@2668
|
428 |
HandleSecurity sec; |
|
pred@2668
|
429 |
|
|
pred@2668
|
430 |
sec.pOwner = NULL; |
|
pred@2668
|
431 |
sec.pIdentity = myself->GetIdentity(); |
|
pred@2668
|
432 |
|
|
pred@2668
|
433 |
Cookie *pCookie; |
|
pred@2668
|
434 |
|
|
pred@2668
|
435 |
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie)) |
|
pred@2668
|
436 |
!= HandleError_None) |
|
pred@2668
|
437 |
{ |
|
pred@2668
|
438 |
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err); |
|
pred@2668
|
439 |
} |
|
pred@2668
|
440 |
|
|
pred@2668
|
441 |
time_t value; |
|
pred@2668
|
442 |
|
|
pred@2668
|
443 |
if (!g_CookieManager.GetCookieTime(pCookie, params[1], &value)) |
|
pred@2668
|
444 |
{ |
|
pred@2668
|
445 |
return 0; |
|
pred@2668
|
446 |
} |
|
pred@2668
|
447 |
|
|
pred@2668
|
448 |
return value; |
|
pred@2668
|
449 |
} |
|
pred@2668
|
450 |
|
|
pred@2009
|
451 |
sp_nativeinfo_t g_ClientPrefNatives[] = |
|
pred@2009
|
452 |
{ |
|
pred@2048
|
453 |
{"RegClientCookie", RegClientPrefCookie}, |
|
pred@2048
|
454 |
{"FindClientCookie", FindClientPrefCookie}, |
|
pred@2048
|
455 |
{"SetClientCookie", SetClientPrefCookie}, |
|
datal30mb@3411
|
456 |
{"SetAuthIdCookie", SetAuthIdCookie}, |
|
pred@2048
|
457 |
{"GetClientCookie", GetClientPrefCookie}, |
|
pred@2009
|
458 |
{"AreClientCookiesCached", AreClientCookiesCached}, |
|
pred@2048
|
459 |
{"GetCookieAccess", GetCookieAccess}, |
|
pred@2048
|
460 |
{"ReadCookieIterator", ReadCookieIterator}, |
|
pred@2048
|
461 |
{"GetCookieIterator", GetCookieIterator}, |
|
pred@2048
|
462 |
{"ShowCookieMenu", ShowSettingsMenu}, |
|
pred@2048
|
463 |
{"SetCookieMenuItem", AddSettingsMenuItem}, |
|
pred@2048
|
464 |
{"SetCookiePrefabMenu", AddSettingsPrefabMenuItem}, |
|
dvander@2915
|
465 |
{"GetClientCookieTime", GetClientCookieTime}, |
|
pred@2009
|
466 |
{NULL, NULL} |
|
pred@2009
|
467 |
}; |