wip
This commit is contained in:
@@ -1,11 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
using Ragon.Core;
|
using Ragon.Core;
|
||||||
|
|
||||||
namespace Game.Source;
|
namespace Game.Source;
|
||||||
|
|
||||||
public class GameAuthorizer: AuthorizationManager
|
public class GameAuthorizer: AuthorizationManager
|
||||||
{
|
{
|
||||||
public override bool OnAuthorize(uint peerId, byte[] payload)
|
private Configuration _configuration;
|
||||||
|
public GameAuthorizer(Configuration configuration)
|
||||||
{
|
{
|
||||||
return true;
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnAuthorize(uint peerId, ref ReadOnlySpan<byte> payload)
|
||||||
|
{
|
||||||
|
var apiKey = Encoding.UTF8.GetString(payload);
|
||||||
|
return _configuration.ApiKey == apiKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@ namespace Game.Source
|
|||||||
{
|
{
|
||||||
public string PluginName { get; set; } = "ExamplePlugin";
|
public string PluginName { get; set; } = "ExamplePlugin";
|
||||||
public PluginBase CreatePlugin(string map) => new ExamplePlugin();
|
public PluginBase CreatePlugin(string map) => new ExamplePlugin();
|
||||||
public AuthorizationManager CreateManager() => new GameAuthorizer();
|
public AuthorizationManager CreateManager(Configuration configuration) => new GameAuthorizer(configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,9 +28,4 @@
|
|||||||
<ProjectReference Include="..\Ragon.Common\Ragon.Common.csproj" />
|
<ProjectReference Include="..\Ragon.Common\Ragon.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Sources\Protocol" />
|
|
||||||
<Folder Include="Sources\Storage" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ namespace Ragon.Core
|
|||||||
private readonly List<RoomThread> _roomThreads = new();
|
private readonly List<RoomThread> _roomThreads = new();
|
||||||
private readonly Dictionary<uint, RoomThread> _socketByRoomThreads = new();
|
private readonly Dictionary<uint, RoomThread> _socketByRoomThreads = new();
|
||||||
private readonly Dictionary<RoomThread, int> _roomThreadCounter = new();
|
private readonly Dictionary<RoomThread, int> _roomThreadCounter = new();
|
||||||
|
private readonly Configuration _configuration;
|
||||||
private readonly ENetServer _socketServer;
|
private readonly ENetServer _socketServer;
|
||||||
|
|
||||||
public Application(PluginFactory factory, Configuration configuration, int threadsCount)
|
public Application(PluginFactory factory, Configuration configuration, int threadsCount)
|
||||||
{
|
{
|
||||||
_socketServer = new ENetServer();
|
_socketServer = new ENetServer();
|
||||||
|
_configuration = configuration;
|
||||||
|
|
||||||
for (var i = 0; i < threadsCount; i++)
|
for (var i = 0; i < threadsCount; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Ragon.Core;
|
namespace Ragon.Core;
|
||||||
|
|
||||||
public class AuthorizationManager
|
public class AuthorizationManager
|
||||||
{
|
{
|
||||||
public virtual bool OnAuthorize(uint peerId, byte[] payload)
|
public virtual bool OnAuthorize(uint peerId, ref ReadOnlySpan<byte> payload)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
namespace Ragon.Core
|
using System;
|
||||||
|
|
||||||
|
namespace Ragon.Core
|
||||||
{
|
{
|
||||||
public class Configuration
|
[Serializable]
|
||||||
|
public struct Configuration
|
||||||
{
|
{
|
||||||
public int UdpPort;
|
public string ApiKey;
|
||||||
public int WsPort;
|
|
||||||
public string Transport;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace Ragon.Core
|
|||||||
{
|
{
|
||||||
public string PluginName { get; set; }
|
public string PluginName { get; set; }
|
||||||
public PluginBase CreatePlugin(string map);
|
public PluginBase CreatePlugin(string map);
|
||||||
public AuthorizationManager CreateManager();
|
public AuthorizationManager CreateManager(Configuration configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -106,8 +106,6 @@ namespace Ragon.Core
|
|||||||
|
|
||||||
public void ProcessEvent(RagonOperation operation, uint peerId, ReadOnlySpan<byte> rawData)
|
public void ProcessEvent(RagonOperation operation, uint peerId, ReadOnlySpan<byte> rawData)
|
||||||
{
|
{
|
||||||
if (_plugin.InternalHandle(peerId, (ushort) operation, ref rawData)) return;
|
|
||||||
|
|
||||||
switch (operation)
|
switch (operation)
|
||||||
{
|
{
|
||||||
case RagonOperation.REPLICATE_ENTITY_STATE:
|
case RagonOperation.REPLICATE_ENTITY_STATE:
|
||||||
@@ -158,6 +156,11 @@ namespace Ragon.Core
|
|||||||
case RagonOperation.REPLICATE_ENTITY_EVENT:
|
case RagonOperation.REPLICATE_ENTITY_EVENT:
|
||||||
{
|
{
|
||||||
Span<byte> data = stackalloc byte[rawData.Length];
|
Span<byte> data = stackalloc byte[rawData.Length];
|
||||||
|
|
||||||
|
var evntCodeData = rawData.Slice(2, 2);
|
||||||
|
var evntId = RagonHeader.ReadUShort(ref evntCodeData);
|
||||||
|
if (_plugin.InternalHandle(peerId, evntId, ref rawData)) return;
|
||||||
|
|
||||||
rawData.CopyTo(data);
|
rawData.CopyTo(data);
|
||||||
Broadcast(_readyPlayers, data, DeliveryType.Reliable);
|
Broadcast(_readyPlayers, data, DeliveryType.Reliable);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Ragon.Core
|
|||||||
_roomThread = roomThread;
|
_roomThread = roomThread;
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
|
|
||||||
_manager = _factory.CreateManager();
|
_manager = _factory.CreateManager(roomThread);
|
||||||
_rooms = new List<Room>();
|
_rooms = new List<Room>();
|
||||||
_peersByRoom = new Dictionary<uint, Room>();
|
_peersByRoom = new Dictionary<uint, Room>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,22 @@ namespace Ragon.Core
|
|||||||
private RingBuffer<Event> _receiveBuffer = new RingBuffer<Event>(8192 + 8192);
|
private RingBuffer<Event> _receiveBuffer = new RingBuffer<Event>(8192 + 8192);
|
||||||
private RingBuffer<Event> _sendBuffer = new RingBuffer<Event>(8192 + 8192);
|
private RingBuffer<Event> _sendBuffer = new RingBuffer<Event>(8192 + 8192);
|
||||||
|
|
||||||
|
public Configuration Configuration { get; private set; }
|
||||||
public bool ReadOutEvent(out Event evnt) => _sendBuffer.TryDequeue(out evnt);
|
public bool ReadOutEvent(out Event evnt) => _sendBuffer.TryDequeue(out evnt);
|
||||||
public void WriteOutEvent(Event evnt) => _sendBuffer.Enqueue(evnt);
|
public void WriteOutEvent(Event evnt) => _sendBuffer.Enqueue(evnt);
|
||||||
|
|
||||||
public bool ReadIntEvent(out Event evnt) => _receiveBuffer.TryDequeue(out evnt);
|
public bool ReadIntEvent(out Event evnt) => _receiveBuffer.TryDequeue(out evnt);
|
||||||
public void WriteInEvent(Event evnt) => _receiveBuffer.Enqueue(evnt);
|
public void WriteInEvent(Event evnt) => _receiveBuffer.Enqueue(evnt);
|
||||||
|
|
||||||
public RoomThread(PluginFactory factory)
|
public RoomThread(PluginFactory factory, Configuration configuration)
|
||||||
{
|
{
|
||||||
_thread = new Thread(Execute);
|
_thread = new Thread(Execute);
|
||||||
_thread.IsBackground = true;
|
_thread.IsBackground = true;
|
||||||
_timer = new Stopwatch();
|
_timer = new Stopwatch();
|
||||||
_socketByRooms = new Dictionary<uint, Room>();
|
_socketByRooms = new Dictionary<uint, Room>();
|
||||||
|
|
||||||
|
Configuration = configuration;
|
||||||
|
|
||||||
_roomManager = new RoomManager(this, factory);
|
_roomManager = new RoomManager(this, factory);
|
||||||
_roomManager.OnJoined += (tuple) => _socketByRooms.Add(tuple.Item1, tuple.Item2);
|
_roomManager.OnJoined += (tuple) => _socketByRooms.Add(tuple.Item1, tuple.Item2);
|
||||||
_roomManager.OnLeaved += (tuple) => _socketByRooms.Remove(tuple.Item1);
|
_roomManager.OnLeaved += (tuple) => _socketByRooms.Remove(tuple.Item1);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Ragon.Core.Storage;
|
||||||
|
|
||||||
|
public struct EntityInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Ragon.Core.Storage;
|
||||||
|
|
||||||
|
public struct PlayerInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Ragon.Core.Storage;
|
||||||
|
|
||||||
|
public struct RoomInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
namespace Ragon.Core.Storage;
|
||||||
|
|
||||||
|
public class Storage
|
||||||
|
{
|
||||||
|
private ConnectionMultiplexer _connection;
|
||||||
|
|
||||||
|
public Storage(Configuration _configuration)
|
||||||
|
{
|
||||||
|
_connection = ConnectionMultiplexer.Connect(_configuration.ApiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateEntity(int entityId)
|
||||||
|
{
|
||||||
|
var db = _connection.GetDatabase();
|
||||||
|
|
||||||
|
db.set("entity_", )
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePlayer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateRoom()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user