Skip to content

Commit e91f5fe

Browse files
Initial commit
0 parents  commit e91f5fe

24 files changed

Lines changed: 5298 additions & 0 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: SimpleTransfer build
2+
on: [ push ]
3+
4+
permissions:
5+
contents: write
6+
7+
jobs:
8+
build:
9+
if: contains(github.event.head_commit.message, '[ci skip]') == false
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: checkout repository
14+
uses: actions/checkout@v5
15+
16+
- name: cache maven packages
17+
uses: actions/cache@v4.3.0
18+
with:
19+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
20+
path: ~/.m2/repository
21+
22+
- name: setup jdk 17
23+
uses: actions/setup-java@v5
24+
with:
25+
java-version: 17
26+
distribution: temurin
27+
28+
- name: get version from pom.xml
29+
id: get_version
30+
run: |
31+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
32+
echo "version=$VERSION" >> $GITHUB_OUTPUT
33+
echo "Building version: $VERSION"
34+
35+
- name: build with maven
36+
run: mvn clean package -DskipTests
37+
38+
- name: capture build artifacts
39+
uses: actions/upload-artifact@v5
40+
with:
41+
name: SimpleTransfer-${{ steps.get_version.outputs.version }}
42+
path: target/simpletransfer-${{ steps.get_version.outputs.version }}.jar
43+
44+
- name: create release
45+
uses: softprops/action-gh-release@v2.4.2
46+
if: github.ref == 'refs/heads/main'
47+
with:
48+
tag_name: v${{ steps.get_version.outputs.version }}
49+
name: SimpleTransfer ${{ steps.get_version.outputs.version }}
50+
draft: false
51+
prerelease: false
52+
generate_release_notes: true
53+
files: target/simpletransfer-${{ steps.get_version.outputs.version }}.jar

.gitignore

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
pom.xml.next
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
.mvn/wrapper/maven-wrapper.jar
12+
13+
# IntelliJ IDEA
14+
.idea/
15+
*.iml
16+
*.iws
17+
*.ipr
18+
out/
19+
20+
# Eclipse
21+
.classpath
22+
.project
23+
.settings/
24+
bin/
25+
26+
# NetBeans
27+
nbproject/
28+
nbbuild/
29+
dist/
30+
nbdist/
31+
.nb-gradle/
32+
33+
# VS Code
34+
.vscode/
35+
*.code-workspace
36+
37+
# macOS
38+
.DS_Store
39+
.AppleDouble
40+
.LSOverride
41+
42+
# Windows
43+
Thumbs.db
44+
ehthumbs.db
45+
Desktop.ini
46+
$RECYCLE.BIN/
47+
48+
# Linux
49+
*~
50+
.directory
51+
52+
# Logs
53+
*.log
54+
logs/
55+
56+
# Temporary files
57+
*.tmp
58+
*.temp
59+
*.swp
60+
*.swo
61+
*~.nib
62+
63+
# Build artifacts
64+
*.jar
65+
*.war
66+
*.ear
67+
*.class
68+
69+
# Package Files
70+
*.nar
71+
*.zip
72+
*.tar.gz
73+
*.rar
74+
75+
# Test output
76+
test-output/
77+
*.h2.db
78+
*.mv.db
79+
*.trace.db

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
GNU GENERAL PUBLIC LICENSE
2+
Version 3, 29 June 2007
3+
4+
Copyright (C) 2025 Minecraft-InCraftTime-Server
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
---
20+
21+
SimpleTransfer - Velocity 线路切换插件
22+
23+
使用本项目源码的衍生作品必须:
24+
1. 保留原作者版权声明
25+
2. 使用相同的 GPL-3.0 协议
26+
3. 公开源代码
27+
28+
完整协议内容请访问: https://www.gnu.org/licenses/gpl-3.0.html

README.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# SimpleTransfer
2+
3+
Velocity 线路切换插件,让玩家在不退出服务器的情况下自动或手动切换到最优线路。
4+
5+
## 核心功能
6+
7+
### 无感切换线路
8+
玩家切换线路时不需要退出服务器,直接在游戏内传送到目标线路服务器。小地图、背包、玩家状态全部保留,不会出现坐标重置或地图错乱的问题。
9+
10+
### 单域名多线路
11+
通过 Velocity 反向代理,玩家只需要记住一个域名(如 `play.example.com`),插件会根据地理位置、网络运营商等条件自动分配最优线路。对外只暴露 Velocity 的 IP,内部子服务器 IP 完全隐藏。
12+
13+
### 智能路由规则
14+
支持基于多种条件的自动转移:
15+
- **地理位置**: 国家、省份
16+
- **网络运营商**: 电信、联通、移动
17+
- **连接域名**: 不同域名进入不同线路(类似 PistonMOTD 的虚拟主机)
18+
- **玩家 UUID**: VIP 专属线路
19+
- **历史记录**: 自动记住玩家上次使用的线路
20+
21+
规则支持逻辑运算:
22+
- `|` 表示或(电信|联通)
23+
- `!` 表示非(!中国 = 海外)
24+
- 多条件 AND 组合
25+
26+
### 线路管理
27+
- 实时延迟监控
28+
- 手动切换线路
29+
- 查看所有可用线路和延迟
30+
- 管理员可以强制转移玩家
31+
32+
## 使用场景
33+
34+
**跨国服务器**
35+
国内玩家分配到 BGP 线路,海外玩家分配到国际线路,延迟都很低。
36+
37+
**多运营商优化**
38+
电信用户走电信专线,联通用户走联通专线,移动用户走 BGP。
39+
40+
**隐藏内部架构**
41+
外部只能看到 Velocity 的 IP,无法直接连接内部子服务器,防止 DDoS 绕过。
42+
43+
**单域名多入口**
44+
配置 `cn.example.com``us.example.com` 解析到同一个 Velocity,插件根据域名自动分流。
45+
46+
## 快速开始
47+
48+
### 安装
49+
1. 下载 `simpletransfer-xx.jar`
50+
2. 放入 Velocity 的 `plugins` 目录
51+
3. 重启 Velocity
52+
4. 编辑 `plugins/simpletransfer/config.toml` 配置线路
53+
5. 编辑 `plugins/simpletransfer/rules.conf` 配置规则
54+
55+
### 基础配置
56+
57+
**config.toml** - 定义线路
58+
```toml
59+
[servers.bgp]
60+
name = "BGP线路"
61+
target = "bgp-server" # Velocity 中注册的服务器名
62+
description = "多线BGP"
63+
64+
[servers.dx]
65+
name = "电信线路"
66+
target = "dx-server"
67+
description = "电信专线"
68+
```
69+
70+
**rules.conf** - 定义规则
71+
```hocon
72+
{
73+
enabled = true
74+
name = "电信用户优化"
75+
conditions {
76+
isp = "电信"
77+
has_history = false
78+
}
79+
action {
80+
transfer = "dx"
81+
}
82+
}
83+
```
84+
85+
### 命令
86+
87+
玩家命令:
88+
- `/st list` - 查看所有线路和延迟
89+
- `/st ping` - 测试当前延迟
90+
- `/st help` - 帮助信息
91+
92+
管理员命令:
93+
- `/st status <玩家>` - 查看玩家信息
94+
- `/st transfer <玩家> <线路>` - 强制转移玩家
95+
- `/st reload [config|rules|all]` - 重载配置
96+
- `/st rules` - 查看规则列表
97+
98+
### 权限
99+
- `simpletransfer.use` - 基础功能
100+
- `simpletransfer.admin` - 管理功能
101+
102+
## 工作原理
103+
104+
```
105+
玩家 -> Velocity (SimpleTransfer) -> 内部子服务器
106+
|
107+
+-- 检测 IP 地理位置
108+
+-- 匹配路由规则
109+
+-- 自动转移到最优线路
110+
+-- 记录历史选择
111+
```
112+
113+
Velocity 作为中转层,所有玩家连接先到 Velocity,插件检测玩家的 IP 地理位置、运营商信息后,根据 `rules.conf` 中的规则自动转移到合适的子服务器。下次进入时直接连接上次的线路。
114+
115+
子服务器之间通过 Velocity 的内网互联,不对外暴露端口。
116+
117+
## 配置示例
118+
119+
### 场景1: 运营商优化
120+
```hocon
121+
# 电信用户走电信线路
122+
{
123+
enabled = true
124+
conditions {
125+
isp = "电信"
126+
has_history = false
127+
}
128+
action { transfer = "dx" }
129+
}
130+
131+
# 联通用户走联通线路
132+
{
133+
enabled = true
134+
conditions {
135+
isp = "联通"
136+
has_history = false
137+
}
138+
action { transfer = "lt" }
139+
}
140+
```
141+
142+
### 场景2: 地理位置分流
143+
```hocon
144+
# 海外玩家
145+
{
146+
enabled = true
147+
conditions {
148+
country = "!中国"
149+
}
150+
action { transfer = "us" }
151+
}
152+
153+
# 广东玩家
154+
{
155+
enabled = true
156+
conditions {
157+
province = "广东"
158+
}
159+
action { transfer = "gd" }
160+
}
161+
```
162+
163+
### 场景3: 域名分流
164+
```hocon
165+
# cn.example.com 进入国内线路
166+
{
167+
enabled = true
168+
conditions {
169+
hostname = "cn.example.com"
170+
}
171+
action { transfer = "bgp" }
172+
}
173+
174+
# us.example.com 进入国际线路
175+
{
176+
enabled = true
177+
conditions {
178+
hostname = "us.example.com"
179+
}
180+
action { transfer = "us" }
181+
}
182+
```
183+
184+
只需将 `cn.example.com``us.example.com` 都解析到 Velocity 的 IP,插件会自动识别玩家连接时使用的域名。
185+
186+
### 场景4: VIP 专线
187+
```hocon
188+
{
189+
enabled = true
190+
conditions {
191+
uuid = [
192+
"123e4567-e89b-12d3-a456-426614174000"
193+
]
194+
}
195+
action { transfer = "vip" }
196+
}
197+
```
198+
199+
## 数据持久化
200+
201+
插件使用 H2 数据库自动保存:
202+
- 玩家最后使用的线路
203+
- 历史连接记录
204+
205+
数据库文件位于 `plugins/simpletransfer/data/simpletransfer.mv.db`
206+
207+
## 注意事项
208+
209+
- 确保 Velocity 配置中已注册所有子服务器
210+
- `rules.conf` 中的 `transfer` 目标必须在 `config.toml``servers` 中定义
211+
- `config.toml` 中的 `target` 必须是 Velocity 中注册的服务器名
212+
- 规则从上到下匹配,第一个符合的规则会被执行
213+
- 地理位置检测使用 ip2region 离线数据库,无需联网
214+
215+
216+
## 构建
217+
218+
```bash
219+
mvn clean package
220+
```
221+
222+
编译后的文件在 `target/simpletransfer-xx.jar`
223+
224+
## 开源协议
225+
226+
GPL-3.0 License
227+
228+
使用本项目源码的衍生作品必须:
229+
- 保留原作者版权声明
230+
- 使用相同的 GPL-3.0 协议
231+
- 公开源代码

0 commit comments

Comments
 (0)