When I start my test server, OnMapStart is called, and when I join it, OnMapStart is called again. That doesn't sound right to me. I know the map is literally starting up again to set the "mapgroup". I don't know what that is, but I want to stop it. Also this somewhat ties into my SQL problem where the callback isn't being called, it's just frozen until the next time OnMapStart is called, and then the callback is called twice. Here is an example code.
PHP Code:
#include <sourcemod>
new String:g_sMapName[64];
new Handle:g_DB;
public OnPluginStart()
{
DB_Connect();
}
public OnMapStart()
{
GetCurrentMap(g_sMapName, sizeof(g_sMapName));
CreateCurrentMapID();
}
DB_Connect()
{
if(g_DB != INVALID_HANDLE)
CloseHandle(g_DB);
new String:error[255];
g_DB = SQL_Connect("timer", true, error, sizeof(error));
if(g_DB == INVALID_HANDLE)
{
LogError(error);
CloseHandle(g_DB);
}
}
CreateCurrentMapID()
{
decl String:query[512];
FormatEx(query, sizeof(query), "INSERT INTO maps (MapName) SELECT * FROM (SELECT '%s') AS tmp WHERE NOT EXISTS (SELECT MapName FROM maps WHERE MapName = '%s') LIMIT 1",
g_sMapName,
g_sMapName);
SQL_TQuery(g_DB, DB_CreateCurrentMapID_Callback, query);
}
public DB_CreateCurrentMapID_Callback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl != INVALID_HANDLE)
{
if(SQL_GetAffectedRows(hndl) > 0)
{
LogMessage("MapID for %s created (%d)", g_sMapName, SQL_GetInsertId(hndl));
}
}
else
{
LogError(error);
}
}
Here's what's happening step-by-step:
1. I start the server
2. OnMapStart is called, also calling CreateCurrentMapID
3. The SQL in CreateCurrentMapID isn't calling the SQL callback (frozen)
4. I join the server
5. OnMapStart is called, also calling CreateCurrentMapID
6. The SQL callback from before is now unfrozen and the callback is being called twice
How is this fixed?