Skip to content

Commit

Permalink
Added delay timer of 5 seconds if multi-connections were established …
Browse files Browse the repository at this point in the history
…with same token given.
  • Loading branch information
Kirollos committed Aug 17, 2019
1 parent e5469ed commit 91837ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Oxide.Ext.Discord/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Discord
{
public static List<DiscordClient> Clients { get; private set; } = new List<DiscordClient>();

public static List<string> PendingTokens = new List<string>();

public static void CreateClient(Plugin plugin, string apiKey)
{
if (plugin == null)
Expand Down
18 changes: 18 additions & 0 deletions Oxide.Ext.Discord/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public void Initialize(Plugin plugin, DiscordSettings settings)
throw new APIKeyException();
}

if(Discord.PendingTokens.Contains(settings.ApiToken))
{
Interface.Oxide.LogError($"Connection with same token in short period.. Connection delayed for plugin {plugin.Name}");
Timer t = new Timer() { AutoReset = false, Interval = 5000f, Enabled = true};
t.Elapsed += (object sender, ElapsedEventArgs e) =>
{
Interface.Oxide.LogError($"Delayed connection for plugin {plugin.Name} is being resumed..");
Initialize(plugin, settings);
};
return;
}

RegisterPlugin(plugin);

Settings = settings;
Expand All @@ -75,6 +87,12 @@ public void Initialize(Plugin plugin, DiscordSettings settings)
_webSocket.Connect(WSSURL);
});
Discord.PendingTokens.Add(settings.ApiToken);
Timer t2 = new Timer() { AutoReset = false, Interval = 5000f, Enabled = true };
t2.Elapsed += (object sender, ElapsedEventArgs e) =>
{
Discord.PendingTokens.Remove(settings.ApiToken);
};
}

public void Disconnect()
Expand Down
2 changes: 1 addition & 1 deletion Oxide.Ext.Discord/Oxide.Ext.Discord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<Version>1.0.1.0</Version>
<Version>1.0.3</Version>
<AssemblyName>Oxide.Ext.Discord</AssemblyName>
<Authors>PsychoTea</Authors>
<Description>An Oxide extension for Discord.</Description>
Expand Down

0 comments on commit 91837ad

Please sign in to comment.