major update
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NLog;
|
||||
using Ragon.Client;
|
||||
using Ragon.Protocol;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Ragon.Core.Tests;
|
||||
|
||||
public class Connection
|
||||
{
|
||||
private readonly ITestOutputHelper _testOutputHelper;
|
||||
|
||||
public Connection(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_testOutputHelper = testOutputHelper;
|
||||
}
|
||||
|
||||
public class Game : IRagonListener
|
||||
{
|
||||
private RagonClient _client;
|
||||
|
||||
public Game(RagonClient client, TaskCompletionSource taskCompletionSource)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public void OnConnected(RagonClient client)
|
||||
{
|
||||
Console.WriteLine("Console Connected");
|
||||
RagonLog.Trace("Connected");
|
||||
|
||||
client.Session.AuthorizeWithKey("defaultkey", "Player Eduard", Array.Empty<byte>());
|
||||
}
|
||||
|
||||
public void OnAuthorizationSuccess(RagonClient client, string playerId, string playerName)
|
||||
{
|
||||
RagonLog.Trace("Authorized");
|
||||
|
||||
client.Session.Create("Example", 1, 20);
|
||||
}
|
||||
|
||||
public void OnAuthorizationFailed(RagonClient client, string message)
|
||||
{
|
||||
RagonLog.Trace($"Authorization failed: {message}");
|
||||
}
|
||||
|
||||
public void OnJoined(RagonClient client)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFailed(RagonClient client, string message)
|
||||
{
|
||||
RagonLog.Trace("Failed to join");
|
||||
}
|
||||
|
||||
public void OnLeft(RagonClient client)
|
||||
{
|
||||
RagonLog.Trace("Left");
|
||||
}
|
||||
|
||||
public void OnDisconnected(RagonClient client)
|
||||
{
|
||||
RagonLog.Trace("Disconnected");
|
||||
}
|
||||
|
||||
public void OnPlayerJoined(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Player joined");
|
||||
}
|
||||
|
||||
public void OnPlayerLeft(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Player left");
|
||||
}
|
||||
|
||||
public void OnOwnershipChanged(RagonClient client, RagonPlayer player)
|
||||
{
|
||||
RagonLog.Trace("Owner ship changed");
|
||||
}
|
||||
|
||||
public void OnLevel(RagonClient client, string sceneName)
|
||||
{
|
||||
RagonLog.Trace($"New level: {sceneName}");
|
||||
client.Room.SceneLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
// [Fact]
|
||||
// public async void Connect()
|
||||
// {
|
||||
// RagonLog.Set(new RagonXUnitLogger(_testOutputHelper));
|
||||
//
|
||||
// var joining = new TaskCompletionSource();
|
||||
// var network = new RagonNetwork();
|
||||
// var game = new Game(network, joining);
|
||||
//
|
||||
// network.AddListener(game);
|
||||
//
|
||||
// var clientConfiguration = new RagonConnectionConfiguration();
|
||||
// clientConfiguration.Type = RagonConnectionType.UDP;
|
||||
// clientConfiguration.Protocol = "1.0.0";
|
||||
// clientConfiguration.Address = "127.0.0.1";
|
||||
// clientConfiguration.Port = 5000;
|
||||
//
|
||||
// network.Connect(clientConfiguration);
|
||||
//
|
||||
// var relayConfiguration = new Configuration()
|
||||
// {
|
||||
// GameProtocol = "1.0.0",
|
||||
// LimitConnections = 4095,
|
||||
// LimitRooms = 20,
|
||||
// LimitPlayersPerRoom = 20,
|
||||
// Port = 5000,
|
||||
// ServerKey = "defaultkey",
|
||||
// ServerTickRate = 30,
|
||||
// ServerType = "enet"
|
||||
// };
|
||||
//
|
||||
// var relay = new RagonServer(relayConfiguration);
|
||||
// relay.Start(true);
|
||||
//
|
||||
// var ticks = 0;
|
||||
// while (true)
|
||||
// {
|
||||
// ticks += 1;
|
||||
// network.Update();
|
||||
//
|
||||
// if (ticks > 100)
|
||||
// break;
|
||||
//
|
||||
// await Task.Delay(100);
|
||||
// }
|
||||
//
|
||||
// Assert.Equal(network.Status, RagonStatus.ROOM);
|
||||
//
|
||||
// network.Dispose();
|
||||
// relay.Dispose();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<RootNamespace>Ragon.Core.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ragon.Client\Ragon.Client.csproj" />
|
||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||
<ProjectReference Include="..\Ragon.Protocol\Ragon.Protocol.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
global using Xunit;
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Client;
|
||||
using Ragon.Protocol;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Ragon.Core.Tests;
|
||||
|
||||
public class RagonXUnitLogger: IRagonLogger
|
||||
{
|
||||
private ITestOutputHelper _outputHelper;
|
||||
public RagonXUnitLogger(ITestOutputHelper outputHelper)
|
||||
{
|
||||
_outputHelper = outputHelper;
|
||||
}
|
||||
|
||||
public void Warn(string message)
|
||||
{
|
||||
_outputHelper.WriteLine($"[Warn] {message}");
|
||||
}
|
||||
|
||||
public void Trace(string message)
|
||||
{
|
||||
_outputHelper.WriteLine($"[Trace] {message}");
|
||||
}
|
||||
|
||||
public void Info(string message)
|
||||
{
|
||||
_outputHelper.WriteLine($"[Info] {message}");
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
_outputHelper.WriteLine($"[Error] {message}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user