Skip to content

Commit 7ca832c

Browse files
author
moruch4nn
committed
🚀最初のコミット!
0 parents  commit 7ca832c

31 files changed

+979
-0
lines changed

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
7+
### IntelliJ IDEA ###
8+
.idea/modules.xml
9+
.idea/jarRepositories.xml
10+
.idea/compiler.xml
11+
.idea/libraries/
12+
*.iws
13+
*.iml
14+
*.ipr
15+
out/
16+
!**/src/main/**/out/
17+
!**/src/test/**/out/
18+
19+
### Eclipse ###
20+
.apt_generated
21+
.classpath
22+
.factorypath
23+
.project
24+
.settings
25+
.springBeans
26+
.sts4-cache
27+
bin/
28+
!**/src/main/**/bin/
29+
!**/src/test/**/bin/
30+
31+
### NetBeans ###
32+
/nbproject/private/
33+
/nbbuild/
34+
/dist/
35+
/nbdist/
36+
/.nb-gradle/
37+
38+
### VS Code ###
39+
.vscode/
40+
41+
### Mac OS ###
42+
.DS_Store

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# vTunnel
2+
ポート解放をせずにVelocityプロキシへサーバーを登録できるトンネリングプラグインです。
3+
子サーバー起動時に自動的にVelocityプロキシへサーバーを登録します。(必要に応じてforcedHostsの登録も行います。)
4+
5+
## セットアップする
6+
vTunnelのセットアップ方法。
7+
### プロキシサイドの設定
8+
1.vTunnelは子サーバーからのトンネリングの際に60000番ポートを使用するため、**60000番ポートを解放**する必要があります。<br>
9+
また、解放する必要はありませんが60001-61000ポートを内部的に使用するため他プロセスで使用しないでください。(dockerでの実行を推奨)<br>
10+
<br>
11+
2.VelocityプロキシのpluginsフォルダにvTunnelプラグインを導入する
12+
3.下記のの環境変数を設定する<br>
13+
(velocity-config.tomlのserversやtryの項目を削除することをお勧めします。)
14+
```yaml
15+
# JWTトークンのシークレットです。極力長い文字列にすることをお勧めします。
16+
VTUNNEL_SECRET: """任意のシークレット文字列""" (require)
17+
18+
# サーバー接続時に最初に接続するサーバーの名前。
19+
VTUNNEL_TRY: "サーバー名1,サーバー名2" (optional)
20+
```
21+
### サーバーサイドの設定
22+
1.サーバーにvTunnelプラグインを導入します。<br>
23+
2.JWTトークンを[ここ](https://jwt.io/)から生成する(下記参照)<br>
24+
2.下記の環境変数を設定する<br>
25+
#### JWTトークンの項目
26+
```yaml
27+
Algorithm: HS512
28+
29+
your-256-bit-secret: """上で設定した$VTUNNEL_SECRETの値"""
30+
31+
PAYLOAD:
32+
name: lobby, #Velocityに登録するサーバー名
33+
forced_hosts: ["lobby.example.com","main.example.com"], #Velocityに登録するforcedHostsのアドレス
34+
exp: 1000000000000, #このトークンの有効期限(unix_time/sec)
35+
iss: moruch4nn, #このトークンの発行者(適当で構いません)
36+
aud: [サーバー運営], #このトークンの想定利用者(適当で構いません)
37+
```
38+
### 環境変数
39+
```yaml
40+
# vTunnelサーバーのホスト名
41+
VTUNNEL_HOST: 478.43.12.432
42+
VTUNNEL_TOKEN: 上で生成したJWTToken。
43+
```

client/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id("com.github.johnrengelman.shadow") version "7.1.2"
3+
kotlin("jvm") version "1.8.20"
4+
kotlin("plugin.serialization") version "1.8.20"
5+
}
6+
7+
group = "dev.mr3n"
8+
version = "1.0-SNAPSHOT"
9+
10+
repositories {
11+
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
12+
maven("https://oss.sonatype.org/content/repositories/snapshots")
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
compileOnly("org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT")
18+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
19+
implementation("com.auth0:java-jwt:4.4.0")
20+
implementation("io.ktor:ktor-client-core:2.2.4")
21+
implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.4")
22+
implementation("io.ktor:ktor-client-cio:2.2.4")
23+
implementation(project(":shared"))
24+
}
25+
26+
tasks.named("build") {
27+
dependsOn("shadowJar")
28+
}
29+
30+
kotlin {
31+
jvmToolchain(8)
32+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package dev.mr3n.vtunnel
2+
3+
import dev.mr3n.vtunnel.model.AuthFrame
4+
import dev.mr3n.vtunnel.model.NewConnectionNotify
5+
import dev.mr3n.vtunnel.tcp.PacketTransfer
6+
import io.ktor.client.*
7+
import io.ktor.client.engine.cio.*
8+
import io.ktor.client.plugins.websocket.*
9+
import io.ktor.serialization.kotlinx.*
10+
import kotlinx.coroutines.runBlocking
11+
import kotlinx.serialization.encodeToString
12+
import kotlinx.serialization.json.Json
13+
import org.bukkit.Bukkit
14+
import org.bukkit.event.EventHandler
15+
import org.bukkit.event.EventPriority
16+
import org.bukkit.event.Listener
17+
import org.bukkit.event.player.PlayerLoginEvent
18+
import org.bukkit.plugin.java.JavaPlugin
19+
import java.net.Socket
20+
import java.util.*
21+
import kotlin.concurrent.thread
22+
23+
class VTunnel: JavaPlugin(), Listener {
24+
25+
init {
26+
Bukkit.getServer().onlineMode
27+
}
28+
29+
override fun onEnable() {
30+
thread { runBlocking { startWebSocketClient() } }
31+
this.server.pluginManager.registerEvents(this, this)
32+
}
33+
34+
val client = HttpClient(CIO) {
35+
install(WebSockets) {
36+
contentConverter = KotlinxWebsocketSerializationConverter(Json)
37+
}
38+
}
39+
40+
suspend fun startWebSocketClient() {
41+
val host = System.getenv("VTUNNEL_HOST")?:"akamachi.net"
42+
val token = System.getenv("VTUNNEL_TOKEN")
43+
while (true) {
44+
try {
45+
client.webSocket(host = host, port = 60000, path = "/vtunnel") {
46+
sendSerialized(AuthFrame(token))
47+
while (true) {
48+
val newConn: NewConnectionNotify = receiveDeserialized()
49+
try {
50+
val bridgeSocket = Socket(host, newConn.port)
51+
val outputSocket = bridgeSocket.getOutputStream()
52+
outputSocket.write(Json.encodeToString(AuthFrame(newConn.token)).toByteArray())
53+
outputSocket.flush()
54+
val clientSocket = Socket("127.0.0.1", server.port)
55+
PacketTransfer(bridgeSocket, clientSocket)
56+
} catch (e: Exception) {
57+
e.printStackTrace()
58+
}
59+
}
60+
}
61+
} catch (e: Exception) {
62+
e.printStackTrace()
63+
}
64+
logger.warning("vTunnelとの接続が切断されたため5秒後に再接続を行います。")
65+
Thread.sleep(5000)
66+
}
67+
}
68+
}

client/src/main/resources/plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
main: dev.mr3n.vtunnel.VTunnel
2+
name: VTunnel
3+
version: 1.0

0 commit comments

Comments
 (0)