refactor: updated order of plugins callbacks

This commit is contained in:
2024-05-12 11:37:44 +03:00
parent 646744c9a1
commit 0ede864f40
4 changed files with 21 additions and 13 deletions
+12
View File
@@ -34,9 +34,21 @@ public class RelayRoomPlugin: BaseRoomPlugin
return true; return true;
} }
public override bool OnPlayerJoined(RagonRoomPlayer player)
{
return false;
}
public override bool OnPlayerLeaved(RagonRoomPlayer player)
{
return false;
}
public override bool OnData(RagonRoomPlayer player, byte[] data) public override bool OnData(RagonRoomPlayer player, byte[] data)
{ {
Console.WriteLine("Data received"); Console.WriteLine("Data received");
return true; return true;
} }
} }
@@ -80,9 +80,6 @@ public sealed class RoomCreateOperation : BaseOperation
var roomPlugin = _serverPlugin.CreateRoomPlugin(information); var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
var room = new RagonRoom(roomId, information, roomPlugin); var room = new RagonRoom(roomId, information, roomPlugin);
if (!roomPlugin.OnPlayerJoined(roomPlayer))
return;
roomPlayer.OnAttached(room); roomPlayer.OnAttached(room);
context.Scheduler.Run(room); context.Scheduler.Run(room);
@@ -95,6 +92,8 @@ public sealed class RoomCreateOperation : BaseOperation
JoinSuccess(roomPlayer, room, Writer); JoinSuccess(roomPlayer, room, Writer);
roomPlugin.OnPlayerJoined(roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}"); _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
} }
@@ -49,15 +49,14 @@ public sealed class RoomJoinOperation : BaseOperation
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name); var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
context.SetRoom(existsRoom, player); context.SetRoom(existsRoom, player);
if (!existsRoom.Plugin.OnPlayerJoined(player))
return;
_webHook.RoomJoined(context, existsRoom, player); _webHook.RoomJoined(context, existsRoom, player);
JoinSuccess(context, existsRoom, Writer); JoinSuccess(context, existsRoom, Writer);
existsRoom.RestoreBufferedEvents(player); existsRoom.RestoreBufferedEvents(player);
existsRoom.Plugin.OnPlayerJoined(player);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to {existsRoom.Id}"); _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to {existsRoom.Id}");
} }
@@ -54,9 +54,6 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
{ {
var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name); var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name);
if (!existsRoom.Plugin.OnPlayerJoined(player))
return;
context.SetRoom(existsRoom, player); context.SetRoom(existsRoom, player);
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player); _ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
@@ -64,6 +61,8 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
JoinSuccess(player, existsRoom, Writer); JoinSuccess(player, existsRoom, Writer);
existsRoom.RestoreBufferedEvents(player); existsRoom.RestoreBufferedEvents(player);
existsRoom.Plugin.OnPlayerJoined(player);
} }
else else
{ {
@@ -78,9 +77,6 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
var roomPlugin = _serverPlugin.CreateRoomPlugin(information); var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
var room = new RagonRoom(roomId, information, roomPlugin); var room = new RagonRoom(roomId, information, roomPlugin);
if (!roomPlugin.OnPlayerJoined(roomPlayer))
return;
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer); _ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
context.Lobby.Persist(room); context.Lobby.Persist(room);
@@ -90,6 +86,8 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
_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);
room.Plugin.OnPlayerJoined(roomPlayer);
} }
} }