feat(wip): Room Property and Player Property
This commit is contained in:
@@ -29,12 +29,14 @@ public sealed class AuthorizationOperation: BaseOperation
|
||||
private readonly RagonWebHookPlugin _webhook;
|
||||
private readonly RagonContextObserver _observer;
|
||||
private readonly RagonBuffer _writer;
|
||||
private readonly RagonServerConfiguration _configuration;
|
||||
|
||||
public AuthorizationOperation(
|
||||
RagonBuffer reader,
|
||||
RagonBuffer writer,
|
||||
RagonWebHookPlugin webhook,
|
||||
RagonContextObserver observer): base(reader, writer)
|
||||
RagonContextObserver observer,
|
||||
RagonServerConfiguration configuration): base(reader, writer)
|
||||
{
|
||||
_webhook = webhook;
|
||||
_observer = observer;
|
||||
@@ -55,7 +57,7 @@ public sealed class AuthorizationOperation: BaseOperation
|
||||
return;
|
||||
}
|
||||
|
||||
var configuration = context.Configuration;
|
||||
var configuration = _configuration;
|
||||
var key = Reader.ReadString();
|
||||
var name = Reader.ReadString();
|
||||
var payload = Reader.ReadString();
|
||||
|
||||
@@ -44,7 +44,7 @@ public sealed class EntityCreateOperation : BaseOperation
|
||||
Authority = eventAuthority,
|
||||
AttachId = attachId,
|
||||
StaticId = 0,
|
||||
BufferedEvents = context.Configuration.LimitBufferedEvents,
|
||||
BufferedEvents = context.LimitBufferedEvents,
|
||||
};
|
||||
|
||||
var entity = new RagonEntity(entityParameters);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler
|
||||
{
|
||||
|
||||
public class PlayerDataOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PlayerDataOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||
{
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var playerDataLen = Reader.ReadUShort();
|
||||
var playerData = Reader.ReadBytes(playerDataLen);
|
||||
var player = context.RoomPlayer;
|
||||
|
||||
// player.SetData(playerData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class RoomRawDataOperation : BaseOperation
|
||||
{
|
||||
public RoomRawDataOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
var room = context.Room;
|
||||
|
||||
var data = Reader.RawData;
|
||||
var dataSize = data.Length - 1;
|
||||
var headerSize = 3;
|
||||
var size = headerSize + dataSize;
|
||||
var sendData = new byte[size];
|
||||
var peerId = player.Connection.Id;
|
||||
|
||||
sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA;
|
||||
sendData[1] = (byte)peerId;
|
||||
sendData[2] = (byte)(peerId >> 8);
|
||||
|
||||
Array.Copy(data, 1, sendData, headerSize, dataSize);
|
||||
|
||||
room.Broadcast(sendData, channel);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public sealed class SceneLoadedOperation : BaseOperation
|
||||
Authority = eventAuthority,
|
||||
AttachId = 0,
|
||||
StaticId = staticId,
|
||||
BufferedEvents = context.Configuration.LimitBufferedEvents,
|
||||
BufferedEvents = context.LimitBufferedEvents,
|
||||
};
|
||||
|
||||
var entity = new RagonEntity(entityParameters);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RagonContext
|
||||
public ConnectionStatus ConnectionStatus { get; set; }
|
||||
public INetworkConnection Connection { get; }
|
||||
public IExecutor Executor { get; private set; }
|
||||
public RagonServerConfiguration Configuration { get; private set; }
|
||||
public int LimitBufferedEvents { get; private set; }
|
||||
public IRagonLobby Lobby { get; private set; }
|
||||
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
||||
|
||||
@@ -36,14 +36,14 @@ public class RagonContext
|
||||
public RagonScheduler Scheduler { get; private set; }
|
||||
|
||||
public RagonContext(
|
||||
INetworkConnection connection,
|
||||
RagonServerConfiguration configuration,
|
||||
IExecutor executor,
|
||||
IRagonLobby lobby,
|
||||
RagonScheduler scheduler)
|
||||
INetworkConnection connection,
|
||||
IExecutor executor,
|
||||
IRagonLobby lobby,
|
||||
RagonScheduler scheduler,
|
||||
int limitBufferedEvents)
|
||||
{
|
||||
ConnectionStatus = ConnectionStatus.Unauthorized;
|
||||
Configuration = configuration;
|
||||
LimitBufferedEvents = limitBufferedEvents;
|
||||
Connection = connection;
|
||||
Executor = executor;
|
||||
Lobby = lobby;
|
||||
@@ -54,15 +54,14 @@ public class RagonContext
|
||||
{
|
||||
LobbyPlayer = player;
|
||||
}
|
||||
|
||||
|
||||
internal void SetRoom(RagonRoom room, RagonRoomPlayer player)
|
||||
{
|
||||
Room?.DetachPlayer(RoomPlayer);
|
||||
|
||||
|
||||
Room = room;
|
||||
RoomPlayer = player;
|
||||
|
||||
|
||||
Room.AttachPlayer(RoomPlayer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_serverPlugin.OnAttached(this);
|
||||
|
||||
_handlers = new BaseOperation[byte.MaxValue];
|
||||
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _webhooks, contextObserver);
|
||||
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _webhooks, contextObserver, configuration);
|
||||
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _webhooks);
|
||||
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin, _webhooks);
|
||||
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer, _webhooks);
|
||||
@@ -93,7 +93,9 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_handlers[(byte)RagonOperation.TRANSFER_ENTITY_OWNERSHIP] = new EntityOwnershipOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampSyncOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomRawDataOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomDataOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerDataOperation(_reader, _writer);
|
||||
|
||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||
}
|
||||
@@ -150,7 +152,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
|
||||
public void OnConnected(INetworkConnection connection)
|
||||
{
|
||||
var context = new RagonContext(connection, _configuration, _executor, _lobby, _scheduler);
|
||||
var context = new RagonContext(connection, _executor, _lobby, _scheduler, _configuration.LimitBufferedEvents);
|
||||
|
||||
_logger.Trace($"Connected: {connection.Id}");
|
||||
_contextsByConnection.Add(connection.Id, context);
|
||||
|
||||
Reference in New Issue
Block a user