chore: update naming game -> simple server

This commit is contained in:
2022-05-14 10:35:17 +04:00
parent 185b5b7ca1
commit 053d5c9383
11 changed files with 121 additions and 27 deletions
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="logs/server-log-${shortdate}.log" layout="[${longdate}][${logger}][${level}] ${message} ${exception:format=ToString}" />
<target name="logconsole" xsi:type="Console" layout="[${date}][${logger}][${level}] ${message} ${exception:format=ToString}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logconsole" />
<logger name="*" minlevel="Trace" writeTo="logfile" />
</rules>
</nlog>
+17
View File
@@ -0,0 +1,17 @@
using System;
using Game.Source;
using Ragon.Core;
namespace SimpleServer
{
class Program
{
static void Main(string[] args)
{
var bootstrap = new Bootstrap();
bootstrap.Configure(new SimplePluginFactory());
Console.Read();
}
}
}
+30
View File
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Game</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ragon\Ragon.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Source\Managers" />
</ItemGroup>
</Project>
+20
View File
@@ -0,0 +1,20 @@
using System;
using System.Text;
using Ragon.Core;
namespace Game.Source;
public class AuthorizerByKey: AuthorizationManager
{
private Configuration _configuration;
public AuthorizerByKey(Configuration configuration)
{
_configuration = configuration;
}
public override bool OnAuthorize(uint peerId, ref ReadOnlySpan<byte> payload)
{
var key = Encoding.UTF8.GetString(payload);
return _configuration.Key == key;
}
}
+19
View File
@@ -0,0 +1,19 @@
using NetStack.Serialization;
using Ragon.Common;
namespace Game.Source.Events;
public class SimpleEvent: IRagonSerializable
{
public string Name;
public void Serialize(BitBuffer buffer)
{
buffer.AddString(Name);
}
public void Deserialize(BitBuffer buffer)
{
Name = buffer.ReadString();
}
}
+31
View File
@@ -0,0 +1,31 @@
using System.Runtime.InteropServices;
using Game.Source.Events;
using NLog;
using Ragon.Common;
using Ragon.Core;
namespace Game.Source
{
public class SimplePlugin: PluginBase
{
public override void OnStart()
{
_logger.Info("Plugin started");
}
public override void OnStop()
{
_logger.Info("Plugin stopped");
}
public override void OnPlayerJoined(Player player)
{
_logger.Info("Player joined " + player.PlayerName);
}
public override void OnPlayerLeaved(Player player)
{
_logger.Info("Player leaved " + player.PlayerName);
}
}
}
@@ -0,0 +1,20 @@
using System.Runtime.InteropServices;
using Ragon.Core;
namespace Game.Source
{
public class SimplePluginFactory : PluginFactory
{
public string PluginName { get; set; } = "SimplePlugin";
public PluginBase CreatePlugin(string map)
{
return new SimplePlugin();
}
public AuthorizationManager CreateManager(Configuration configuration)
{
return new AuthorizerByKey(configuration);
}
}
}