-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require geofence files to be specified in Discord server config inste…
…ad of loading implicitly (#105) * Require Geofence files to be explicitly listed in each Discord server (under new "geofences" property, similar to alarms) instead of loading all files implicitly * Add method to retrieve all geofences for a particular server (for another contributor's PR later) * Add missing lock-blocks for access to _geofences cache * Make a couple example geofence files use a json extension to show off GeoJSON support * Allow alarms to specify geofence files that are not specified for any servers * To ensure only one instance of the WhConfig class is alive anywhere, use an object holder to keep track of that instance and allow it to be swapped out when the config is reloaded * Store geofences on DiscordServerConfig class and use them for area-accepting commands when EnableCities is false * Probably should just use lock() here * Fix a merge issue * Update SubscriptionManager.cs * Update Bot.cs Co-authored-by: versx <[email protected]> Co-authored-by: versx <[email protected]>
- Loading branch information
1 parent
4e129c2
commit c1047c6
Showing
14 changed files
with
443 additions
and
230 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
|
||
namespace WhMgr.Configuration | ||
{ | ||
/// <summary> | ||
/// This class holds a singleton instance of WhConfig which can be swapped out (e.g. after a config reload) without everybody | ||
/// needing to update their references to the config itself. | ||
/// </summary> | ||
public class WhConfigHolder | ||
{ | ||
private readonly object _instanceMutex = new object(); | ||
|
||
private WhConfig _instance; | ||
|
||
public WhConfigHolder(WhConfig instance) | ||
{ | ||
_instance = instance; | ||
} | ||
|
||
/// <summary> | ||
/// Fired after the config instance was swapped for a new one | ||
/// </summary> | ||
public event Action Reloaded; | ||
|
||
/// <summary> | ||
/// Provides thread-safe access to the internal WhConfig instance | ||
/// </summary> | ||
public WhConfig Instance | ||
{ | ||
get | ||
{ | ||
WhConfig value; | ||
|
||
lock (_instanceMutex) | ||
value = _instance; | ||
|
||
return value; | ||
} | ||
set | ||
{ | ||
lock (_instanceMutex) | ||
_instance = value; | ||
|
||
Reloaded?.Invoke(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.