Skip to content

Instantly share code, notes, and snippets.

@nosoop
Last active September 12, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosoop/21ef2df6f871312f46a9e9d7afd88703 to your computer and use it in GitHub Desktop.
Save nosoop/21ef2df6f871312f46a9e9d7afd88703 to your computer and use it in GitHub Desktop.
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