wip
This commit is contained in:
@@ -76,11 +76,10 @@ namespace Ragon.Server.Handler
|
||||
|
||||
var information = new RoomInformation()
|
||||
{
|
||||
Scene = _roomParameters.Scene,
|
||||
Max = _roomParameters.Max,
|
||||
Min = _roomParameters.Min,
|
||||
};
|
||||
|
||||
|
||||
if (information.Max > _configuration.LimitPlayersPerRoom)
|
||||
information.Max = _configuration.LimitPlayersPerRoom;
|
||||
|
||||
@@ -97,8 +96,7 @@ namespace Ragon.Server.Handler
|
||||
context.Lobby.Persist(room);
|
||||
context.SetRoom(room, roomPlayer);
|
||||
|
||||
_logger.Trace(
|
||||
$"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
|
||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id}");
|
||||
|
||||
JoinSuccess(roomPlayer, room, Writer);
|
||||
|
||||
@@ -114,7 +112,6 @@ namespace Ragon.Server.Handler
|
||||
writer.WriteString(room.Id);
|
||||
writer.WriteUShort((ushort)room.PlayerMin);
|
||||
writer.WriteUShort((ushort)room.PlayerMax);
|
||||
writer.WriteString(room.Scene);
|
||||
writer.WriteString(player.Id);
|
||||
writer.WriteString(room.Owner.Id);
|
||||
|
||||
|
||||
@@ -1,52 +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;
|
||||
using Ragon.Server.IO;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class RoomDataOperation : BaseOperation
|
||||
{
|
||||
public RoomDataOperation(RagonStream reader, RagonStream writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
var room = context.Room;
|
||||
|
||||
|
||||
var data = Reader.ReadBinary(Reader.Lenght);
|
||||
var dataSize = data.Length - 1;
|
||||
var headerSize = 3;
|
||||
var size = headerSize + dataSize;
|
||||
var sendData = new byte[size];
|
||||
var peerId = player.Connection.Id;
|
||||
|
||||
sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA;
|
||||
sendData[1] = (byte)peerId;
|
||||
sendData[2] = (byte)(peerId >> 8);
|
||||
|
||||
var pluginData = new byte[dataSize];
|
||||
Array.Copy(data, 1, pluginData, 0, dataSize);
|
||||
room.Plugin.OnData(player, pluginData);
|
||||
|
||||
Array.Copy(data, 1, sendData, headerSize, dataSize);
|
||||
room.Broadcast(sendData, room.ReadyPlayersList, NetworkChannel.RELIABLE);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,6 @@ public sealed class RoomJoinOperation : BaseOperation
|
||||
writer.WriteString(room.Id);
|
||||
writer.WriteUShort((ushort)room.PlayerMin);
|
||||
writer.WriteUShort((ushort)room.PlayerMax);
|
||||
writer.WriteString(room.Scene);
|
||||
writer.WriteString(context.RoomPlayer.Id);
|
||||
writer.WriteString(room.Owner.Id);
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
||||
private readonly RagonRoomParameters _roomParameters = new();
|
||||
private readonly IServerPlugin _serverPlugin;
|
||||
private readonly RagonServerConfiguration _configuration;
|
||||
|
||||
|
||||
public RoomJoinOrCreateOperation(
|
||||
RagonStream reader,
|
||||
RagonStream writer,
|
||||
IServerPlugin serverPlugin,
|
||||
IServerPlugin serverPlugin,
|
||||
RagonServerConfiguration configuration
|
||||
) : base(reader, writer)
|
||||
{
|
||||
@@ -52,52 +52,35 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
||||
|
||||
var roomId = Guid.NewGuid().ToString();
|
||||
var lobbyPlayer = context.LobbyPlayer;
|
||||
|
||||
|
||||
_roomParameters.Deserialize(Reader);
|
||||
|
||||
if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
|
||||
|
||||
var information = new RoomInformation()
|
||||
{
|
||||
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
Max = _roomParameters.Max,
|
||||
Min = _roomParameters.Min,
|
||||
};
|
||||
|
||||
context.SetRoom(existsRoom, player);
|
||||
if (information.Max > _configuration.LimitPlayersPerRoom)
|
||||
information.Max = _configuration.LimitPlayersPerRoom;
|
||||
|
||||
JoinSuccess(player, existsRoom, Writer);
|
||||
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||
|
||||
existsRoom.RestoreBufferedEvents(player);
|
||||
_serverPlugin.OnRoomCreate(lobbyPlayer, room);
|
||||
|
||||
existsRoom.Plugin.OnPlayerJoined(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
var information = new RoomInformation()
|
||||
{
|
||||
Scene = _roomParameters.Scene,
|
||||
Max = _roomParameters.Max,
|
||||
Min = _roomParameters.Min,
|
||||
};
|
||||
room.Plugin.OnAttached(room);
|
||||
|
||||
if (information.Max > _configuration.LimitPlayersPerRoom)
|
||||
information.Max = _configuration.LimitPlayersPerRoom;
|
||||
context.Lobby.Persist(room);
|
||||
context.Scheduler.Run(room);
|
||||
context.SetRoom(room, roomPlayer);
|
||||
|
||||
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id}");
|
||||
|
||||
_serverPlugin.OnRoomCreate(lobbyPlayer, room);
|
||||
JoinSuccess(roomPlayer, room, Writer);
|
||||
|
||||
room.Plugin.OnAttached(room);
|
||||
|
||||
context.Lobby.Persist(room);
|
||||
context.Scheduler.Run(room);
|
||||
context.SetRoom(room, roomPlayer);
|
||||
|
||||
_logger.Trace(
|
||||
$"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
|
||||
|
||||
JoinSuccess(roomPlayer, room, Writer);
|
||||
|
||||
room.Plugin.OnPlayerJoined(roomPlayer);
|
||||
}
|
||||
room.Plugin.OnPlayerJoined(roomPlayer);
|
||||
}
|
||||
|
||||
private void JoinSuccess(RagonRoomPlayer player, RagonRoom room, RagonStream writer)
|
||||
@@ -107,7 +90,6 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
||||
writer.WriteString(room.Id);
|
||||
writer.WriteUShort((ushort)room.PlayerMin);
|
||||
writer.WriteUShort((ushort)room.PlayerMax);
|
||||
writer.WriteString(room.Scene);
|
||||
writer.WriteString(player.Id);
|
||||
writer.WriteString(room.Owner.Id);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public sealed class RoomLeaveOperation: BaseOperation
|
||||
|
||||
public RoomLeaveOperation(RagonStream reader, RagonStream writer): base(reader, writer)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
|
||||
Reference in New Issue
Block a user