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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "extension.h"
|
|
|
|
#include "cookie.h"
|
2008-05-12 10:06:47 +02:00
|
|
|
#include "menus.h"
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
cell_t RegClientPrefCookie(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
char *name;
|
|
|
|
pContext->LocalToString(params[1], &name);
|
|
|
|
|
|
|
|
if (name[0] == '\0')
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Cannot create preference cookie with no name");
|
|
|
|
}
|
|
|
|
|
|
|
|
char *desc;
|
|
|
|
pContext->LocalToString(params[2], &desc);
|
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
Cookie *pCookie = g_CookieManager.CreateCookie(name, desc, (CookieAccess)params[3]);
|
2008-04-17 06:58:09 +02:00
|
|
|
|
|
|
|
if (!pCookie)
|
|
|
|
{
|
|
|
|
return BAD_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handlesys->CreateHandle(g_CookieType,
|
|
|
|
pCookie,
|
|
|
|
pContext->GetIdentity(),
|
|
|
|
myself->GetIdentity(),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t FindClientPrefCookie(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
char *name;
|
|
|
|
pContext->LocalToString(params[1], &name);
|
|
|
|
|
|
|
|
Cookie *pCookie = g_CookieManager.FindCookie(name);
|
|
|
|
|
|
|
|
if (!pCookie)
|
|
|
|
{
|
|
|
|
return BAD_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handlesys->CreateHandle(g_CookieType,
|
|
|
|
pCookie,
|
|
|
|
pContext->GetIdentity(),
|
|
|
|
myself->GetIdentity(),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2014-11-15 15:34:49 +01:00
|
|
|
size_t IsAuthIdConnected(char *authID)
|
|
|
|
{
|
|
|
|
IGamePlayer *player;
|
|
|
|
const char *authString;
|
|
|
|
|
|
|
|
for (int playerIndex = playerhelpers->GetMaxClients()+1; --playerIndex > 0;)
|
|
|
|
{
|
|
|
|
player = playerhelpers->GetGamePlayer(playerIndex);
|
|
|
|
if (player == NULL || !player->IsConnected())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
authString = player->GetAuthString();
|
|
|
|
if (authString == NULL || authString[0] == '\0' || strcmp(authString, authID) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
authString = player->GetSteam2Id();
|
|
|
|
if (authString == NULL || authString[0] == '\0' || strcmp(authString, authID) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
authString = player->GetSteam3Id();
|
|
|
|
if (authString == NULL || authString[0] == '\0' || strcmp(authString, authID) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return playerIndex;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-14 17:28:53 +02:00
|
|
|
cell_t SetAuthIdCookie(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2011-10-14 17:28:53 +02:00
|
|
|
|
|
|
|
char *steamID;
|
|
|
|
pContext->LocalToString(params[1], &steamID);
|
|
|
|
|
|
|
|
// convert cookie handle to Cookie*
|
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[2]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i_dbId = pCookie->dbid;
|
|
|
|
char *value;
|
|
|
|
pContext->LocalToString(params[3], &value);
|
|
|
|
|
|
|
|
// make sure the steamID isn't currently connected
|
|
|
|
if (int client = IsAuthIdConnected(steamID))
|
|
|
|
{
|
|
|
|
// use regular code for connected players
|
|
|
|
return g_CookieManager.SetCookieValue(pCookie, client, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor calls strncpy for us
|
|
|
|
CookieData *payload = new CookieData(value);
|
|
|
|
|
|
|
|
// set changed so players connecting later in during the same map will have the correct value
|
|
|
|
payload->changed = true;
|
|
|
|
payload->timestamp = time(NULL);
|
|
|
|
|
|
|
|
// edit database table
|
|
|
|
TQueryOp *op = new TQueryOp(Query_InsertData, pCookie);
|
|
|
|
// limit player auth length which doubles for cookie name length
|
2013-02-28 22:51:49 +01:00
|
|
|
UTIL_strncpy(op->m_params.steamId, steamID, MAX_NAME_LENGTH);
|
2011-10-14 17:28:53 +02:00
|
|
|
op->m_params.cookieId = i_dbId;
|
|
|
|
op->m_params.data = payload;
|
|
|
|
|
|
|
|
g_ClientPrefs.AddQueryToQueue(op);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
cell_t SetClientPrefCookie(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
int client = params[1];
|
|
|
|
|
|
|
|
if ((client < 1) || (client > playerhelpers->GetMaxClients()))
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[2]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *value;
|
|
|
|
pContext->LocalToString(params[3], &value);
|
|
|
|
|
|
|
|
return g_CookieManager.SetCookieValue(pCookie, client, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t GetClientPrefCookie(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
int client = params[1];
|
|
|
|
|
|
|
|
if ((client < 1) || (client > playerhelpers->GetMaxClients()))
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[2]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *value = NULL;
|
|
|
|
|
|
|
|
g_CookieManager.GetCookieValue(pCookie, client, &value);
|
|
|
|
|
|
|
|
pContext->StringToLocal(params[3], params[4], value);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t AreClientCookiesCached(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
int client = params[1];
|
|
|
|
|
|
|
|
if ((client < 1) || (client > playerhelpers->GetMaxClients()))
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_CookieManager.AreClientCookiesCached(client);
|
|
|
|
}
|
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
cell_t GetCookieAccess(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pCookie->access;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cell_t GetCookieIterator(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
size_t *iter = new size_t;
|
|
|
|
*iter = 0;
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
Handle_t hndl = handlesys->CreateHandle(g_CookieIterator, iter, pContext->GetIdentity(), myself->GetIdentity(), NULL);
|
|
|
|
if (hndl == BAD_HANDLE)
|
|
|
|
{
|
|
|
|
delete iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hndl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cell_t ReadCookieIterator(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
size_t *iter;
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieIterator, &sec, (void **)&iter))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie iterator handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
if (*iter >= g_CookieManager.cookieList.length())
|
2008-05-12 10:06:47 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
Cookie *pCookie = g_CookieManager.cookieList[(*iter)++];
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
pContext->StringToLocalUTF8(params[2], params[3], pCookie->name, NULL);
|
|
|
|
pContext->StringToLocalUTF8(params[5], params[6], pCookie->description, NULL);
|
|
|
|
|
|
|
|
cell_t *addr;
|
|
|
|
pContext->LocalToPhysAddr(params[4], &addr);
|
|
|
|
*addr = pCookie->access;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t ShowSettingsMenu(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
char message[256];
|
|
|
|
Translate(message, sizeof(message), "%T:", 2, NULL, "Client Settings", ¶ms[1]);
|
|
|
|
|
|
|
|
g_CookieManager.clientMenu->SetDefaultTitle(message);
|
|
|
|
g_CookieManager.clientMenu->Display(params[1], 0, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
char *display;
|
|
|
|
pContext->LocalToString(params[3], &display);
|
|
|
|
|
|
|
|
/* Register a callback */
|
|
|
|
ItemHandler *pItem = new ItemHandler;
|
|
|
|
pItem->isAutoMenu = false;
|
|
|
|
pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell);
|
|
|
|
|
|
|
|
pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[1]));
|
|
|
|
|
|
|
|
char info[20];
|
|
|
|
AutoMenuData *data = new AutoMenuData;
|
|
|
|
data->datavalue = params[2];
|
|
|
|
data->handler = pItem;
|
2013-02-28 22:51:49 +01:00
|
|
|
g_pSM->Format(info, sizeof(info), "%x", data);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
ItemDrawInfo draw(display, 0);
|
|
|
|
|
|
|
|
g_CookieManager.clientMenu->AppendItem(info, draw);
|
|
|
|
|
|
|
|
/* Track this in case the plugin unloads */
|
|
|
|
|
|
|
|
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext());
|
2014-06-05 06:49:48 +02:00
|
|
|
ke::Vector<char *> *pList = NULL;
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList)
|
|
|
|
{
|
2014-06-05 06:49:48 +02:00
|
|
|
pList = new ke::Vector<char *>;
|
2008-05-12 10:06:47 +02:00
|
|
|
pPlugin->SetProperty("SettingsMenuItems", pList);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *copyarray = new char[strlen(display)+1];
|
2013-02-28 22:51:49 +01:00
|
|
|
g_pSM->Format(copyarray, strlen(display)+1, "%s", display);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
pList->append(copyarray);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t AddSettingsPrefabMenuItem(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2008-07-15 02:24:08 +02:00
|
|
|
|
2008-05-12 10:06:47 +02:00
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register a callback */
|
|
|
|
ItemHandler *pItem = new ItemHandler;
|
|
|
|
pItem->isAutoMenu = true;
|
|
|
|
pItem->autoMenuType = (CookieMenu)params[2];
|
|
|
|
|
|
|
|
|
|
|
|
/* User passed a function id for a callback */
|
|
|
|
if (params[4] != -1)
|
|
|
|
{
|
|
|
|
pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell);
|
|
|
|
pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[4]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pItem->forward = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *display;
|
|
|
|
pContext->LocalToString(params[3], &display);
|
|
|
|
|
|
|
|
ItemDrawInfo draw(display, 0);
|
|
|
|
|
|
|
|
char info[20];
|
|
|
|
AutoMenuData *data = new AutoMenuData;
|
|
|
|
data->datavalue = params[5];
|
|
|
|
data->pCookie = pCookie;
|
|
|
|
data->type = (CookieMenu)params[2];
|
|
|
|
data->handler = pItem;
|
2013-02-28 22:51:49 +01:00
|
|
|
g_pSM->Format(info, sizeof(info), "%x", data);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
g_CookieManager.clientMenu->AppendItem(info, draw);
|
|
|
|
|
|
|
|
/* Track this in case the plugin unloads */
|
|
|
|
|
|
|
|
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext());
|
2014-06-05 06:49:48 +02:00
|
|
|
ke::Vector<char *> *pList = NULL;
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList)
|
|
|
|
{
|
2014-06-05 06:49:48 +02:00
|
|
|
pList = new ke::Vector<char *>;
|
2008-05-12 10:06:47 +02:00
|
|
|
pPlugin->SetProperty("SettingsMenuItems", pList);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *copyarray = new char[strlen(display)+1];
|
2013-02-28 22:51:49 +01:00
|
|
|
g_pSM->Format(copyarray, strlen(display)+1, "%s", display);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
2014-06-05 06:49:48 +02:00
|
|
|
pList->append(copyarray);
|
2008-05-12 10:06:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-17 00:30:21 +01:00
|
|
|
cell_t GetClientCookieTime(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2013-02-28 22:51:49 +01:00
|
|
|
g_ClientPrefs.AttemptReconnection();
|
2009-03-17 00:30:21 +01:00
|
|
|
|
|
|
|
Handle_t hndl = static_cast<Handle_t>(params[2]);
|
|
|
|
HandleError err;
|
|
|
|
HandleSecurity sec;
|
|
|
|
|
|
|
|
sec.pOwner = NULL;
|
|
|
|
sec.pIdentity = myself->GetIdentity();
|
|
|
|
|
|
|
|
Cookie *pCookie;
|
|
|
|
|
|
|
|
if ((err = handlesys->ReadHandle(hndl, g_CookieType, &sec, (void **)&pCookie))
|
|
|
|
!= HandleError_None)
|
|
|
|
{
|
|
|
|
return pContext->ThrowNativeError("Invalid Cookie handle %x (error %d)", hndl, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t value;
|
|
|
|
|
|
|
|
if (!g_CookieManager.GetCookieTime(pCookie, params[1], &value))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2008-04-17 06:58:09 +02:00
|
|
|
sp_nativeinfo_t g_ClientPrefNatives[] =
|
|
|
|
{
|
2008-05-12 10:06:47 +02:00
|
|
|
{"RegClientCookie", RegClientPrefCookie},
|
|
|
|
{"FindClientCookie", FindClientPrefCookie},
|
|
|
|
{"SetClientCookie", SetClientPrefCookie},
|
2011-10-14 17:28:53 +02:00
|
|
|
{"SetAuthIdCookie", SetAuthIdCookie},
|
2008-05-12 10:06:47 +02:00
|
|
|
{"GetClientCookie", GetClientPrefCookie},
|
2008-04-17 06:58:09 +02:00
|
|
|
{"AreClientCookiesCached", AreClientCookiesCached},
|
2008-05-12 10:06:47 +02:00
|
|
|
{"GetCookieAccess", GetCookieAccess},
|
|
|
|
{"ReadCookieIterator", ReadCookieIterator},
|
|
|
|
{"GetCookieIterator", GetCookieIterator},
|
|
|
|
{"ShowCookieMenu", ShowSettingsMenu},
|
|
|
|
{"SetCookieMenuItem", AddSettingsMenuItem},
|
|
|
|
{"SetCookiePrefabMenu", AddSettingsPrefabMenuItem},
|
2010-02-09 04:58:36 +01:00
|
|
|
{"GetClientCookieTime", GetClientCookieTime},
|
2008-04-17 06:58:09 +02:00
|
|
|
{NULL, NULL}
|
|
|
|
};
|