From 9843567381de17b50e12963e757bf04aaae0e67a Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 01:34:25 +0900 Subject: [PATCH 01/12] =?UTF-8?q?chore:=20sbt=E3=81=AE=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E3=82=92=E4=B8=8A=E3=81=92=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bsp/sbt.json | 1 + project/build.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .bsp/sbt.json diff --git a/.bsp/sbt.json b/.bsp/sbt.json new file mode 100644 index 0000000..03e1471 --- /dev/null +++ b/.bsp/sbt.json @@ -0,0 +1 @@ +{"name":"sbt","version":"1.6.1","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["C:\\Users\\rito\\.jdks\\openjdk-18.0.2.1/bin/java","-Xms100m","-Xmx100m","-classpath","C:/Users/rito/AppData/Local/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.7571.182.plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=C:/Users/rito/AppData/Local/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.7571.182.plugins/Scala/launcher/sbt-launch.jar"]} \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index 302b6be..50fd0c7 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.3.13 \ No newline at end of file +sbt.version = 1.6.1 \ No newline at end of file From 5aaeca0e037a122ebfcb18ee69f83742460b44a6 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 02:48:10 +0900 Subject: [PATCH 02/12] =?UTF-8?q?chore:=20=E5=87=A6=E7=90=86=E3=81=AE?= =?UTF-8?q?=E6=B5=81=E3=82=8C=E3=81=AB=E3=83=AD=E3=82=B0=E3=82=92=E4=BB=95?= =?UTF-8?q?=E8=BE=BC=E3=82=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bungeesemaphore/BungeeSemaphorePlugin.scala | 2 +- .../application/EmitGlobalLock.scala | 7 +++++-- .../actions/AwaitDataSaveConfirmation.scala | 8 ++++++-- .../listeners/SemaphoringServerSwitcher.scala | 17 +++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala index c001979..1a66766 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala @@ -58,7 +58,7 @@ class BungeeSemaphorePlugin extends Plugin { val listeners = Vector( connectionLockSynchronizer, - new SemaphoringServerSwitcher[IO] + new SemaphoringServerSwitcher[IO](getLogger) ) listeners.foreach { listener => diff --git a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala index 39b8ab2..1f6dee9 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala @@ -1,14 +1,17 @@ package click.seichi.bungeesemaphore.application import cats.effect.Sync +import cats.implicits._ import click.seichi.bungeesemaphore.application.configuration.Configuration import click.seichi.bungeesemaphore.domain.{PlayerName, ServerName} +import java.util.logging.Logger + object EmitGlobalLock { - def of[F[_]: HasGlobalPlayerDataSaveLock: Sync](playerName: PlayerName, disconnectionSource: ServerName) + def of[F[_]: HasGlobalPlayerDataSaveLock: Sync](playerName: PlayerName, disconnectionSource: ServerName, logger: Logger) (implicit configuration: Configuration): F[Unit] = { if (configuration.emitsSaveSignalOnDisconnect(disconnectionSource)) { - HasGlobalPlayerDataSaveLock[F].lock(playerName) + HasGlobalPlayerDataSaveLock[F].lock(playerName) >> Sync[F].delay { logger.info(s"$playerName's data being saved'") } } else { Sync[F].unit } diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala index 52c14b2..9938d4a 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala @@ -7,11 +7,13 @@ import click.seichi.bungeesemaphore.domain.{PlayerName, ServerName} import net.md_5.bungee.api.config.ServerInfo import net.md_5.bungee.api.connection.ProxiedPlayer +import java.util.logging.Logger + object AwaitDataSaveConfirmation { import cats.implicits._ - def of[F[_] : Sync : HasGlobalPlayerDataSaveLock](player: ProxiedPlayer, targetServer: ServerInfo) + def of[F[_] : Sync : HasGlobalPlayerDataSaveLock](player: ProxiedPlayer, targetServer: ServerInfo, logger: Logger) (implicit configuration: Configuration): F[Unit] = { if (configuration.shouldAwaitForSaveSignal(ServerName(targetServer.getName))) { HasGlobalPlayerDataSaveLock[F] @@ -20,7 +22,9 @@ object AwaitDataSaveConfirmation { Sync[F].delay { player.disconnect(configuration.errorMessages.downstreamCouldNotSaveData) } - } + } >> Sync[F].delay { + logger.info(s"${player.getName}'s data has been saved'") + } } else { Sync[F].unit } diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala index 610db92..9031ec8 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala @@ -11,6 +11,7 @@ import net.md_5.bungee.api.plugin.Listener import net.md_5.bungee.event.{EventHandler, EventPriority} import java.util.concurrent.ConcurrentHashMap +import java.util.logging.Logger import scala.collection.mutable /** @@ -60,7 +61,7 @@ import scala.collection.mutable */ class SemaphoringServerSwitcher[ F[_]: ConcurrentEffect: HasGlobalPlayerDataSaveLock: HasPlayerConnectionLock: Timer -](implicit configuration: Configuration, effectEnvironment: EffectEnvironment, proxy: ProxyServer) +](logger: Logger)(implicit configuration: Configuration, effectEnvironment: EffectEnvironment, proxy: ProxyServer) extends Listener { import cats.implicits._ @@ -73,7 +74,7 @@ class SemaphoringServerSwitcher[ effectEnvironment.unsafeRunEffectAsync( "Lock on disconnection", - EmitGlobalLock.of[F](playerName, serverName) >> + EmitGlobalLock.of[F](playerName, serverName, logger) >> ConnectionModifications.disconnectFromServer(player) ) } @@ -93,6 +94,8 @@ class SemaphoringServerSwitcher[ val targetServer = event.getTarget val playerName = PlayerName(player.getName) + logger.info(s"${player.getName} requested a connection to ${targetServer.getName}") + // If we get a server switch command from a player // that tries to go to the same server the player is already connected (e.g. sending `/server lobby` in lobby), // the ServerConnectEvent is not called hence the connection hangs. @@ -108,8 +111,8 @@ class SemaphoringServerSwitcher[ case null => Sync[F].unit case originalServer => ConnectionModifications.letConnectionLinger[F](player) >> - EmitGlobalLock.of[F](playerName, ServerName(originalServer.getInfo.getName)) >> - ConnectionModifications.disconnectFromServer(player) + EmitGlobalLock.of[F](playerName, ServerName(originalServer.getInfo.getName), logger) >> + ConnectionModifications.disconnectFromServer(player) >> Sync[F].delay { logger.info(s"Notification of $playerName's connection'") } } val reconnectToTarget = Sync[F].delay { @@ -117,6 +120,8 @@ class SemaphoringServerSwitcher[ playersBeingConnectedToNewServer.add(playerName) player.connect(targetServer) + + logger.info(s"Notification of $playerName's connection'") } event.setCancelled(true) @@ -125,9 +130,9 @@ class SemaphoringServerSwitcher[ "Execute semaphoric flow on server switching", disconnectSourceIfExists >> ConcurrentEffect[F].race( - AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget, + AwaitDataSaveConfirmation.of[F](player, targetServer, logger) >> reconnectToTarget, HasPlayerConnectionLock[F].awaitDisconnectedState(playerName) - ) + ) >> Sync[F].delay { logger.info(s"$playerName is notified a world switch") } ) } else { // so that this listener ignores one `ServerConnectEvent` for marked players From 27b95b57bb2c93c6e1bf5a5bb163707f86148c2a Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 02:52:32 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20gitignore=E3=81=AB.bsp=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c17faa5..69fb367 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # IntelliJ IDEA .idea/ *.iml +.bsp/ # SBT /project/target From 20402353ec6cfd3c97e9aa2b622370fde0ced292 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 02:53:11 +0900 Subject: [PATCH 04/12] =?UTF-8?q?chore:=20.bsp=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bsp/sbt.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .bsp/sbt.json diff --git a/.bsp/sbt.json b/.bsp/sbt.json deleted file mode 100644 index 03e1471..0000000 --- a/.bsp/sbt.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"sbt","version":"1.6.1","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["C:\\Users\\rito\\.jdks\\openjdk-18.0.2.1/bin/java","-Xms100m","-Xmx100m","-classpath","C:/Users/rito/AppData/Local/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.7571.182.plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=C:/Users/rito/AppData/Local/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.7571.182.plugins/Scala/launcher/sbt-launch.jar"]} \ No newline at end of file From 802882ddf3ae02029f0cfb896f0093675450c3b5 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 03:07:58 +0900 Subject: [PATCH 05/12] =?UTF-8?q?style:=20logger=E3=82=92implicit=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seichi/bungeesemaphore/BungeeSemaphorePlugin.scala | 6 ++++-- .../bungeesemaphore/application/EmitGlobalLock.scala | 4 ++-- .../bugeecord/actions/AwaitDataSaveConfirmation.scala | 4 ++-- .../bugeecord/listeners/SemaphoringServerSwitcher.scala | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala index 1a66766..687091f 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala @@ -1,7 +1,6 @@ package click.seichi.bungeesemaphore import java.util.concurrent.Executors - import akka.actor.ActorSystem import cats.effect.{ContextShift, IO, SyncIO, Timer} import click.seichi.bungeesemaphore.application.configuration.Configuration @@ -15,6 +14,7 @@ import click.seichi.generic.concurrent.synchronization.barrier.IndexedSwitchable import net.md_5.bungee.api.ProxyServer import net.md_5.bungee.api.plugin.Plugin +import java.util.logging.Logger import scala.concurrent.duration.Duration import scala.concurrent.{Await, ExecutionContext} @@ -56,9 +56,11 @@ class BungeeSemaphorePlugin extends Plugin { implicit val _proxy: ProxyServer = getProxy + implicit val logger: Logger = getLogger + val listeners = Vector( connectionLockSynchronizer, - new SemaphoringServerSwitcher[IO](getLogger) + new SemaphoringServerSwitcher[IO] ) listeners.foreach { listener => diff --git a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala index 1f6dee9..8beef4c 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala @@ -8,8 +8,8 @@ import click.seichi.bungeesemaphore.domain.{PlayerName, ServerName} import java.util.logging.Logger object EmitGlobalLock { - def of[F[_]: HasGlobalPlayerDataSaveLock: Sync](playerName: PlayerName, disconnectionSource: ServerName, logger: Logger) - (implicit configuration: Configuration): F[Unit] = { + def of[F[_]: HasGlobalPlayerDataSaveLock: Sync](playerName: PlayerName, disconnectionSource: ServerName) + (implicit configuration: Configuration, logger: Logger): F[Unit] = { if (configuration.emitsSaveSignalOnDisconnect(disconnectionSource)) { HasGlobalPlayerDataSaveLock[F].lock(playerName) >> Sync[F].delay { logger.info(s"$playerName's data being saved'") } } else { diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala index 9938d4a..7e47f3f 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala @@ -13,8 +13,8 @@ object AwaitDataSaveConfirmation { import cats.implicits._ - def of[F[_] : Sync : HasGlobalPlayerDataSaveLock](player: ProxiedPlayer, targetServer: ServerInfo, logger: Logger) - (implicit configuration: Configuration): F[Unit] = { + def of[F[_] : Sync : HasGlobalPlayerDataSaveLock](player: ProxiedPlayer, targetServer: ServerInfo) + (implicit configuration: Configuration, logger: Logger): F[Unit] = { if (configuration.shouldAwaitForSaveSignal(ServerName(targetServer.getName))) { HasGlobalPlayerDataSaveLock[F] .awaitLockAvailability(PlayerName(player.getName)) diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala index 9031ec8..c00d2ec 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala @@ -61,7 +61,7 @@ import scala.collection.mutable */ class SemaphoringServerSwitcher[ F[_]: ConcurrentEffect: HasGlobalPlayerDataSaveLock: HasPlayerConnectionLock: Timer -](logger: Logger)(implicit configuration: Configuration, effectEnvironment: EffectEnvironment, proxy: ProxyServer) +](implicit configuration: Configuration, effectEnvironment: EffectEnvironment, proxy: ProxyServer, logger: Logger) extends Listener { import cats.implicits._ @@ -74,7 +74,7 @@ class SemaphoringServerSwitcher[ effectEnvironment.unsafeRunEffectAsync( "Lock on disconnection", - EmitGlobalLock.of[F](playerName, serverName, logger) >> + EmitGlobalLock.of[F](playerName, serverName) >> ConnectionModifications.disconnectFromServer(player) ) } @@ -111,7 +111,7 @@ class SemaphoringServerSwitcher[ case null => Sync[F].unit case originalServer => ConnectionModifications.letConnectionLinger[F](player) >> - EmitGlobalLock.of[F](playerName, ServerName(originalServer.getInfo.getName), logger) >> + EmitGlobalLock.of[F](playerName, ServerName(originalServer.getInfo.getName)) >> ConnectionModifications.disconnectFromServer(player) >> Sync[F].delay { logger.info(s"Notification of $playerName's connection'") } } @@ -130,7 +130,7 @@ class SemaphoringServerSwitcher[ "Execute semaphoric flow on server switching", disconnectSourceIfExists >> ConcurrentEffect[F].race( - AwaitDataSaveConfirmation.of[F](player, targetServer, logger) >> reconnectToTarget, + AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget, HasPlayerConnectionLock[F].awaitDisconnectedState(playerName) ) >> Sync[F].delay { logger.info(s"$playerName is notified a world switch") } ) From ac21e4925b15688d3424d2562d4f5e85bb731e7d Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 03:11:24 +0900 Subject: [PATCH 06/12] =?UTF-8?q?docs:=20=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E6=98=8E=E7=A2=BA=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seichi/bungeesemaphore/application/EmitGlobalLock.scala | 4 +++- .../bugeecord/actions/AwaitDataSaveConfirmation.scala | 4 ++-- .../bugeecord/listeners/SemaphoringServerSwitcher.scala | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala index 8beef4c..5940127 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/application/EmitGlobalLock.scala @@ -11,7 +11,9 @@ object EmitGlobalLock { def of[F[_]: HasGlobalPlayerDataSaveLock: Sync](playerName: PlayerName, disconnectionSource: ServerName) (implicit configuration: Configuration, logger: Logger): F[Unit] = { if (configuration.emitsSaveSignalOnDisconnect(disconnectionSource)) { - HasGlobalPlayerDataSaveLock[F].lock(playerName) >> Sync[F].delay { logger.info(s"$playerName's data being saved'") } + HasGlobalPlayerDataSaveLock[F].lock(playerName) >> Sync[F].delay { + logger.info(s"Globally locked $playerName's data-save lock") + } } else { Sync[F].unit } diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala index 7e47f3f..e51311a 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala @@ -23,8 +23,8 @@ object AwaitDataSaveConfirmation { player.disconnect(configuration.errorMessages.downstreamCouldNotSaveData) } } >> Sync[F].delay { - logger.info(s"${player.getName}'s data has been saved'") - } + logger.info(s"${player.getName}'s save-lock has been cleared") + } } else { Sync[F].unit } diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala index c00d2ec..83afae7 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala @@ -112,7 +112,9 @@ class SemaphoringServerSwitcher[ case originalServer => ConnectionModifications.letConnectionLinger[F](player) >> EmitGlobalLock.of[F](playerName, ServerName(originalServer.getInfo.getName)) >> - ConnectionModifications.disconnectFromServer(player) >> Sync[F].delay { logger.info(s"Notification of $playerName's connection'") } + ConnectionModifications.disconnectFromServer(player) >> Sync[F].delay { + logger.info(s"Disconnected $playerName from current server. Holding connection for further actions...") + } } val reconnectToTarget = Sync[F].delay { @@ -121,7 +123,7 @@ class SemaphoringServerSwitcher[ player.connect(targetServer) - logger.info(s"Notification of $playerName's connection'") + logger.info(s"Connected $playerName to the original destination server") } event.setCancelled(true) From a76d9b8f09eee58abeb260cfab7116ea6ca7f930 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 03:12:27 +0900 Subject: [PATCH 07/12] =?UTF-8?q?fix:=20=E3=83=AD=E3=82=B0=E3=81=AE?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=82=92=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bugeecord/listeners/SemaphoringServerSwitcher.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala index 83afae7..4c19a44 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala @@ -132,9 +132,11 @@ class SemaphoringServerSwitcher[ "Execute semaphoric flow on server switching", disconnectSourceIfExists >> ConcurrentEffect[F].race( - AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget, + AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget >> Sync[F].delay { + logger.info(s"$playerName is notified a world switch") + }, HasPlayerConnectionLock[F].awaitDisconnectedState(playerName) - ) >> Sync[F].delay { logger.info(s"$playerName is notified a world switch") } + ) ) } else { // so that this listener ignores one `ServerConnectEvent` for marked players From 41286733819e5158ec20d1b437dfb3c528613ab5 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 16:32:09 +0900 Subject: [PATCH 08/12] =?UTF-8?q?style:=20=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=82=92=E6=B8=9B=E3=82=89=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bugeecord/listeners/SemaphoringServerSwitcher.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala index 4c19a44..b7f2571 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/listeners/SemaphoringServerSwitcher.scala @@ -132,9 +132,7 @@ class SemaphoringServerSwitcher[ "Execute semaphoric flow on server switching", disconnectSourceIfExists >> ConcurrentEffect[F].race( - AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget >> Sync[F].delay { - logger.info(s"$playerName is notified a world switch") - }, + AwaitDataSaveConfirmation.of[F](player, targetServer) >> reconnectToTarget, HasPlayerConnectionLock[F].awaitDisconnectedState(playerName) ) ) From faa5e333c0c82ab3e4c6cd388cedd95bbcfd00b3 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 17:55:53 +0900 Subject: [PATCH 09/12] =?UTF-8?q?fix:=20=E3=83=AD=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=81=8C=E5=A4=96=E3=81=95=E3=82=8C=E3=82=8B=E9=81=8E=E7=A8=8B?= =?UTF-8?q?=E3=82=82=E5=90=AB=E3=82=81=E3=81=A6=E3=83=AD=E3=82=B0=E3=82=92?= =?UTF-8?q?=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bugeecord/actions/AwaitDataSaveConfirmation.scala | 3 +-- .../infrastructure/redis/LocalLockRedisBridge.scala | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala index e51311a..61e3621 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala @@ -21,9 +21,8 @@ object AwaitDataSaveConfirmation { .orElse { Sync[F].delay { player.disconnect(configuration.errorMessages.downstreamCouldNotSaveData) + logger.info(s"${player.getName}'s save-lock has been cleared. But was not data saved.") } - } >> Sync[F].delay { - logger.info(s"${player.getName}'s save-lock has been cleared") } } else { Sync[F].unit diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/redis/LocalLockRedisBridge.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/redis/LocalLockRedisBridge.scala index 6bc7c04..7cbbf66 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/redis/LocalLockRedisBridge.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/redis/LocalLockRedisBridge.scala @@ -11,6 +11,7 @@ import click.seichi.bungeesemaphore.domain.PlayerName import click.seichi.generic.concurrent.synchronization.barrier.IndexedSwitchableBarrier import redis.RedisClient +import java.util.logging.Logger import scala.concurrent.duration.{Duration, FiniteDuration} object LocalLockRedisBridge { @@ -44,7 +45,8 @@ object LocalLockRedisBridge { (implicit configuration: Configuration, actorSystem: ActorSystem, effectEnvironment: EffectEnvironment, - publishingContext: ContextShift[IO]): F[HasGlobalPlayerDataSaveLock[F]] = { + publishingContext: ContextShift[IO], + logger: Logger): F[HasGlobalPlayerDataSaveLock[F]] = { val pxMillis = configuration.saveLockTimeout match { case _: Duration.Infinite => None @@ -90,6 +92,10 @@ object LocalLockRedisBridge { localLock(playerName).await, requestLocalPromise.get ) + + _ <- Sync[F].delay { + logger.info(s"${playerName.value}'s save-lock has been successfully cleared") + } } yield () } } From 828f9e14470bb425043e61538f58dda1db5d4f5f Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 18:09:06 +0900 Subject: [PATCH 10/12] =?UTF-8?q?docs:=20awaitLockAvaliability=E3=81=AB?= =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=B3=E3=82=BB=E3=83=AB=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E5=8F=AF=E8=83=BD=E6=80=A7=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E3=81=A8=E3=81=8D=E3=81=AE=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/HasGlobalPlayerDataSaveLock.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/application/HasGlobalPlayerDataSaveLock.scala b/src/main/scala/click/seichi/bungeesemaphore/application/HasGlobalPlayerDataSaveLock.scala index 8c1f354..c2058f3 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/application/HasGlobalPlayerDataSaveLock.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/application/HasGlobalPlayerDataSaveLock.scala @@ -12,7 +12,8 @@ import simulacrum.typeclass /** * Await for an availability of the lock on given `playerName`. * - * This action is cancellable. + * This action is cancellable when next case. + * - When it is found that data save has failed. */ def awaitLockAvailability(playerName: PlayerName): F[Unit] } \ No newline at end of file From 85824c65f3b0adf496cd8ed203f952d9ecf1017b Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 18:12:30 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix:=20logger=E3=81=AE=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=82=92=E4=B8=8A=E3=81=AB=E6=8C=81?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala index 687091f..78158cc 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/BungeeSemaphorePlugin.scala @@ -26,6 +26,7 @@ class BungeeSemaphorePlugin extends Plugin { implicit val _contextShift: ContextShift[IO] = IO.contextShift(_executionContext) implicit val _effectEnvironment: EffectEnvironment = JulLoggerEffectEnvironment(getLogger) implicit val _timer: Timer[IO] = IO.timer(_executionContext) + implicit val logger: Logger = getLogger implicit val _configuration: Configuration = { new PluginConfiguration[SyncIO](getDataFolder).getConfiguration.unsafeRunSync() @@ -56,8 +57,6 @@ class BungeeSemaphorePlugin extends Plugin { implicit val _proxy: ProxyServer = getProxy - implicit val logger: Logger = getLogger - val listeners = Vector( connectionLockSynchronizer, new SemaphoringServerSwitcher[IO] From 2f6efebbffbd8310eb40ed52710b7aa58b55ae76 Mon Sep 17 00:00:00 2001 From: rito528 Date: Sun, 11 Dec 2022 19:58:16 +0900 Subject: [PATCH 12/12] =?UTF-8?q?docs:=20=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bungeesemaphore/application/HasPlayerConnectionLock.scala | 2 ++ .../bugeecord/actions/AwaitDataSaveConfirmation.scala | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/scala/click/seichi/bungeesemaphore/application/HasPlayerConnectionLock.scala b/src/main/scala/click/seichi/bungeesemaphore/application/HasPlayerConnectionLock.scala index 8a57872..4b52c2e 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/application/HasPlayerConnectionLock.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/application/HasPlayerConnectionLock.scala @@ -11,6 +11,8 @@ import simulacrum.typeclass * An action to semantically block until the player with given `playerName` disconnects from the proxy server. * * This action is cancellable. + * + * This action is cancelled when the data save has been reported failed. */ def awaitDisconnectedState(playerName: PlayerName): F[Unit] } diff --git a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala index 61e3621..e8dbd29 100644 --- a/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala +++ b/src/main/scala/click/seichi/bungeesemaphore/infrastructure/bugeecord/actions/AwaitDataSaveConfirmation.scala @@ -21,7 +21,7 @@ object AwaitDataSaveConfirmation { .orElse { Sync[F].delay { player.disconnect(configuration.errorMessages.downstreamCouldNotSaveData) - logger.info(s"${player.getName}'s save-lock has been cleared. But was not data saved.") + logger.info(s"${player.getName}'s save-lock has been cleared, but data was not saved successfully.") } } } else {