chore: update naming game -> simple server
This commit is contained in:
@@ -54,7 +54,7 @@ namespace Ragon.Core
|
||||
_thread = new Thread(Execute);
|
||||
_thread.Name = "NetworkThread";
|
||||
_thread.Start();
|
||||
_logger.Info($"Socket Server Started at port {port}");
|
||||
_logger.Info($"ENet Server Started at port {port}");
|
||||
}
|
||||
|
||||
private void Execute()
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using DisruptorUnity3d;
|
||||
using NLog;
|
||||
|
||||
namespace Ragon.Core;
|
||||
|
||||
public class WebsocketServer : IDisposable
|
||||
{
|
||||
private HttpListener _httpListener;
|
||||
private ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
private Thread _thread;
|
||||
private ENet.Event _netEvent;
|
||||
|
||||
private RingBuffer<Event> _receiveBuffer;
|
||||
private RingBuffer<Event> _sendBuffer;
|
||||
|
||||
public void WriteEvent(Event evnt) => _sendBuffer.Enqueue(evnt);
|
||||
public bool ReadEvent(out Event evnt) => _receiveBuffer.TryDequeue(out evnt);
|
||||
|
||||
public void Start(ushort port)
|
||||
{
|
||||
// _httpListener = new HttpListener();
|
||||
// _httpListener.Prefixes.Add("http://localhost/");
|
||||
// _httpListener.Start();
|
||||
//
|
||||
// _thread = new Thread(Execute);
|
||||
// _thread.Name = "NetworkThread";
|
||||
// _thread.Start();
|
||||
// _logger.Info($"Socket Server Started at port {port}");
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async void ExecuteAsync()
|
||||
{
|
||||
// while (true)
|
||||
// {
|
||||
// HttpListenerContext context = await _httpListener.GetContextAsync();
|
||||
// if (context.Request.IsWebSocketRequest)
|
||||
// {
|
||||
// HttpListenerWebSocketContext webSocketContext = await context.AcceptWebSocketAsync(null);
|
||||
// WebSocket webSocket = webSocketContext.WebSocket;
|
||||
// while (webSocket.State == WebSocketState.Open)
|
||||
// {
|
||||
// await webSocket.SendAsync(... );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Ragon.Core.Storage;
|
||||
|
||||
public class Storage
|
||||
{
|
||||
private ConnectionMultiplexer _connection;
|
||||
// private ConnectionMultiplexer _connection;
|
||||
|
||||
public Storage(Configuration _configuration)
|
||||
{
|
||||
_connection = ConnectionMultiplexer.Connect(_configuration.ApiKey);
|
||||
// _connection = ConnectionMultiplexer.Connect(_configuration.Key);
|
||||
}
|
||||
|
||||
public void UpdateEntity(int entityId)
|
||||
{
|
||||
var db = _connection.GetDatabase();
|
||||
// var db = _connection.GetDatabase();
|
||||
|
||||
// db.set("entity_", )
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Ragon.Core;
|
||||
|
||||
public class WebsocketServer
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using Game.Source;
|
||||
using NetStack.Serialization;
|
||||
using Ragon.Core;
|
||||
|
||||
namespace Game
|
||||
namespace SimpleServer
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var bootstrap = new Bootstrap();
|
||||
bootstrap.Configure(new GameFactory());
|
||||
bootstrap.Configure(new SimplePluginFactory());
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
<RootNamespace>Game</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="NLog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
@@ -19,4 +23,8 @@
|
||||
<ProjectReference Include="..\Ragon\Ragon.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Source\Managers" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,17 +4,17 @@ using Ragon.Core;
|
||||
|
||||
namespace Game.Source;
|
||||
|
||||
public class GameAuthorizer: AuthorizationManager
|
||||
public class AuthorizerByKey: AuthorizationManager
|
||||
{
|
||||
private Configuration _configuration;
|
||||
public GameAuthorizer(Configuration configuration)
|
||||
public AuthorizerByKey(Configuration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public override bool OnAuthorize(uint peerId, ref ReadOnlySpan<byte> payload)
|
||||
{
|
||||
var apiKey = Encoding.UTF8.GetString(payload);
|
||||
return _configuration.ApiKey == apiKey;
|
||||
var key = Encoding.UTF8.GetString(payload);
|
||||
return _configuration.Key == key;
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,17 @@ using Ragon.Common;
|
||||
|
||||
namespace Game.Source.Events;
|
||||
|
||||
public class TestEvent: IRagonSerializable
|
||||
public class SimpleEvent: IRagonSerializable
|
||||
{
|
||||
public string TestData;
|
||||
public string Name;
|
||||
|
||||
public void Serialize(BitBuffer buffer)
|
||||
{
|
||||
buffer.AddString(TestData);
|
||||
buffer.AddString(Name);
|
||||
}
|
||||
|
||||
public void Deserialize(BitBuffer buffer)
|
||||
{
|
||||
TestData = buffer.ReadString();
|
||||
Name = buffer.ReadString();
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,18 @@ using Ragon.Core;
|
||||
|
||||
namespace Game.Source
|
||||
{
|
||||
public class GameFactory : PluginFactory
|
||||
public class SimplePluginFactory : PluginFactory
|
||||
{
|
||||
public string PluginName { get; set; } = "ExamplePlugin";
|
||||
public string PluginName { get; set; } = "SimplePlugin";
|
||||
public PluginBase CreatePlugin(string map)
|
||||
{
|
||||
|
||||
return new ExamplePlugin();
|
||||
return new SimplePlugin();
|
||||
}
|
||||
|
||||
public AuthorizationManager CreateManager(Configuration configuration) => new GameAuthorizer(configuration);
|
||||
public AuthorizationManager CreateManager(Configuration configuration)
|
||||
{
|
||||
return new AuthorizerByKey(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user