feat(wip): room properties
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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)
|
||||
{
|
||||
@@ -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);
|
||||
|
||||
@@ -46,20 +46,21 @@ namespace Ragon.Client
|
||||
_callback = null!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
public int MaxPlayers => _parameters.Max;
|
||||
public string Scene => _scene.Name;
|
||||
|
||||
|
||||
public IReadOnlyList<RagonPlayer> Players => _playerCache.Players;
|
||||
public RagonPlayer Local => _playerCache.Local;
|
||||
public RagonPlayer Owner => _playerCache.Owner;
|
||||
@@ -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();
|
||||
|
||||
@@ -282,6 +282,7 @@ namespace Ragon.Protocol
|
||||
|
||||
_write += numBits;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint Read(int numBits = 16)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
||||
public int PlayerMax { get; private set; }
|
||||
public int PlayerMin { get; private set; }
|
||||
public int PlayerCount => WaitPlayersList.Count;
|
||||
|
||||
|
||||
public RagonData UserData { get; set; }
|
||||
public RagonRoomPlayer Owner { get; private set; }
|
||||
public RagonBuffer Writer { get; }
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user