I've spent the better part of the day writing debug logs for a plugin which I eventually plan to add functionality to. But for now, it simply grabs whatever the map, game mode, and server slots are set to when the server first starts up - and when all players disconnect it changes those settings back.
So, to test this manually, all you have to do is connect and disconnect from the server, and it'll write a log file to "logs/RestoreOnEmptyDebug.log".
I have my server startup script set to c1m4_atrium, and the game mode I switch between survival and coop. When it starts on survival, this plugin works fine and resets the map + game mode correctly - but when the game mode is set to coop, after everyone disconnects it sets the map to the first chapter (c1m1_hotel) instead of the 4th (c1m4_atrium).
I was trying to further debug the issue - but it appears the server actually thinks that the map is set correctly, though the server browser clearly says it's on "c1m1_hotel" after I disconnect.
PHP Code:
public void OnMapStart()
{
if (g_bEnforceCorrectMap) // debug tool to try and manually call another map change if it gets set on the wrong map during the first map change..
{
#if DEBUG
LogToFile(sDebugLog, "........................");
LogToFile(sDebugLog, "OnMapStart - 'g_bEnforceCorrectMap' executed.");
#endif
char sCurrentMap[64];
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
if (StrEqual(sCurrentMap, g_sMap))
{
#if DEBUG
LogToFile(sDebugLog, "........................");
LogToFile(sDebugLog, "Current Map [%s] Matches the map originally stored on bootup [%s]. PASS", sCurrentMap, g_sMap);
#endif
g_bEnforceCorrectMap = false;
}
else
{
#if DEBUG
LogToFile(sDebugLog, "........................");
LogToFile(sDebugLog, "Current Map [%s] doesn't match map originally stored on bootup [%s]. Forcing level change..", sCurrentMap, g_sMap);
#endif
ServerCommand("changelevel %s", g_sMap);
//ForceChangeLevel(g_sMap, "Resetting map..");
}
}
// ... some other code
if (g_bGrabGameSettings) // Store map, gamemode, sv_maxslots settings. Only done once during lifetime of plugin.
{
g_bGrabGameSettings = false;
GetCurrentMap(g_sMap, sizeof(g_sMap));
GetConVarString(g_hGameMode, g_sGameMode, sizeof(g_sGameMode));
g_iSlots = GetConVarInt(g_hMaxSlots);
if (g_iSlots == -1) // sv_maxplayers not set in server.cfg
{
g_iSlots = 4;
}
#if DEBUG
LogToFile(sDebugLog, "........................");
LogToFile(sDebugLog, "OnMapStart - storing map, gamemode, and slots on first bootup.");
LogToFile(sDebugLog, "Map detected: %s", g_sMap);
LogToFile(sDebugLog, "Game Mode detected: %s", g_sGameMode);
LogToFile(sDebugLog, "Slots detected: %i", g_iSlots);
#endif
}
}
Debug log:
Code:
L 09/28/2018 - 17:14:25: [plugin.smx] ........................
L 09/28/2018 - 17:14:25: [plugin.smx] Current Map [c1m4_atrium] Matches the map originally stored on bootup [c1m4_atrium]. PASS
L 09/28/2018 - 17:14:25: [plugin.smx] ........................
The code's a mess right now because I've been heavily focused on debugging everything to see where the problem lies. So far all the other debug logs have passed correctly except this one.