Skip to content

Commit 8530df6

Browse files
committed
支持 KCP 协议
1 parent 0e5e0ce commit 8530df6

File tree

18 files changed

+870
-264
lines changed

18 files changed

+870
-264
lines changed

.github/workflows/build.yml

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
12+
jobs:
13+
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
# Linux builds
21+
- goos: linux
22+
goarch: amd64
23+
name: linux-amd64
24+
- goos: linux
25+
goarch: arm64
26+
name: linux-arm64
27+
- goos: linux
28+
goarch: arm
29+
goarm: 7
30+
name: linux-armv7
31+
- goos: linux
32+
goarch: arm
33+
goarm: 6
34+
name: linux-armv6
35+
- goos: linux
36+
goarch: 386
37+
name: linux-386
38+
- goos: linux
39+
goarch: loong64
40+
name: linux-loong64
41+
- goos: linux
42+
goarch: mips
43+
name: linux-mips
44+
- goos: linux
45+
goarch: mips64
46+
name: linux-mips64
47+
- goos: linux
48+
goarch: mips64le
49+
name: linux-mips64le
50+
- goos: linux
51+
goarch: mipsle
52+
name: linux-mipsle
53+
- goos: linux
54+
goarch: ppc64
55+
name: linux-ppc64
56+
- goos: linux
57+
goarch: ppc64le
58+
name: linux-ppc64le
59+
- goos: linux
60+
goarch: riscv64
61+
name: linux-riscv64
62+
- goos: linux
63+
goarch: s390x
64+
name: linux-s390x
65+
66+
# Windows builds
67+
- goos: windows
68+
goarch: amd64
69+
name: windows-amd64
70+
ext: .exe
71+
- goos: windows
72+
goarch: arm64
73+
name: windows-arm64
74+
ext: .exe
75+
- goos: windows
76+
goarch: 386
77+
name: windows-386
78+
ext: .exe
79+
80+
# macOS builds
81+
- goos: darwin
82+
goarch: amd64
83+
name: darwin-amd64
84+
- goos: darwin
85+
goarch: arm64
86+
name: darwin-arm64
87+
88+
# FreeBSD builds
89+
- goos: freebsd
90+
goarch: amd64
91+
name: freebsd-amd64
92+
- goos: freebsd
93+
goarch: arm64
94+
name: freebsd-arm64
95+
- goos: freebsd
96+
goarch: 386
97+
name: freebsd-386
98+
- goos: freebsd
99+
goarch: arm
100+
name: freebsd-arm
101+
- goos: freebsd
102+
goarch: riscv64
103+
name: freebsd-riscv64
104+
105+
- goos: aix
106+
goarch: ppc64
107+
name: aix-ppc64
108+
- goos: dragonfly
109+
goarch: amd64
110+
name: dragonfly-amd64
111+
- goos: illumos
112+
goarch: amd64
113+
name: illumos-amd64
114+
- goos: netbsd
115+
goarch: 386
116+
name: netbsd-386
117+
- goos: netbsd
118+
goarch: amd64
119+
name: netbsd-amd64
120+
- goos: netbsd
121+
goarch: arm
122+
name: netbsd-arm
123+
- goos: netbsd
124+
goarch: arm64
125+
name: netbsd-arm64
126+
- goos: openbsd
127+
goarch: 386
128+
name: openbsd-386
129+
- goos: openbsd
130+
goarch: amd64
131+
name: openbsd-amd64
132+
- goos: openbsd
133+
goarch: arm
134+
name: openbsd-arm
135+
- goos: openbsd
136+
goarch: arm64
137+
name: openbsd-arm64
138+
- goos: openbsd
139+
goarch: ppc64
140+
name: openbsd-ppc64
141+
- goos: openbsd
142+
goarch: riscv64
143+
name: openbsd-riscv64
144+
- goos: plan9
145+
goarch: 386
146+
name: plan9-386
147+
- goos: plan9
148+
goarch: amd64
149+
name: plan9-amd64
150+
- goos: plan9
151+
goarch: arm
152+
name: plan9-arm
153+
- goos: solaris
154+
goarch: amd64
155+
name: solaris-amd64
156+
157+
steps:
158+
- uses: actions/checkout@v4
159+
160+
- name: Set up Go
161+
uses: actions/setup-go@v4
162+
with:
163+
go-version: '1.23.1'
164+
165+
- name: Build Gateway
166+
run: go build -ldflags="-s -w" -o gateway-${{ matrix.name }}${{ matrix.ext }} ./cmd/gateway
167+
env:
168+
GOOS: ${{ matrix.goos }}
169+
GOARCH: ${{ matrix.goarch }}
170+
GOARM: ${{ matrix.goarm }}
171+
172+
- name: Build KCP
173+
run: go build -ldflags="-s -w" -o kcp-${{ matrix.name }}${{ matrix.ext }} ./cmd/kcp
174+
env:
175+
GOOS: ${{ matrix.goos }}
176+
GOARCH: ${{ matrix.goarch }}
177+
GOARM: ${{ matrix.goarm }}
178+
179+
- name: Build QUIC
180+
run: go build -ldflags="-s -w" -o quic-${{ matrix.name }}${{ matrix.ext }} ./cmd/quic
181+
env:
182+
GOOS: ${{ matrix.goos }}
183+
GOARCH: ${{ matrix.goarch }}
184+
GOARM: ${{ matrix.goarm }}
185+
186+
- name: Upload artifacts artifacts
187+
uses: actions/upload-artifact@v4
188+
with:
189+
name: binaries-${{ matrix.name }}
190+
path: |
191+
gateway-${{ matrix.name }}${{ matrix.ext }}
192+
kcp-${{ matrix.name }}${{ matrix.ext }}
193+
quic-${{ matrix.name }}${{ matrix.ext }}
194+
195+
# 合并所有构建产物
196+
merge-artifacts:
197+
needs: build
198+
runs-on: ubuntu-latest
199+
steps:
200+
- name: Download all artifacts
201+
uses: actions/download-artifact@v4
202+
with:
203+
path: ./artifacts
204+
merge-multiple: true # 合并所有 artifacts
205+
206+
- name: Display structure
207+
run: ls -la ./artifacts
208+
209+
- name: Upload merged artifacts
210+
uses: actions/upload-artifact@v4
211+
with:
212+
name: mc-gateway-all-platforms
213+
path: ./artifacts/*
214+
retention-days: 30

.github/workflows/go.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vscode
22

33
config.json
4+
config.toml
45
/gateway
56
/logs/

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
# mc-gateway
2-
This project is a Minecraft game server gateway. It allows you to access multiple game servers through different hostnames, using the same port.
2+
3+
一个简易的 Minecraft 网关,通过 host 将客户端的流量转发到对应的后端 Minecraft 服务器。
4+
5+
## 配置
6+
7+
目前 mc-gateway 只支持读取当前目录的 `config.toml` 作为配置。在 `config.toml` 被修改时,可以自动加载并更新部分配置,以达到不停机修改配置的效果。支持热加载的配置有:
8+
9+
- hosts
10+
- log
11+
- KCP 的 data_shards 和 parity_Shards
12+
- QUIC 的 application_protocols
13+
14+
### hosts
15+
16+
hosts 使用期望的 host 做 key,转发的目的地址为 value。参考`config.example.toml`
17+
18+
### log
19+
20+
| 配置 | 类型 | 备注 |
21+
| ----- | ------ | -------- |
22+
| level | Level | 日志等级 |
23+
| file | string | 日志文件 |
24+
25+
> 日志适配 logrotate,可以使用 logrotate 进行日志分片、压缩等日常运维操作,参考配置:
26+
27+
```logrotate
28+
/var/log/mc-gateway.log {
29+
copytruncate
30+
daily
31+
missingok
32+
rotate 14
33+
compress
34+
compresscmd /usr/bin/zstd
35+
compressext .zst
36+
compressoptions -T0 --long
37+
uncompresscmd /usr/bin/unzstd
38+
notifempty
39+
delaycompress
40+
dateext
41+
postrotate
42+
# 向程序发送 SIGHUP 信号
43+
# mc-gateway 默认会将当前进程的 pid 写入 /var/run/mc-gateway.pid
44+
if [ -f /var/run/mc-gateway.pid ]; then
45+
kill -SIGHUP $(cat /var/run/mc-gateway.pid)
46+
fi
47+
endscript
48+
}
49+
```
50+
51+
### TCP
52+
53+
| 配置 | 类型 | 备注 |
54+
| ------ | ---- | -------- |
55+
| enable | bool | 是否启用 |
56+
| port | int | 端口 |
57+
58+
### KCP
59+
60+
| 配置 | 类型 | 备注 |
61+
| ------------- | ---- | -------- |
62+
| enable | bool | 是否启用 |
63+
| port | int | 端口 |
64+
| data_shards | int | 数据分片 |
65+
| parity_Shards | int | 校验分片 |
66+
67+
### QUIC
68+
69+
| 配置 | 类型 | 备注 |
70+
| --------------------- | -------- | ------------ |
71+
| enable | bool | 是否启用 |
72+
| port | int | 端口 |
73+
| application_protocols | []string | 应用协议列表 |
74+
75+
> application_protocols 只要客户端与服务端有一个能够对应上就可以成功连接
76+
> 默认值为 ["minecraft", "quic", "raw", "h3"]

0 commit comments

Comments
 (0)