feat(wip) room properties
This commit is contained in:
@@ -26,8 +26,7 @@ namespace Ragon.Client
|
|||||||
public ushort PeerId { get; set; }
|
public ushort PeerId { get; set; }
|
||||||
public bool IsRoomOwner { get; set; }
|
public bool IsRoomOwner { get; set; }
|
||||||
public bool IsLocal { get; set; }
|
public bool IsLocal { get; set; }
|
||||||
|
public byte[] Data { get; private set; }
|
||||||
public IRagonSerializable Data { get; set; }
|
|
||||||
|
|
||||||
public RagonPlayer(ushort peerId, string playerId, string name, bool isRoomOwner, bool isLocal)
|
public RagonPlayer(ushort peerId, string playerId, string name, bool isRoomOwner, bool isLocal)
|
||||||
{
|
{
|
||||||
@@ -37,5 +36,10 @@ namespace Ragon.Client
|
|||||||
Name = name;
|
Name = name;
|
||||||
Id = playerId;
|
Id = playerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetData(byte[] data)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Ragon.Protocol;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Data;
|
||||||
|
|
||||||
|
public class RagonData
|
||||||
|
{
|
||||||
|
private byte[] _data = Array.Empty<byte>();
|
||||||
|
public bool IsDirty { get; set; }
|
||||||
|
public byte[] Data
|
||||||
|
{
|
||||||
|
get => _data;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_data = value;
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonData(byte[] data)
|
||||||
|
{
|
||||||
|
_data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,7 @@ public sealed class AuthorizationOperation: BaseOperation
|
|||||||
|
|
||||||
var playerId = context.LobbyPlayer.Id;
|
var playerId = context.LobbyPlayer.Id;
|
||||||
var playerName = context.LobbyPlayer.Name;
|
var playerName = context.LobbyPlayer.Name;
|
||||||
|
|
||||||
var playerPayload = context.LobbyPlayer.Payload;
|
var playerPayload = context.LobbyPlayer.Payload;
|
||||||
|
|
||||||
_writer.Clear();
|
_writer.Clear();
|
||||||
|
|||||||
@@ -24,9 +24,20 @@ namespace Ragon.Server.Handler
|
|||||||
|
|
||||||
var playerDataLen = Reader.ReadUShort();
|
var playerDataLen = Reader.ReadUShort();
|
||||||
var playerData = Reader.ReadBytes(playerDataLen);
|
var playerData = Reader.ReadBytes(playerDataLen);
|
||||||
var player = context.RoomPlayer;
|
|
||||||
|
|
||||||
// player.SetData(playerData);
|
var roomPlayer = context.RoomPlayer;
|
||||||
|
if (roomPlayer != null)
|
||||||
|
{
|
||||||
|
roomPlayer.UserData.Data = playerData;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lobbyPlayer = context.RoomPlayer;
|
||||||
|
if (lobbyPlayer != null)
|
||||||
|
{
|
||||||
|
lobbyPlayer.UserData.Data = playerData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Ragon.Server.Data;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
|
||||||
namespace Ragon.Server.Lobby;
|
namespace Ragon.Server.Lobby;
|
||||||
@@ -30,13 +31,14 @@ public class RagonLobbyPlayer
|
|||||||
public INetworkConnection Connection { get; }
|
public INetworkConnection Connection { get; }
|
||||||
public string Id { get; private set; }
|
public string Id { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public string Payload { get; private set; }
|
|
||||||
|
|
||||||
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, string payload)
|
public RagonData UserData { get; private set; }
|
||||||
|
|
||||||
|
public RagonLobbyPlayer(INetworkConnection connection, string id, string name, byte[] payload)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Payload = payload;
|
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
|
UserData = new RagonData(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
using System.Text;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.Handler;
|
using Ragon.Server.Handler;
|
||||||
@@ -58,7 +59,8 @@ public class RagonWebHookPlugin
|
|||||||
var authorizationResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(content);
|
var authorizationResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(content);
|
||||||
if (authorizationResponse != null)
|
if (authorizationResponse != null)
|
||||||
{
|
{
|
||||||
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, authorizationResponse.Id, authorizationResponse.Name, authorizationResponse.Payload);
|
var bytes = Encoding.UTF8.GetBytes(authorizationResponse.Payload);
|
||||||
|
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, authorizationResponse.Id, authorizationResponse.Name, bytes);
|
||||||
|
|
||||||
context.SetPlayer(lobbyPlayer);
|
context.SetPlayer(lobbyPlayer);
|
||||||
authorizationOperation.Approve(context);
|
authorizationOperation.Approve(context);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Ragon.Server.Data;
|
||||||
using Ragon.Server.Entity;
|
using Ragon.Server.Entity;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
|
||||||
@@ -29,12 +30,15 @@ public class RagonRoomPlayer
|
|||||||
public RagonRoom Room { get; private set; }
|
public RagonRoom Room { get; private set; }
|
||||||
public RagonEntityCache Entities { get; private set; }
|
public RagonEntityCache Entities { get; private set; }
|
||||||
|
|
||||||
|
public RagonData UserData { get; private set; }
|
||||||
|
|
||||||
public RagonRoomPlayer(INetworkConnection connection, string id, string name)
|
public RagonRoomPlayer(INetworkConnection connection, string id, string name)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Connection = connection;
|
Connection = connection;
|
||||||
Entities = new RagonEntityCache();
|
Entities = new RagonEntityCache();
|
||||||
|
UserData = new RagonData(Array.Empty<byte>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AttachEntity(RagonEntity entity)
|
public void AttachEntity(RagonEntity entity)
|
||||||
|
|||||||
Reference in New Issue
Block a user