Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Add ddrop_debug config for outputting debug
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonWizard committed Jan 22, 2019
1 parent 964067f commit 94d9e7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DisconnectDrop/DisconnectDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace DisconnectDrop
name = "DisconnectDrop",
description = "Drops player items on disconnection.",
id = "xyz.wizardlywonders.DisconnectDrop",
version = "1.6.0",
version = "1.6.1",
SmodMajor = 3,
SmodMinor = 2,
SmodRevision = 2
Expand All @@ -32,6 +32,7 @@ public override void Register()
{
// Register config settings
this.AddConfig(new ConfigSetting("ddrop_enable", true, SettingType.BOOL, true, "Whether DisconnectDrop should be enabled on server start."));
this.AddConfig(new ConfigSetting("ddrop_debug", false, SettingType.BOOL, true, "Enables debugging output for DisconnectDrop."));
this.AddConfig(new ConfigSetting("ddrop_inventory_refreshrate", 2, SettingType.NUMERIC, true, "How often player inventories are cached (in seconds)."));

// Register events
Expand Down
19 changes: 17 additions & 2 deletions DisconnectDrop/MiscEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@ class MiscEventHandler : IEventHandlerPlayerJoin, IEventHandlerDisconnect, IEven
{
private readonly DisconnectDrop plugin;

private bool debugging;

private float pTime = 0;
private bool roundOver = true;

public Dictionary<string, List<Item>> inventories = new Dictionary<string, List<Item>>(); // steamId: inventory
public Dictionary<string, Vector> locations = new Dictionary<string, Vector>(); // steamId: position

public MiscEventHandler(DisconnectDrop plugin) => this.plugin = plugin;
public MiscEventHandler(DisconnectDrop plugin)
{
this.plugin = plugin;
this.debugging = this.plugin.GetConfigBool("ddrop_debug");
}

public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
{
if (!this.plugin.GetConfigBool("ddrop_enable")) this.plugin.pluginManager.DisablePlugin(plugin);

// refresh these on round restart
this.inventories = new Dictionary<string, List<Item>>();
this.locations = new Dictionary<string, Vector>();

this.pTime = 0;
this.debugging = this.plugin.GetConfigBool("ddrop_debug");
}

// this is crucial so inventories aren't mass-dropped on server restart
Expand All @@ -53,6 +60,7 @@ public void OnDisconnect(DisconnectEvent ev)
{
if (this.roundOver) return;

this.Debug("Dropping player inventory.");
Thread myThread = new Thread(new ThreadStart(RealDisconnectHandler));
myThread.Start();
}
Expand Down Expand Up @@ -143,5 +151,12 @@ public void OnFixedUpdate(FixedUpdateEvent ev)
}
}
}

private void Debug(string str)
{
if (!this.debugging) return;

this.plugin.Info("DEBUG: " + str);
}
}
}

0 comments on commit 94d9e7f

Please sign in to comment.