wip
This commit is contained in:
@@ -38,7 +38,7 @@ internal class AuthorizeSuccessHandler: IHandler
|
||||
var playerName = reader.ReadString();
|
||||
var playerPayload = reader.ReadString();
|
||||
|
||||
_client.SetStatus(RagonStatus.LOBBY);
|
||||
_client.UpdateState(RagonState.LOBBY);
|
||||
_listenerList.OnAuthorizationSuccess(playerId, playerName, playerPayload);
|
||||
}
|
||||
}
|
||||
@@ -42,16 +42,15 @@ internal class JoinSuccessHandler : IHandler
|
||||
private readonly RagonListenerList _listenerList;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
private readonly RagonClient _client;
|
||||
private readonly RagonRoom _room;
|
||||
|
||||
public JoinSuccessHandler(
|
||||
RagonClient client,
|
||||
RagonListenerList listenerList,
|
||||
RagonPlayerCache playerCache
|
||||
RagonRoom room
|
||||
)
|
||||
{
|
||||
_client = client;
|
||||
_listenerList = listenerList;
|
||||
_playerCache = playerCache;
|
||||
_room = room;
|
||||
}
|
||||
|
||||
public void Handle(RagonStream reader)
|
||||
@@ -59,17 +58,14 @@ internal class JoinSuccessHandler : IHandler
|
||||
var roomId = reader.ReadString();
|
||||
var min = reader.ReadUShort();
|
||||
var max = reader.ReadUShort();
|
||||
var sceneName = reader.ReadString();
|
||||
var localId = reader.ReadString();
|
||||
var ownerId = reader.ReadString();
|
||||
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
|
||||
|
||||
_playerCache.SetOwnerAndLocal(ownerId, localId);
|
||||
|
||||
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
|
||||
var room = new RagonRoom(_client, _playerCache, roomInfo);
|
||||
_room.Reset(roomInfo);
|
||||
_room.UserData.Read(reader);
|
||||
|
||||
room.UserData.Read(reader);
|
||||
|
||||
var playersCount = reader.ReadUShort();
|
||||
RagonLog.Trace("Players: " + playersCount);
|
||||
for (var i = 0; i < playersCount; i++)
|
||||
@@ -79,15 +75,14 @@ internal class JoinSuccessHandler : IHandler
|
||||
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);
|
||||
|
||||
|
||||
_client.UpdateState(RagonState.ROOM);
|
||||
|
||||
_listenerList.OnJoined();
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ internal class LeaveRoomHandler : IHandler
|
||||
public void Handle(RagonStream reader)
|
||||
{
|
||||
_listenerList.OnLeft();
|
||||
_client.Room.Cleanup();
|
||||
|
||||
_client.Room.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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 RoomDataHandler: IHandler
|
||||
{
|
||||
private readonly RagonListenerList _listeners;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
|
||||
public RoomDataHandler(
|
||||
RagonPlayerCache playerCache,
|
||||
RagonListenerList listeners)
|
||||
{
|
||||
_playerCache = playerCache;
|
||||
_listeners = listeners;
|
||||
}
|
||||
|
||||
public void Handle(RagonStream reader)
|
||||
{
|
||||
var rawData = reader.ReadBinary(reader.Lenght);
|
||||
var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
|
||||
|
||||
RagonPlayer player = null;
|
||||
if (peerId != 10000)
|
||||
{
|
||||
player = _playerCache.GetPlayerByPeer(peerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found");
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var headerSize = 3;
|
||||
var payload = new byte[rawData.Length - headerSize];
|
||||
|
||||
Array.Copy(rawData, headerSize, payload, 0, payload.Length);
|
||||
|
||||
_listeners.OnData(player, payload);
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,13 @@ public class RoomEventHandler : IHandler
|
||||
{
|
||||
var eventCode = buffer.ReadUShort();
|
||||
var peerId = buffer.ReadUShort();
|
||||
var executionMode = (RagonReplicationMode)buffer.ReadByte();
|
||||
var executionMode = (RagonReplicationMode) buffer.ReadByte();
|
||||
|
||||
var player = _playerCache.GetPlayerByPeer(peerId);
|
||||
if (player == null)
|
||||
{
|
||||
RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}");
|
||||
|
||||
|
||||
_playerCache.Dump();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@ public class TimestampHandler: IHandler
|
||||
var timestamp1 = (uint)buffer.ReadInt();
|
||||
var value = new DoubleToUInt { Int0 = timestamp0, Int1 = timestamp1 };
|
||||
|
||||
_client.SetTimestamp(value.Double);
|
||||
_client.UpdateTimestamp(value.Double);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user