fix: added checking max players per room from config
This commit is contained in:
@@ -29,10 +29,17 @@ namespace Ragon.Server.Handler
|
|||||||
|
|
||||||
private readonly RagonRoomParameters _roomParameters = new();
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
private readonly IServerPlugin _serverPlugin;
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly RagonServerConfiguration _configuration;
|
||||||
|
|
||||||
public RoomCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin) : base(reader,
|
public RoomCreateOperation(
|
||||||
|
RagonBuffer reader,
|
||||||
|
RagonBuffer writer,
|
||||||
|
IServerPlugin serverPlugin,
|
||||||
|
RagonServerConfiguration configuration
|
||||||
|
) : base(reader,
|
||||||
writer)
|
writer)
|
||||||
{
|
{
|
||||||
|
_configuration = configuration;
|
||||||
_serverPlugin = serverPlugin;
|
_serverPlugin = serverPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +81,9 @@ namespace Ragon.Server.Handler
|
|||||||
Min = _roomParameters.Min,
|
Min = _roomParameters.Min,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (information.Max > _configuration.LimitPlayersPerRoom)
|
||||||
|
information.Max = _configuration.LimitPlayersPerRoom;
|
||||||
|
|
||||||
var lobbyPlayer = context.LobbyPlayer;
|
var lobbyPlayer = context.LobbyPlayer;
|
||||||
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,16 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
|
|
||||||
private readonly RagonRoomParameters _roomParameters = new();
|
private readonly RagonRoomParameters _roomParameters = new();
|
||||||
private readonly IServerPlugin _serverPlugin;
|
private readonly IServerPlugin _serverPlugin;
|
||||||
|
private readonly RagonServerConfiguration _configuration;
|
||||||
|
|
||||||
public RoomJoinOrCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin): base(reader, writer)
|
public RoomJoinOrCreateOperation(
|
||||||
|
RagonBuffer reader,
|
||||||
|
RagonBuffer writer,
|
||||||
|
IServerPlugin serverPlugin,
|
||||||
|
RagonServerConfiguration configuration
|
||||||
|
) : base(reader, writer)
|
||||||
{
|
{
|
||||||
|
_configuration = configuration;
|
||||||
_serverPlugin = serverPlugin;
|
_serverPlugin = serverPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +76,9 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
Min = _roomParameters.Min,
|
Min = _roomParameters.Min,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (information.Max > _configuration.LimitPlayersPerRoom)
|
||||||
|
information.Max = _configuration.LimitPlayersPerRoom;
|
||||||
|
|
||||||
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
|
||||||
var room = new RagonRoom(roomId, information, roomPlugin);
|
var room = new RagonRoom(roomId, information, roomPlugin);
|
||||||
@@ -81,7 +91,8 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
|
|||||||
context.Scheduler.Run(room);
|
context.Scheduler.Run(room);
|
||||||
context.SetRoom(room, roomPlayer);
|
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} with scene {information.Scene}");
|
||||||
|
|
||||||
JoinSuccess(roomPlayer, room, Writer);
|
JoinSuccess(roomPlayer, room, Writer);
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
|
|
||||||
_handlers = new BaseOperation[byte.MaxValue];
|
_handlers = new BaseOperation[byte.MaxValue];
|
||||||
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _serverPlugin, contextObserver, configuration);
|
_handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, _serverPlugin, contextObserver, configuration);
|
||||||
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin);
|
_handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _configuration);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin);
|
_handlers[(byte)RagonOperation.CREATE_ROOM] = new RoomCreateOperation(_reader, _writer, plugin, _configuration);
|
||||||
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer);
|
||||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadOperation(_reader, _writer);
|
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadOperation(_reader, _writer);
|
||||||
|
|||||||
Reference in New Issue
Block a user