diff --git a/Twilight.cmd b/Twilight.cmd index 1b37b28..940cc88 100644 --- a/Twilight.cmd +++ b/Twilight.cmd @@ -21,7 +21,7 @@ CHOICE /M APPLY IF %ERRORLEVEL% == 1 ( - wsl ssh taehui@taehui sudo service twilight restart + wsl ssh taehui.ddns.net sudo service twilight restart ) CHOICE /M VCS diff --git a/build.gradle.kts b/build.gradle.kts index 000a5a1..ce4c0ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,8 +20,8 @@ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1") implementation("com.github.pemistahl:lingua:1.2.2") - implementation("com.google.protobuf:protobuf-java:4.27.1") - implementation("com.google.protobuf:protobuf-kotlin:4.27.1") + implementation("com.google.protobuf:protobuf-java:4.27.2") + implementation("com.google.protobuf:protobuf-kotlin:4.27.2") implementation("com.ibm.icu:icu4j:75.1") implementation("com.lmax:disruptor:4.0.0") implementation("com.sun.mail:jakarta.mail:2.0.1") diff --git a/src/main/java/CommentOuterClass.java b/src/main/java/CommentOuterClass.java index e4a4e55..ad99b2d 100644 --- a/src/main/java/CommentOuterClass.java +++ b/src/main/java/CommentOuterClass.java @@ -1,6 +1,7 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto -// Protobuf Java Version: 4.26.0 +// Protobuf Java Version: 4.27.2 public final class CommentOuterClass { private CommentOuterClass() {} @@ -8,8 +9,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", CommentOuterClass.class.getName()); } @@ -224,8 +225,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", Comment.class.getName()); } @@ -3098,8 +3099,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", InputEvent.class.getName()); } @@ -3744,8 +3745,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", MultiplierEvent.class.getName()); } @@ -4327,8 +4328,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", JudgmentMeterEvent.class.getName()); } @@ -4921,8 +4922,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", PaintEvent.class.getName()); } @@ -5631,8 +5632,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", AudioMultiplierEvent.class.getName()); } diff --git a/src/main/java/EventOuterClass.java b/src/main/java/EventOuterClass.java index 8d9c037..9e40fe1 100644 --- a/src/main/java/EventOuterClass.java +++ b/src/main/java/EventOuterClass.java @@ -1,6 +1,7 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Event.proto -// Protobuf Java Version: 4.26.0 +// Protobuf Java Version: 4.27.2 public final class EventOuterClass { private EventOuterClass() {} @@ -8,8 +9,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", EventOuterClass.class.getName()); } @@ -353,8 +354,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", Event.class.getName()); } @@ -406,8 +407,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", AvatarNetStatus.class.getName()); } @@ -880,8 +881,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", EventID.class.getName()); } @@ -1469,8 +1470,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightCallNet.class.getName()); } @@ -1634,8 +1635,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", CallNetItem.class.getName()); } @@ -4674,8 +4675,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightCallNet.class.getName()); } @@ -9887,8 +9888,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", NetDrawing.class.getName()); } @@ -9937,8 +9938,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", Variety.class.getName()); } @@ -10819,8 +10820,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", DrawingComponent.class.getName()); } @@ -11366,8 +11367,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIOInput.class.getName()); } @@ -12209,8 +12210,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIOInput.class.getName()); } @@ -12888,8 +12889,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIOJudge.class.getName()); } @@ -13731,8 +13732,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIOJudge.class.getName()); } @@ -14416,8 +14417,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIOJudgmentMeter.class.getName()); } @@ -15333,8 +15334,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIOJudgmentMeter.class.getName()); } @@ -16086,8 +16087,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIONoteVisibility.class.getName()); } @@ -17003,8 +17004,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIONoteVisibility.class.getName()); } @@ -17744,8 +17745,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIOMultiplier.class.getName()); } @@ -18517,8 +18518,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIOMultiplier.class.getName()); } @@ -19126,8 +19127,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightIOAudioMultiplier.class.getName()); } @@ -19899,8 +19900,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightIOAudioMultiplier.class.getName()); } @@ -20489,8 +20490,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightAudioInput.class.getName()); } @@ -21171,8 +21172,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", QwilightPostItem.class.getName()); } @@ -22109,8 +22110,8 @@ com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion( com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 4, - /* minor= */ 26, - /* patch= */ 0, + /* minor= */ 27, + /* patch= */ 2, /* suffix= */ "", TwilightPostItem.class.getName()); } diff --git a/src/main/kotlin/AudioMultiplierEventKt.kt b/src/main/kotlin/AudioMultiplierEventKt.kt index 00c1721..5880fc0 100644 --- a/src/main/kotlin/AudioMultiplierEventKt.kt +++ b/src/main/kotlin/AudioMultiplierEventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/CommentKt.kt b/src/main/kotlin/CommentKt.kt index 34a7ef6..3e6ba40 100644 --- a/src/main/kotlin/CommentKt.kt +++ b/src/main/kotlin/CommentKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/CommentOuterClassKt.kt b/src/main/kotlin/CommentOuterClassKt.kt index b05555c..affb6de 100644 --- a/src/main/kotlin/CommentOuterClassKt.kt +++ b/src/main/kotlin/CommentOuterClassKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/EventKt.kt b/src/main/kotlin/EventKt.kt index a6f6f73..1d3b0f9 100644 --- a/src/main/kotlin/EventKt.kt +++ b/src/main/kotlin/EventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Event.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/EventOuterClassKt.kt b/src/main/kotlin/EventOuterClassKt.kt index 12b4b7e..45620e9 100644 --- a/src/main/kotlin/EventOuterClassKt.kt +++ b/src/main/kotlin/EventOuterClassKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Event.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/InputEventKt.kt b/src/main/kotlin/InputEventKt.kt index 733bd07..61c06eb 100644 --- a/src/main/kotlin/InputEventKt.kt +++ b/src/main/kotlin/InputEventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/JudgmentMeterEventKt.kt b/src/main/kotlin/JudgmentMeterEventKt.kt index 87d9b09..ff3a132 100644 --- a/src/main/kotlin/JudgmentMeterEventKt.kt +++ b/src/main/kotlin/JudgmentMeterEventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/MultiplierEventKt.kt b/src/main/kotlin/MultiplierEventKt.kt index 63c070a..6a843b8 100644 --- a/src/main/kotlin/MultiplierEventKt.kt +++ b/src/main/kotlin/MultiplierEventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/PaintEventKt.kt b/src/main/kotlin/PaintEventKt.kt index f0f9fad..7c553b9 100644 --- a/src/main/kotlin/PaintEventKt.kt +++ b/src/main/kotlin/PaintEventKt.kt @@ -1,4 +1,5 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE // source: Comment.proto // Generated files should ignore deprecation warnings diff --git a/src/main/kotlin/net/taehui/twilight/Twilight.kt b/src/main/kotlin/net/taehui/twilight/Twilight.kt index c710825..03cab7f 100644 --- a/src/main/kotlin/net/taehui/twilight/Twilight.kt +++ b/src/main/kotlin/net/taehui/twilight/Twilight.kt @@ -13,6 +13,9 @@ import org.apache.commons.lang3.SystemUtils import org.fusesource.jansi.AnsiConsole import java.io.IOException +import java.net.BindException +import java.net.InetSocketAddress +import java.nio.channels.DatagramChannel import java.nio.file.Files import java.nio.file.Paths import java.security.KeyStore @@ -25,7 +28,14 @@ @JvmStatic fun main(args: Array) { AnsiConsole.systemInstall() - PIDClass.doHaveIt() + + try { + val datagramChannel = DatagramChannel.open() + datagramChannel?.bind(InetSocketAddress("localhost", 6101)) + } catch (e: BindException) { + System.err.println("Twilight is already running") + exitProcess(1) + } try { Files.createDirectories(TwilightComponent.NOTE_ENTRY_PATH) @@ -53,12 +63,21 @@ AbilitySystem.loadAbility() BannedIP.loadBannedIP() BannedNote.loadBannedNote() + TVSystem.loadBannedTV() EdgeSystem.loadEdge() AvatarIPSystem.loadAvatarIP() LevelSystem.loadLevel() TitleSystem.loadTitle() VoteSystem.loadVote() AutoSystem.handleSystem() + TVSystem.handleSystem() + NoteFilesSystem.loadNoteFiles() + PlatformIDSystem.loadPlatformID() + PlatformSystem.handleSystem() + QwilightNamesSystem.loadQwilightNames() + WitSystem.handleSystem() + AwilightHandler.eventLoopGroup = eventLoopGroup + AwilightHandler.setAwilightCount(Configure.awilightCount) val sslContext = Files.newInputStream(Paths.get("Twilight.jks")).use { val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) keyStore.load(it, Configure.javaCipherStore.pw0) @@ -68,23 +87,15 @@ sslContext.init(keyManagerFactory.keyManagers, null, null) sslContext } - val qwilightChannel = QwilightBoot(eventLoopGroup, eventChannel, sslContext).run() - val siteChannel = SiteBoot(eventLoopGroup, eventChannel).run() - val wwwChannel = WwwBoot(eventLoopGroup, eventChannel).run() - val taehuiChannel = TaehuiBoot(eventLoopGroup, eventChannel).run() - TVSystem.handleSystem() - NoteFilesSystem.loadNoteFiles() - PlatformIDSystem.loadPlatformID() - PlatformSystem.handleSystem() - WitSystem.handleSystem() - QwilightNamesSystem.loadQwilightNames() - AwilightHandler.eventLoopGroup = eventLoopGroup - AwilightHandler.setAwilightCount(Configure.awilightCount) - AvatarHandler.sendClose(IO.handleSystem()) - qwilightChannel.close() - siteChannel.close() - wwwChannel.close() - taehuiChannel.close() + QwilightBoot(eventLoopGroup, eventChannel, sslContext).use { + SiteBoot(eventLoopGroup, eventChannel).use { + WwwBoot(eventLoopGroup, eventChannel).use { + TaehuiBoot(eventLoopGroup, eventChannel).use { + AvatarHandler.sendClose(IO.handleSystem()) + } + } + } + } } finally { WitSystem.dispose() PlatformIDSystem.savePlatformID() @@ -94,6 +105,7 @@ AvatarIPSystem.saveAvatarIP() BannedIP.saveBannedIP() BannedNote.saveBannedNote() + TVSystem.saveBannedTV() Configure.saveConfigure() } } diff --git a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt index 27cc53d..b192970 100644 --- a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightBoot.kt @@ -15,30 +15,29 @@ import javax.net.ssl.SSLContext class QwilightBoot( - eventLoopGroup: EventLoopGroup, - eventChannel: Class, - sslContext: SSLContext -) : Logger { + eventLoopGroup: EventLoopGroup, eventChannel: Class, sslContext: SSLContext +) : Logger, AutoCloseable { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { - ch.pipeline() - .addLast(SslHandler(sslContext.createSSLEngine().apply { + ch.pipeline().addLast(SslHandler(sslContext.createSSLEngine().apply { useClientMode = false - })) - .addLast(ProtobufVarint32FrameDecoder()) + })).addLast(ProtobufVarint32FrameDecoder()) .addLast(ProtobufDecoder(EventOuterClass.Event.getDefaultInstance())) - .addLast(ProtobufVarint32LengthFieldPrepender()) - .addLast(ProtobufEncoder()) + .addLast(ProtobufVarint32LengthFieldPrepender()).addLast(ProtobufEncoder()) .addLast(QwilightAvatar()) } }) + private val mainChannel: Channel - fun run(): Channel { + init { logInfo("Loading Qwilight") - return mainBootstrap.bind(6101).channel().closeFuture() - .addListener { + mainChannel = mainBootstrap.bind(6101).channel().closeFuture().addListener { logInfo("Closed Qwilight") }.channel() } + + override fun close() { + mainChannel.close() + } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt b/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt index 8f64d32..8268e63 100644 --- a/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/site/SiteBoot.kt @@ -12,7 +12,7 @@ import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler import net.taehui.twilight.Logger -class SiteBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { +class SiteBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, AutoCloseable { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -24,12 +24,17 @@ .addLast(SiteAvatar()) } }) + private val mainChannel: Channel - fun run(): Channel { + init { logInfo("Loading Site") - return mainBootstrap.bind(6704).channel().closeFuture() + mainChannel = mainBootstrap.bind(6704).channel().closeFuture() .addListener { logInfo("Closed Site") }.channel() } + + override fun close() { + mainChannel.close() + } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/IO.kt b/src/main/kotlin/net/taehui/twilight/system/IO.kt index 5564b00..81ce119 100644 --- a/src/main/kotlin/net/taehui/twilight/system/IO.kt +++ b/src/main/kotlin/net/taehui/twilight/system/IO.kt @@ -491,11 +491,27 @@ TVSystem.dispose() continue } + + "ban" -> { + if (w.size > 2) { + TVSystem.putBannedTV(w[2]) + continue + } + } + + "allow" -> { + if (w.size > 2) { + TVSystem.wipeBannedTV(w[2]) + continue + } + } } } logInfo("tv view: View TV") logInfo("tv handle: Handle TV") logInfo("tv dispose: Close TV") + logInfo("tv ban : Ban TV") + logInfo("tv allow : Allow TV") } else -> { diff --git a/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt b/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt deleted file mode 100644 index a2a4f74..0000000 --- a/src/main/kotlin/net/taehui/twilight/system/PIDClass.kt +++ /dev/null @@ -1,21 +0,0 @@ -package net.taehui.twilight.system - -import net.taehui.twilight.Logger -import java.net.BindException -import java.net.InetSocketAddress -import java.nio.channels.DatagramChannel -import kotlin.system.exitProcess - -object PIDClass : Logger { - private var datagramChannel: DatagramChannel? = null - - fun doHaveIt() { - try { - datagramChannel = DatagramChannel.open() - datagramChannel?.bind(InetSocketAddress("localhost", 6101)) - } catch (e: BindException) { - logInfo("Twilight is already running") - exitProcess(1) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt index 80c47bd..483c889 100644 --- a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt @@ -44,7 +44,7 @@ class Client { var platform = "" var qwilight = 0L - var siteHello = 0L + var siteHi = 0L var siteNotify = 0L var siteComment = 0L var siteDefault = 0L @@ -121,8 +121,8 @@ override fun onGuildMemberJoin(event: GuildMemberJoinEvent) { doCallPlatformAvatars() - qwilightPlatform?.getTextChannelById(platformClient.siteHello) - ?.sendMessage("<@${event.user.id}>")?.addActionRow( + qwilightPlatform?.getTextChannelById(platformClient.siteHi) + ?.sendMessage("Hi, <@${event.user.id}>")?.addActionRow( Button.primary("login", "Log in to Qwilight Channel") )?.queue() } @@ -134,11 +134,10 @@ modalEvent.replyModal( Modal.create("login", "Log in to Qwilight Channel").addComponents( ActionRow.of( - TextInput.create("avatarID", "ID", TextInputStyle.SHORT).setMinLength(1) - .build() + TextInput.create("avatarID", "ID", TextInputStyle.SHORT).setMinLength(1).build() ), ActionRow.of( - TextInput.create("avatarCipher", "PW", TextInputStyle.SHORT) - .setMinLength(1).build() + TextInput.create("avatarCipher", "PW", TextInputStyle.SHORT).setMinLength(1) + .build() ) ).build() ).queue() @@ -152,8 +151,7 @@ qwilightPlatform?.retrieveMemberById(platformID)?.queue { avatar -> qwilightPlatform?.modifyMemberRoles( avatar, - *(qwilightPlatform?.getRolesByName(abilityName, true)?.toTypedArray() - ?: emptyArray()) + *(qwilightPlatform?.getRolesByName(abilityName, true)?.toTypedArray() ?: emptyArray()) )?.queue() } return abilityName diff --git a/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt b/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt index 328b362..b5f4cfe 100644 --- a/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt @@ -1,5 +1,7 @@ package net.taehui.twilight.system +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper import net.taehui.twilight.Logger import org.openqa.selenium.By import org.openqa.selenium.TimeoutException @@ -8,11 +10,11 @@ import org.openqa.selenium.edge.EdgeOptions import org.openqa.selenium.support.ui.ExpectedConditions import org.openqa.selenium.support.ui.WebDriverWait +import java.io.IOException +import java.nio.file.Files +import java.nio.file.Paths import java.time.Duration -import java.util.concurrent.Executors -import java.util.concurrent.ScheduledExecutorService -import java.util.concurrent.ScheduledFuture -import java.util.concurrent.TimeUnit +import java.util.concurrent.* object TVSystem : Logger { class TVItem(val href: String, val title: String, val text: String) { @@ -36,6 +38,7 @@ } private var tv: WebDriver? = null private var future: ScheduledFuture<*>? = null + private var bannedTVStore = ConcurrentSkipListSet() fun handleSystem() { if (tv != null) { @@ -88,7 +91,9 @@ ) }.toSet() - val elements = elements0.plus(elements1) + val elements = elements0.plus(elements1).filter { + !bannedTVStore.contains(it.text) + }.toSet() elements.subtract(lastElements).filter { pendingElements.remove(it) == null }.forEach { @@ -123,4 +128,32 @@ tv?.quit() tv = null } + + fun loadBannedTV() { + try { + bannedTVStore.addAll( + ObjectMapper().readValue( + Paths.get("Banned TV.json").toFile().absoluteFile, + object : TypeReference>() {}) + ) + logInfo("Loaded Banned TV") + saveBannedTV() + } catch (e: IOException) { + logFault(e) + } + } + + fun saveBannedTV() { + Files.newOutputStream(Paths.get("Banned TV.json")) + .use { ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(it, bannedTVStore) } + logInfo("Saved Banned TV") + } + + fun putBannedTV(tv: String) { + bannedTVStore.add(tv) + } + + fun wipeBannedTV(tv: String) { + bannedTVStore.remove(tv) + } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt b/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt index 5115560..c71bd60 100644 --- a/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/taehui/TaehuiBoot.kt @@ -11,7 +11,7 @@ import io.netty.handler.codec.http.HttpServerCodec import net.taehui.twilight.Logger -class TaehuiBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { +class TaehuiBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, AutoCloseable { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { @@ -22,12 +22,17 @@ .addLast(TaehuiAvatar()) } }) + private val mainChannel: Channel - fun run(): Channel { + init { logInfo("Loading Taehui") - return mainBootstrap.bind(8300).channel().closeFuture() + mainChannel = mainBootstrap.bind(8300).channel().closeFuture() .addListener { logInfo("Closed Taehui") }.channel() } + + override fun close() { + mainChannel.close() + } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt b/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt index 8423f22..065ec34 100644 --- a/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt +++ b/src/main/kotlin/net/taehui/twilight/www/WwwBoot.kt @@ -11,23 +11,24 @@ import io.netty.handler.codec.http.HttpServerCodec import net.taehui.twilight.Logger -class WwwBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger { +class WwwBoot(eventLoopGroup: EventLoopGroup, eventChannel: Class) : Logger, AutoCloseable { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(eventChannel) .childHandler(object : ChannelInitializer() { public override fun initChannel(ch: SocketChannel) { - ch.pipeline() - .addLast(HttpServerCodec()) - .addLast(HttpObjectAggregator(Int.MAX_VALUE)) - .addLast(HttpClientCodec()) - .addLast(WwwAvatar()) + ch.pipeline().addLast(HttpServerCodec()).addLast(HttpObjectAggregator(Int.MAX_VALUE)) + .addLast(HttpClientCodec()).addLast(WwwAvatar()) } }) + private val mainChannel: Channel - fun run(): Channel { + init { logInfo("Loading Www") - return mainBootstrap.bind(7301).channel().closeFuture() - .addListener { + mainChannel = mainBootstrap.bind(7301).channel().closeFuture().addListener { logInfo("Closed Www") }.channel() } + + override fun close() { + mainChannel.close() + } } \ No newline at end of file