🚧 plugin system, webhook system
This commit is contained in:
@@ -18,7 +18,7 @@ public class Game : IRagonListener
|
|||||||
public void OnConnected(RagonClient client)
|
public void OnConnected(RagonClient client)
|
||||||
{
|
{
|
||||||
RagonLog.Trace("Connected");
|
RagonLog.Trace("Connected");
|
||||||
_client.Session.AuthorizeWithKey("defaultkey", "Player Eduard", Array.Empty<byte>());
|
_client.Session.AuthorizeWithKey("defaultkey", "Player Eduard");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAuthorizationSuccess(RagonClient client, string playerId, string playerName)
|
public void OnAuthorizationSuccess(RagonClient client, string playerId, string playerName)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<OutputPath>/Users/edmand46/RagonProjects/ragon-unity-sdk/Assets/Ragon/Runtime/Plugins</OutputPath>
|
<OutputPath>/Users/edmand46/RagonProjects/ragon-oss-sdk/Assets/Ragon/Plugins/</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace Ragon.Client;
|
namespace Ragon.Client;
|
||||||
|
|
||||||
public interface IRagonConnectedListener
|
public interface IRagonConnectionListener
|
||||||
{
|
{
|
||||||
void OnConnected(RagonClient client);
|
void OnConnected(RagonClient client);
|
||||||
void OnDisconnected(RagonClient client);
|
void OnDisconnected(RagonClient client);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Ragon.Client
|
|||||||
{
|
{
|
||||||
public interface IRagonListener :
|
public interface IRagonListener :
|
||||||
IRagonAuthorizationListener,
|
IRagonAuthorizationListener,
|
||||||
IRagonConnectedListener,
|
IRagonConnectionListener,
|
||||||
IRagonFailedListener,
|
IRagonFailedListener,
|
||||||
IRagonJoinListener,
|
IRagonJoinListener,
|
||||||
IRagonLeftListener,
|
IRagonLeftListener,
|
||||||
|
|||||||
@@ -87,23 +87,18 @@ namespace Ragon.Client
|
|||||||
_handlers = new Handler[byte.MaxValue];
|
_handlers = new Handler[byte.MaxValue];
|
||||||
_handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(_listenerList);
|
_handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(_listenerList);
|
||||||
_handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(_listenerList);
|
_handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(_listenerList);
|
||||||
_handlers[(byte)RagonOperation.JOIN_SUCCESS] =
|
_handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, _readBuffer, _listenerList, _playerCache, _entityCache);
|
||||||
new JoinSuccessHandler(this, _readBuffer, _listenerList, _playerCache, _entityCache);
|
|
||||||
_handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(_listenerList);
|
_handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(_listenerList);
|
||||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, _listenerList, _entityCache);
|
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, _listenerList, _entityCache);
|
||||||
_handlers[(byte)RagonOperation.OWNERSHIP_CHANGED] =
|
_handlers[(byte)RagonOperation.OWNERSHIP_CHANGED] = new OwnershipHandler(_listenerList, _playerCache, _entityCache);
|
||||||
new OwnershipHandler(_listenerList, _playerCache, _entityCache);
|
|
||||||
_handlers[(byte)RagonOperation.PLAYER_JOINED] = new PlayerJoinHandler(_playerCache, _listenerList);
|
_handlers[(byte)RagonOperation.PLAYER_JOINED] = new PlayerJoinHandler(_playerCache, _listenerList);
|
||||||
_handlers[(byte)RagonOperation.PLAYER_LEAVED] =
|
_handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, _listenerList);
|
||||||
new PlayerLeftHandler(_entityCache, _playerCache, _listenerList);
|
|
||||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listenerList);
|
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listenerList);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateHandler(this, _playerCache, _entityCache);
|
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateHandler(this, _playerCache, _entityCache);
|
||||||
_handlers[(byte)RagonOperation.DESTROY_ENTITY] = new EntityDestroyHandler(_entityCache);
|
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityDestroyHandler(_entityCache);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new StateEntityHandler(_entityCache);
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new StateEntityHandler(_entityCache);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] =
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventHandler(this, _playerCache, _entityCache);
|
||||||
new EntityEventHandler(this, _playerCache, _entityCache);
|
_handlers[(byte)RagonOperation.SNAPSHOT] = new SnapshotHandler(this, _listenerList, _entityCache, _playerCache);
|
||||||
_handlers[(byte)RagonOperation.SNAPSHOT] =
|
|
||||||
new SnapshotHandler(this, _listenerList, _entityCache, _playerCache);
|
|
||||||
|
|
||||||
var protocolRaw = RagonVersion.Parse(protocol);
|
var protocolRaw = RagonVersion.Parse(protocol);
|
||||||
_connection.Connect(address, port, protocolRaw);
|
_connection.Connect(address, port, protocolRaw);
|
||||||
@@ -144,7 +139,7 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void AddListener(IRagonListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonListener listener) => _listenerList.Add(listener);
|
||||||
public void AddListener(IRagonAuthorizationListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonAuthorizationListener listener) => _listenerList.Add(listener);
|
||||||
public void AddListener(IRagonConnectedListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonConnectionListener listener) => _listenerList.Add(listener);
|
||||||
public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener);
|
||||||
public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener);
|
||||||
public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener);
|
public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener);
|
||||||
@@ -155,7 +150,7 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void RemoveListener(IRagonListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonListener listener) => _listenerList.Remove(listener);
|
||||||
public void RemoveListener(IRagonAuthorizationListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonAuthorizationListener listener) => _listenerList.Remove(listener);
|
||||||
public void RemoveListener(IRagonConnectedListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonConnectionListener listener) => _listenerList.Remove(listener);
|
||||||
public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener);
|
||||||
public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener);
|
||||||
public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener);
|
public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener);
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public sealed class RagonEntityCache
|
|||||||
var buffer = _client.Buffer;
|
var buffer = _client.Buffer;
|
||||||
|
|
||||||
buffer.Clear();
|
buffer.Clear();
|
||||||
buffer.WriteOperation(RagonOperation.DESTROY_ENTITY);
|
buffer.WriteOperation(RagonOperation.REMOVE_ENTITY);
|
||||||
buffer.WriteUShort(entity.Id);
|
buffer.WriteUShort(entity.Id);
|
||||||
|
|
||||||
destroyPayload?.Serialize(buffer);
|
destroyPayload?.Serialize(buffer);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace Ragon.Client
|
|||||||
{
|
{
|
||||||
private readonly RagonClient _client;
|
private readonly RagonClient _client;
|
||||||
private readonly List<IRagonAuthorizationListener> _authorizationListeners = new();
|
private readonly List<IRagonAuthorizationListener> _authorizationListeners = new();
|
||||||
private readonly List<IRagonConnectedListener> _connectionListeners = new();
|
private readonly List<IRagonConnectionListener> _connectionListeners = new();
|
||||||
private readonly List<IRagonFailedListener> _failedListeners = new();
|
private readonly List<IRagonFailedListener> _failedListeners = new();
|
||||||
private readonly List<IRagonJoinListener> _joinListeners = new();
|
private readonly List<IRagonJoinListener> _joinListeners = new();
|
||||||
private readonly List<IRagonLeftListener> _leftListeners = new();
|
private readonly List<IRagonLeftListener> _leftListeners = new();
|
||||||
@@ -65,7 +65,7 @@ namespace Ragon.Client
|
|||||||
_authorizationListeners.Add(listener);
|
_authorizationListeners.Add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(IRagonConnectedListener listener)
|
public void Add(IRagonConnectionListener listener)
|
||||||
{
|
{
|
||||||
_connectionListeners.Add(listener);
|
_connectionListeners.Add(listener);
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ namespace Ragon.Client
|
|||||||
_authorizationListeners.Remove(listener);
|
_authorizationListeners.Remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(IRagonConnectedListener listener)
|
public void Remove(IRagonConnectionListener listener)
|
||||||
{
|
{
|
||||||
_connectionListeners.Remove(listener);
|
_connectionListeners.Remove(listener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,13 +93,13 @@ namespace Ragon.Client
|
|||||||
_client.Reliable.Send(sendData);
|
_client.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AuthorizeWithKey(string key, string playerName, byte[] additonalData)
|
public void AuthorizeWithKey(string key, string playerName, string payload = "")
|
||||||
{
|
{
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
_buffer.WriteOperation(RagonOperation.AUTHORIZE);
|
_buffer.WriteOperation(RagonOperation.AUTHORIZE);
|
||||||
_buffer.WriteString(key);
|
_buffer.WriteString(key);
|
||||||
_buffer.WriteString(playerName);
|
_buffer.WriteString(playerName);
|
||||||
_buffer.WriteBytes(additonalData);
|
_buffer.WriteString(payload);
|
||||||
|
|
||||||
var sendData = _buffer.ToArray();
|
var sendData = _buffer.ToArray();
|
||||||
_client.Reliable.Send(sendData);
|
_client.Reliable.Send(sendData);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Ragon.Protocol
|
|||||||
PLAYER_JOINED,
|
PLAYER_JOINED,
|
||||||
PLAYER_LEAVED,
|
PLAYER_LEAVED,
|
||||||
CREATE_ENTITY,
|
CREATE_ENTITY,
|
||||||
DESTROY_ENTITY,
|
REMOVE_ENTITY,
|
||||||
SNAPSHOT,
|
SNAPSHOT,
|
||||||
REPLICATE_ENTITY_STATE,
|
REPLICATE_ENTITY_STATE,
|
||||||
REPLICATE_ENTITY_EVENT,
|
REPLICATE_ENTITY_EVENT,
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ using Ragon.Server;
|
|||||||
using Ragon.Server.ENet;
|
using Ragon.Server.ENet;
|
||||||
using Ragon.Server.DotNetWebsockets;
|
using Ragon.Server.DotNetWebsockets;
|
||||||
|
|
||||||
|
|
||||||
namespace Ragon.Relay;
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
public class Relay
|
public class Relay
|
||||||
@@ -32,21 +31,19 @@ public class Relay
|
|||||||
var configuration = Configuration.Load("relay.config.json");
|
var configuration = Configuration.Load("relay.config.json");
|
||||||
var serverType = Configuration.GetServerType(configuration.ServerType);
|
var serverType = Configuration.GetServerType(configuration.ServerType);
|
||||||
|
|
||||||
INetworkServer server = null;
|
INetworkServer networkServer = new ENetServer();
|
||||||
|
IServerPlugin plugin = new RelayServerPlugin();
|
||||||
switch (serverType)
|
switch (serverType)
|
||||||
{
|
{
|
||||||
case ServerType.ENET:
|
case ServerType.ENET:
|
||||||
server = new ENetServer();
|
networkServer = new ENetServer();
|
||||||
break;
|
break;
|
||||||
case ServerType.WEBSOCKET:
|
case ServerType.WEBSOCKET:
|
||||||
server = new DotNetWebSocketServer();
|
networkServer = new DotNetWebSocketServer();
|
||||||
break;
|
|
||||||
default:
|
|
||||||
server = new ENetServer();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var relay = new RagonServer(server, configuration);
|
var relay = new RagonServer(networkServer, plugin, configuration);
|
||||||
logger.Info("Started");
|
logger.Info("Started");
|
||||||
relay.Start();
|
relay.Start();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using Ragon.Server;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayRoomPlugin: IRoomPlugin
|
||||||
|
{
|
||||||
|
public void Tick(float dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAttached()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Room attached");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDetached()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Room detached");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Entity created: {entity.Id}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnEntityRemove(RagonRoomPlayer destroyer, RagonEntity entity)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Entity destroyed: {entity.Id}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Ragon.Server;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayServerPlugin: IServerPlugin
|
||||||
|
{
|
||||||
|
private HttpClient httpClient;
|
||||||
|
public IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||||
|
{
|
||||||
|
return new RelayRoomPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelayServerPlugin()
|
||||||
|
{
|
||||||
|
httpClient = new HttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnRoomLeave(RagonRoomPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnRoomJoin(RagonRoomPlayer player, RagonRoom room)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,5 +6,12 @@
|
|||||||
"port": 5000,
|
"port": 5000,
|
||||||
"limitConnections": 4095,
|
"limitConnections": 4095,
|
||||||
"limitPlayersPerRoom": 20,
|
"limitPlayersPerRoom": 20,
|
||||||
"limitRooms": 200
|
"limitRooms": 200,
|
||||||
|
"webHooks":
|
||||||
|
{
|
||||||
|
"room-created": "http://127.0.0.1:3000/service/create-room",
|
||||||
|
"room-removed": "http://127.0.0.1:3000/service/remove-room",
|
||||||
|
"room-joined": "http://127.0.0.1:3000/service/join-room",
|
||||||
|
"room-leaved": "http://127.0.0.1:3000/service/leave-room"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,11 @@ public sealed class WebSocketConnection : INetworkConnection
|
|||||||
Unreliable = unreliableChannel;
|
Unreliable = unreliableChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task Flush()
|
public async Task Flush()
|
||||||
{
|
{
|
||||||
foreach (var channel in _channels)
|
foreach (var channel in _channels)
|
||||||
|
|||||||
@@ -23,11 +23,19 @@ public sealed class ENetConnection: INetworkConnection
|
|||||||
public ushort Id { get; }
|
public ushort Id { get; }
|
||||||
public INetworkChannel Reliable { get; private set; }
|
public INetworkChannel Reliable { get; private set; }
|
||||||
public INetworkChannel Unreliable { get; private set; }
|
public INetworkChannel Unreliable { get; private set; }
|
||||||
|
private Peer _peer;
|
||||||
|
|
||||||
public ENetConnection(Peer peer)
|
public ENetConnection(Peer peer)
|
||||||
{
|
{
|
||||||
|
_peer = peer;
|
||||||
|
|
||||||
Id = (ushort) peer.ID;
|
Id = (ushort) peer.ID;
|
||||||
Reliable = new ENetReliableChannel(peer, 0);
|
Reliable = new ENetReliableChannel(peer, 0);
|
||||||
Unreliable = new ENetUnreliableChannel(peer, 1);
|
Unreliable = new ENetUnreliableChannel(peer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
_peer.Disconnect(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonEntity
|
public class RagonEntity
|
||||||
{
|
{
|
||||||
@@ -30,29 +31,33 @@ public class RagonEntity
|
|||||||
public RagonAuthority Authority { get; private set; }
|
public RagonAuthority Authority { get; private set; }
|
||||||
public RagonPayload Payload { get; private set; }
|
public RagonPayload Payload { get; private set; }
|
||||||
public RagonEntityState State { get; private set; }
|
public RagonEntityState State { get; private set; }
|
||||||
|
|
||||||
private readonly List<RagonEvent> _bufferedEvents;
|
private readonly List<RagonEvent> _bufferedEvents;
|
||||||
|
|
||||||
public RagonEntity(RagonRoomPlayer owner, ushort type, ushort staticId, ushort attachId, RagonAuthority eventAuthority)
|
public RagonEntity(RagonEntityParameters parameters)
|
||||||
{
|
{
|
||||||
Owner = owner;
|
|
||||||
StaticId = staticId;
|
|
||||||
Type = type;
|
|
||||||
AttachId = attachId;
|
|
||||||
Id = _idGenerator++;
|
Id = _idGenerator++;
|
||||||
Authority = eventAuthority;
|
|
||||||
|
StaticId = parameters.StaticId;
|
||||||
|
Type = parameters.Type;
|
||||||
|
AttachId = parameters.AttachId;
|
||||||
|
Authority = parameters.Authority;
|
||||||
|
|
||||||
State = new RagonEntityState(this);
|
State = new RagonEntityState(this);
|
||||||
Payload = new RagonPayload();
|
Payload = new RagonPayload();
|
||||||
|
|
||||||
_bufferedEvents = new List<RagonEvent>();
|
_bufferedEvents = new List<RagonEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Attach(RagonRoomPlayer owner)
|
||||||
public void SetOwner(RagonRoomPlayer owner)
|
|
||||||
{
|
{
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Detach()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void RestoreBufferedEvents(RagonRoomPlayer roomPlayer, RagonBuffer writer)
|
public void RestoreBufferedEvents(RagonRoomPlayer roomPlayer, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
foreach (var evnt in _bufferedEvents)
|
foreach (var evnt in _bufferedEvents)
|
||||||
@@ -96,7 +101,7 @@ public class RagonEntity
|
|||||||
var buffer = room.Writer;
|
var buffer = room.Writer;
|
||||||
|
|
||||||
buffer.Clear();
|
buffer.Clear();
|
||||||
buffer.WriteOperation(RagonOperation.DESTROY_ENTITY);
|
buffer.WriteOperation(RagonOperation.REMOVE_ENTITY);
|
||||||
buffer.WriteUShort(Id);
|
buffer.WriteUShort(Id);
|
||||||
|
|
||||||
Payload.Write(buffer);
|
Payload.Write(buffer);
|
||||||
@@ -209,4 +214,17 @@ public class RagonEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Write(RagonBuffer writer)
|
||||||
|
{
|
||||||
|
State.Write(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Read(RagonRoomPlayer player, RagonBuffer reader)
|
||||||
|
{
|
||||||
|
if (Owner.Connection.Id != player.Connection.Id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
State.Read(reader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Ragon.Protocol;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
|
public ref struct RagonEntityParameters
|
||||||
|
{
|
||||||
|
public ushort Type;
|
||||||
|
public ushort StaticId;
|
||||||
|
public ushort AttachId;
|
||||||
|
public RagonAuthority Authority;
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonEntityState
|
public class RagonEntityState
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonEvent
|
public class RagonEvent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonPayload
|
public class RagonPayload
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,11 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
using System.ComponentModel;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonProperty : RagonPayload
|
public class RagonProperty : RagonPayload
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,40 +16,94 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Hander;
|
||||||
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
|
||||||
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class AuthorizationOperation: IRagonOperation
|
public sealed class AuthorizationOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
private readonly WebHookPlugin _webHook;
|
||||||
|
private readonly Configuration _configuration;
|
||||||
|
private readonly RagonBuffer _writer;
|
||||||
|
|
||||||
|
public AuthorizationOperation(
|
||||||
|
WebHookPlugin webHook,
|
||||||
|
RagonBuffer writer,
|
||||||
|
Configuration configuration)
|
||||||
|
{
|
||||||
|
_webHook = webHook;
|
||||||
|
_configuration = configuration;
|
||||||
|
_writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
if (context.LobbyPlayer.Status == LobbyPlayerStatus.Authorized)
|
if (context.ConnectionStatus == ConnectionStatus.Authorized)
|
||||||
{
|
{
|
||||||
_logger.Warn("Player already authorized");
|
_logger.Warn("Player already authorized!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.ConnectionStatus == ConnectionStatus.InProcess)
|
||||||
|
{
|
||||||
|
_logger.Warn("Player already request authorization!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = reader.ReadString();
|
var key = reader.ReadString();
|
||||||
var playerName = reader.ReadString();
|
var name = reader.ReadString();
|
||||||
var additionalPayload = new RagonPayload();
|
var payload = reader.ReadString();
|
||||||
additionalPayload.Read(reader);
|
|
||||||
|
|
||||||
context.LobbyPlayer.Name = playerName;
|
if (key == _configuration.ServerKey)
|
||||||
context.LobbyPlayer.AdditionalData = Array.Empty<byte>();
|
{
|
||||||
context.LobbyPlayer.Status = LobbyPlayerStatus.Authorized;
|
if (_webHook.RequestAuthorization(context, name, payload))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var lobbyPlayer = new RagonLobbyPlayer(Guid.NewGuid().ToString(), name, payload);
|
||||||
|
context.SetPlayer(lobbyPlayer);
|
||||||
|
|
||||||
|
Approve(context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Reject(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Approve(RagonContext context)
|
||||||
|
{
|
||||||
|
context.ConnectionStatus = ConnectionStatus.Authorized;
|
||||||
|
|
||||||
var playerId = context.LobbyPlayer.Id;
|
var playerId = context.LobbyPlayer.Id;
|
||||||
|
var playerName = context.LobbyPlayer.Name;
|
||||||
|
var playerPayload = context.LobbyPlayer.Payload;
|
||||||
|
|
||||||
writer.Clear();
|
_writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.AUTHORIZED_SUCCESS);
|
_writer.WriteOperation(RagonOperation.AUTHORIZED_SUCCESS);
|
||||||
writer.WriteString(playerId);
|
_writer.WriteString(playerId);
|
||||||
writer.WriteString(playerName);
|
_writer.WriteString(playerName);
|
||||||
|
_writer.WriteString(playerPayload);
|
||||||
|
|
||||||
var sendData = writer.ToArray();
|
var sendData = _writer.ToArray();
|
||||||
context.Connection.Reliable.Send(sendData);
|
context.Connection.Reliable.Send(sendData);
|
||||||
|
|
||||||
_logger.Trace($"Connection {context.Connection.Id} as {playerId}|{context.LobbyPlayer.Name} authorized");
|
_logger.Trace($"Connection {context.Connection.Id} as {playerId}|{context.LobbyPlayer.Name} authorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Reject(RagonContext context)
|
||||||
|
{
|
||||||
|
_writer.Clear();
|
||||||
|
_writer.WriteOperation(RagonOperation.AUTHORIZED_FAILED);
|
||||||
|
|
||||||
|
var sendData = _writer.ToArray();
|
||||||
|
|
||||||
|
context.Connection.Reliable.Send(sendData);
|
||||||
|
context.Connection.Close();
|
||||||
|
|
||||||
|
_logger.Trace($"Connection {context.Connection.Id}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Entity;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityCreateOperation : IRagonOperation
|
public sealed class EntityCreateOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
@@ -32,7 +33,15 @@ public sealed class EntityCreateOperation : IRagonOperation
|
|||||||
var eventAuthority = (RagonAuthority) reader.ReadByte();
|
var eventAuthority = (RagonAuthority) reader.ReadByte();
|
||||||
var propertiesCount = reader.ReadUShort();
|
var propertiesCount = reader.ReadUShort();
|
||||||
|
|
||||||
var entity = new RagonEntity(player, entityType, 0, attachId, eventAuthority);
|
var entityParameters = new RagonEntityParameters()
|
||||||
|
{
|
||||||
|
Type = entityType,
|
||||||
|
Authority = eventAuthority,
|
||||||
|
AttachId = attachId,
|
||||||
|
StaticId = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var entity = new RagonEntity(entityParameters);
|
||||||
for (var i = 0; i < propertiesCount; i++)
|
for (var i = 0; i < propertiesCount; i++)
|
||||||
{
|
{
|
||||||
var propertyType = reader.ReadBool();
|
var propertyType = reader.ReadBool();
|
||||||
@@ -44,6 +53,11 @@ public sealed class EntityCreateOperation : IRagonOperation
|
|||||||
if (reader.Capacity > 0)
|
if (reader.Capacity > 0)
|
||||||
entity.Payload.Read(reader);
|
entity.Payload.Read(reader);
|
||||||
|
|
||||||
|
var roomPlugin = room.Plugin;
|
||||||
|
if (!roomPlugin.OnEntityCreate(player, entity))
|
||||||
|
return;
|
||||||
|
|
||||||
|
entity.Attach(player);
|
||||||
room.AttachEntity(entity);
|
room.AttachEntity(entity);
|
||||||
player.AttachEntity(entity);
|
player.AttachEntity(entity);
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Hander;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityEventOperation : IRagonOperation
|
public sealed class EntityEventOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-2
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Hander;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityDestroyOperation: IRagonOperation
|
public sealed class EntityDestroyOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
@@ -17,29 +17,25 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class EntityStateOperation: IRagonOperation
|
public sealed class EntityStateOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
|
var player = context.RoomPlayer;
|
||||||
var entitiesCount = reader.ReadUShort();
|
var entitiesCount = reader.ReadUShort();
|
||||||
|
|
||||||
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
|
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
|
||||||
{
|
{
|
||||||
var entityId = reader.ReadUShort();
|
var entityId = reader.ReadUShort();
|
||||||
if (room.Entities.TryGetValue(entityId, out var entity) && entity.Owner.Connection.Id == context.Connection.Id)
|
if (room.Entities.TryGetValue(entityId, out var entity))
|
||||||
{
|
entity.Read(player, reader);
|
||||||
entity.State.Read(reader);
|
|
||||||
room.Track(entity);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_logger.Error($"Entity with Id {entityId} not found, replication interrupted");
|
_logger.Error($"Entity with Id {entityId} not found, replication interrupted");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public interface IRagonOperation
|
public interface IRagonOperation
|
||||||
{
|
{
|
||||||
@@ -16,17 +16,28 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Hander;
|
||||||
|
|
||||||
public sealed class RoomCreateOperation: IRagonOperation
|
public sealed class RoomCreateOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private RagonRoomParameters _roomParameters = new();
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly WebHookPlugin _webHookPlugin;
|
||||||
|
|
||||||
|
public RoomCreateOperation(IServerPlugin serverPlugin, WebHookPlugin webHook)
|
||||||
|
{
|
||||||
|
_serverPlugin = serverPlugin;
|
||||||
|
_webHookPlugin = webHook;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
if (context.LobbyPlayer.Status == LobbyPlayerStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||||
return;
|
return;
|
||||||
@@ -62,17 +73,20 @@ public sealed class RoomCreateOperation: IRagonOperation
|
|||||||
};
|
};
|
||||||
|
|
||||||
var lobbyPlayer = context.LobbyPlayer;
|
var lobbyPlayer = context.LobbyPlayer;
|
||||||
|
var roomPlayer = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
|
|
||||||
|
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||||
|
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||||
|
|
||||||
var room = new RagonRoom(roomId, information);
|
|
||||||
context.Scheduler.Run(room);
|
context.Scheduler.Run(room);
|
||||||
context.Lobby.Persist(room);
|
context.Lobby.Persist(room);
|
||||||
|
context.SetRoom(room, roomPlayer);
|
||||||
|
|
||||||
var player = new RagonRoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
_webHookPlugin.RoomCreated(context, room);
|
||||||
context.SetRoom(room, player);
|
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} {information}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}");
|
||||||
|
|
||||||
JoinSuccess(player, room, writer);
|
JoinSuccess(roomPlayer, room, writer);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
|
||||||
}
|
}
|
||||||
@@ -84,9 +98,9 @@ public sealed class RoomCreateOperation: IRagonOperation
|
|||||||
writer.WriteString(room.Id);
|
writer.WriteString(room.Id);
|
||||||
writer.WriteString(player.Id);
|
writer.WriteString(player.Id);
|
||||||
writer.WriteString(room.Owner.Id);
|
writer.WriteString(room.Owner.Id);
|
||||||
writer.WriteUShort((ushort) room.Info.Min);
|
writer.WriteUShort((ushort) room.PlayerMin);
|
||||||
writer.WriteUShort((ushort) room.Info.Max);
|
writer.WriteUShort((ushort) room.PlayerMax);
|
||||||
writer.WriteString(room.Info.Map);
|
writer.WriteString(room.Map);
|
||||||
|
|
||||||
var sendData = writer.ToArray();
|
var sendData = writer.ToArray();
|
||||||
player.Connection.Reliable.Send(sendData);
|
player.Connection.Reliable.Send(sendData);
|
||||||
|
|||||||
@@ -16,12 +16,21 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Web;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomJoinOperation : IRagonOperation
|
public sealed class RoomJoinOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly WebHookPlugin _webHookPlugin;
|
||||||
|
|
||||||
|
public RoomJoinOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
|
||||||
|
{
|
||||||
|
_serverPlugin = serverPlugin;
|
||||||
|
_webHookPlugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
@@ -30,42 +39,47 @@ public sealed class RoomJoinOperation : IRagonOperation
|
|||||||
|
|
||||||
if (!context.Lobby.FindRoomById(roomId, out var existsRoom))
|
if (!context.Lobby.FindRoomById(roomId, out var existsRoom))
|
||||||
{
|
{
|
||||||
JoinFailed(lobbyPlayer, writer);
|
JoinFailed(context, writer);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} failed to join room {roomId}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} failed to join room {roomId}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var player = new RagonRoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
context.SetRoom(existsRoom, player);
|
context.SetRoom(existsRoom, player);
|
||||||
|
|
||||||
JoinSuccess(player, existsRoom, writer);
|
if (!_serverPlugin.OnRoomJoin(player, existsRoom))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_webHookPlugin.RoomJoined(context, existsRoom, player);
|
||||||
|
|
||||||
|
JoinSuccess(context, existsRoom, writer);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to {existsRoom.Id}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to {existsRoom.Id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void JoinSuccess(RagonRoomPlayer player, RagonRoom room, RagonBuffer writer)
|
private void JoinSuccess(RagonContext context, RagonRoom room, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
writer.Clear();
|
writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.JOIN_SUCCESS);
|
writer.WriteOperation(RagonOperation.JOIN_SUCCESS);
|
||||||
writer.WriteString(room.Id);
|
writer.WriteString(room.Id);
|
||||||
writer.WriteString(player.Id);
|
writer.WriteString(context.RoomPlayer.Id);
|
||||||
writer.WriteString(room.Owner.Id);
|
writer.WriteString(room.Owner.Id);
|
||||||
writer.WriteUShort((ushort) room.Info.Min);
|
writer.WriteUShort((ushort) room.PlayerMin);
|
||||||
writer.WriteUShort((ushort) room.Info.Max);
|
writer.WriteUShort((ushort) room.PlayerMax);
|
||||||
writer.WriteString(room.Info.Map);
|
writer.WriteString(room.Map);
|
||||||
|
|
||||||
var sendData = writer.ToArray();
|
var sendData = writer.ToArray();
|
||||||
player.Connection.Reliable.Send(sendData);
|
context.Connection.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void JoinFailed(RagonLobbyPlayer player, RagonBuffer writer)
|
private void JoinFailed(RagonContext context, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
writer.Clear();
|
writer.Clear();
|
||||||
writer.WriteOperation(RagonOperation.JOIN_FAILED);
|
writer.WriteOperation(RagonOperation.JOIN_FAILED);
|
||||||
writer.WriteString($"Room not exists");
|
writer.WriteString($"Room not exists");
|
||||||
|
|
||||||
var sendData = writer.ToArray();
|
var sendData = writer.ToArray();
|
||||||
player.Connection.Reliable.Send(sendData);
|
context.Connection.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,17 +16,26 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Web;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomJoinOrCreateOperation : IRagonOperation
|
public sealed class RoomJoinOrCreateOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private RagonRoomParameters _roomParameters = new();
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly WebHookPlugin _webHookPlugin;
|
||||||
|
|
||||||
|
public RoomJoinOrCreateOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
|
||||||
|
{
|
||||||
|
_serverPlugin = serverPlugin;
|
||||||
|
_webHookPlugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
if (context.LobbyPlayer.Status == LobbyPlayerStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
{
|
{
|
||||||
_logger.Warn("Player not authorized for this request");
|
_logger.Warn("Player not authorized for this request");
|
||||||
return;
|
return;
|
||||||
@@ -39,9 +48,11 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
|
|||||||
|
|
||||||
if (context.Lobby.FindRoomByMap(_roomParameters.Map, out var existsRoom))
|
if (context.Lobby.FindRoomByMap(_roomParameters.Map, out var existsRoom))
|
||||||
{
|
{
|
||||||
var player = new RagonRoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
context.SetRoom(existsRoom, player);
|
context.SetRoom(existsRoom, player);
|
||||||
|
|
||||||
|
_webHookPlugin.RoomJoined(context, existsRoom, player);
|
||||||
|
|
||||||
JoinSuccess(player, existsRoom, writer);
|
JoinSuccess(player, existsRoom, writer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -53,14 +64,17 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
|
|||||||
Min = _roomParameters.Min,
|
Min = _roomParameters.Min,
|
||||||
};
|
};
|
||||||
|
|
||||||
var room = new RagonRoom(roomId, information);
|
var roomPlayer = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
|
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||||
|
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||||
|
|
||||||
|
_webHookPlugin.RoomCreated(context, room);
|
||||||
|
|
||||||
context.Lobby.Persist(room);
|
context.Lobby.Persist(room);
|
||||||
context.Scheduler.Run(room);
|
context.Scheduler.Run(room);
|
||||||
|
|
||||||
var roomPlayer = new RagonRoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
|
||||||
context.SetRoom(room, roomPlayer);
|
context.SetRoom(room, roomPlayer);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} {information}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}");
|
||||||
|
|
||||||
JoinSuccess(roomPlayer, room, writer);
|
JoinSuccess(roomPlayer, room, writer);
|
||||||
}
|
}
|
||||||
@@ -73,9 +87,9 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
|
|||||||
writer.WriteString(room.Id);
|
writer.WriteString(room.Id);
|
||||||
writer.WriteString(player.Id);
|
writer.WriteString(player.Id);
|
||||||
writer.WriteString(room.Owner.Id);
|
writer.WriteString(room.Owner.Id);
|
||||||
writer.WriteUShort((ushort) room.Info.Min);
|
writer.WriteUShort((ushort) room.PlayerMin);
|
||||||
writer.WriteUShort((ushort) room.Info.Max);
|
writer.WriteUShort((ushort) room.PlayerMax);
|
||||||
writer.WriteString(room.Info.Map);
|
writer.WriteString(room.Map);
|
||||||
|
|
||||||
var sendData = writer.ToArray();
|
var sendData = writer.ToArray();
|
||||||
player.Connection.Reliable.Send(sendData);
|
player.Connection.Reliable.Send(sendData);
|
||||||
|
|||||||
@@ -16,18 +16,30 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class RoomLeaveOperation: IRagonOperation
|
public sealed class RoomLeaveOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly WebHookPlugin _webHookPlugin;
|
||||||
|
public RoomLeaveOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
|
||||||
|
{
|
||||||
|
_serverPlugin = serverPlugin;
|
||||||
|
_webHookPlugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
var room = context.Room;
|
var room = context.Room;
|
||||||
var roomPlayer = context.RoomPlayer;
|
var roomPlayer = context.RoomPlayer;
|
||||||
|
|
||||||
if (room != null)
|
if (room != null)
|
||||||
{
|
{
|
||||||
|
_serverPlugin.OnRoomLeave(roomPlayer, room);
|
||||||
|
_webHookPlugin.RoomLeaved(context, room, roomPlayer);
|
||||||
context.Room?.DetachPlayer(roomPlayer);
|
context.Room?.DetachPlayer(roomPlayer);
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public class SceneLoadOperation: IRagonOperation
|
public class SceneLoadOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,16 +16,23 @@
|
|||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Entity;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Handler;
|
||||||
|
|
||||||
public sealed class SceneLoadedOperation : IRagonOperation
|
public sealed class SceneLoadedOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public SceneLoadedOperation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
{
|
{
|
||||||
if (context.LobbyPlayer.Status == LobbyPlayerStatus.Unauthorized)
|
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var owner = context.Room.Owner;
|
var owner = context.Room.Owner;
|
||||||
@@ -34,6 +41,7 @@ public sealed class SceneLoadedOperation : IRagonOperation
|
|||||||
|
|
||||||
if (player == owner)
|
if (player == owner)
|
||||||
{
|
{
|
||||||
|
|
||||||
var statics = reader.ReadUShort();
|
var statics = reader.ReadUShort();
|
||||||
for (var staticIndex = 0; staticIndex < statics; staticIndex++)
|
for (var staticIndex = 0; staticIndex < statics; staticIndex++)
|
||||||
{
|
{
|
||||||
@@ -42,7 +50,15 @@ public sealed class SceneLoadedOperation : IRagonOperation
|
|||||||
var staticId = reader.ReadUShort();
|
var staticId = reader.ReadUShort();
|
||||||
var propertiesCount = reader.ReadUShort();
|
var propertiesCount = reader.ReadUShort();
|
||||||
|
|
||||||
var entity = new RagonEntity(player, entityType, staticId, 0, eventAuthority);
|
var entityParameters = new RagonEntityParameters()
|
||||||
|
{
|
||||||
|
Type = entityType,
|
||||||
|
Authority = eventAuthority,
|
||||||
|
AttachId = 0,
|
||||||
|
StaticId = staticId,
|
||||||
|
};
|
||||||
|
|
||||||
|
var entity = new RagonEntity(entityParameters);
|
||||||
for (var propertyIndex = 0; propertyIndex < propertiesCount; propertyIndex++)
|
for (var propertyIndex = 0; propertyIndex < propertiesCount; propertyIndex++)
|
||||||
{
|
{
|
||||||
var propertyType = reader.ReadBool();
|
var propertyType = reader.ReadBool();
|
||||||
@@ -50,11 +66,15 @@ public sealed class SceneLoadedOperation : IRagonOperation
|
|||||||
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var roomPlugin = room.Plugin;
|
||||||
|
if (roomPlugin.OnEntityCreate(player, entity)) continue;
|
||||||
|
|
||||||
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
||||||
var entityInfo = $"{entity.Id}:{entity.Type}";
|
var entityInfo = $"{entity.Id}:{entity.Type}";
|
||||||
|
|
||||||
_logger.Trace($"{playerInfo} created entity {entityInfo}");
|
_logger.Trace($"{playerInfo} created entity {entityInfo}");
|
||||||
|
|
||||||
|
entity.Attach(player);
|
||||||
room.AttachEntity(entity);
|
room.AttachEntity(entity);
|
||||||
player.AttachEntity(entity);
|
player.AttachEntity(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public class Executor: TaskScheduler, IExecutor
|
public class Executor: TaskScheduler, IExecutor
|
||||||
{
|
{
|
||||||
@@ -25,9 +25,9 @@ public class Executor: TaskScheduler, IExecutor
|
|||||||
private Queue<Task> _pendingTasks;
|
private Queue<Task> _pendingTasks;
|
||||||
private TaskFactory _taskFactory;
|
private TaskFactory _taskFactory;
|
||||||
|
|
||||||
public void Run(Action action)
|
public Task Run(Action action)
|
||||||
{
|
{
|
||||||
_taskFactory.StartNew(action);
|
return _taskFactory.StartNew(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Executor()
|
public Executor()
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public interface IExecutor
|
public interface IExecutor
|
||||||
{
|
{
|
||||||
public void Run(Action action);
|
public Task Run(Action action);
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public interface INetworkChannel
|
public interface INetworkChannel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public interface INetworkConnection
|
public interface INetworkConnection
|
||||||
{
|
{
|
||||||
public ushort Id { get; }
|
public ushort Id { get; }
|
||||||
public INetworkChannel Reliable { get; }
|
public INetworkChannel Reliable { get; }
|
||||||
public INetworkChannel Unreliable { get; }
|
public INetworkChannel Unreliable { get; }
|
||||||
|
public void Close();
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public interface INetworkListener
|
public interface INetworkListener
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public interface INetworkServer
|
public interface INetworkServer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.IO;
|
||||||
|
|
||||||
public struct NetworkConfiguration
|
public struct NetworkConfiguration
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,13 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Lobby;
|
||||||
|
|
||||||
public interface IRagonLobby
|
public interface IRagonLobby
|
||||||
{
|
{
|
||||||
public bool FindRoomById(string roomId, [MaybeNullWhen(false)] out RagonRoom room);
|
public bool FindRoomById(string roomId, [MaybeNullWhen(false)] out RagonRoom room);
|
||||||
public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room);
|
public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room);
|
||||||
public void Persist(RagonRoom room);
|
public void Persist(RagonRoom room);
|
||||||
public void RemoveIfEmpty(RagonRoom room);
|
public bool RemoveIfEmpty(RagonRoom room);
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Lobby;
|
||||||
|
|
||||||
public class LobbyInMemory : IRagonLobby
|
public class LobbyInMemory : IRagonLobby
|
||||||
{
|
{
|
||||||
@@ -28,8 +29,7 @@ public class LobbyInMemory : IRagonLobby
|
|||||||
{
|
{
|
||||||
foreach (var existRagonRoom in _rooms)
|
foreach (var existRagonRoom in _rooms)
|
||||||
{
|
{
|
||||||
var info = existRagonRoom.Info;
|
if (existRagonRoom.Id == RagonRoomId && existRagonRoom.PlayerMin < existRagonRoom.PlayerMax)
|
||||||
if (existRagonRoom.Id == RagonRoomId && info.Min < info.Max)
|
|
||||||
{
|
{
|
||||||
room = existRagonRoom;
|
room = existRagonRoom;
|
||||||
return true;
|
return true;
|
||||||
@@ -44,8 +44,7 @@ public class LobbyInMemory : IRagonLobby
|
|||||||
{
|
{
|
||||||
foreach (var existsRoom in _rooms)
|
foreach (var existsRoom in _rooms)
|
||||||
{
|
{
|
||||||
var info = existsRoom.Info;
|
if (existsRoom.Map == map && existsRoom.PlayerCount < existsRoom.PlayerMax)
|
||||||
if (info.Map == map && existsRoom.Players.Count < info.Max)
|
|
||||||
{
|
{
|
||||||
room = existsRoom;
|
room = existsRoom;
|
||||||
return true;
|
return true;
|
||||||
@@ -62,18 +61,23 @@ public class LobbyInMemory : IRagonLobby
|
|||||||
_logger.Trace($"New room: {room.Id}");
|
_logger.Trace($"New room: {room.Id}");
|
||||||
|
|
||||||
foreach (var r in _rooms)
|
foreach (var r in _rooms)
|
||||||
_logger.Trace($"Room: {r.Id} {r.Info} Players: {r.Players.Count} Entities: {r.Entities.Count}");
|
_logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveIfEmpty(RagonRoom room)
|
public bool RemoveIfEmpty(RagonRoom room)
|
||||||
{
|
{
|
||||||
|
var result = false;
|
||||||
if (room.Players.Count == 0)
|
if (room.Players.Count == 0)
|
||||||
{
|
{
|
||||||
_rooms.Remove(room);
|
_rooms.Remove(room);
|
||||||
_logger.Trace($"Room {room.Id} removed");
|
_logger.Trace($"Room {room.Id} removed");
|
||||||
|
|
||||||
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var r in _rooms)
|
foreach (var r in _rooms)
|
||||||
_logger.Trace($"Room: {r.Id} {r.Info} Players: {r.Players.Count} Entities: {r.Entities.Count}");
|
_logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}");
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,28 +14,25 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Lobby;
|
||||||
|
|
||||||
public enum LobbyPlayerStatus
|
public enum ConnectionStatus
|
||||||
{
|
{
|
||||||
Unauthorized,
|
Unauthorized,
|
||||||
|
InProcess,
|
||||||
Authorized,
|
Authorized,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RagonLobbyPlayer
|
public class RagonLobbyPlayer
|
||||||
{
|
{
|
||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; private set; }
|
||||||
public byte[] AdditionalData { get; set; }
|
public string Payload { get; private set; }
|
||||||
public LobbyPlayerStatus Status { get; set; }
|
|
||||||
public INetworkConnection Connection { get; private set; }
|
|
||||||
|
|
||||||
public RagonLobbyPlayer(INetworkConnection connection)
|
public RagonLobbyPlayer(string id, string name, string payload)
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid().ToString();
|
Id = id;
|
||||||
Connection = connection;
|
Name = name;
|
||||||
Status = LobbyPlayerStatus.Unauthorized;
|
Payload = payload;
|
||||||
Name = "None";
|
|
||||||
AdditionalData = Array.Empty<byte>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Ragon.Server.Plugin;
|
||||||
|
|
||||||
|
public interface IRoomPlugin
|
||||||
|
{
|
||||||
|
void Tick(float dt);
|
||||||
|
void OnAttached();
|
||||||
|
void OnDetached();
|
||||||
|
bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity);
|
||||||
|
bool OnEntityRemove(RagonRoomPlayer remover, RagonEntity entity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.Server.Lobby;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Plugin;
|
||||||
|
|
||||||
|
public interface IServerPlugin
|
||||||
|
{
|
||||||
|
bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room);
|
||||||
|
bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room);
|
||||||
|
bool OnRoomLeave(RagonRoomPlayer player, RagonRoom room);
|
||||||
|
bool OnRoomJoin(RagonRoomPlayer player, RagonRoom room);
|
||||||
|
|
||||||
|
IRoomPlugin CreateRoomPlugin(RoomInformation information);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class AuthorizationRequest
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
public string Token;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class RoomCreatedRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
public class RoomJoinedRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class RoomLeavedRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class RoomRemovedRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Ragon.Server.Plugin.Web;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class AuthorizationResponse
|
||||||
|
{
|
||||||
|
public string Id;
|
||||||
|
public string Name;
|
||||||
|
public string Payload;
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Plugin.Web;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Plugin;
|
||||||
|
|
||||||
|
public class WebHookPlugin
|
||||||
|
{
|
||||||
|
private Dictionary<string, string> _webHooks;
|
||||||
|
|
||||||
|
private RagonServer _server;
|
||||||
|
private HttpClient _httpClient;
|
||||||
|
|
||||||
|
public WebHookPlugin(RagonServer server, Configuration configuration)
|
||||||
|
{
|
||||||
|
_webHooks = new Dictionary<string, string>(configuration.WebHooks);
|
||||||
|
_httpClient = new HttpClient();
|
||||||
|
_server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool RequestAuthorization(RagonContext context, string name, string password)
|
||||||
|
{
|
||||||
|
if (_webHooks.TryGetValue("authorization-request", out var value))
|
||||||
|
{
|
||||||
|
var httpContent = new StringContent("");
|
||||||
|
var executor = context.Executor;
|
||||||
|
executor.Run(async () =>
|
||||||
|
{
|
||||||
|
var authorizationOperation = (AuthorizationOperation) _server.Resolve(RagonOperation.AUTHORIZE);
|
||||||
|
var response = await _httpClient.PostAsync(new Uri(value), httpContent);
|
||||||
|
if (response.StatusCode != HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
authorizationOperation.Reject(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
var authorizationResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(content);
|
||||||
|
if (authorizationResponse != null)
|
||||||
|
{
|
||||||
|
var lobbyPlayer = new RagonLobbyPlayer(authorizationResponse.Id, authorizationResponse.Name, authorizationResponse.Payload);
|
||||||
|
|
||||||
|
context.SetPlayer(lobbyPlayer);
|
||||||
|
authorizationOperation.Approve(context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
authorizationOperation.Reject(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RoomCreated(RagonContext context, RagonRoom room)
|
||||||
|
{
|
||||||
|
if (_webHooks.TryGetValue("room-created", out var value) && !string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
var request = new RoomCreatedRequest()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
var content = JsonContent.Create(request);
|
||||||
|
var executor = context.Executor;
|
||||||
|
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RoomRemoved(RagonContext context, RagonRoom ragonRoom)
|
||||||
|
{
|
||||||
|
if (_webHooks.TryGetValue("room-removed", out var value) && !string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
var request = new RoomCreatedRequest()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
var content = JsonContent.Create(request);
|
||||||
|
var executor = context.Executor;
|
||||||
|
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RoomJoined(RagonContext context, RagonRoom existsRoom, RagonRoomPlayer player)
|
||||||
|
{
|
||||||
|
if (_webHooks.TryGetValue("room-joined", out var value) && !string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
var request = new RoomCreatedRequest()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
var content = JsonContent.Create(request);
|
||||||
|
var executor = context.Executor;
|
||||||
|
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RoomLeaved(RagonContext context, RagonRoom room, RagonRoomPlayer roomPlayer)
|
||||||
|
{
|
||||||
|
if (_webHooks.TryGetValue("room-leaved", out var value) && !string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
var request = new RoomCreatedRequest()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
var content = JsonContent.Create(request);
|
||||||
|
var executor = context.Executor;
|
||||||
|
executor.Run(() => _httpClient.PostAsync(new Uri(value), content, CancellationToken.None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,31 +14,44 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Ragon.Core.Time;
|
using Ragon.Server.IO;
|
||||||
using Ragon.Server;
|
using Ragon.Server.Lobby;
|
||||||
|
using Ragon.Server.Time;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
public class RagonContext
|
public class RagonContext
|
||||||
{
|
{
|
||||||
public INetworkConnection Connection { get; }
|
public INetworkConnection Connection { get; }
|
||||||
|
public ConnectionStatus ConnectionStatus { get; set; }
|
||||||
|
|
||||||
public IExecutor Executor { get; private set; }
|
public IExecutor Executor { get; private set; }
|
||||||
|
|
||||||
public IRagonLobby Lobby { get; private set; }
|
public IRagonLobby Lobby { get; private set; }
|
||||||
public RagonLobbyPlayer LobbyPlayer { get; private set; }
|
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
||||||
|
|
||||||
public RagonRoom? Room { get; private set; }
|
public RagonRoom? Room { get; private set; }
|
||||||
public RagonRoomPlayer? RoomPlayer { get; private set; }
|
public RagonRoomPlayer? RoomPlayer { get; private set; }
|
||||||
|
|
||||||
public RagonScheduler Scheduler { get; private set; }
|
public RagonScheduler Scheduler { get; private set; }
|
||||||
|
|
||||||
public RagonContext(INetworkConnection connection, IExecutor executor, IRagonLobby lobby, RagonScheduler scheduler, RagonLobbyPlayer lobbyPlayer)
|
public RagonContext(
|
||||||
|
INetworkConnection connection,
|
||||||
|
IExecutor executor,
|
||||||
|
IRagonLobby lobby,
|
||||||
|
RagonScheduler scheduler)
|
||||||
{
|
{
|
||||||
|
ConnectionStatus = ConnectionStatus.Unauthorized;
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
Executor = executor;
|
Executor = executor;
|
||||||
Lobby = lobby;
|
Lobby = lobby;
|
||||||
Scheduler = scheduler;
|
Scheduler = scheduler;
|
||||||
LobbyPlayer = lobbyPlayer;
|
}
|
||||||
|
|
||||||
|
internal void SetPlayer(RagonLobbyPlayer player)
|
||||||
|
{
|
||||||
|
LobbyPlayer = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetRoom(RagonRoom room, RagonRoomPlayer player)
|
internal void SetRoom(RagonRoom room, RagonRoomPlayer player)
|
||||||
|
|||||||
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Core.Time;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server;
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Time;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ public class RagonServer : INetworkListener
|
|||||||
private readonly INetworkServer _server;
|
private readonly INetworkServer _server;
|
||||||
private readonly Thread _dedicatedThread;
|
private readonly Thread _dedicatedThread;
|
||||||
private readonly Executor _executor;
|
private readonly Executor _executor;
|
||||||
|
private readonly WebHookPlugin _webhooks;
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
private readonly IRagonOperation[] _handlers;
|
private readonly IRagonOperation[] _handlers;
|
||||||
private readonly RagonBuffer _reader;
|
private readonly RagonBuffer _reader;
|
||||||
@@ -35,50 +36,56 @@ public class RagonServer : INetworkListener
|
|||||||
private readonly IRagonLobby _lobby;
|
private readonly IRagonLobby _lobby;
|
||||||
private readonly RagonScheduler _scheduler;
|
private readonly RagonScheduler _scheduler;
|
||||||
private readonly Dictionary<ushort, RagonContext> _contexts;
|
private readonly Dictionary<ushort, RagonContext> _contexts;
|
||||||
private long _tickrate = 0;
|
private readonly Stopwatch _timer;
|
||||||
private Stopwatch _timer;
|
private readonly long _tickRate = 0;
|
||||||
|
|
||||||
public RagonServer(INetworkServer server, Configuration configuration)
|
public RagonServer(
|
||||||
|
INetworkServer server,
|
||||||
|
IServerPlugin plugin,
|
||||||
|
Configuration configuration)
|
||||||
{
|
{
|
||||||
_server = server;
|
_server = server;
|
||||||
_executor = _server.Executor;
|
_executor = _server.Executor;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_dedicatedThread = new Thread(Execute);
|
|
||||||
_dedicatedThread.IsBackground = true;
|
|
||||||
_contexts = new Dictionary<ushort, RagonContext>();
|
_contexts = new Dictionary<ushort, RagonContext>();
|
||||||
_lobby = new LobbyInMemory();
|
_lobby = new LobbyInMemory();
|
||||||
_scheduler = new RagonScheduler();
|
_scheduler = new RagonScheduler();
|
||||||
|
_webhooks = new WebHookPlugin(this, configuration);
|
||||||
|
_dedicatedThread = new Thread(Execute);
|
||||||
|
_dedicatedThread.IsBackground = true;
|
||||||
|
|
||||||
_reader = new RagonBuffer();
|
_reader = new RagonBuffer();
|
||||||
_writer = new RagonBuffer();
|
_writer = new RagonBuffer();
|
||||||
_tickrate = 1000 / _configuration.ServerTickRate;
|
_tickRate = 1000 / _configuration.ServerTickRate;
|
||||||
_timer = new Stopwatch();
|
_timer = new Stopwatch();
|
||||||
|
|
||||||
_handlers = new IRagonOperation[byte.MaxValue];
|
_handlers = new IRagonOperation[byte.MaxValue];
|
||||||
_handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation();
|
_handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation(_webhooks, _writer, configuration);
|
||||||
_handlers[(byte) RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation();
|
_handlers[(byte) RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.CREATE_ROOM] = new RoomCreateOperation();
|
_handlers[(byte) RagonOperation.CREATE_ROOM] = new RoomCreateOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.JOIN_ROOM] = new RoomJoinOperation();
|
_handlers[(byte) RagonOperation.JOIN_ROOM] = new RoomJoinOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation();
|
_handlers[(byte) RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.LOAD_SCENE] = new SceneLoadOperation();
|
_handlers[(byte) RagonOperation.LOAD_SCENE] = new SceneLoadOperation();
|
||||||
_handlers[(byte) RagonOperation.SCENE_LOADED] = new SceneLoadedOperation();
|
_handlers[(byte) RagonOperation.SCENE_LOADED] = new SceneLoadedOperation();
|
||||||
_handlers[(byte) RagonOperation.CREATE_ENTITY] = new EntityCreateOperation();
|
_handlers[(byte) RagonOperation.CREATE_ENTITY] = new EntityCreateOperation();
|
||||||
_handlers[(byte) RagonOperation.DESTROY_ENTITY] = new EntityDestroyOperation();
|
_handlers[(byte) RagonOperation.REMOVE_ENTITY] = new EntityDestroyOperation();
|
||||||
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation();
|
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation();
|
||||||
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation();
|
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation();
|
||||||
|
|
||||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IRagonOperation Resolve(RagonOperation operation) => _handlers[(byte)operation];
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (_timer.ElapsedMilliseconds > _tickrate)
|
if (_timer.ElapsedMilliseconds > _tickRate)
|
||||||
{
|
{
|
||||||
_executor.Update();
|
_executor.Update();
|
||||||
_scheduler.Update();
|
_scheduler.Update(_timer.ElapsedMilliseconds / 1000.0f);
|
||||||
_timer.Restart();
|
_timer.Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,8 +120,7 @@ public class RagonServer : INetworkListener
|
|||||||
|
|
||||||
public void OnConnected(INetworkConnection connection)
|
public void OnConnected(INetworkConnection connection)
|
||||||
{
|
{
|
||||||
var lobbyPlayer = new RagonLobbyPlayer(connection);
|
var context = new RagonContext(connection, _executor, _lobby, _scheduler);
|
||||||
var context = new RagonContext(connection, _executor, _lobby, _scheduler, lobbyPlayer);
|
|
||||||
|
|
||||||
_logger.Trace($"Connected: {connection.Id}");
|
_logger.Trace($"Connected: {connection.Id}");
|
||||||
_contexts.Add(connection.Id, context);
|
_contexts.Add(connection.Id, context);
|
||||||
@@ -128,10 +134,11 @@ public class RagonServer : INetworkListener
|
|||||||
if (room != null)
|
if (room != null)
|
||||||
{
|
{
|
||||||
room.DetachPlayer(context.RoomPlayer);
|
room.DetachPlayer(context.RoomPlayer);
|
||||||
_lobby.RemoveIfEmpty(room);
|
if (_lobby.RemoveIfEmpty(room))
|
||||||
|
_webhooks.RoomRemoved(context, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace($"Disconnected: {connection.Id}|{context.LobbyPlayer.Name}|{context.LobbyPlayer.Id}");
|
_logger.Trace($"Disconnected: {connection.Id}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -168,7 +175,6 @@ public class RagonServer : INetworkListener
|
|||||||
_reader.Clear();
|
_reader.Clear();
|
||||||
_reader.FromArray(data);
|
_reader.FromArray(data);
|
||||||
|
|
||||||
// Console.WriteLine($"{string.Join(",", data.Select(d => d.ToString()))}");
|
|
||||||
var operation = _reader.ReadByte();
|
var operation = _reader.ReadByte();
|
||||||
_handlers[operation].Handle(context, _reader, _writer);
|
_handlers[operation].Handle(context, _reader, _writer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ public enum ServerType
|
|||||||
WEBSOCKET,
|
WEBSOCKET,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class WebHook
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct Configuration
|
public struct Configuration
|
||||||
{
|
{
|
||||||
@@ -36,6 +41,7 @@ public struct Configuration
|
|||||||
public int LimitConnections;
|
public int LimitConnections;
|
||||||
public int LimitPlayersPerRoom;
|
public int LimitPlayersPerRoom;
|
||||||
public int LimitRooms;
|
public int LimitRooms;
|
||||||
|
public Dictionary<string, string> WebHooks;
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
private static readonly string ServerVersion = "1.1.3-rc";
|
private static readonly string ServerVersion = "1.1.3-rc";
|
||||||
@@ -45,20 +51,6 @@ public struct Configuration
|
|||||||
{"websocket", Server.ServerType.WEBSOCKET}
|
{"websocket", Server.ServerType.WEBSOCKET}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static void CopyrightInfo()
|
|
||||||
{
|
|
||||||
Logger.Info($"Server Version: {ServerVersion}");
|
|
||||||
Logger.Info($"Machine Name: {Environment.MachineName}");
|
|
||||||
Logger.Info($"OS: {Environment.OSVersion}");
|
|
||||||
Logger.Info($"Processors: {Environment.ProcessorCount}");
|
|
||||||
Logger.Info($"Runtime Version: {Environment.Version}");
|
|
||||||
Logger.Info("==================================");
|
|
||||||
Logger.Info("| |");
|
|
||||||
Logger.Info("| Ragon |");
|
|
||||||
Logger.Info("| |");
|
|
||||||
Logger.Info("==================================");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Configuration Load(string filePath)
|
public static Configuration Load(string filePath)
|
||||||
{
|
{
|
||||||
CopyrightInfo();
|
CopyrightInfo();
|
||||||
@@ -68,5 +60,20 @@ public struct Configuration
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CopyrightInfo()
|
||||||
|
{
|
||||||
|
Logger.Info($"Server Version: {ServerVersion}");
|
||||||
|
Logger.Info($"Machine Name: {Environment.MachineName}");
|
||||||
|
Logger.Info($"OS: {Environment.OSVersion}");
|
||||||
|
Logger.Info($"Processors: {Environment.ProcessorCount}");
|
||||||
|
Logger.Info($"Runtime Version: {Environment.Version}");
|
||||||
|
Logger.Info("==================================");
|
||||||
|
Logger.Info(@" ___ _ ___ ___ _ _ ");
|
||||||
|
Logger.Info(@" | _ \ /_\ / __|/ _ \| \| |");
|
||||||
|
Logger.Info(@" | / / _ \ (_ | (_) | .` |");
|
||||||
|
Logger.Info(@" |_|_\/_/ \_\___|\___/|_|\_|");
|
||||||
|
Logger.Info("==================================");
|
||||||
|
}
|
||||||
|
|
||||||
public static ServerType GetServerType(string type) => _serverTypes[type];
|
public static ServerType GetServerType(string type) => _serverTypes[type];
|
||||||
}
|
}
|
||||||
@@ -14,17 +14,24 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Ragon.Core.Time;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.Time;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server.Room;
|
||||||
|
|
||||||
public class RagonRoom: IRagonAction
|
public class RagonRoom : IRagonAction
|
||||||
{
|
{
|
||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public RoomInformation Info { get; private set; }
|
public string Map { get; private set; }
|
||||||
|
public int PlayerMax { get; private set; }
|
||||||
|
public int PlayerMin { get; private set; }
|
||||||
|
public int PlayerCount => WaitPlayersList.Count;
|
||||||
|
|
||||||
public RagonRoomPlayer Owner { get; private set; }
|
public RagonRoomPlayer Owner { get; private set; }
|
||||||
public RagonBuffer Writer { get; }
|
public RagonBuffer Writer { get; }
|
||||||
|
public IRoomPlugin Plugin { get; private set; }
|
||||||
|
|
||||||
public Dictionary<ushort, RagonRoomPlayer> Players { get; private set; }
|
public Dictionary<ushort, RagonRoomPlayer> Players { get; private set; }
|
||||||
public List<RagonRoomPlayer> WaitPlayersList { get; private set; }
|
public List<RagonRoomPlayer> WaitPlayersList { get; private set; }
|
||||||
public List<RagonRoomPlayer> ReadyPlayersList { get; private set; }
|
public List<RagonRoomPlayer> ReadyPlayersList { get; private set; }
|
||||||
@@ -37,10 +44,13 @@ public class RagonRoom: IRagonAction
|
|||||||
|
|
||||||
private readonly HashSet<RagonEntity> _entitiesDirtySet;
|
private readonly HashSet<RagonEntity> _entitiesDirtySet;
|
||||||
|
|
||||||
public RagonRoom(string roomId, RoomInformation info)
|
public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin)
|
||||||
{
|
{
|
||||||
Id = roomId;
|
Id = roomId;
|
||||||
Info = info;
|
Map = info.Map;
|
||||||
|
PlayerMax = info.Max;
|
||||||
|
PlayerMin = info.Min;
|
||||||
|
Plugin = roomPlugin;
|
||||||
|
|
||||||
Players = new Dictionary<ushort, RagonRoomPlayer>(info.Max);
|
Players = new Dictionary<ushort, RagonRoomPlayer>(info.Max);
|
||||||
WaitPlayersList = new List<RagonRoomPlayer>(info.Max);
|
WaitPlayersList = new List<RagonRoomPlayer>(info.Max);
|
||||||
@@ -78,9 +88,9 @@ public class RagonRoom: IRagonAction
|
|||||||
_entitiesDirtySet.Remove(entity);
|
_entitiesDirtySet.Remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick(float dt)
|
||||||
{
|
{
|
||||||
var entities = (ushort) _entitiesDirtySet.Count;
|
var entities = (ushort)_entitiesDirtySet.Count;
|
||||||
if (entities > 0)
|
if (entities > 0)
|
||||||
{
|
{
|
||||||
Writer.Clear();
|
Writer.Clear();
|
||||||
@@ -88,7 +98,7 @@ public class RagonRoom: IRagonAction
|
|||||||
Writer.WriteUShort(entities);
|
Writer.WriteUShort(entities);
|
||||||
|
|
||||||
foreach (var entity in _entitiesDirtySet)
|
foreach (var entity in _entitiesDirtySet)
|
||||||
entity.State.Write(Writer);
|
entity.Write(Writer);
|
||||||
|
|
||||||
_entitiesDirtySet.Clear();
|
_entitiesDirtySet.Clear();
|
||||||
|
|
||||||
@@ -121,7 +131,7 @@ public class RagonRoom: IRagonAction
|
|||||||
Writer.WriteString(player.Id);
|
Writer.WriteString(player.Id);
|
||||||
|
|
||||||
var entitiesToDelete = player.Entities.DynamicList;
|
var entitiesToDelete = player.Entities.DynamicList;
|
||||||
Writer.WriteUShort((ushort) entitiesToDelete.Count);
|
Writer.WriteUShort((ushort)entitiesToDelete.Count);
|
||||||
foreach (var entity in entitiesToDelete)
|
foreach (var entity in entitiesToDelete)
|
||||||
{
|
{
|
||||||
Writer.WriteUShort(entity.Id);
|
Writer.WriteUShort(entity.Id);
|
||||||
@@ -138,18 +148,18 @@ public class RagonRoom: IRagonAction
|
|||||||
|
|
||||||
Owner = nextOwner;
|
Owner = nextOwner;
|
||||||
|
|
||||||
var entitiesToUpdate = roomPlayer.Entities.StaticList;
|
var entitiesToUpdate = roomPlayer.Entities.StaticList;
|
||||||
|
|
||||||
Writer.Clear();
|
Writer.Clear();
|
||||||
Writer.WriteOperation(RagonOperation.OWNERSHIP_CHANGED);
|
Writer.WriteOperation(RagonOperation.OWNERSHIP_CHANGED);
|
||||||
Writer.WriteString(Owner.Id);
|
Writer.WriteString(Owner.Id);
|
||||||
Writer.WriteUShort((ushort) entitiesToUpdate.Count);
|
Writer.WriteUShort((ushort)entitiesToUpdate.Count);
|
||||||
|
|
||||||
foreach (var entity in entitiesToUpdate)
|
foreach (var entity in entitiesToUpdate)
|
||||||
{
|
{
|
||||||
Writer.WriteUShort(entity.Id);
|
Writer.WriteUShort(entity.Id);
|
||||||
|
|
||||||
entity.SetOwner(nextOwner);
|
entity.Attach(nextOwner);
|
||||||
nextOwner.Entities.Add(entity);
|
nextOwner.Entities.Add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,12 +180,7 @@ public class RagonRoom: IRagonAction
|
|||||||
|
|
||||||
public void UpdateMap(string sceneName)
|
public void UpdateMap(string sceneName)
|
||||||
{
|
{
|
||||||
Info = new RoomInformation()
|
Map = sceneName;
|
||||||
{
|
|
||||||
Max = Info.Max,
|
|
||||||
Min = Info.Min,
|
|
||||||
Map = sceneName,
|
|
||||||
};
|
|
||||||
|
|
||||||
DynamicEntitiesList.Clear();
|
DynamicEntitiesList.Clear();
|
||||||
StaticEntitiesList.Clear();
|
StaticEntitiesList.Clear();
|
||||||
|
|||||||
@@ -16,14 +16,9 @@
|
|||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
public class RoomInformation
|
public ref struct RoomInformation
|
||||||
{
|
{
|
||||||
public string Map { get; init; } = "none";
|
public string Map;
|
||||||
public int Min { get; init; }
|
public int Min;
|
||||||
public int Max { get; init; }
|
public int Max;
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"Map: {Map} Count: {Min}/{Max}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Server;
|
using Ragon.Server.IO;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Room;
|
||||||
|
|
||||||
public class RagonRoomPlayer
|
public class RagonRoomPlayer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Core.Time;
|
namespace Ragon.Server.Time;
|
||||||
|
|
||||||
public interface IRagonAction
|
public interface IRagonAction
|
||||||
{
|
{
|
||||||
public void Tick();
|
public void Tick(float dt);
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Ragon.Core.Time;
|
namespace Ragon.Server.Time;
|
||||||
|
|
||||||
public class RagonScheduler
|
public class RagonScheduler
|
||||||
{
|
{
|
||||||
@@ -35,9 +35,9 @@ public class RagonScheduler
|
|||||||
_tasks.Remove(task);
|
_tasks.Remove(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update(float dt)
|
||||||
{
|
{
|
||||||
foreach (var task in _tasks)
|
foreach (var task in _tasks)
|
||||||
task.Tick();
|
task.Tick(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user