feat(wip): room properties

This commit is contained in:
2024-05-05 15:45:28 +03:00
parent b4cba20d82
commit 6886808132
8 changed files with 43 additions and 13 deletions
@@ -55,7 +55,6 @@ namespace Ragon.Client
public ushort Id { get; private set; }
public ushort Type { get; private set; }
public RagonAuthority Authority { get; private set; }
public RagonPlayer Owner { get; private set; }
public RagonEntityState State { get; private set; }
@@ -4,9 +4,17 @@ namespace Ragon.Client
{
public class RoomDataHandler: IHandler
{
private readonly RagonClient _client;
public RoomDataHandler(RagonClient client)
{
_client = client;
}
public void Handle(RagonBuffer reader)
{
var len = reader.ReadUShort();
_client.Room?.Data(reader);
}
}
}
@@ -19,12 +19,12 @@ using Ragon.Protocol;
namespace Ragon.Client;
internal class RawDataHandler: IHandler
internal class RoomRawDataHandler: IHandler
{
private readonly RagonListenerList _listeners;
private readonly RagonPlayerCache _playerCache;
public RawDataHandler(
public RoomRawDataHandler(
RagonPlayerCache playerCache,
RagonListenerList listeners)
{
+1 -1
View File
@@ -121,7 +121,7 @@ namespace Ragon.Client
_handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventHandler(this, _playerCache);
_handlers[(byte)RagonOperation.SNAPSHOT] = new SnapshotHandler(this, _listeners, _entityCache, _playerCache, _entityListener);
_handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampHandler(this);
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RawDataHandler(_playerCache, _listeners);
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomRawDataHandler(_playerCache, _listeners);
_handlers[(byte)RagonOperation.ROOM_LIST_UPDATED] = new RoomListHandler(_session, _listeners);
var protocolRaw = RagonVersion.Parse(protocol);
+11 -5
View File
@@ -49,11 +49,12 @@ namespace Ragon.Client
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
private RagonClient _client;
private RagonScene _scene;
private RagonEntityCache _entityCache;
private RagonPlayerCache _playerCache;
private RoomParameters _parameters;
private readonly RagonClient _client;
private readonly RagonScene _scene;
private readonly RagonEntityCache _entityCache;
private readonly RagonPlayerCache _playerCache;
private readonly RoomParameters _parameters;
private readonly Dictionary<string, RagonProperty> _properties = new();
public string Id => _parameters.RoomId;
public int MinPlayers => _parameters.Min;
@@ -100,6 +101,11 @@ namespace Ragon.Client
RagonLog.Warn($"Handler event on entity {Id} with eventCode {eventCode} not defined");
}
internal void Data(RagonBuffer buffer)
{
}
public IDisposable OnEvent<TEvent>(Action<RagonPlayer, TEvent> callback) where TEvent : IRagonEvent, new()
{
var t = new TEvent();
+1
View File
@@ -283,6 +283,7 @@ namespace Ragon.Protocol
_write += numBits;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public uint Read(int numBits = 16)
{
+2
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
using Ragon.Server.Data;
using Ragon.Server.Entity;
using Ragon.Server.IO;
@@ -26,6 +27,7 @@ public interface IRagonRoom
public int PlayerMin { get; }
public int PlayerMax { get; }
public int PlayerCount { get; }
public RagonData UserData { get; }
RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection);
RagonRoomPlayer GetPlayerById(string id);
+14
View File
@@ -110,6 +110,20 @@ public class RagonRoom : IRagonRoom, IRagonAction
foreach (var roomPlayer in ReadyPlayersList)
roomPlayer.Connection.Unreliable.Send(sendData);
}
if (UserData.IsDirty)
{
Writer.Clear();
Writer.WriteOperation(RagonOperation.ROOM_DATA_UPDATED);
Writer.WriteUShort((ushort)UserData.Data.Length);
Writer.WriteBytes(UserData.Data);
var sendData = Writer.ToArray();
foreach (var roomPlayer in ReadyPlayersList)
roomPlayer.Connection.Reliable.Send(sendData);
UserData.IsDirty = false;
}
}
public void AttachPlayer(RagonRoomPlayer player)