feat(wip): player properties
This commit is contained in:
@@ -4,7 +4,7 @@ namespace Ragon.Server.Data;
|
||||
|
||||
public class RagonData
|
||||
{
|
||||
private byte[] _data = Array.Empty<byte>();
|
||||
private byte[] _data;
|
||||
public bool IsDirty { get; set; }
|
||||
public byte[] Data
|
||||
{
|
||||
|
||||
@@ -86,7 +86,6 @@ public sealed class AuthorizationOperation: BaseOperation
|
||||
|
||||
var playerId = context.LobbyPlayer.Id;
|
||||
var playerName = context.LobbyPlayer.Name;
|
||||
|
||||
var playerPayload = context.LobbyPlayer.Payload;
|
||||
|
||||
_writer.Clear();
|
||||
|
||||
@@ -5,7 +5,6 @@ using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler
|
||||
{
|
||||
|
||||
public class PlayerDataOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
@@ -24,20 +23,8 @@ namespace Ragon.Server.Handler
|
||||
|
||||
var playerDataLen = Reader.ReadUShort();
|
||||
var playerData = Reader.ReadBytes(playerDataLen);
|
||||
|
||||
var roomPlayer = context.RoomPlayer;
|
||||
if (roomPlayer != null)
|
||||
{
|
||||
roomPlayer.UserData.Data = playerData;
|
||||
return;
|
||||
}
|
||||
|
||||
var lobbyPlayer = context.RoomPlayer;
|
||||
if (lobbyPlayer != null)
|
||||
{
|
||||
lobbyPlayer.UserData.Data = playerData;
|
||||
}
|
||||
|
||||
|
||||
context.UserData.Data = playerData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
|
||||
@@ -28,22 +27,11 @@ public sealed class RoomDataOperation : BaseOperation
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
var playerDataLen = Reader.ReadUShort();
|
||||
var playerData = Reader.ReadBytes(playerDataLen);
|
||||
|
||||
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);
|
||||
if (room != null)
|
||||
room.UserData.Data = playerData;
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,13 @@ public class RagonLobbyPlayer
|
||||
public INetworkConnection Connection { get; }
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Payload { get; private set; }
|
||||
|
||||
public RagonData UserData { get; private set; }
|
||||
|
||||
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, byte[] payload)
|
||||
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, string payload)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Connection = connection;
|
||||
UserData = new RagonData(payload);
|
||||
Payload = payload;
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,7 @@ public class RagonWebHookPlugin
|
||||
var authorizationResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(content);
|
||||
if (authorizationResponse != null)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(authorizationResponse.Payload);
|
||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, authorizationResponse.Id, authorizationResponse.Name, bytes);
|
||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, authorizationResponse.Id, authorizationResponse.Name, authorizationResponse.Payload);
|
||||
|
||||
context.SetPlayer(lobbyPlayer);
|
||||
authorizationOperation.Approve(context);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Server.Data;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Lobby;
|
||||
using Ragon.Server.Time;
|
||||
@@ -29,10 +30,11 @@ public class RagonContext
|
||||
public int LimitBufferedEvents { get; private set; }
|
||||
public IRagonLobby Lobby { get; private set; }
|
||||
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
||||
|
||||
public RagonRoom? Room { get; private set; }
|
||||
public RagonRoomPlayer? RoomPlayer { get; private set; }
|
||||
|
||||
public RagonData UserData { get; private set; }
|
||||
|
||||
public RagonScheduler Scheduler { get; private set; }
|
||||
|
||||
public RagonContext(
|
||||
@@ -48,6 +50,7 @@ public class RagonContext
|
||||
Executor = executor;
|
||||
Lobby = lobby;
|
||||
Scheduler = scheduler;
|
||||
UserData = new RagonData(Array.Empty<byte>());
|
||||
}
|
||||
|
||||
internal void SetPlayer(RagonLobbyPlayer player)
|
||||
|
||||
@@ -74,6 +74,7 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
|
||||
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomList, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendUserData, 0.2f));
|
||||
|
||||
_serverPlugin.OnAttached(this);
|
||||
|
||||
@@ -246,6 +247,23 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
}
|
||||
}
|
||||
|
||||
public void SendUserData()
|
||||
{
|
||||
foreach (var (_, value) in _contextsByPlayerId)
|
||||
{
|
||||
if (value.UserData.IsDirty)
|
||||
{
|
||||
_writer.Clear();
|
||||
_writer.WriteOperation(RagonOperation.PLAYER_DATA_UPDATED);
|
||||
_writer.WriteUShort(value.Connection.Id);
|
||||
_writer.WriteBytes(value.UserData.Data);
|
||||
|
||||
var sendData = _writer.ToArray();
|
||||
_server.Broadcast(sendData, NetworkChannel.RELIABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseOperation ResolveHandler(RagonOperation operation)
|
||||
{
|
||||
return _handlers[(byte)operation];
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.Data;
|
||||
using Ragon.Server.Entity;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Plugin;
|
||||
@@ -29,7 +30,8 @@ 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; }
|
||||
public IRoomPlugin Plugin { get; private set; }
|
||||
|
||||
@@ -30,15 +30,12 @@ public class RagonRoomPlayer
|
||||
public RagonRoom Room { get; private set; }
|
||||
public RagonEntityCache Entities { get; private set; }
|
||||
|
||||
public RagonData UserData { get; private set; }
|
||||
|
||||
public RagonRoomPlayer(INetworkConnection connection, string id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Connection = connection;
|
||||
Entities = new RagonEntityCache();
|
||||
UserData = new RagonData(Array.Empty<byte>());
|
||||
}
|
||||
|
||||
public void AttachEntity(RagonEntity entity)
|
||||
|
||||
Reference in New Issue
Block a user