-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ca832c
Showing
31 changed files
with
979 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# vTunnel | ||
ポート解放をせずにVelocityプロキシへサーバーを登録できるトンネリングプラグインです。 | ||
子サーバー起動時に自動的にVelocityプロキシへサーバーを登録します。(必要に応じてforcedHostsの登録も行います。) | ||
|
||
## セットアップする | ||
vTunnelのセットアップ方法。 | ||
### プロキシサイドの設定 | ||
1.vTunnelは子サーバーからのトンネリングの際に60000番ポートを使用するため、**60000番ポートを解放**する必要があります。<br> | ||
また、解放する必要はありませんが60001-61000ポートを内部的に使用するため他プロセスで使用しないでください。(dockerでの実行を推奨)<br> | ||
<br> | ||
2.VelocityプロキシのpluginsフォルダにvTunnelプラグインを導入する | ||
3.下記のの環境変数を設定する<br> | ||
(velocity-config.tomlのserversやtryの項目を削除することをお勧めします。) | ||
```yaml | ||
# JWTトークンのシークレットです。極力長い文字列にすることをお勧めします。 | ||
VTUNNEL_SECRET: """任意のシークレット文字列""" (require) | ||
|
||
# サーバー接続時に最初に接続するサーバーの名前。 | ||
VTUNNEL_TRY: "サーバー名1,サーバー名2" (optional) | ||
``` | ||
### サーバーサイドの設定 | ||
1.サーバーにvTunnelプラグインを導入します。<br> | ||
2.JWTトークンを[ここ](https://jwt.io/)から生成する(下記参照)<br> | ||
2.下記の環境変数を設定する<br> | ||
#### JWTトークンの項目 | ||
```yaml | ||
Algorithm: HS512 | ||
|
||
your-256-bit-secret: """上で設定した$VTUNNEL_SECRETの値""" | ||
|
||
PAYLOAD: | ||
name: lobby, #Velocityに登録するサーバー名 | ||
forced_hosts: ["lobby.example.com","main.example.com"], #Velocityに登録するforcedHostsのアドレス | ||
exp: 1000000000000, #このトークンの有効期限(unix_time/sec) | ||
iss: moruch4nn, #このトークンの発行者(適当で構いません) | ||
aud: [サーバー運営], #このトークンの想定利用者(適当で構いません) | ||
``` | ||
### 環境変数 | ||
```yaml | ||
# vTunnelサーバーのホスト名 | ||
VTUNNEL_HOST: 478.43.12.432 | ||
VTUNNEL_TOKEN: 上で生成したJWTToken。 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
kotlin("jvm") version "1.8.20" | ||
kotlin("plugin.serialization") version "1.8.20" | ||
} | ||
|
||
group = "dev.mr3n" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") | ||
maven("https://oss.sonatype.org/content/repositories/snapshots") | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compileOnly("org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT") | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") | ||
implementation("com.auth0:java-jwt:4.4.0") | ||
implementation("io.ktor:ktor-client-core:2.2.4") | ||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.4") | ||
implementation("io.ktor:ktor-client-cio:2.2.4") | ||
implementation(project(":shared")) | ||
} | ||
|
||
tasks.named("build") { | ||
dependsOn("shadowJar") | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(8) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dev.mr3n.vtunnel | ||
|
||
import dev.mr3n.vtunnel.model.AuthFrame | ||
import dev.mr3n.vtunnel.model.NewConnectionNotify | ||
import dev.mr3n.vtunnel.tcp.PacketTransfer | ||
import io.ktor.client.* | ||
import io.ktor.client.engine.cio.* | ||
import io.ktor.client.plugins.websocket.* | ||
import io.ktor.serialization.kotlinx.* | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.bukkit.Bukkit | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerLoginEvent | ||
import org.bukkit.plugin.java.JavaPlugin | ||
import java.net.Socket | ||
import java.util.* | ||
import kotlin.concurrent.thread | ||
|
||
class VTunnel: JavaPlugin(), Listener { | ||
|
||
init { | ||
Bukkit.getServer().onlineMode | ||
} | ||
|
||
override fun onEnable() { | ||
thread { runBlocking { startWebSocketClient() } } | ||
this.server.pluginManager.registerEvents(this, this) | ||
} | ||
|
||
val client = HttpClient(CIO) { | ||
install(WebSockets) { | ||
contentConverter = KotlinxWebsocketSerializationConverter(Json) | ||
} | ||
} | ||
|
||
suspend fun startWebSocketClient() { | ||
val host = System.getenv("VTUNNEL_HOST")?:"akamachi.net" | ||
val token = System.getenv("VTUNNEL_TOKEN") | ||
while (true) { | ||
try { | ||
client.webSocket(host = host, port = 60000, path = "/vtunnel") { | ||
sendSerialized(AuthFrame(token)) | ||
while (true) { | ||
val newConn: NewConnectionNotify = receiveDeserialized() | ||
try { | ||
val bridgeSocket = Socket(host, newConn.port) | ||
val outputSocket = bridgeSocket.getOutputStream() | ||
outputSocket.write(Json.encodeToString(AuthFrame(newConn.token)).toByteArray()) | ||
outputSocket.flush() | ||
val clientSocket = Socket("127.0.0.1", server.port) | ||
PacketTransfer(bridgeSocket, clientSocket) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
logger.warning("vTunnelとの接続が切断されたため5秒後に再接続を行います。") | ||
Thread.sleep(5000) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
main: dev.mr3n.vtunnel.VTunnel | ||
name: VTunnel | ||
version: 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2023-04-21 10:45:47 [01:45:47 INFO]: [long, class net.minecraft.server.network.PlayerConnection, class net.minecraft.server.MinecraftServer, class net.minecraft.server.level.PlayerInteractManager, int, int, boolean, boolean, class net.minecraft.world.entity.monster.warden.WardenSpawnTracker, interface net.minecraft.world.inventory.ContainerSynchronizer, int, boolean, long, int, boolean, class net.minecraft.network.protocol.game.PacketPlayOutUpdateHealth, int, class [I, class com.destroystokyo.paper.util.PooledHashSets$PooledObjectLinkedOpenHashSet, class java.lang.String, interface net.kyori.adventure.text.Component, interface net.minecraft.network.chat.IChatBaseComponent, class org.bukkit.Location, int, int, int, boolean, double, boolean, boolean, boolean, class java.lang.Integer, boolean, double, class com.destroystokyo.paper.util.misc.PooledLinkedHashSets$PooledObjectLinkedOpenHashSet, class com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent, class org.bukkit.event.player.PlayerQuitEvent$QuitReason, class java.lang.String, class java.util.Locale, long, boolean, class org.bukkit.WeatherType, int, int, int, int, int, float, float, float, float, class net.minecraft.world.entity.EntitySize, class net.minecraft.network.syncher.DataWatcherObject, class net.minecraft.world.inventory.ContainerPlayer, class net.minecraft.world.inventory.Container, float, float, int, double, double, double, double, double, double, int, int, int, float, int, class com.mojang.authlib.GameProfile, class net.minecraft.world.entity.projectile.EntityFishingHook, float, boolean, class net.kyori.adventure.util.TriState, boolean, int, int, int, int, int, int, int, double, double, int, int, class net.minecraft.network.syncher.DataWatcherObject, class net.minecraft.network.syncher.DataWatcherObject, float, class net.minecraft.world.damagesource.CombatTracker, interface java.util.Map, boolean, class net.minecraft.world.EnumHand, int, int, int, int, int, int, float, float, class net.minecraft.world.entity.WalkAnimationState, int, float, float, float, float, float, float, class net.minecraft.world.entity.player.EntityHuman, int, float, boolean, float, float, float, boolean, class net.minecraft.world.entity.EntityLiving, int, int, boolean, class java.util.ArrayList, class org.bukkit.craftbukkit.v1_19_R3.attribute.CraftAttributeMap, boolean, interface java.util.Set, boolean, boolean, class net.kyori.adventure.util.TriState, int, boolean, interface net.minecraft.util.RandomSource, class org.bukkit.event.entity.CreatureSpawnEvent$SpawnReason, class com.destroystokyo.paper.loottable.PaperLootableInventoryData, boolean, class net.minecraft.server.level.PlayerChunkMap$EntityTracker, class java.lang.Throwable, class java.lang.String, class java.lang.String, int, int, int, double, float, int, int, class java.lang.String, boolean, class com.google.common.collect.ImmutableList, class net.minecraft.world.level.World, double, double, double, float, float, boolean, boolean, boolean, boolean, boolean, boolean, float, float, float, float, float, float, float, double, double, double, boolean, int, int, boolean, int, boolean, boolean, int, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, int, interface org.bukkit.projectiles.ProjectileSource, boolean, boolean, class net.minecraft.core.BlockPosition, class org.spigotmc.ActivationRange$ActivationType, boolean, long, long, boolean, boolean, boolean, boolean, boolean, class net.minecraft.server.level.PlayerChunk$State, int, int, int, boolean, boolean, class net.minecraft.core.BlockPosition, class net.minecraft.server.level.WorldServer, class java.lang.Object, interface net.minecraft.commands.ICommandListener] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.code.style=official |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.