Files

88 lines
2.4 KiB
C#
Raw Permalink Normal View History

2023-03-06 10:06:43 +04:00
/*
2024-05-19 12:26:42 +03:00
* Copyright 2023-2024 Eduard Kargin <kargin.eduard@gmail.com>
2023-03-06 10:06:43 +04:00
*
* 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;
2024-04-13 16:17:31 +03:00
public struct RoomParameters
2023-03-06 10:06:43 +04:00
{
2024-04-13 16:17:31 +03:00
public RoomParameters(string roomId, string playerId, string ownerId, ushort min, ushort max)
2023-03-06 10:06:43 +04:00
{
RoomId = roomId;
PlayerId = playerId;
OwnerId = ownerId;
Min = min;
Max = max;
}
public string RoomId { get; private set; }
public string PlayerId { get; private set; }
public string OwnerId { get; private set; }
public ushort Min { get; private set; }
public ushort Max { get; private set; }
}
2023-10-04 14:42:59 +03:00
internal class JoinSuccessHandler : IHandler
2023-03-06 10:06:43 +04:00
{
private readonly RagonListenerList _listenerList;
private readonly RagonPlayerCache _playerCache;
private readonly RagonClient _client;
2025-01-18 17:30:03 +03:00
private readonly RagonRoom _room;
2023-03-06 10:06:43 +04:00
public JoinSuccessHandler(
RagonClient client,
2025-01-18 17:30:03 +03:00
RagonRoom room
2023-03-06 10:06:43 +04:00
)
{
_client = client;
2025-01-18 17:30:03 +03:00
_room = room;
2023-03-06 10:06:43 +04:00
}
2024-09-28 20:11:56 +03:00
public void Handle(RagonStream reader)
2023-03-06 10:06:43 +04:00
{
2023-10-08 21:13:31 +03:00
var roomId = reader.ReadString();
var min = reader.ReadUShort();
var max = reader.ReadUShort();
var localId = reader.ReadString();
var ownerId = reader.ReadString();
2025-01-18 17:30:03 +03:00
var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max);
_playerCache.SetOwnerAndLocal(ownerId, localId);
2025-01-18 17:30:03 +03:00
_room.Reset(roomInfo);
_room.UserData.Read(reader);
2023-03-06 10:06:43 +04:00
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);
2025-01-18 17:30:03 +03:00
player.UserData.Read(reader);
RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}");
}
2025-01-18 17:30:03 +03:00
_client.UpdateState(RagonState.ROOM);
_listenerList.OnJoined();
2023-03-06 10:06:43 +04:00
}
}