Compare commits
32 Commits
feat/rawData
...
v1.4.3
| Author | SHA1 | Date | |
|---|---|---|---|
| f1c5c99417 | |||
| e52e940fda | |||
| e78e8048ff | |||
| 5136f08dab | |||
| f7719e1bca | |||
| 211b24fe2b | |||
| bdf7d4f94a | |||
| 3bec19c2b2 | |||
| 0f2d316523 | |||
| 7cf1353869 | |||
| 6199af3d1e | |||
| e9dc45265a | |||
| b84538b238 | |||
| 7a2196ff50 | |||
| 5634a182e6 | |||
| 0ede864f40 | |||
| 646744c9a1 | |||
| a9e6a3e853 | |||
| c74ce0f00f | |||
| d3ae5a4465 | |||
| 5bf1881f81 | |||
| 6886808132 | |||
| b4cba20d82 | |||
| b39bd8bd0a | |||
| 12b80c546c | |||
| accd442388 | |||
| d115c98b79 | |||
| 5c20fbafc1 | |||
| bd0c6df5ea | |||
| c4811ef052 | |||
| d82964526c | |||
| acedaef270 |
@@ -49,7 +49,7 @@ jobs:
|
||||
- name: Setup dotnet
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 7.0.x
|
||||
dotnet-version: 8.0.x
|
||||
- name: Build
|
||||
shell: bash
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>10</LangVersion>
|
||||
<RootNamespace>Ragon.Client.Simulation</RootNamespace>
|
||||
<Authors>Eduard Kargin (Edmand46)</Authors>
|
||||
<Authors>Eduard Kargin</Authors>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,7 +55,6 @@ namespace Ragon.Client
|
||||
public ushort Id { get; private set; }
|
||||
public ushort Type { get; private set; }
|
||||
|
||||
|
||||
public RagonAuthority Authority { get; private set; }
|
||||
public RagonPlayer Owner { get; private set; }
|
||||
public RagonEntityState State { get; private set; }
|
||||
@@ -72,15 +71,15 @@ namespace Ragon.Client
|
||||
internal bool PropertiesChanged => _propertiesChanged;
|
||||
internal ushort SceneId => _sceneId;
|
||||
|
||||
private ushort _sceneId;
|
||||
private readonly ushort _sceneId;
|
||||
private bool _propertiesChanged;
|
||||
|
||||
private RagonPayload _spawnPayload;
|
||||
private RagonPayload _destroyPayload;
|
||||
|
||||
private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
private readonly Dictionary<int, OnEventDelegate> _events = new();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new();
|
||||
|
||||
public RagonEntity(ushort type = 0, ushort sceneId = 0, bool replicated = true)
|
||||
{
|
||||
@@ -126,7 +125,14 @@ namespace Ragon.Client
|
||||
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;
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,9 @@ using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public struct RagonRoomInformation
|
||||
public struct RoomParameters
|
||||
{
|
||||
public RagonRoomInformation(string roomId, string playerId, string ownerId, ushort min, ushort max)
|
||||
public RoomParameters(string roomId, string playerId, string ownerId, ushort min, ushort max)
|
||||
{
|
||||
RoomId = roomId;
|
||||
PlayerId = playerId;
|
||||
@@ -60,19 +60,39 @@ internal class JoinSuccessHandler : IHandler
|
||||
public void Handle(RagonBuffer reader)
|
||||
{
|
||||
var roomId = reader.ReadString();
|
||||
var localId = reader.ReadString();
|
||||
var ownerId = reader.ReadString();
|
||||
var min = reader.ReadUShort();
|
||||
var max = reader.ReadUShort();
|
||||
var sceneName = reader.ReadString();
|
||||
|
||||
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
|
||||
var roomInfo = new RagonRoomInformation(roomId, localId, ownerId, min, max);
|
||||
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
|
||||
var localId = reader.ReadString();
|
||||
var ownerId = reader.ReadString();
|
||||
|
||||
_playerCache.SetOwnerAndLocal(ownerId, localId);
|
||||
_client.AssignRoom(room);
|
||||
|
||||
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
|
||||
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
|
||||
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
|
||||
|
||||
room.UserData.Read(reader);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client
|
||||
{
|
||||
|
||||
internal class PlayerUserDataHandler: IHandler
|
||||
{
|
||||
private RagonPlayerCache _playerCache;
|
||||
private RagonListenerList _listenerList;
|
||||
|
||||
public PlayerUserDataHandler(
|
||||
RagonPlayerCache playerCache,
|
||||
RagonListenerList listenerList
|
||||
)
|
||||
{
|
||||
_playerCache = playerCache;
|
||||
_listenerList = listenerList;
|
||||
}
|
||||
public void Handle(RagonBuffer reader)
|
||||
{
|
||||
var playerPeerId = reader.ReadUShort();
|
||||
var player = _playerCache.GetPlayerByPeer(playerPeerId);
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
var changes = player.UserData.Read(reader);
|
||||
|
||||
_listenerList.OnPlayerUserData(player, changes);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RagonLog.Warn("Received user data for unknown player.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
* 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 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)
|
||||
{
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found");
|
||||
@@ -45,6 +48,7 @@ internal class RoomDataHandler: IHandler
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var headerSize = 3;
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,6 +50,6 @@ public class RoomEventHandler : IHandler
|
||||
if (player.IsLocal && executionMode == RagonReplicationMode.LocalAndServer)
|
||||
return;
|
||||
|
||||
_client.Room.Event(eventCode, player, buffer);
|
||||
_client.Room.HandleEvent(eventCode, player, buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
internal class RoomListHandler: IHandler
|
||||
{
|
||||
private RagonListenerList _listenerList;
|
||||
private RagonSession _session;
|
||||
|
||||
public RoomListHandler(RagonSession session, RagonListenerList list)
|
||||
{
|
||||
_session = session;
|
||||
_listenerList = list;
|
||||
}
|
||||
|
||||
public void Handle(RagonBuffer reader)
|
||||
{
|
||||
var roomCount = reader.ReadUShort();
|
||||
var roomList = new RagonRoomInformation[roomCount];
|
||||
for (int i = 0; i < roomCount; i++)
|
||||
{
|
||||
var id = reader.ReadString();
|
||||
var scene = reader.ReadString();
|
||||
var maxPlayers = reader.ReadUShort();
|
||||
var minPlayers = reader.ReadUShort();
|
||||
var players = reader.ReadUShort();
|
||||
|
||||
var roomInfo = new RagonRoomInformation()
|
||||
{
|
||||
Id = id,
|
||||
Scene = scene,
|
||||
PlayerCount = players,
|
||||
PlayerMax = maxPlayers,
|
||||
PlayerMin = minPlayers,
|
||||
Properties = new Dictionary<string, byte[]>()
|
||||
};
|
||||
|
||||
roomList[i] = roomInfo;
|
||||
}
|
||||
|
||||
_listenerList.OnRoomList(roomList);
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
* Copyright 2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,22 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client.Simulation.Sources;
|
||||
|
||||
public class PlayerPayload : IRagonPayload
|
||||
namespace Ragon.Client
|
||||
{
|
||||
public uint Name { get; set; }
|
||||
|
||||
public void Serialize(RagonBuffer buffer)
|
||||
internal class RoomUserDataHandler : IHandler
|
||||
{
|
||||
buffer.Write(Name, 16);
|
||||
private readonly RagonClient _client;
|
||||
private readonly RagonListenerList _listenerList;
|
||||
|
||||
public RoomUserDataHandler(RagonClient client, RagonListenerList listenerList)
|
||||
{
|
||||
_client = client;
|
||||
_listenerList = listenerList;
|
||||
}
|
||||
|
||||
public void Deserialize(RagonBuffer buffer)
|
||||
public void Handle(RagonBuffer reader)
|
||||
{
|
||||
Name = buffer.Read(16);
|
||||
var changes = _client.Room?.UserData.Read(reader);
|
||||
_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");
|
||||
* 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)
|
||||
{
|
||||
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();
|
||||
RagonLog.Trace("Dynamic Entities: " + dynamicEntities);
|
||||
for (var i = 0; i < dynamicEntities; i++)
|
||||
@@ -123,12 +110,6 @@ internal class SnapshotHandler : IHandler
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
||||
if (_client.Status == RagonStatus.LOBBY)
|
||||
{
|
||||
_client.SetStatus(RagonStatus.ROOM);
|
||||
_listenerList.OnJoined();
|
||||
}
|
||||
|
||||
foreach (var entity in entities)
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+8
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
* Copyright 2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,11 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Server.Plugin.Web;
|
||||
namespace Ragon.Client;
|
||||
|
||||
[Serializable]
|
||||
public class RoomRemovedRequest
|
||||
public interface IUserData
|
||||
{
|
||||
public RoomDto Room { get; set; }
|
||||
public byte[] this[string key] { get; set; }
|
||||
bool Dirty { get; }
|
||||
IReadOnlyList<string> Read(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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,5 +18,5 @@ namespace Ragon.Client;
|
||||
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,10 @@ namespace Ragon.Client
|
||||
IRagonSceneListener,
|
||||
IRagonOwnershipChangedListener,
|
||||
IRagonPlayerJoinListener,
|
||||
IRagonPlayerLeftListener
|
||||
IRagonPlayerLeftListener,
|
||||
IRagonRoomListListener,
|
||||
IRagonRoomUserDataListener,
|
||||
IRagonPlayerUserDataListener
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+4
-6
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,11 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Ragon.Server.Plugin.Web;
|
||||
namespace Ragon.Client;
|
||||
|
||||
[Serializable]
|
||||
public class RoomCreatedRequest
|
||||
public interface IRagonPlayerUserDataListener
|
||||
{
|
||||
public RoomDto Room { get; set; }
|
||||
public PlayerDto Player { get; set; }
|
||||
void OnPlayerUserDataUpdated(RagonClient client, RagonPlayer player, IReadOnlyList<string> changes);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface IRagonRoomListListener
|
||||
{
|
||||
public void OnRoomListUpdate(RagonClient client, IReadOnlyList<RagonRoomInformation> roomsInfos);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface IRagonRoomUserDataListener
|
||||
{
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,7 @@ namespace Ragon.Client
|
||||
private RagonBuffer _writeBuffer;
|
||||
private RagonRoom _room;
|
||||
private RagonSession _session;
|
||||
private RagonListenerList listeners;
|
||||
private RagonListenerList _listeners;
|
||||
private RagonPlayerCache _playerCache;
|
||||
private RagonEntityCache _entityCache;
|
||||
private RagonEventCache _eventCache;
|
||||
@@ -56,7 +56,7 @@ namespace Ragon.Client
|
||||
|
||||
public RagonClient(INetworkConnection connection, int rate)
|
||||
{
|
||||
listeners = new RagonListenerList(this);
|
||||
_listeners = new RagonListenerList(this);
|
||||
|
||||
_connection = connection;
|
||||
_connection.OnData += OnData;
|
||||
@@ -98,30 +98,37 @@ namespace Ragon.Client
|
||||
|
||||
_writeBuffer = new RagonBuffer();
|
||||
_readBuffer = new RagonBuffer();
|
||||
_session = new RagonSession(this, _writeBuffer);
|
||||
|
||||
_playerCache = new RagonPlayerCache();
|
||||
_session = new RagonSession(this, _writeBuffer);
|
||||
_entityCache = new RagonEntityCache(this, _playerCache, _sceneCollector);
|
||||
|
||||
_handlers = new IHandler[byte.MaxValue];
|
||||
_handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(this, listeners);
|
||||
_handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(listeners);
|
||||
_handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(listeners);
|
||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, listeners, _entityCache);
|
||||
_handlers[(byte)RagonOperation.OWNERSHIP_ROOM_CHANGED] = new OwnershipRoomHandler(listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.OWNERSHIP_ENTITY_CHANGED] = new EntityOwnershipHandler(listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.PLAYER_JOINED] = new PlayerJoinHandler(_playerCache, listeners);
|
||||
_handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, listeners);
|
||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, listeners);
|
||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateHandler(this, _playerCache, _entityCache, _entityListener);
|
||||
_handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(this, _listeners);
|
||||
_handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(_listeners);
|
||||
_handlers[(byte)RagonOperation.JOIN_SUCCESS] =
|
||||
new JoinSuccessHandler(this, _listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(_listeners);
|
||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, _listeners, _entityCache);
|
||||
_handlers[(byte)RagonOperation.OWNERSHIP_ROOM_CHANGED] =
|
||||
new OwnershipRoomHandler(_listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.OWNERSHIP_ENTITY_CHANGED] =
|
||||
new EntityOwnershipHandler(_listeners, _playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.PLAYER_JOINED] = new PlayerJoinHandler(_playerCache, _listeners);
|
||||
_handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, _listeners);
|
||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listeners);
|
||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] =
|
||||
new EntityCreateHandler(this, _playerCache, _entityCache, _entityListener);
|
||||
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityRemoveHandler(_entityCache);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new StateEntityHandler(_entityCache);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventHandler(_playerCache, _entityCache);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventHandler(this, _playerCache);
|
||||
_handlers[(byte)RagonOperation.SNAPSHOT] = new SnapshotHandler(this, listeners, _entityCache, _playerCache, _entityListener);
|
||||
_handlers[(byte)RagonOperation.SNAPSHOT] =
|
||||
new SnapshotHandler(this, _listeners, _entityCache, _playerCache, _entityListener);
|
||||
_handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampHandler(this);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataHandler(_playerCache, listeners);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataHandler(_playerCache, _listeners);
|
||||
_handlers[(byte)RagonOperation.ROOM_LIST_UPDATED] = new RoomListHandler(_session, _listeners);
|
||||
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataHandler(this, _listeners);
|
||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataHandler(_playerCache, _listeners);
|
||||
|
||||
var protocolRaw = RagonVersion.Parse(protocol);
|
||||
_connection.Connect(address, port, protocolRaw);
|
||||
@@ -147,12 +154,14 @@ namespace Ragon.Client
|
||||
_entityCache.WriteState(_writeBuffer);
|
||||
|
||||
SendTimestamp();
|
||||
SendRoomUserData();
|
||||
SendPlayerUserData();
|
||||
}
|
||||
|
||||
_stats.Update(_connection.BytesSent, _connection.BytesReceived, _connection.Ping, dt);
|
||||
}
|
||||
|
||||
listeners.Update();
|
||||
_listeners.Update();
|
||||
_connection.Update();
|
||||
}
|
||||
|
||||
@@ -163,34 +172,40 @@ namespace Ragon.Client
|
||||
_status = RagonStatus.DISCONNECTED;
|
||||
_connection.Disconnect();
|
||||
}
|
||||
|
||||
_connection.Dispose();
|
||||
}
|
||||
|
||||
public void AddListener(IRagonListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonAuthorizationListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonConnectionListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonFailedListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonJoinListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonLeftListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonOwnershipChangedListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonPlayerJoinListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonPlayerLeftListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonSceneListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonSceneRequestListener listener) => listeners.Add(listener);
|
||||
public void AddListener(IRagonDataListener listener) => listeners.Add(listener);
|
||||
|
||||
public void RemoveListener(IRagonListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonAuthorizationListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonConnectionListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonFailedListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonJoinListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonLeftListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonOwnershipChangedListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerJoinListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerLeftListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonSceneListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonSceneRequestListener listener) => listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonDataListener listener) => listeners.Remove(listener);
|
||||
public void AddListener(IRagonListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonAuthorizationListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonConnectionListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonFailedListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonJoinListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonLeftListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonOwnershipChangedListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonPlayerJoinListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonPlayerLeftListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonSceneListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonSceneRequestListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonDataListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonRoomListListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonPlayerUserDataListener listener) => _listeners.Add(listener);
|
||||
public void AddListener(IRagonRoomUserDataListener listener) => _listeners.Add(listener);
|
||||
public void RemoveListener(IRagonListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonAuthorizationListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonConnectionListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonFailedListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonJoinListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonLeftListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonOwnershipChangedListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerJoinListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerLeftListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonSceneListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonSceneRequestListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonDataListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonRoomListListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonRoomUserDataListener listener) => _listeners.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerUserDataListener listener) => _listeners.Remove(listener);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -230,11 +245,43 @@ namespace Ragon.Client
|
||||
_writeBuffer.Write(value.Int1, 32);
|
||||
}
|
||||
|
||||
private void SendRoomUserData()
|
||||
{
|
||||
if (_room == null) return;
|
||||
|
||||
var props = _room.UserData;
|
||||
if (!props.Dirty) return;
|
||||
|
||||
_writeBuffer.Clear();
|
||||
_writeBuffer.WriteOperation(RagonOperation.ROOM_DATA_UPDATED);
|
||||
|
||||
props.Write(_writeBuffer);
|
||||
|
||||
var sendData = _writeBuffer.ToArray();
|
||||
_connection.Reliable.Send(sendData);
|
||||
}
|
||||
|
||||
private void SendPlayerUserData()
|
||||
{
|
||||
if (_playerCache.Local == null) return;
|
||||
|
||||
var props = _playerCache.Local.UserData;
|
||||
if (!props.Dirty) return;
|
||||
|
||||
_writeBuffer.Clear();
|
||||
_writeBuffer.WriteOperation(RagonOperation.PLAYER_DATA_UPDATED);
|
||||
|
||||
props.Write(_writeBuffer);
|
||||
|
||||
var sendData = _writeBuffer.ToArray();
|
||||
_connection.Reliable.Send(sendData);
|
||||
}
|
||||
|
||||
private void OnConnected()
|
||||
{
|
||||
RagonLog.Trace("Connected");
|
||||
|
||||
listeners.OnConnected();
|
||||
_listeners.OnConnected();
|
||||
_status = RagonStatus.CONNECTED;
|
||||
}
|
||||
|
||||
@@ -242,7 +289,7 @@ namespace Ragon.Client
|
||||
{
|
||||
RagonLog.Trace($"Disconnected: {reason}");
|
||||
|
||||
listeners.OnDisconnected(reason);
|
||||
_listeners.OnDisconnected(reason);
|
||||
_status = RagonStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,9 @@ namespace Ragon.Client
|
||||
private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new();
|
||||
private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new();
|
||||
private readonly List<IRagonDataListener> _dataListeners = new();
|
||||
private readonly List<IRagonRoomListListener> _roomListListeners = new();
|
||||
private readonly List<IRagonRoomUserDataListener> _roomUserDataListeners = new();
|
||||
private readonly List<IRagonPlayerUserDataListener> _playerUserDataListeners = new();
|
||||
private readonly List<Action> _delayedActions = new();
|
||||
|
||||
public RagonListenerList(RagonClient client)
|
||||
@@ -50,6 +53,8 @@ namespace Ragon.Client
|
||||
_ownershipChangedListeners.Add(listener);
|
||||
_playerJoinListeners.Add(listener);
|
||||
_playerLeftListeners.Add(listener);
|
||||
_roomUserDataListeners.Add(listener);
|
||||
_playerUserDataListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Remove(IRagonListener listener)
|
||||
@@ -65,6 +70,8 @@ namespace Ragon.Client
|
||||
_ownershipChangedListeners.Remove(listener);
|
||||
_playerJoinListeners.Remove(listener);
|
||||
_playerLeftListeners.Remove(listener);
|
||||
_roomUserDataListeners.Remove(listener);
|
||||
_playerUserDataListeners.Remove(listener);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,6 +138,21 @@ namespace Ragon.Client
|
||||
_playerLeftListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonRoomListListener listener)
|
||||
{
|
||||
_roomListListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonRoomUserDataListener listener)
|
||||
{
|
||||
_roomUserDataListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonPlayerUserDataListener listener)
|
||||
{
|
||||
_playerUserDataListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Remove(IRagonDataListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _dataListeners.Remove(listener));
|
||||
@@ -186,6 +208,21 @@ namespace Ragon.Client
|
||||
_delayedActions.Add(() => _playerLeftListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonRoomListListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _roomListListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonRoomUserDataListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _roomUserDataListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonPlayerUserDataListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _playerUserDataListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void OnAuthorizationSuccess(string playerId, string playerName, string payload)
|
||||
{
|
||||
foreach (var listener in _authorizationListeners)
|
||||
@@ -261,7 +298,25 @@ namespace Ragon.Client
|
||||
public void OnData(RagonPlayer player, byte[] data)
|
||||
{
|
||||
foreach (var listener in _dataListeners)
|
||||
listener.OnData(player, data);
|
||||
listener.OnData(_client, player, data);
|
||||
}
|
||||
|
||||
public void OnRoomList(RagonRoomInformation[] roomInfos)
|
||||
{
|
||||
foreach (var listListener in _roomListListeners)
|
||||
listListener.OnRoomListUpdate(_client, roomInfos);
|
||||
}
|
||||
|
||||
public void OnRoomUserData(IReadOnlyList<string> changes)
|
||||
{
|
||||
foreach (var userDataListener in _roomUserDataListeners)
|
||||
userDataListener.OnUserDataUpdated(_client, changes);
|
||||
}
|
||||
|
||||
public void OnPlayerUserData(RagonPlayer player, IReadOnlyList<string> changes)
|
||||
{
|
||||
foreach(var playerUserDataListener in _playerUserDataListeners)
|
||||
playerUserDataListener.OnPlayerUserDataUpdated(_client, player, 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ namespace Ragon.Client
|
||||
public ushort PeerId { get; set; }
|
||||
public bool IsRoomOwner { get; set; }
|
||||
public bool IsLocal { get; set; }
|
||||
public IUserData UserData { get; private set; }
|
||||
|
||||
public RagonPlayer(ushort peerId, string playerId, string name, bool isRoomOwner, bool isLocal)
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace Ragon.Client
|
||||
IsLocal = isLocal;
|
||||
Name = name;
|
||||
Id = playerId;
|
||||
UserData = isLocal ? new RagonUserData() : new RagonUserDataReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,10 +52,10 @@ public sealed class RagonPlayerCache
|
||||
_localId = localId;
|
||||
}
|
||||
|
||||
public void AddPlayer(ushort peerId, string playerId, string playerName)
|
||||
public RagonPlayer AddPlayer(ushort peerId, string playerId, string playerName)
|
||||
{
|
||||
if (_playersById.ContainsKey(playerId))
|
||||
return;
|
||||
return null;
|
||||
|
||||
var isOwner = playerId == _ownerId;
|
||||
var isLocal = playerId == _localId;
|
||||
@@ -73,6 +73,8 @@ public sealed class RagonPlayerCache
|
||||
_players.Add(player);
|
||||
_playersById.Add(player.Id, player);
|
||||
_playersByConnection.Add(player.PeerId, player);
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
public void RemovePlayer(string playerId)
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,38 +20,72 @@ namespace Ragon.Client
|
||||
{
|
||||
public class RagonRoom : IDisposable
|
||||
{
|
||||
private class EventSubscription : IDisposable
|
||||
{
|
||||
private List<Action<RagonPlayer, IRagonEvent>> _callbacks;
|
||||
private List<Action<RagonPlayer, IRagonEvent>> _localCallbacks;
|
||||
private Action<RagonPlayer, IRagonEvent> _callback;
|
||||
|
||||
public EventSubscription(
|
||||
List<Action<RagonPlayer, IRagonEvent>> callbacks,
|
||||
List<Action<RagonPlayer, IRagonEvent>> localCallbacks,
|
||||
Action<RagonPlayer, IRagonEvent> callback)
|
||||
{
|
||||
_callbacks = callbacks;
|
||||
_localCallbacks = localCallbacks;
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_callbacks?.Remove(_callback);
|
||||
_localCallbacks?.Remove(_callback);
|
||||
|
||||
_callbacks = null!;
|
||||
_localCallbacks = null!;
|
||||
_callback = null!;
|
||||
}
|
||||
}
|
||||
|
||||
private delegate void OnEventDelegate(RagonPlayer player, RagonBuffer serializer);
|
||||
|
||||
private RagonClient _client;
|
||||
private RagonScene _scene;
|
||||
private RagonEntityCache _entityCache;
|
||||
private RagonPlayerCache _playerCache;
|
||||
private RagonRoomInformation _information;
|
||||
private readonly RagonClient _client;
|
||||
private readonly RagonScene _scene;
|
||||
private readonly RagonEntityCache _entityCache;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
private readonly RoomParameters _parameters;
|
||||
private readonly RagonUserData _userData;
|
||||
|
||||
public string Id => _information.RoomId;
|
||||
public int MinPlayers => _information.Min;
|
||||
public int MaxPlayers => _information.Max;
|
||||
public string Id => _parameters.RoomId;
|
||||
public int MinPlayers => _parameters.Min;
|
||||
public int MaxPlayers => _parameters.Max;
|
||||
public string Scene => _scene.Name;
|
||||
|
||||
public IReadOnlyList<RagonPlayer> Players => _playerCache.Players;
|
||||
public RagonPlayer Local => _playerCache.Local;
|
||||
public RagonPlayer Owner => _playerCache.Owner;
|
||||
public RagonUserData UserData => _userData;
|
||||
|
||||
private readonly Dictionary<int, OnEventDelegate> _events = new Dictionary<int, OnEventDelegate>();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners = new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _localListeners =
|
||||
new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
|
||||
private readonly Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>> _listeners =
|
||||
new Dictionary<int, List<Action<RagonPlayer, IRagonEvent>>>();
|
||||
|
||||
public RagonRoom(RagonClient client,
|
||||
RagonEntityCache entityCache,
|
||||
RagonPlayerCache playerCache,
|
||||
RagonRoomInformation information,
|
||||
RoomParameters parameters,
|
||||
RagonScene scene)
|
||||
{
|
||||
_client = client;
|
||||
_information = information;
|
||||
_parameters = parameters;
|
||||
_entityCache = entityCache;
|
||||
_playerCache = playerCache;
|
||||
_scene = scene;
|
||||
_userData = new RagonUserData();
|
||||
}
|
||||
|
||||
internal void Cleanup()
|
||||
@@ -65,19 +99,23 @@ namespace Ragon.Client
|
||||
_scene.Update(sceneName);
|
||||
}
|
||||
|
||||
internal void Event(ushort eventCode, RagonPlayer caller, RagonBuffer buffer)
|
||||
internal void HandleEvent(ushort eventCode, RagonPlayer caller, RagonBuffer buffer)
|
||||
{
|
||||
if (_events.TryGetValue(eventCode, out var evnt))
|
||||
evnt?.Invoke(caller, buffer);
|
||||
else
|
||||
RagonLog.Warn($"Handler event on entity {Id} with eventCode {eventCode} not defined");
|
||||
RagonLog.Warn($"Handler event {Id} with eventCode {eventCode} not defined");
|
||||
}
|
||||
|
||||
public Action<RagonPlayer, IRagonEvent> OnEvent<TEvent>(Action<RagonPlayer, TEvent> callback) where TEvent : IRagonEvent, new()
|
||||
internal void HandleUserData(RagonBuffer buffer)
|
||||
{
|
||||
_userData.Read(buffer);
|
||||
}
|
||||
|
||||
public IDisposable OnEvent<TEvent>(Action<RagonPlayer, TEvent> callback) where TEvent : IRagonEvent, new()
|
||||
{
|
||||
var t = new TEvent();
|
||||
var eventCode = _client.Event.GetEventCode(t);
|
||||
|
||||
var action = (RagonPlayer player, IRagonEvent eventData) => callback.Invoke(player, (TEvent)eventData);
|
||||
|
||||
if (!_listeners.TryGetValue(eventCode, out var callbacks))
|
||||
@@ -106,26 +144,18 @@ namespace Ragon.Client
|
||||
});
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
public void OffEvent<TEvent>(Action<RagonPlayer, IRagonEvent> callback) where TEvent : IRagonEvent, new()
|
||||
{
|
||||
var t = new TEvent();
|
||||
var eventCode = _client.Event.GetEventCode(t);
|
||||
|
||||
if (_listeners.TryGetValue(eventCode, out var callbacks))
|
||||
callbacks.Remove(callback);
|
||||
|
||||
if (_localListeners.TryGetValue(eventCode, out var localCallbacks))
|
||||
localCallbacks.Remove(callback);
|
||||
return new EventSubscription(callbacks, localCallbacks, action);
|
||||
}
|
||||
|
||||
public void LoadScene(string sceneName) => _scene.Load(sceneName);
|
||||
public void SceneLoaded() => _scene.SceneLoaded();
|
||||
|
||||
public void ReplicateEvent<TEvent>(TEvent evnt, RagonTarget target, RagonReplicationMode mode) where TEvent : IRagonEvent, new() => _scene.ReplicateEvent(evnt, target, mode);
|
||||
public void ReplicateEvent<TEvent>(TEvent evnt, RagonPlayer target, RagonReplicationMode mode) where TEvent : IRagonEvent, new() => _scene.ReplicateEvent(evnt, target, mode);
|
||||
public void ReplicateEvent<TEvent>(TEvent evnt, RagonTarget target, RagonReplicationMode mode)
|
||||
where TEvent : IRagonEvent, new() => _scene.ReplicateEvent(evnt, target, mode);
|
||||
|
||||
public void ReplicateEvent<TEvent>(TEvent evnt, RagonPlayer target, RagonReplicationMode mode)
|
||||
where TEvent : IRagonEvent, new() => _scene.ReplicateEvent(evnt, target, mode);
|
||||
|
||||
public void ReplicateData(byte[] data, bool reliable = false) => _scene.ReplicateData(data, reliable);
|
||||
|
||||
public void CreateEntity(RagonEntity entity) => CreateEntity(entity, null);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Ragon.Client
|
||||
{
|
||||
public struct RagonRoomInformation
|
||||
{
|
||||
public string Id;
|
||||
public string Scene;
|
||||
public int PlayerMax;
|
||||
public int PlayerMin;
|
||||
public int PlayerCount;
|
||||
public Dictionary<string, byte[]> Properties;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
* 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)target);
|
||||
|
||||
evnt.Serialize(buffer);
|
||||
|
||||
var sendData = buffer.ToArray();
|
||||
_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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client
|
||||
{
|
||||
public class RagonUserData : IUserData
|
||||
{
|
||||
public byte[] this[string key]
|
||||
{
|
||||
get => _properties[key];
|
||||
set
|
||||
{
|
||||
_properties[key] = value;
|
||||
|
||||
if (!_changesCache.ContainsKey(key))
|
||||
{
|
||||
_localChanges.Add(key);
|
||||
_changesCache.Add(key, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
public RagonUserData()
|
||||
{
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> Read(RagonBuffer buffer)
|
||||
{
|
||||
var len = buffer.ReadUShort();
|
||||
var changes = new List<string>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
var key = buffer.ReadString();
|
||||
var valueSize = buffer.ReadUShort();
|
||||
if (valueSize > 0)
|
||||
{
|
||||
var value = buffer.ReadBytes(valueSize);
|
||||
_properties[key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_properties.Remove(key);
|
||||
}
|
||||
|
||||
changes.Add(key);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
public void Write(RagonBuffer buffer)
|
||||
{
|
||||
buffer.WriteUShort((ushort)_localChanges.Count);
|
||||
foreach (var propertyChanged in _localChanges)
|
||||
{
|
||||
buffer.WriteString(propertyChanged);
|
||||
if (_properties.TryGetValue(propertyChanged, out var property))
|
||||
{
|
||||
buffer.WriteUShort((ushort)property.Length);
|
||||
buffer.WriteBytes(property);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.WriteUShort(0);
|
||||
}
|
||||
}
|
||||
|
||||
_localChanges.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2024 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public class RagonUserDataReadOnly : IUserData
|
||||
{
|
||||
public byte[] this[string key]
|
||||
{
|
||||
get => _properties[key];
|
||||
set { }
|
||||
}
|
||||
|
||||
public bool Dirty => _dirty;
|
||||
|
||||
private bool _dirty = false;
|
||||
private readonly Dictionary<string, byte[]> _properties = new();
|
||||
|
||||
public RagonUserDataReadOnly()
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(RagonBuffer buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> Read(RagonBuffer buffer)
|
||||
{
|
||||
var len = buffer.ReadUShort();
|
||||
var changes = new List<string>(len);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
var key = buffer.ReadString();
|
||||
var valueSize = buffer.ReadUShort();
|
||||
if (valueSize > 0)
|
||||
{
|
||||
var value = buffer.ReadBytes(valueSize);
|
||||
_properties[key] = value;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_properties.Remove(key);
|
||||
}
|
||||
|
||||
changes.Add(key);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Title>Ragon.Protocol</Title>
|
||||
<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>
|
||||
<RepositoryType>Source</RepositoryType>
|
||||
<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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace Ragon.Protocol
|
||||
{
|
||||
public class RagonBuffer
|
||||
{
|
||||
private const int MaxBufferSize = 1024 * 1024; // 1MB max buffer size
|
||||
|
||||
private int _read;
|
||||
private int _write;
|
||||
private uint[] _buckets;
|
||||
@@ -283,6 +285,7 @@ namespace Ragon.Protocol
|
||||
_write += numBits;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint Read(int numBits = 16)
|
||||
{
|
||||
@@ -330,6 +333,9 @@ namespace Ragon.Protocol
|
||||
var limit = (size + 32 - 1) / 32;
|
||||
var capacity = size;
|
||||
|
||||
if (index + limit >= _buckets.Length)
|
||||
Resize(size);
|
||||
|
||||
for (int i = 0; i < limit; i++)
|
||||
{
|
||||
var dataSize = capacity > 32 ? 32 : capacity;
|
||||
@@ -400,6 +406,12 @@ namespace Ragon.Protocol
|
||||
public void FromArray(byte[] data)
|
||||
{
|
||||
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;
|
||||
|
||||
if (_buckets.Length < bucketsCount)
|
||||
@@ -489,7 +501,14 @@ namespace Ragon.Protocol
|
||||
|
||||
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);
|
||||
_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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,5 +44,8 @@ namespace Ragon.Protocol
|
||||
TRANSFER_ROOM_OWNERSHIP = 23,
|
||||
TRANSFER_ENTITY_OWNERSHIP = 24,
|
||||
TIMESTAMP_SYNCHRONIZATION = 25,
|
||||
ROOM_LIST_UPDATED = 26,
|
||||
PLAYER_DATA_UPDATED = 27,
|
||||
ROOM_DATA_UPDATED = 28,
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Ragon.Relay</RootNamespace>
|
||||
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
@@ -28,4 +28,9 @@
|
||||
<ProjectReference Include="..\Ragon.Server\Ragon.Server.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.3.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,27 +14,35 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NLog;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using Ragon.Server;
|
||||
using Ragon.Server.ENetServer;
|
||||
using Ragon.Server.WebSocketServer;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Logging;
|
||||
using Ragon.Server.Plugin;
|
||||
using Ragon.Server.WebSocketServer;
|
||||
|
||||
namespace Ragon.Relay;
|
||||
|
||||
namespace Ragon.Relay
|
||||
{
|
||||
public class Relay
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
var logger = LogManager.GetLogger("Ragon.Relay");
|
||||
LoggerManager.SetLoggerFactory(new RelayLoggerFactory());
|
||||
|
||||
var logger = LoggerManager.GetLogger("Relay");
|
||||
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);
|
||||
|
||||
INetworkServer networkServer = new ENetServer();
|
||||
IServerPlugin plugin = new RelayServerPlugin();
|
||||
|
||||
switch (serverType)
|
||||
{
|
||||
case ServerType.ENET:
|
||||
@@ -45,8 +53,30 @@ public class Relay
|
||||
break;
|
||||
}
|
||||
|
||||
var relay = new RagonServer(networkServer, plugin, configuration);
|
||||
logger.Info("Started");
|
||||
var serverConfiguration = new RagonServerConfiguration()
|
||||
{
|
||||
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();
|
||||
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,20 +1,15 @@
|
||||
{
|
||||
"serverKey": "defaultkey",
|
||||
"serverType": "enet",
|
||||
"serverAddress": "*",
|
||||
"serverTickRate": 30,
|
||||
"gameProtocol": "1.0.0",
|
||||
"port": 5000,
|
||||
"httpPort": 5001,
|
||||
"httpKey": "defaultkey",
|
||||
"protocol": "1.0.0",
|
||||
"port": 8000,
|
||||
"limitConnections": 4095,
|
||||
"limitPlayersPerRoom": 20,
|
||||
"limitRooms": 200,
|
||||
"limitBufferedEvents": 50,
|
||||
"webHooks":
|
||||
{
|
||||
"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"
|
||||
}
|
||||
"limitUserDataSize": 1024,
|
||||
"limitPropertySize": 512,
|
||||
"limitConnectionsPerProject": 100
|
||||
}
|
||||
@@ -4,12 +4,21 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<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>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ENet-CSharp" Version="2.4.8" />
|
||||
<PackageReference Include="NLog" Version="5.2.2" />
|
||||
</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");
|
||||
* 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
|
||||
{
|
||||
private static ushort _iterator = 0;
|
||||
public ushort Id { get; }
|
||||
public INetworkChannel Reliable { get; private set; }
|
||||
public INetworkChannel Unreliable { get; private set; }
|
||||
@@ -30,7 +31,8 @@ public sealed class ENetConnection: INetworkConnection
|
||||
{
|
||||
_peer = peer;
|
||||
|
||||
Id = (ushort) peer.ID;
|
||||
// Id = (ushort) peer.ID;
|
||||
Id = _iterator++;
|
||||
Reliable = new ENetReliableChannel(peer, NetworkChannel.RELIABLE);
|
||||
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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,26 +15,24 @@
|
||||
*/
|
||||
|
||||
using ENet;
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Logging;
|
||||
|
||||
namespace Ragon.Server.ENetServer
|
||||
{
|
||||
public sealed class ENetServer : INetworkServer
|
||||
{
|
||||
public Executor Executor => _executor;
|
||||
|
||||
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 INetworkListener _listener;
|
||||
private uint _protocol;
|
||||
private ENet.Event _event;
|
||||
private Executor _executor = new();
|
||||
|
||||
public void Start(INetworkListener listener, NetworkConfiguration configuration)
|
||||
public void Listen(INetworkListener listener, NetworkConfiguration configuration)
|
||||
{
|
||||
Library.Initialize();
|
||||
|
||||
@@ -51,7 +49,7 @@ namespace Ragon.Server.ENetServer
|
||||
_host.Create(address, _connections.Length, 2, 0, 0, 1024 * 1024);
|
||||
|
||||
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}");
|
||||
}
|
||||
|
||||
@@ -79,7 +77,7 @@ namespace Ragon.Server.ENetServer
|
||||
{
|
||||
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);
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user