Skip to content

Commit

Permalink
fix: error not being thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Jun 29, 2022
1 parent 4bc5de5 commit f8bcbe7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 184 deletions.
17 changes: 5 additions & 12 deletions Oxide.Ext.GamingApi/GamingApiNats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private GamingApiNats(LoggingInterface logger)
this.Logger.Error("NATS: Error: ");
this.Logger.Error("NATS: Server: " + args.Conn.ConnectedUrl);
this.Logger.Error("NATS: Message: " + args.Error);
this.Logger.Error("NATS: Subject: " + args.Subscription.Subject);
this.Logger.Error("NATS: Subject: " + args.Subscription?.Subject);
};

opts.ServerDiscoveredEventHandler += (sender, args) =>
Expand Down Expand Up @@ -84,10 +84,7 @@ private string GetNatsHost()
Console.WriteLine($"NATS: {envName} environment variable not sat using default value.");
return "nats://localhost:4222";
}
else
{
return value;
}
return value;
}
private string GetNatsNkeyUser()
{
Expand All @@ -98,9 +95,7 @@ private string GetNatsNkeyUser()
Console.WriteLine($"NATS: {envName} environment variable not sat using default value.");
return "UCNCZJYZY7EHLN64DBIEWJVLJGL5T3JFK7OAUXXCH7XJM337LEVFOSCX";
}
else{
return value;
}
return value;
}
private string GetNatsNkeySeed()
{
Expand All @@ -111,10 +106,8 @@ private string GetNatsNkeySeed()
Console.WriteLine($"NATS: {envName} environment variable not sat using default value.");
return "SUACNAC2QZKPXKLKOE3TM3OPZ45P6VGQDVUPBLMFZEMKFPBBVHMLDOKFCQ";
}
else
{
return value;
}
return value;

}
#region Singleton
static ReaderWriterLock rwl = new ReaderWriterLock();
Expand Down
35 changes: 19 additions & 16 deletions Oxide.Ext.GamingApi/Oxide.Ext.GamingApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
<FileVersion>0.10.0.0</FileVersion>
<RepositoryUrl>https://github.com/GamingAPI/umod-rust-server-extension.git</RepositoryUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net461|AnyCPU'">
<WarningLevel>1</WarningLevel>
</PropertyGroup>
<ItemGroup>
<None Remove="NATS.Client"/>
<None Remove="RustGameAPI"/>
<None Remove="NATS.Client" />
<None Remove="RustGameAPI" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Oxide.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dependencies\Oxide.Core.dll</HintPath>
Expand All @@ -31,19 +34,19 @@
<Reference Include="Rust.UI">
<HintPath>..\dependencies\Rust.UI.dll</HintPath>
</Reference>
<PackageReference Include="RustGameAPI" Version="0.*"/>
<PackageReference Include="NATS.Client" Version="0.12.0"/>
<Reference Include="System"/>
<Reference Include="System.Configuration"/>
<Reference Include="System.Configuration.Install"/>
<Reference Include="System.Data"/>
<Reference Include="System.Drawing"/>
<Reference Include="System.Numerics"/>
<Reference Include="System.Runtime.Serialization"/>
<Reference Include="System.Security"/>
<Reference Include="System.Transactions"/>
<Reference Include="System.Xml"/>
<Reference Include="System.Xml.Linq"/>
<PackageReference Include="RustGameAPI" Version="0.*" />
<PackageReference Include="NATS.Client" Version="0.12.0" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Unity.TextMeshPro">
<HintPath>..\dependencies\Unity.TextMeshPro.dll</HintPath>
</Reference>
Expand Down
128 changes: 24 additions & 104 deletions Oxide.Ext.GamingApiTests/GamingApiNatsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NATS.Client;
using Asyncapi.Nats.Client;
using NATS.Client;
using NUnit.Framework;
using System;
using System.Diagnostics;
Expand All @@ -10,61 +11,34 @@ namespace Oxide.Ext.GamingApi.Tests
[TestFixture()]
public class GamingApiNatsTests
{
public static string GetConfigDir()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
var evan = System.Environment.CurrentDirectory;
var configDirPath = Path.Combine(evan, "../../setup");
if (!Directory.Exists(configDirPath))
throw new DirectoryNotFoundException($"The Config dir was not found at: '{configDirPath}'.");

return configDirPath;
}

GamingApiNats blackhawkNats;
GamingApiTestNats blackhawkTestNats;
AutoResetEvent stopWaitHandle = new AutoResetEvent(false);

[SetUp()]
public void setup()
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
blackhawkNats = GamingApiNats.GetInstance();
Trace.AutoFlush = true;
Trace.Indent();
blackhawkTestNats = GamingApiTestNats.getInstance();
Options opts = ConnectionFactory.GetDefaultOptions();
opts.AsyncErrorEventHandler += (sender, args) =>
{
Trace.WriteLine("Error: ");
Trace.WriteLine(" Server: " + args.Conn.ConnectedUrl);
Trace.WriteLine(" Message: " + args.Error);
Trace.WriteLine(" Subject: " + args.Subscription.Subject);
};
Environment.SetEnvironmentVariable("GAMINGAPI_NATS_NKEY_USER", "UCI2NCSIEV3DXLYYR5KQXYCZ7CIW4KYXHLSGXJOZ7TSRRKHP2BM5IVMU");
Environment.SetEnvironmentVariable("GAMINGAPI_NATS_NKEY_SEED", "SUAHZGQCK3PKMY5JBY2PBJUK2SA2IAGNX7VXYQJ75MLIU2IWQE235OBLJM");
blackhawkNats = GamingApiNats.SetInstance();
}

opts.ServerDiscoveredEventHandler += (sender, args) =>
{
Trace.WriteLine("A new server has joined the cluster:");
Trace.WriteLine(" " + String.Join(", ", args.Conn.DiscoveredServers));
};
[TearDown()]
public void teardown()
{
blackhawkNats?.Close();
}

opts.ClosedEventHandler += (sender, args) =>
{
Trace.WriteLine("Connection Closed: ");
Trace.WriteLine(" Server: " + args.Conn.ConnectedUrl);
};
[Test()]
[Ignore("For now")]
public void shouldSetup()
{
NatsClient instance = new NatsClient();
Options opts = ConnectionFactory.GetDefaultOptions();

opts.DisconnectedEventHandler += (sender, args) =>
{
Trace.WriteLine("Connection Disconnected: ");
Trace.WriteLine(" Server: " + args.Conn.ConnectedUrl);
};
opts.Url = "nats://localhost:42222";

var configDirPath = Path.Combine(GetConfigDir(), "user.nk");
opts.Url = "nats://localhost:4222";
EventHandler<UserSignatureEventArgs> sigEh = (sender, args) =>
{
// get a private key seed from your environment.
string seed = "SUACNAC2QZKPXKLKOE3TM3OPZ45P6VGQDVUPBLMFZEMKFPBBVHMLDOKFCQ";
string seed = "SUAHZGQCK3PKMY5JBY2PBJUK2SA2IAGNX7VXYQJ75MLIU2IWQE235OBLJM";

// Generate a NkeyPair
NkeyPair kp = Nkeys.FromSeed(seed);
Expand All @@ -73,70 +47,16 @@ public void setup()
// args property. This must be set.
args.SignedNonce = kp.Sign(args.ServerNonce);
};
opts.SetNkey("UCNCZJYZY7EHLN64DBIEWJVLJGL5T3JFK7OAUXXCH7XJM337LEVFOSCX", sigEh);
blackhawkNats.Connect(opts);
blackhawkTestNats.Connect(opts);
}
[TearDown()]
public void teardown()
{
blackhawkNats.Close();
}
[Test()]
public void SubscribeToRustServersServerIdPlayersSteamIdTitlesAquiredTest()
{
AutoResetEvent stopWaitHandle = new AutoResetEvent(false);
Assert.IsTrue(blackhawkNats.IsConnected());
Assert.IsTrue(blackhawkTestNats.IsConnected());
String gotServerId = string.Empty;
String gotSteamId = string.Empty;
PublishForServerPlayerTitleAcquired gotMessage = new PublishForServerPlayerTitleAcquired();
String serverId = "1234";
String steamId = "test";
var test = new RustServersServerIdPlayersSteamIdTitlesAquiredOnRequest((PublishForServerPlayerTitleAcquired request, string server_id, string steam_id) =>
{
gotServerId = server_id;
gotSteamId = steam_id;
gotMessage = request;
stopWaitHandle.Set();
});
blackhawkNats.SubscribeToRustServersServerIdPlayersSteamIdTitlesAquired(test, "*", "*");
var message = new PublishForServerPlayerTitleAcquired();
message.Description = "description";
message.SteamId = "TEst";
message.Title = "TitleTest";
message.TitleColor = "#21321";
message.TitleId = 21;
blackhawkTestNats.PublishToRustServersServerIdPlayersSteamIdTitlesAquired(message, serverId, steamId);
stopWaitHandle.WaitOne();
Assert.AreEqual(serverId, gotServerId);
Assert.AreEqual(steamId, gotSteamId);
Assert.AreEqual(message.Description, gotMessage.Description);
Assert.AreEqual(message.SteamId, gotMessage.SteamId);
Assert.AreEqual(message.Title, gotMessage.Title);
Assert.AreEqual(message.TitleColor, gotMessage.TitleColor);
Assert.AreEqual(message.TitleId, gotMessage.TitleId);
opts.SetNkey("UCI2NCSIEV3DXLYYR5KQXYCZ7CIW4KYXHLSGXJOZ7TSRRKHP2BM5IVMU", sigEh);
instance.Connect(opts);
}

[Test()]
public void replyToRustApiprocessServersServerIdEventsStartedTest()
{
Assert.IsTrue(blackhawkNats.IsConnected());
Assert.IsTrue(blackhawkTestNats.IsConnected());
String gotServerId = string.Empty;
var messageToReply = new ReplyForServerStarted();
messageToReply.StatusMessage = "Everything ok";
RustApiprocessServersServerIdEventsStartedOnRequest test = new RustApiprocessServersServerIdEventsStartedOnRequest((string server_id) =>
{
gotServerId = server_id;
return messageToReply;
});
blackhawkTestNats.ReplyToRustApiprocessServersServerIdEventsStarted(test, "test");
ReplyForServerStarted reply = blackhawkNats.RequestRustApiprocessServersServerIdEventsStarted("test");
Trace.WriteLine(gotServerId);
Assert.AreEqual("test", gotServerId);
Assert.AreEqual(reply.StatusMessage, messageToReply.StatusMessage);
blackhawkNats.PublishToV0RustServersServerIdEventsStarted("101");
}

}
}
45 changes: 0 additions & 45 deletions Oxide.Ext.GamingApiTests/GamingApiTestNats.cs

This file was deleted.

36 changes: 33 additions & 3 deletions Oxide.Ext.GamingApiTests/Oxide.Ext.GamingApiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Oxide.Ext.GamingApiTests</RootNamespace>
<AssemblyName>Oxide.Ext.GamingApiTests</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down Expand Up @@ -40,6 +40,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NATS.Client, Version=0.14.6.0, Culture=neutral, PublicKeyToken=5b58bc7249e111a9, processorArchitecture=MSIL">
<HintPath>..\packages\NATS.Client.0.14.6\lib\net46\NATS.Client.dll</HintPath>
</Reference>
Expand All @@ -49,13 +53,29 @@
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="RustGameAPI, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RustGameAPI.0.5.0\lib\net461\RustGameAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Specialized, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Specialized.4.3.0\lib\net46\System.Collections.Specialized.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
Expand All @@ -68,6 +88,18 @@
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.5.0.1\lib\net461\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.5.0.2\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
Expand All @@ -79,8 +111,6 @@
</Choose>
<ItemGroup>
<Compile Include="GamingApiNatsTests.cs" />
<Compile Include="GamingApiTestNats.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
Loading

0 comments on commit f8bcbe7

Please sign in to comment.