Merge: this'll teach me to not pull first
This commit is contained in:
commit
81e30e75c4
@ -145,10 +145,7 @@ Cookie *CookieManager::CreateCookie(const char *name, const char *description, C
|
||||
|
||||
bool CookieManager::GetCookieValue(Cookie *pCookie, int client, char **value)
|
||||
{
|
||||
if (pCookie == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
assert(pCookie);
|
||||
|
||||
CookieData *data = pCookie->data[client];
|
||||
|
||||
@ -160,6 +157,7 @@ bool CookieManager::GetCookieValue(Cookie *pCookie, int client, char **value)
|
||||
clientData[client].push_back(data);
|
||||
pCookie->data[client] = data;
|
||||
data->changed = true;
|
||||
data->timestamp = time(NULL);
|
||||
}
|
||||
|
||||
*value = &data->value[0];
|
||||
@ -169,10 +167,7 @@ bool CookieManager::GetCookieValue(Cookie *pCookie, int client, char **value)
|
||||
|
||||
bool CookieManager::SetCookieValue(Cookie *pCookie, int client, char *value)
|
||||
{
|
||||
if (pCookie == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
assert(pCookie);
|
||||
|
||||
CookieData *data = pCookie->data[client];
|
||||
|
||||
@ -190,6 +185,7 @@ bool CookieManager::SetCookieValue(Cookie *pCookie, int client, char *value)
|
||||
}
|
||||
|
||||
data->changed = true;
|
||||
data->timestamp = time(NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -302,6 +298,10 @@ void CookieManager::ClientConnectCallback(int serial, IQuery *data)
|
||||
CookieData *pData = new CookieData(value);
|
||||
pData->changed = false;
|
||||
|
||||
unsigned int timestamp = 0;
|
||||
row->GetInt(4, (int *)×tamp);
|
||||
pData->timestamp = timestamp;
|
||||
|
||||
Cookie *parent = FindCookie(name);
|
||||
|
||||
if (parent == NULL)
|
||||
@ -417,3 +417,19 @@ void CookieManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
}
|
||||
}
|
||||
|
||||
bool CookieManager::GetCookieTime(Cookie *pCookie, int client, time_t *value)
|
||||
{
|
||||
assert(pCookie);
|
||||
|
||||
CookieData *data = pCookie->data[client];
|
||||
|
||||
/* Check if a value has been set before */
|
||||
if (data == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = data->timestamp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ struct CookieData
|
||||
|
||||
char value[MAX_VALUE_LENGTH];
|
||||
bool changed;
|
||||
time_t timestamp;
|
||||
Cookie *parent;
|
||||
};
|
||||
|
||||
@ -118,6 +119,7 @@ public:
|
||||
|
||||
bool GetCookieValue(Cookie *pCookie, int client, char **value);
|
||||
bool SetCookieValue(Cookie *pCookie, int client, char *value);
|
||||
bool GetCookieTime(Cookie *pCookie, int client, time_t *value);
|
||||
|
||||
void Unload();
|
||||
|
||||
|
@ -132,6 +132,23 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
phrases->AddPhraseFile("clientprefs.phrases");
|
||||
phrases->AddPhraseFile("common.phrases");
|
||||
|
||||
if (late)
|
||||
{
|
||||
int maxclients = playerhelpers->GetMaxClients();
|
||||
|
||||
for (int i = 1; i <= maxclients; i++)
|
||||
{
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
|
||||
|
||||
if (!pPlayer || !pPlayer->IsAuthorized())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
g_CookieManager.OnClientAuthorized(i, pPlayer->GetAuthString());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,38 @@ cell_t AddSettingsPrefabMenuItem(IPluginContext *pContext, const cell_t *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
cell_t GetClientCookieTime(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
if (g_ClientPrefs.Database == NULL && !g_ClientPrefs.databaseLoading)
|
||||
{
|
||||
return pContext->ThrowNativeError("Clientprefs is disabled due to a failed database connection");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
sp_nativeinfo_t g_ClientPrefNatives[] =
|
||||
{
|
||||
{"RegClientCookie", RegClientPrefCookie},
|
||||
|
@ -200,7 +200,7 @@ bool TQueryOp::BindParamsAndRun()
|
||||
UTIL_Format(query,
|
||||
sizeof(query),
|
||||
"SELECT sm_cookies.name, sm_cookie_cache.value, sm_cookies.description, \
|
||||
sm_cookies.access \
|
||||
sm_cookies.access, sm_cookie_cache.timestamp \
|
||||
FROM sm_cookies \
|
||||
JOIN sm_cookie_cache \
|
||||
ON sm_cookies.id = sm_cookie_cache.cookie_id \
|
||||
@ -214,7 +214,6 @@ bool TQueryOp::BindParamsAndRun()
|
||||
|
||||
case Query_InsertData:
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
char safe_id[128];
|
||||
char safe_val[MAX_VALUE_LENGTH*2 + 1];
|
||||
|
||||
@ -238,9 +237,9 @@ bool TQueryOp::BindParamsAndRun()
|
||||
safe_id,
|
||||
m_params.cookieId,
|
||||
safe_val,
|
||||
(unsigned int)t,
|
||||
(unsigned int)m_params.data->timestamp,
|
||||
safe_val,
|
||||
(unsigned int)t);
|
||||
(unsigned int)m_params.data->timestamp);
|
||||
}
|
||||
else if (g_DriverType == Driver_SQLite)
|
||||
{
|
||||
@ -252,7 +251,7 @@ bool TQueryOp::BindParamsAndRun()
|
||||
safe_id,
|
||||
m_params.cookieId,
|
||||
safe_val,
|
||||
(unsigned int)t);
|
||||
(unsigned int)m_params.data->timestamp);
|
||||
}
|
||||
|
||||
if (!m_database->DoSimpleQuery(query))
|
||||
|
@ -222,6 +222,15 @@ native bool:ReadCookieIterator(Handle:iter,
|
||||
*/
|
||||
native CookieAccess:GetCookieAccess(Handle:cookie);
|
||||
|
||||
/**
|
||||
* Returns the last updated timestamp for a client cookie
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param cookie Cookie handle.
|
||||
* @return Last updated timestamp.
|
||||
*/
|
||||
native GetClientCookieTime(client, Handle:cookie);
|
||||
|
||||
/**
|
||||
* Do not edit below this line!
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <IAdminSystem.h>
|
||||
|
||||
#define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
|
||||
#define SMINTERFACE_PLAYERMANAGER_VERSION 9
|
||||
#define SMINTERFACE_PLAYERMANAGER_VERSION 10
|
||||
|
||||
struct edict_t;
|
||||
class IPlayerInfo;
|
||||
@ -190,6 +190,13 @@ namespace SourceMod
|
||||
* @return Serial number.
|
||||
*/
|
||||
virtual unsigned int GetSerial() =0;
|
||||
|
||||
/**
|
||||
* @brief Return whether the client is authorized.
|
||||
*
|
||||
* @return True if authorized, false otherwise.
|
||||
*/
|
||||
virtual bool IsAuthorized() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user