-
-
Save nosoop/21ef2df6f871312f46a9e9d7afd88703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum eLeaverData { | |
Leaver_Account = 0, | |
Leaver_Time | |
}; | |
ArrayList g_Leavers; | |
public void OnPluginStart() { | |
g_Leavers = new ArrayList(eLeaverData); // 2d array list with blocksize 2 (size of eLeaverData) | |
} | |
// you may prefer using a "player_disconnect" event callback as this callback fires on map change | |
public void OnClientDisconnect(int client) { | |
int account = GetSteamAccountID(client); | |
// make sure account is available | |
if (account) { | |
// push the information to the end of the list | |
int entry = g_Leavers.Push(account); // implicitly assigned to Leaver_Account (block 0) | |
g_Leavers.Set(entry, GetTime(), Leaver_Time); | |
} | |
} | |
public void OnClientPutInServer(int client) { | |
// TODO get account id and use ArrayList.Find to remove any present matching entries | |
} | |
const int LEAVER_GRACE_PERIOD = 600; | |
/** | |
* There's multiple ways to transfer the entries out; this is one intended to be called at an | |
* interval | |
*/ | |
void TransferLeaverEntries() { | |
// iterate until there are no entries left or we find a disconnect time that hasn't left | |
// our grace period yet | |
while (g_Leavers.Length && g_Leavers.Get(0, Leaver_Time) < GetTime() - LEAVER_GRACE_PERIOD) { | |
// log this incident | |
int account = g_Leavers.Get(0, Leaver_Account); | |
int leaveTime = g_Leavers.Get(0, Leaver_Time); | |
// remove head from queue | |
g_Leavers.Erase(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment