Replace SourceHook list usages in clientprefs with AMTL.

This commit is contained in:
Kyle Sanderson 2014-06-04 21:49:48 -07:00
parent c37dbe131e
commit 695fc802a9
5 changed files with 40 additions and 46 deletions

View File

@ -59,8 +59,8 @@ void CookieManager::Unload()
}
/* Find all cookies and delete them */
for (SourceHook::List<Cookie *>::iterator _iter = cookieList.begin(); _iter != cookieList.end(); _iter++)
delete (*_iter);
for (size_t iter = 0; iter < cookieList.length(); ++iter)
delete cookieList[iter];
cookieList.clear();
}
@ -95,7 +95,7 @@ Cookie *CookieManager::CreateCookie(const char *name, const char *description, C
op->m_params.cookie = pCookie;
cookieFinder.insert(name, pCookie);
cookieList.push_back(pCookie);
cookieList.append(pCookie);
g_ClientPrefs.AddQueryToQueue(op);
@ -111,7 +111,7 @@ bool CookieManager::GetCookieValue(Cookie *pCookie, int client, char **value)
{
data = new CookieData("");
data->parent = pCookie;
clientData[client].push_back(data);
clientData[client].append(data);
pCookie->data[client] = data;
data->changed = false;
data->timestamp = 0;
@ -130,7 +130,7 @@ bool CookieManager::SetCookieValue(Cookie *pCookie, int client, const char *valu
{
data = new CookieData(value);
data->parent = pCookie;
clientData[client].push_back(data);
clientData[client].append(data);
pCookie->data[client] = data;
}
else
@ -185,10 +185,10 @@ void CookieManager::OnClientDisconnecting(int client)
g_ClientPrefs.ClearQueryCache(player->GetSerial());
}
for (SourceHook::List<CookieData *>::iterator _iter = clientData[client].begin();\
_iter != clientData[client].end(); _iter++)
ke::Vector<CookieData *> &clientvec = clientData[client];
for (size_t iter = 0; iter < clientvec.length(); ++iter)
{
current = (CookieData *)*_iter;
current = clientvec[iter];
dbId = current->parent->dbid;
if (player == NULL || pAuth == NULL || !current->changed || dbId == -1)
@ -209,7 +209,7 @@ void CookieManager::OnClientDisconnecting(int client)
current->parent->data[client] = NULL;
}
clientData[client].clear();
clientvec.clear();
}
void CookieManager::ClientConnectCallback(int serial, IQuery *data)
@ -263,7 +263,7 @@ void CookieManager::ClientConnectCallback(int serial, IQuery *data)
pData->parent = parent;
parent->data[client] = pData;
clientData[client].push_back(pData);
clientData[client].append(pData);
}
statsLoaded[client] = true;
@ -317,19 +317,20 @@ bool CookieManager::AreClientCookiesPending(int client)
void CookieManager::OnPluginDestroyed(IPlugin *plugin)
{
SourceHook::List<char *> *pList;
ke::Vector<char *> *pList;
if (plugin->GetProperty("SettingsMenuItems", (void **)&pList, true))
{
ke::Vector<char *> &menuitems = (*pList);
char *name;
ItemDrawInfo draw;
const char *info;
AutoMenuData * data;
unsigned itemcount;
for (SourceHook::List<char *>::iterator p_iter = pList->begin(); p_iter != pList->end(); p_iter++)
for (size_t p_iter = 0; p_iter < menuitems.length(); ++p_iter)
{
name = (char *)*p_iter;
name = menuitems[p_iter];
itemcount = clientMenu->GetItemCount();
//remove from this plugins list
for (unsigned int i=0; i < itemcount; i++)
@ -360,7 +361,7 @@ void CookieManager::OnPluginDestroyed(IPlugin *plugin)
delete [] name;
}
pList->clear();
menuitems.clear();
}
}

View File

@ -33,7 +33,7 @@
#define _INCLUDE_SOURCEMOD_CLIENTPREFS_COOKIE_H_
#include "extension.h"
#include "sh_list.h"
#include "am-vector.h"
#include <sm_namehashset.h>
#define MAX_NAME_LENGTH 30
@ -128,12 +128,12 @@ public:
public:
IForward *cookieDataLoadedForward;
SourceHook::List<Cookie *> cookieList;
ke::Vector<Cookie *> cookieList;
IBaseMenu *clientMenu;
private:
NameHashSet<Cookie *> cookieFinder;
SourceHook::List<CookieData *> clientData[SM_MAXPLAYERS+1];
ke::Vector<CookieData *> clientData[SM_MAXPLAYERS+1];
bool connected[SM_MAXPLAYERS+1];
bool statsLoaded[SM_MAXPLAYERS+1];

View File

@ -319,7 +319,7 @@ bool ClientPrefs::AddQueryToQueue(TQueryOp *query)
AutoLock lock(&queryLock);
if (!Database)
{
cachedQueries.push_back(query);
cachedQueries.append(query);
return false;
}
@ -339,10 +339,9 @@ void ClientPrefs::ProcessQueryCache()
if (!Database)
return;
TQueryOp *op;
for (SourceHook::List<TQueryOp *>::iterator iter = cachedQueries.begin(); iter != cachedQueries.end(); iter++)
for (size_t iter = 0; iter < cachedQueries.length(); ++iter)
{
op = *iter;
TQueryOp *op = cachedQueries[iter];
op->SetDatabase(Database);
dbi->AddToThreadQueue(op, PrioQueue_Normal);
}
@ -402,18 +401,14 @@ void ClientPrefs::CatchLateLoadClients()
void ClientPrefs::ClearQueryCache(int serial)
{
AutoLock lock(&queryLock);
for (SourceHook::List<TQueryOp *>::iterator iter = cachedQueries.begin(); iter != cachedQueries.end();)
for (size_t iter = 0; iter < cachedQueries.length(); ++iter)
{
TQueryOp *op = *iter;
TQueryOp *op = cachedQueries[iter];
if (op && op->PullQueryType() == Query_SelectData && op->PullQuerySerial() == serial)
{
op->Destroy();
iter = cachedQueries.erase(iter);
}
else
{
iter++;
}
cachedQueries.remove(iter--);
}
}
}

View File

@ -35,7 +35,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include "smsdk_ext.h"
#include "sh_list.h"
#include "am-vector.h"
#include <am-thread-utils.h>
#include <am-refcounting.h>
@ -158,7 +158,7 @@ public:
bool databaseLoading;
private:
SourceHook::List<TQueryOp *> cachedQueries;
ke::Vector<TQueryOp *> cachedQueries;
ke::Mutex queryLock;
IdentityToken_t *identity;
};
@ -177,7 +177,7 @@ class CookieIteratorHandler : public IHandleTypeDispatch
public:
void OnHandleDestroy(HandleType_t type, void *object)
{
delete (SourceHook::List<Cookie *>::iterator *)object;
delete (size_t *)object;
}
};

View File

@ -243,8 +243,8 @@ static cell_t GetCookieIterator(IPluginContext *pContext, const cell_t *params)
{
g_ClientPrefs.AttemptReconnection();
SourceHook::List<Cookie *>::iterator *iter = new SourceHook::List<Cookie *>::iterator;
*iter = g_CookieManager.cookieList.begin();
size_t *iter = new size_t;
*iter = 0;
Handle_t hndl = handlesys->CreateHandle(g_CookieIterator, iter, pContext->GetIdentity(), myself->GetIdentity(), NULL);
if (hndl == BAD_HANDLE)
@ -259,7 +259,7 @@ static cell_t ReadCookieIterator(IPluginContext *pContext, const cell_t *params)
{
g_ClientPrefs.AttemptReconnection();
SourceHook::List<Cookie *>::iterator *iter;
size_t *iter;
Handle_t hndl = static_cast<Handle_t>(params[1]);
HandleError err;
@ -274,14 +274,12 @@ static cell_t ReadCookieIterator(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid Cookie iterator handle %x (error %d)", hndl, err);
}
if (*iter == g_CookieManager.cookieList.end())
if (*iter >= g_CookieManager.cookieList.length())
{
return 0;
}
Cookie *pCookie = (Cookie *)**iter;
(*iter)++;
Cookie *pCookie = g_CookieManager.cookieList[(*iter)++];
pContext->StringToLocalUTF8(params[2], params[3], pCookie->name, NULL);
pContext->StringToLocalUTF8(params[5], params[6], pCookie->description, NULL);
@ -333,18 +331,18 @@ cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params)
/* Track this in case the plugin unloads */
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext());
SourceHook::List<char *> *pList = NULL;
ke::Vector<char *> *pList = NULL;
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList)
{
pList = new SourceHook::List<char *>;
pList = new ke::Vector<char *>;
pPlugin->SetProperty("SettingsMenuItems", pList);
}
char *copyarray = new char[strlen(display)+1];
g_pSM->Format(copyarray, strlen(display)+1, "%s", display);
pList->push_back(copyarray);
pList->append(copyarray);
return 0;
}
@ -403,18 +401,18 @@ cell_t AddSettingsPrefabMenuItem(IPluginContext *pContext, const cell_t *params)
/* Track this in case the plugin unloads */
IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext());
SourceHook::List<char *> *pList = NULL;
ke::Vector<char *> *pList = NULL;
if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList)
{
pList = new SourceHook::List<char *>;
pList = new ke::Vector<char *>;
pPlugin->SetProperty("SettingsMenuItems", pList);
}
char *copyarray = new char[strlen(display)+1];
g_pSM->Format(copyarray, strlen(display)+1, "%s", display);
pList->push_back(copyarray);
pList->append(copyarray);
return 0;
}