|
| 1 | +# go-metin2-server |
| 2 | + |
| 3 | +Clean-room Metin2 server emulator in Go, targeting TMP4-era client compatibility. |
| 4 | + |
| 5 | +## Status |
| 6 | + |
| 7 | +This repository is the public bootstrap for a fresh, protocol-first rewrite. |
| 8 | + |
| 9 | +Current scope of the project: |
| 10 | +- Go 1.26 baseline. |
| 11 | +- Clean-room process: no legacy server/client code is vendored into this repository. |
| 12 | +- Separate `authd` and `gamed` binaries from day zero. |
| 13 | +- A dedicated pprof/ops HTTP server for profiling goroutines, heap, allocs, mutex contention and blocking. |
| 14 | +- Multi-stage Docker build with a lightweight runtime image that keeps Go debug information intact by avoiding stripped builds. |
| 15 | + |
| 16 | +## Near-term goal |
| 17 | + |
| 18 | +The first real milestone is not “full gameplay”. |
| 19 | +It is a minimal but complete TMP4-compatible boot path: |
| 20 | +- handshake, |
| 21 | +- login/auth, |
| 22 | +- character list, |
| 23 | +- create character, |
| 24 | +- select character, |
| 25 | +- enter game, |
| 26 | +- spawn in a minimal world, |
| 27 | +- basic movement. |
| 28 | + |
| 29 | +## Project layout |
| 30 | + |
| 31 | +- `cmd/authd` — auth daemon entrypoint |
| 32 | +- `cmd/gamed` — game daemon entrypoint |
| 33 | +- `internal/config` — runtime config loading |
| 34 | +- `internal/ops` — health and pprof endpoints |
| 35 | +- `internal/service` — shared service bootstrap / shutdown helpers |
| 36 | +- `docs/` — engineering and clean-room documentation |
| 37 | +- `spec/protocol` — protocol notes and packet inventory |
| 38 | + |
| 39 | +## pprof |
| 40 | + |
| 41 | +Both binaries expose an ops server with: |
| 42 | +- `/healthz` |
| 43 | +- `/debug/pprof/` |
| 44 | +- `/debug/pprof/goroutine` |
| 45 | +- `/debug/pprof/heap` |
| 46 | +- `/debug/pprof/profile` |
| 47 | +- `/debug/pprof/allocs` |
| 48 | +- `/debug/pprof/block` |
| 49 | +- `/debug/pprof/mutex` |
| 50 | +- `/debug/pprof/trace` |
| 51 | + |
| 52 | +Default addresses: |
| 53 | +- `gamed`: `:6060` |
| 54 | +- `authd`: `:6061` |
| 55 | + |
| 56 | +Global override: |
| 57 | +- `METIN2_PPROF_ADDR` |
| 58 | + |
| 59 | +Per-service overrides: |
| 60 | +- `METIN2_GAMED_PPROF_ADDR` |
| 61 | +- `METIN2_AUTHD_PPROF_ADDR` |
| 62 | + |
| 63 | +Examples: |
| 64 | + |
| 65 | +```bash |
| 66 | +go tool pprof http://127.0.0.1:6060/debug/pprof/heap |
| 67 | +go tool pprof http://127.0.0.1:6060/debug/pprof/goroutine |
| 68 | +go tool pprof http://127.0.0.1:6060/debug/pprof/profile?seconds=30 |
| 69 | +curl http://127.0.0.1:6060/debug/pprof/goroutine?debug=1 |
| 70 | +``` |
| 71 | + |
| 72 | +Do not expose pprof directly to the public internet. |
| 73 | + |
| 74 | +## Development |
| 75 | + |
| 76 | +### Local |
| 77 | + |
| 78 | +```bash |
| 79 | +make test |
| 80 | +``` |
| 81 | + |
| 82 | +Run the daemons locally: |
| 83 | + |
| 84 | +```bash |
| 85 | +go run ./cmd/authd |
| 86 | +go run ./cmd/gamed |
| 87 | +``` |
| 88 | + |
| 89 | +### Docker |
| 90 | + |
| 91 | +Build the default lightweight runtime image: |
| 92 | + |
| 93 | +```bash |
| 94 | +docker build --target runtime -t go-metin2-server:latest . |
| 95 | +``` |
| 96 | + |
| 97 | +Build the debug-flavoured runtime image: |
| 98 | + |
| 99 | +```bash |
| 100 | +docker build --target runtime-debug -t go-metin2-server:debug . |
| 101 | +``` |
| 102 | + |
| 103 | +Why this Dockerfile keeps debug information: |
| 104 | +- it uses a multi-stage build, |
| 105 | +- it keeps the final image small with Distroless, |
| 106 | +- it deliberately does not pass `-ldflags="-s -w"`, so DWARF/debug symbols remain available. |
| 107 | + |
| 108 | +## Clean-room rule |
| 109 | + |
| 110 | +This repository must only contain code, documentation and fixtures produced for this project. |
| 111 | +Do not copy legacy Metin2 server/client source into this repository. |
| 112 | + |
| 113 | +See: |
| 114 | +- `docs/clean-room-policy.md` |
| 115 | +- `docs/development.md` |
| 116 | +- `docs/debugging-and-profiling.md` |
| 117 | +- `spec/protocol/README.md` |
0 commit comments