Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1c5c99417 | |||
| e52e940fda | |||
| e78e8048ff | |||
| 5136f08dab | |||
| f7719e1bca | |||
| 211b24fe2b | |||
| bdf7d4f94a | |||
| 3bec19c2b2 | |||
| 0f2d316523 | |||
| 7cf1353869 | |||
| 6199af3d1e | |||
| e9dc45265a | |||
| b84538b238 | |||
| 7a2196ff50 | |||
| 5634a182e6 | |||
| 0ede864f40 | |||
| 646744c9a1 | |||
| a9e6a3e853 | |||
| c74ce0f00f | |||
| b39bd8bd0a | |||
| 12b80c546c |
@@ -49,7 +49,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 7.0.x
|
dotnet-version: 8.0.x
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>10</LangVersion>
|
||||||
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
|
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
|
||||||
<Authors>Eduard Kargin (Edmand46)</Authors>
|
<Authors>Eduard Kargin</Authors>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -71,15 +71,15 @@ namespace Ragon.Client
|
|||||||
internal bool PropertiesChanged => _propertiesChanged;
|
internal bool PropertiesChanged => _propertiesChanged;
|
||||||
internal ushort SceneId => _sceneId;
|
internal ushort SceneId => _sceneId;
|
||||||
|
|
||||||
private ushort _sceneId;
|
private readonly ushort _sceneId;
|
||||||
private bool _propertiesChanged;
|
private bool _propertiesChanged;
|
||||||
|
|
||||||
private RagonPayload _spawnPayload;
|
private RagonPayload _spawnPayload;
|
||||||
private RagonPayload _destroyPayload;
|
private RagonPayload _destroyPayload;
|
||||||
|
|
||||||
private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
|
private readonly Dictionary<int, OnEventDelegate> _events = new();
|
||||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new();
|
||||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new();
|
||||||
|
|
||||||
public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true)
|
public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true)
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,14 @@ namespace Ragon.Client
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Prepare(RagonClient client, ushort entityId, ushort entityType, bool hasAuthority, RagonPlayer player, RagonPayload payload)
|
public void Prepare(
|
||||||
|
RagonClient client,
|
||||||
|
ushort entityId,
|
||||||
|
ushort entityType,
|
||||||
|
bool hasAuthority,
|
||||||
|
RagonPlayer player,
|
||||||
|
RagonPayload payload
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Type = entityType;
|
Type = entityType;
|
||||||
Id = entityId;
|
Id = entityId;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,8 +39,6 @@ public struct RoomParameters
|
|||||||
|
|
||||||
internal class JoinSuccessHandler : IHandler
|
internal class JoinSuccessHandler : IHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private readonly RagonListenerList _listenerList;
|
private readonly RagonListenerList _listenerList;
|
||||||
private readonly RagonPlayerCache _playerCache;
|
private readonly RagonPlayerCache _playerCache;
|
||||||
private readonly RagonEntityCache _entityCache;
|
private readonly RagonEntityCache _entityCache;
|
||||||
@@ -62,19 +60,39 @@ internal class JoinSuccessHandler : IHandler
|
|||||||
public void Handle(RagonBuffer reader)
|
public void Handle(RagonBuffer reader)
|
||||||
{
|
{
|
||||||
var roomId = reader.ReadString();
|
var roomId = reader.ReadString();
|
||||||
var localId = reader.ReadString();
|
|
||||||
var ownerId = reader.ReadString();
|
|
||||||
var min = reader.ReadUShort();
|
var min = reader.ReadUShort();
|
||||||
var max = reader.ReadUShort();
|
var max = reader.ReadUShort();
|
||||||
var sceneName = reader.ReadString();
|
var sceneName = reader.ReadString();
|
||||||
|
var localId = reader.ReadString();
|
||||||
|
var ownerId = reader.ReadString();
|
||||||
|
|
||||||
|
_playerCache.SetOwnerAndLocal(ownerId, localId);
|
||||||
|
|
||||||
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
|
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
|
||||||
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
|
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
|
||||||
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
|
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
|
||||||
|
|
||||||
_playerCache.SetOwnerAndLocal(ownerId, localId);
|
room.UserData.Read(reader);
|
||||||
_client.AssignRoom(room);
|
|
||||||
|
|
||||||
|
var playersCount = reader.ReadUShort();
|
||||||
|
RagonLog.Trace("Players: " + playersCount);
|
||||||
|
for (var i = 0; i < playersCount; i++)
|
||||||
|
{
|
||||||
|
var playerPeerId = reader.ReadUShort();
|
||||||
|
var playerId = reader.ReadString();
|
||||||
|
var playerName = reader.ReadString();
|
||||||
|
|
||||||
|
var player = _playerCache.AddPlayer(playerPeerId, playerId, playerName);
|
||||||
|
|
||||||
|
player.UserData.Read(reader);
|
||||||
|
|
||||||
|
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
_client.AssignRoom(room);
|
||||||
|
_client.SetStatus(RagonStatus.ROOM);
|
||||||
|
|
||||||
|
_listenerList.OnJoined();
|
||||||
_listenerList.OnSceneRequest(sceneName);
|
_listenerList.OnSceneRequest(sceneName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
player.UserData.Read(reader);
|
var changes = player.UserData.Read(reader);
|
||||||
|
|
||||||
_listenerList.OnPlayerUserData(player);
|
_listenerList.OnPlayerUserData(player, changes);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,8 +36,11 @@ internal class RoomDataHandler: IHandler
|
|||||||
{
|
{
|
||||||
var rawData = reader.RawData;
|
var rawData = reader.RawData;
|
||||||
var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
|
var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
|
||||||
var player = _playerCache.GetPlayerByPeer(peerId);
|
|
||||||
|
|
||||||
|
RagonPlayer player = null;
|
||||||
|
if (peerId != 10000)
|
||||||
|
{
|
||||||
|
player = _playerCache.GetPlayerByPeer(peerId);
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
RagonLog.Error($"Player with peerId:{peerId} not found");
|
RagonLog.Error($"Player with peerId:{peerId} not found");
|
||||||
@@ -45,6 +48,7 @@ internal class RoomDataHandler: IHandler
|
|||||||
_playerCache.Dump();
|
_playerCache.Dump();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var headerSize = 3;
|
var headerSize = 3;
|
||||||
var payload = new byte[rawData.Length - headerSize];
|
var payload = new byte[rawData.Length - headerSize];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void Handle(RagonBuffer reader)
|
public void Handle(RagonBuffer reader)
|
||||||
{
|
{
|
||||||
_client.Room?.HandleUserData(reader);
|
var changes = _client.Room?.UserData.Read(reader);
|
||||||
_listenerList.OnRoomUserData();
|
_listenerList.OnRoomUserData(changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -46,19 +46,6 @@ internal class SnapshotHandler : IHandler
|
|||||||
public void Handle(RagonBuffer buffer)
|
public void Handle(RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
var entities = new List<RagonEntity>();
|
var entities = new List<RagonEntity>();
|
||||||
var playersCount = buffer.ReadUShort();
|
|
||||||
RagonLog.Trace("Players: " + playersCount);
|
|
||||||
for (var i = 0; i < playersCount; i++)
|
|
||||||
{
|
|
||||||
var playerPeerId = buffer.ReadUShort();
|
|
||||||
var playerId = buffer.ReadString();
|
|
||||||
var playerName = buffer.ReadString();
|
|
||||||
|
|
||||||
_playerCache.AddPlayer(playerPeerId, playerId, playerName);
|
|
||||||
|
|
||||||
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dynamicEntities = buffer.ReadUShort();
|
var dynamicEntities = buffer.ReadUShort();
|
||||||
RagonLog.Trace("Dynamic Entities: " + dynamicEntities);
|
RagonLog.Trace("Dynamic Entities: " + dynamicEntities);
|
||||||
for (var i = 0; i < dynamicEntities; i++)
|
for (var i = 0; i < dynamicEntities; i++)
|
||||||
@@ -123,12 +110,6 @@ internal class SnapshotHandler : IHandler
|
|||||||
entities.Add(entity);
|
entities.Add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_client.Status == RagonStatus.LOBBY)
|
|
||||||
{
|
|
||||||
_client.SetStatus(RagonStatus.ROOM);
|
|
||||||
_listenerList.OnJoined();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var entity in entities)
|
foreach (var entity in entities)
|
||||||
entity.Attach();
|
entity.Attach();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ public interface IUserData
|
|||||||
{
|
{
|
||||||
public byte[] this[string key] { get; set; }
|
public byte[] this[string key] { get; set; }
|
||||||
bool Dirty { get; }
|
bool Dirty { get; }
|
||||||
void Read(RagonBuffer buffer);
|
IReadOnlyList<string> Read(RagonBuffer buffer);
|
||||||
void Write(RagonBuffer buffer);
|
void Write(RagonBuffer buffer);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,5 +18,5 @@ namespace Ragon.Client;
|
|||||||
|
|
||||||
public interface IRagonDataListener
|
public interface IRagonDataListener
|
||||||
{
|
{
|
||||||
public void OnData(RagonPlayer player, byte[] data);
|
public void OnData(RagonClient client, RagonPlayer player, byte[] data);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,5 +18,5 @@ namespace Ragon.Client;
|
|||||||
|
|
||||||
public interface IRagonPlayerUserDataListener
|
public interface IRagonPlayerUserDataListener
|
||||||
{
|
{
|
||||||
void OnPlayerUserDataUpdated(RagonClient client, RagonPlayer player);
|
void OnPlayerUserDataUpdated(RagonClient client, RagonPlayer player, IReadOnlyList<string> changes);
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@ namespace Ragon.Client;
|
|||||||
|
|
||||||
public interface IRagonRoomListListener
|
public interface IRagonRoomListListener
|
||||||
{
|
{
|
||||||
public void OnRoomListUpdate(IReadOnlyList<RagonRoomInformation> roomsInfos);
|
public void OnRoomListUpdate(RagonClient client, IReadOnlyList<RagonRoomInformation> roomsInfos);
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@ namespace Ragon.Client;
|
|||||||
|
|
||||||
public interface IRagonRoomUserDataListener
|
public interface IRagonRoomUserDataListener
|
||||||
{
|
{
|
||||||
public void OnUserDataUpdated(RagonClient client);
|
public void OnUserDataUpdated(RagonClient client, IReadOnlyList<string> changes);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -298,25 +298,25 @@ namespace Ragon.Client
|
|||||||
public void OnData(RagonPlayer player, byte[] data)
|
public void OnData(RagonPlayer player, byte[] data)
|
||||||
{
|
{
|
||||||
foreach (var listener in _dataListeners)
|
foreach (var listener in _dataListeners)
|
||||||
listener.OnData(player, data);
|
listener.OnData(_client, player, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRoomList(RagonRoomInformation[] roomInfos)
|
public void OnRoomList(RagonRoomInformation[] roomInfos)
|
||||||
{
|
{
|
||||||
foreach (var listListener in _roomListListeners)
|
foreach (var listListener in _roomListListeners)
|
||||||
listListener.OnRoomListUpdate(roomInfos);
|
listListener.OnRoomListUpdate(_client, roomInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRoomUserData()
|
public void OnRoomUserData(IReadOnlyList<string> changes)
|
||||||
{
|
{
|
||||||
foreach (var userDataListener in _roomUserDataListeners)
|
foreach (var userDataListener in _roomUserDataListeners)
|
||||||
userDataListener.OnUserDataUpdated(_client);
|
userDataListener.OnUserDataUpdated(_client, changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPlayerUserData(RagonPlayer player)
|
public void OnPlayerUserData(RagonPlayer player, IReadOnlyList<string> changes)
|
||||||
{
|
{
|
||||||
foreach(var playerUserDataListener in _playerUserDataListeners)
|
foreach(var playerUserDataListener in _playerUserDataListeners)
|
||||||
playerUserDataListener.OnPlayerUserDataUpdated(_client, player);
|
playerUserDataListener.OnPlayerUserDataUpdated(_client, player, changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,10 +52,10 @@ public sealed class RagonPlayerCache
|
|||||||
_localId = localId;
|
_localId = localId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddPlayer(ushort peerId, string playerId, string playerName)
|
public RagonPlayer AddPlayer(ushort peerId, string playerId, string playerName)
|
||||||
{
|
{
|
||||||
if (_playersById.ContainsKey(playerId))
|
if (_playersById.ContainsKey(playerId))
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
var isOwner = playerId == _ownerId;
|
var isOwner = playerId == _ownerId;
|
||||||
var isLocal = playerId == _localId;
|
var isLocal = playerId == _localId;
|
||||||
@@ -73,6 +73,8 @@ public sealed class RagonPlayerCache
|
|||||||
_players.Add(player);
|
_players.Add(player);
|
||||||
_playersById.Add(player.Id, player);
|
_playersById.Add(player.Id, player);
|
||||||
_playersByConnection.Add(player.PeerId, player);
|
_playersByConnection.Add(player.PeerId, player);
|
||||||
|
|
||||||
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovePlayer(string playerId)
|
public void RemovePlayer(string playerId)
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace Ragon.Client
|
|||||||
if (_events.TryGetValue(eventCode, out var evnt))
|
if (_events.TryGetValue(eventCode, out var evnt))
|
||||||
evnt?.Invoke(caller, buffer);
|
evnt?.Invoke(caller, buffer);
|
||||||
else
|
else
|
||||||
RagonLog.Warn($"Handler event on entity {Id} with eventCode {eventCode} not defined");
|
RagonLog.Warn($"Handler event {Id} with eventCode {eventCode} not defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void HandleUserData(RagonBuffer buffer)
|
internal void HandleUserData(RagonBuffer buffer)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -80,6 +80,8 @@ public class RagonScene
|
|||||||
buffer.WriteByte((byte)replicationMode);
|
buffer.WriteByte((byte)replicationMode);
|
||||||
buffer.WriteByte((byte)target);
|
buffer.WriteByte((byte)target);
|
||||||
|
|
||||||
|
evnt.Serialize(buffer);
|
||||||
|
|
||||||
var sendData = buffer.ToArray();
|
var sendData = buffer.ToArray();
|
||||||
_client.Reliable.Send(sendData);
|
_client.Reliable.Send(sendData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,11 +31,11 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
|
public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
var parameters = new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
|
var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
|
||||||
CreateOrJoin(parameters);
|
CreateOrJoin(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateOrJoin(RagonRoomPayload parameters)
|
public void CreateOrJoin(RagonRoomParameters parameters)
|
||||||
{
|
{
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
_buffer.WriteOperation(RagonOperation.JOIN_OR_CREATE_ROOM);
|
_buffer.WriteOperation(RagonOperation.JOIN_OR_CREATE_ROOM);
|
||||||
@@ -48,15 +48,15 @@ namespace Ragon.Client
|
|||||||
|
|
||||||
public void Create(string sceneName, int minPlayers, int maxPlayers)
|
public void Create(string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
Create(null, new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers)
|
public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers)
|
||||||
{
|
{
|
||||||
Create(roomId, new RagonRoomPayload() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
Create(roomId, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(string roomId, RagonRoomPayload parameters)
|
public void Create(string roomId, RagonRoomParameters parameters)
|
||||||
{
|
{
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
_buffer.WriteOperation(RagonOperation.CREATE_ROOM);
|
_buffer.WriteOperation(RagonOperation.CREATE_ROOM);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using Ragon.Protocol;
|
|||||||
|
|
||||||
namespace Ragon.Client
|
namespace Ragon.Client
|
||||||
{
|
{
|
||||||
public class RagonUserData: IUserData
|
public class RagonUserData : IUserData
|
||||||
{
|
{
|
||||||
public byte[] this[string key]
|
public byte[] this[string key]
|
||||||
{
|
{
|
||||||
@@ -27,44 +27,78 @@ namespace Ragon.Client
|
|||||||
{
|
{
|
||||||
_properties[key] = value;
|
_properties[key] = value;
|
||||||
|
|
||||||
_dirty = true;
|
if (!_changesCache.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_localChanges.Add(key);
|
||||||
|
_changesCache.Add(key, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool Dirty => _dirty;
|
|
||||||
|
|
||||||
private bool _dirty = false;
|
public void Remove(string key)
|
||||||
|
{
|
||||||
|
if (_properties.Remove(key))
|
||||||
|
{
|
||||||
|
if (!_changesCache.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_localChanges.Add(key);
|
||||||
|
_changesCache.Add(key, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Dirty => _localChanges.Count > 0;
|
||||||
|
|
||||||
|
private readonly List<string> _localChanges = new();
|
||||||
|
private readonly Dictionary<string, bool> _changesCache = new();
|
||||||
private readonly Dictionary<string, byte[]> _properties = new();
|
private readonly Dictionary<string, byte[]> _properties = new();
|
||||||
|
|
||||||
public RagonUserData()
|
public RagonUserData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Read(RagonBuffer buffer)
|
public IReadOnlyList<string> Read(RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
_properties.Clear();
|
|
||||||
|
|
||||||
var len = buffer.ReadUShort();
|
var len = buffer.ReadUShort();
|
||||||
|
var changes = new List<string>(len);
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var key = buffer.ReadString();
|
var key = buffer.ReadString();
|
||||||
var valueSize = buffer.ReadUShort();
|
var valueSize = buffer.ReadUShort();
|
||||||
|
if (valueSize > 0)
|
||||||
|
{
|
||||||
var value = buffer.ReadBytes(valueSize);
|
var value = buffer.ReadBytes(valueSize);
|
||||||
|
|
||||||
_properties[key] = value;
|
_properties[key] = value;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_properties.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
changes.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(RagonBuffer buffer)
|
public void Write(RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
buffer.WriteUShort((ushort)_properties.Count);
|
buffer.WriteUShort((ushort)_localChanges.Count);
|
||||||
foreach (var property in _properties)
|
foreach (var propertyChanged in _localChanges)
|
||||||
{
|
{
|
||||||
buffer.WriteString(property.Key);
|
buffer.WriteString(propertyChanged);
|
||||||
buffer.WriteUShort((ushort) property.Value.Length);
|
if (_properties.TryGetValue(propertyChanged, out var property))
|
||||||
buffer.WriteBytes(property.Value);
|
{
|
||||||
|
buffer.WriteUShort((ushort)property.Length);
|
||||||
|
buffer.WriteBytes(property);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.WriteUShort(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirty = false;
|
_localChanges.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,29 +37,31 @@ public class RagonUserDataReadOnly : IUserData
|
|||||||
|
|
||||||
public void Write(RagonBuffer buffer)
|
public void Write(RagonBuffer buffer)
|
||||||
{
|
{
|
||||||
buffer.WriteUShort((ushort)_properties.Count);
|
|
||||||
foreach (var property in _properties)
|
|
||||||
{
|
|
||||||
buffer.WriteString(property.Key);
|
|
||||||
buffer.WriteUShort((ushort)property.Value.Length);
|
|
||||||
buffer.WriteBytes(property.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirty = false;
|
public IReadOnlyList<string> Read(RagonBuffer buffer)
|
||||||
}
|
|
||||||
|
|
||||||
public void Read(RagonBuffer buffer)
|
|
||||||
{
|
{
|
||||||
_properties.Clear();
|
|
||||||
|
|
||||||
var len = buffer.ReadUShort();
|
var len = buffer.ReadUShort();
|
||||||
|
var changes = new List<string>(len);
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var key = buffer.ReadString();
|
var key = buffer.ReadString();
|
||||||
var valueSize = buffer.ReadUShort();
|
var valueSize = buffer.ReadUShort();
|
||||||
|
if (valueSize > 0)
|
||||||
|
{
|
||||||
var value = buffer.ReadBytes(valueSize);
|
var value = buffer.ReadBytes(valueSize);
|
||||||
|
|
||||||
_properties[key] = value;
|
_properties[key] = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_properties.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
changes.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Title>Ragon.Protocol</Title>
|
<Title>Ragon.Protocol</Title>
|
||||||
<Copyright>Eduard Kargin</Copyright>
|
<Copyright>Eduard Kargin</Copyright>
|
||||||
<PackageProjectUrl>https://ragon-server.com</PackageProjectUrl>
|
<Version>1.4.0</Version>
|
||||||
|
<Authors>Eduard Kargin</Authors>
|
||||||
|
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||||
<RepositoryType>Source</RepositoryType>
|
<RepositoryType>Source</RepositoryType>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ namespace Ragon.Protocol
|
|||||||
{
|
{
|
||||||
public class RagonBuffer
|
public class RagonBuffer
|
||||||
{
|
{
|
||||||
|
private const int MaxBufferSize = 1024 * 1024; // 1MB max buffer size
|
||||||
|
|
||||||
private int _read;
|
private int _read;
|
||||||
private int _write;
|
private int _write;
|
||||||
private uint[] _buckets;
|
private uint[] _buckets;
|
||||||
@@ -331,6 +333,9 @@ namespace Ragon.Protocol
|
|||||||
var limit = (size + 32 - 1) / 32;
|
var limit = (size + 32 - 1) / 32;
|
||||||
var capacity = size;
|
var capacity = size;
|
||||||
|
|
||||||
|
if (index + limit >= _buckets.Length)
|
||||||
|
Resize(size);
|
||||||
|
|
||||||
for (int i = 0; i < limit; i++)
|
for (int i = 0; i < limit; i++)
|
||||||
{
|
{
|
||||||
var dataSize = capacity > 32 ? 32 : capacity;
|
var dataSize = capacity > 32 ? 32 : capacity;
|
||||||
@@ -401,6 +406,12 @@ namespace Ragon.Protocol
|
|||||||
public void FromArray(byte[] data)
|
public void FromArray(byte[] data)
|
||||||
{
|
{
|
||||||
var length = data.Length;
|
var length = data.Length;
|
||||||
|
|
||||||
|
if (length > MaxBufferSize)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Input data exceeds maximum buffer size: {length} bytes > {MaxBufferSize} bytes");
|
||||||
|
}
|
||||||
|
|
||||||
var bucketsCount = length / 4 + 1;
|
var bucketsCount = length / 4 + 1;
|
||||||
|
|
||||||
if (_buckets.Length < bucketsCount)
|
if (_buckets.Length < bucketsCount)
|
||||||
@@ -490,7 +501,14 @@ namespace Ragon.Protocol
|
|||||||
|
|
||||||
private void Resize(int capacity)
|
private void Resize(int capacity)
|
||||||
{
|
{
|
||||||
var buckets = new uint[_buckets.Length * 2 + capacity];
|
var newSize = _buckets.Length * 2 + capacity;
|
||||||
|
|
||||||
|
if (newSize * 4 > MaxBufferSize)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Buffer size limit exceeded: {newSize * 4} bytes > {MaxBufferSize} bytes");
|
||||||
|
}
|
||||||
|
|
||||||
|
var buckets = new uint[newSize];
|
||||||
Array.Copy(_buckets, buckets, _buckets.Length);
|
Array.Copy(_buckets, buckets, _buckets.Length);
|
||||||
_buckets = buckets;
|
_buckets = buckets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
namespace Ragon.Protocol
|
namespace Ragon.Protocol
|
||||||
{
|
{
|
||||||
public class RagonRoomPayload: IRagonSerializable
|
public class RagonRoomParameters: IRagonSerializable
|
||||||
{
|
{
|
||||||
public string Scene { get; set; }
|
public string Scene { get; set; }
|
||||||
public int Min { get; set; }
|
public int Min { get; set; }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>Ragon.Relay</RootNamespace>
|
<RootNamespace>Ragon.Relay</RootNamespace>
|
||||||
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
@@ -28,4 +28,9 @@
|
|||||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="NLog" Version="5.3.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using NLog;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayLogger: IRagonLogger
|
||||||
|
{
|
||||||
|
private Logger _nlogger;
|
||||||
|
|
||||||
|
public RelayLogger(string tag)
|
||||||
|
{
|
||||||
|
_nlogger = LogManager.GetLogger(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Warning(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(Exception ex)
|
||||||
|
{
|
||||||
|
_nlogger.Error(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Trace(string message)
|
||||||
|
{
|
||||||
|
_nlogger.Trace(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
|
namespace Ragon.Relay;
|
||||||
|
|
||||||
|
public class RelayLoggerFactory: IRagonLoggerFactory
|
||||||
|
{
|
||||||
|
public IRagonLogger GetLogger(string tag)
|
||||||
|
{
|
||||||
|
return new RelayLogger(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Ragon.Server;
|
||||||
|
using Ragon.Server.Plugin;
|
||||||
|
|
||||||
|
namespace Ragon.Relay
|
||||||
|
{
|
||||||
|
|
||||||
|
public class RelayServerPlugin : BaseServerPlugin
|
||||||
|
{
|
||||||
|
public override bool OnCommand(string command, string payload)
|
||||||
|
{
|
||||||
|
Console.WriteLine(command);
|
||||||
|
if (command == "kick-player")
|
||||||
|
{
|
||||||
|
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
|
||||||
|
var player = Server.GetContextById(commandPayload.Id);
|
||||||
|
if (player != null)
|
||||||
|
player.Connection.Close();
|
||||||
|
else
|
||||||
|
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||||
|
{
|
||||||
|
return new RelayRoomPlugin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,27 +14,35 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Ragon.Server;
|
using Ragon.Server;
|
||||||
using Ragon.Server.ENetServer;
|
using Ragon.Server.ENetServer;
|
||||||
using Ragon.Server.WebSocketServer;
|
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
using Ragon.Server.Plugin;
|
using Ragon.Server.Plugin;
|
||||||
|
using Ragon.Server.WebSocketServer;
|
||||||
|
|
||||||
namespace Ragon.Relay;
|
namespace Ragon.Relay
|
||||||
|
|
||||||
public class Relay
|
|
||||||
{
|
{
|
||||||
|
public class Relay
|
||||||
|
{
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
var logger = LogManager.GetLogger("Ragon.Relay");
|
LoggerManager.SetLoggerFactory(new RelayLoggerFactory());
|
||||||
|
|
||||||
|
var logger = LoggerManager.GetLogger("Relay");
|
||||||
logger.Info("Relay Application");
|
logger.Info("Relay Application");
|
||||||
|
|
||||||
var configuration = RagonServerConfiguration.Load("relay.config.json");
|
var data = File.ReadAllText("relay.config.json");
|
||||||
|
var configuration = JsonConvert.DeserializeObject<RelayConfiguration>(data);
|
||||||
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType);
|
||||||
|
|
||||||
INetworkServer networkServer = new ENetServer();
|
INetworkServer networkServer = new ENetServer();
|
||||||
IServerPlugin plugin = new RelayServerPlugin();
|
IServerPlugin plugin = new RelayServerPlugin();
|
||||||
|
|
||||||
switch (serverType)
|
switch (serverType)
|
||||||
{
|
{
|
||||||
case ServerType.ENET:
|
case ServerType.ENET:
|
||||||
@@ -45,8 +53,30 @@ public class Relay
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var relay = new RagonServer(networkServer, plugin, configuration);
|
var serverConfiguration = new RagonServerConfiguration()
|
||||||
logger.Info("Started");
|
{
|
||||||
|
LimitConnections = configuration.LimitConnections,
|
||||||
|
LimitRooms = configuration.LimitRooms,
|
||||||
|
LimitBufferedEvents = configuration.LimitBufferedEvents,
|
||||||
|
LimitPlayersPerRoom = configuration.LimitPlayersPerRoom,
|
||||||
|
LimitUserDataSize = configuration.LimitUserDataSize,
|
||||||
|
LimitPropertySize = configuration.LimitPropertySize,
|
||||||
|
Port = configuration.Port,
|
||||||
|
Protocol = configuration.Protocol,
|
||||||
|
ServerKey = configuration.ServerKey,
|
||||||
|
ServerTickRate = configuration.ServerTickRate,
|
||||||
|
ServerAddress = configuration.ServerAddress,
|
||||||
|
};
|
||||||
|
|
||||||
|
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
||||||
relay.Start();
|
relay.Start();
|
||||||
|
while (relay.IsRunning)
|
||||||
|
{
|
||||||
|
relay.Tick();
|
||||||
|
Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
relay.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ragon.Relay
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public struct RelayConfiguration
|
||||||
|
{
|
||||||
|
public string ServerKey;
|
||||||
|
public string ServerType;
|
||||||
|
public string ServerAddress;
|
||||||
|
public ushort ServerTickRate;
|
||||||
|
public string Protocol;
|
||||||
|
public ushort Port;
|
||||||
|
public int LimitConnections;
|
||||||
|
public int LimitPlayersPerRoom;
|
||||||
|
public int LimitRooms;
|
||||||
|
public int LimitBufferedEvents;
|
||||||
|
public int LimitUserDataSize;
|
||||||
|
public int LimitPropertySize;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Ragon.Server;
|
|
||||||
using Ragon.Server.Plugin;
|
|
||||||
|
|
||||||
namespace Ragon.Relay;
|
|
||||||
|
|
||||||
public class RelayServerPlugin: BaseServerPlugin
|
|
||||||
{
|
|
||||||
public override bool OnCommand(string command, string payload)
|
|
||||||
{
|
|
||||||
Console.WriteLine(command);
|
|
||||||
if (command == "kick-player")
|
|
||||||
{
|
|
||||||
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
|
|
||||||
var player = Server.GetPlayerById(commandPayload.Id);
|
|
||||||
if (player != null)
|
|
||||||
player.Connection.Close();
|
|
||||||
else
|
|
||||||
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
|
||||||
{
|
|
||||||
return new RelayRoomPlugin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,15 @@
|
|||||||
{
|
{
|
||||||
"serverKey": "defaultkey",
|
"serverKey": "defaultkey",
|
||||||
"serverType": "enet",
|
"serverType": "enet",
|
||||||
|
"serverAddress": "*",
|
||||||
"serverTickRate": 30,
|
"serverTickRate": 30,
|
||||||
"gameProtocol": "1.0.0",
|
"protocol": "1.0.0",
|
||||||
"port": 5000,
|
"port": 8000,
|
||||||
"httpPort": 5001,
|
|
||||||
"httpKey": "defaultkey",
|
|
||||||
"limitConnections": 4095,
|
"limitConnections": 4095,
|
||||||
"limitPlayersPerRoom": 20,
|
"limitPlayersPerRoom": 20,
|
||||||
"limitRooms": 200,
|
"limitRooms": 200,
|
||||||
"limitBufferedEvents": 50,
|
"limitBufferedEvents": 50,
|
||||||
"limitUserData": 1024,
|
"limitUserDataSize": 1024,
|
||||||
"webHooks":
|
"limitPropertySize": 512,
|
||||||
{
|
"limitConnectionsPerProject": 100
|
||||||
"room-created": "http://127.0.0.1:3000/service/create-room",
|
|
||||||
"room-removed": "http://127.0.0.1:3000/service/remove-room",
|
|
||||||
"room-joined": "http://127.0.0.1:3000/service/join-room",
|
|
||||||
"room-leaved": "http://127.0.0.1:3000/service/leave-room"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,21 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<RootNamespace>Ragon.ENet</RootNamespace>
|
<RootNamespace>Ragon.ENet</RootNamespace>
|
||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Copyright>Eduard Kargin</Copyright>
|
||||||
|
<Authors>Eduard Kargin</Authors>
|
||||||
|
<Version>1.4.0</Version>
|
||||||
|
<Title>Ragon Server ENet</Title>
|
||||||
|
<Description>Ragon Server ENet transport</Description>
|
||||||
|
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||||
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||||
|
<RepositoryType>Source</RepositoryType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
||||||
<PackageReference Include="NLog" Version="5.2.2" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ namespace Ragon.Server.ENetServer;
|
|||||||
|
|
||||||
public sealed class ENetConnection: INetworkConnection
|
public sealed class ENetConnection: INetworkConnection
|
||||||
{
|
{
|
||||||
|
private static ushort _iterator = 0;
|
||||||
public ushort Id { get; }
|
public ushort Id { get; }
|
||||||
public INetworkChannel Reliable { get; private set; }
|
public INetworkChannel Reliable { get; private set; }
|
||||||
public INetworkChannel Unreliable { get; private set; }
|
public INetworkChannel Unreliable { get; private set; }
|
||||||
@@ -30,7 +31,8 @@ public sealed class ENetConnection: INetworkConnection
|
|||||||
{
|
{
|
||||||
_peer = peer;
|
_peer = peer;
|
||||||
|
|
||||||
Id = (ushort) peer.ID;
|
// Id = (ushort) peer.ID;
|
||||||
|
Id = _iterator++;
|
||||||
Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE);
|
Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE);
|
||||||
Unreliable = new ENetUnreliableChannel(peer, NetworkChannel.UNRELIABLE);
|
Unreliable = new ENetUnreliableChannel(peer, NetworkChannel.UNRELIABLE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,26 +15,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using ENet;
|
using ENet;
|
||||||
using NLog;
|
|
||||||
using Ragon.Protocol;
|
using Ragon.Protocol;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.ENetServer
|
namespace Ragon.Server.ENetServer
|
||||||
{
|
{
|
||||||
public sealed class ENetServer : INetworkServer
|
public sealed class ENetServer : INetworkServer
|
||||||
{
|
{
|
||||||
public Executor Executor => _executor;
|
|
||||||
|
|
||||||
private readonly Host _host = new();
|
private readonly Host _host = new();
|
||||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(ENetServer));
|
||||||
|
|
||||||
private ENetConnection[] _connections = Array.Empty<ENetConnection>();
|
private ENetConnection[] _connections = Array.Empty<ENetConnection>();
|
||||||
private INetworkListener _listener;
|
private INetworkListener _listener;
|
||||||
private uint _protocol;
|
private uint _protocol;
|
||||||
private ENet.Event _event;
|
private ENet.Event _event;
|
||||||
private Executor _executor = new();
|
|
||||||
|
|
||||||
public void Start(INetworkListener listener, NetworkConfiguration configuration)
|
public void Listen(INetworkListener listener, NetworkConfiguration configuration)
|
||||||
{
|
{
|
||||||
Library.Initialize();
|
Library.Initialize();
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ namespace Ragon.Server.ENetServer
|
|||||||
_host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024);
|
_host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024);
|
||||||
|
|
||||||
var protocolDecoded = RagonVersion.Parse(_protocol);
|
var protocolDecoded = RagonVersion.Parse(_protocol);
|
||||||
_logger.Info($"Listen at 127.0.0.1:{configuration.Port}");
|
_logger.Info($"Listen at {configuration.Address}:{configuration.Port}");
|
||||||
_logger.Info($"Protocol: {protocolDecoded}");
|
_logger.Info($"Protocol: {protocolDecoded}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +77,7 @@ namespace Ragon.Server.ENetServer
|
|||||||
{
|
{
|
||||||
if (!IsValidProtocol(_event.Data))
|
if (!IsValidProtocol(_event.Data))
|
||||||
{
|
{
|
||||||
_logger.Warn($"Mismatched protocol Server: {RagonVersion.Parse(_protocol)} Client: {RagonVersion.Parse(_event.Data)}, close connection");
|
_logger.Warning($"Mismatched protocol Server: {RagonVersion.Parse(_protocol)} Client: {RagonVersion.Parse(_event.Data)}, close connection");
|
||||||
_event.Peer.DisconnectNow(0);
|
_event.Peer.DisconnectNow(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -4,13 +4,19 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<RootNamespace>Ragon.WebSockets</RootNamespace>
|
<RootNamespace>Ragon.WebSockets</RootNamespace>
|
||||||
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||||
|
<Copyright>Eduard Kargin</Copyright>
|
||||||
|
<Authors>Eduard Kargin</Authors>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Version>1.4.0</Version>
|
||||||
|
<Title>Ragon Server WebSocket</Title>
|
||||||
|
<Description>Ragon Server WebSocket transport</Description>
|
||||||
|
<PackageProjectUrl>https://ragon.io</PackageProjectUrl>
|
||||||
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
<RepositoryUrl>https://github.com/edmand46/Ragon</RepositoryUrl>
|
||||||
|
<RepositoryType>Source</RepositoryType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="NLog" Version="5.2.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using NLog;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Logging;
|
||||||
|
|
||||||
namespace Ragon.Server.WebSocketServer;
|
namespace Ragon.Server.WebSocketServer;
|
||||||
|
|
||||||
public sealed class WebSocketConnection : INetworkConnection
|
public sealed class WebSocketConnection : INetworkConnection
|
||||||
{
|
{
|
||||||
private Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(WebSocketConnection));
|
||||||
public ushort Id { get; }
|
public ushort Id { get; }
|
||||||
public INetworkChannel Reliable { get; private set; }
|
public INetworkChannel Reliable { get; private set; }
|
||||||
public INetworkChannel Unreliable { get; private set; }
|
public INetworkChannel Unreliable { get; private set; }
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user