From 43d6527b4281e34bfeb99dae7d36d914cd330abf Mon Sep 17 00:00:00 2001 From: Ilya Groshev Date: Mon, 20 Apr 2026 11:46:42 +0300 Subject: [PATCH] Add --grpc-port support --- README.md | 26 ++++++++++++++------------ server/cmd/lunar-tear/grpc.go | 14 +++++++++----- server/cmd/lunar-tear/main.go | 2 ++ server/docker-compose.yaml | 3 ++- server/entrypoint.sh | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index de2da35..0f2dbc8 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,13 @@ go run ./cmd/import-snapshot \ ```bash cd server -sudo go run ./cmd/lunar-tear \ +go run ./cmd/lunar-tear \ --host 10.0.2.2 \ - --http-port 8080 + --http-port 8080 \ + --grpc-port 8003 ``` -`sudo` is needed because gRPC binds to port 443 (privileged). On Linux you can use `setcap` instead: +The default gRPC port is 443, which requires `sudo` (privileged port). Use `--grpc-port` with a high port to avoid this. If you do need port 443, either use `sudo` or grant the binary the capability on Linux: ```bash go build -o lunar-tear ./cmd/lunar-tear @@ -82,18 +83,19 @@ sudo setcap cap_net_bind_service=+ep ./lunar-tear ### Ports -| Protocol | Port | Notes | -| -------- | ---- | ---------------------------------------------------- | -| gRPC | 443 | hardcoded by the client, not configurable | -| HTTP | 8080 | Octo asset API + game web pages (`--http-port` flag) | +| Protocol | Port | Notes | +| -------- | ---- | ----------------------------------------------------------- | +| gRPC | 443 | default; configurable with `--grpc-port` (requires patched client) | +| HTTP | 8080 | Octo asset API + game web pages (`--http-port` flag) | ### Flags -| Flag | Default | Description | -| ------------- | ------------ | ------------------------------- | -| `--host` | `127.0.0.1` | hostname/IP given to the client | -| `--http-port` | `8080` | HTTP/Octo server port | -| `--db` | `db/game.db` | SQLite database path | +| Flag | Default | Description | +| ------------- | ------------ | ---------------------------------------------------- | +| `--host` | `127.0.0.1` | hostname/IP given to the client | +| `--http-port` | `8080` | HTTP/Octo server port | +| `--grpc-port` | `443` | gRPC server port (client must be patched to match) | +| `--db` | `db/game.db` | SQLite database path | ### Docker diff --git a/server/cmd/lunar-tear/grpc.go b/server/cmd/lunar-tear/grpc.go index 733654b..7abd6a8 100644 --- a/server/cmd/lunar-tear/grpc.go +++ b/server/cmd/lunar-tear/grpc.go @@ -37,6 +37,7 @@ func (l loggingListener) Accept() (net.Conn, error) { func startGRPC( host string, + grpcPort int, octoURL string, userStore interface { store.UserRepository @@ -64,9 +65,10 @@ func startGRPC( sideStoryCatalog *masterdata.SideStoryCatalog, bigHuntCatalog *masterdata.BigHuntCatalog, ) { - lis, err := net.Listen("tcp", ":443") + addr := fmt.Sprintf(":%d", grpcPort) + lis, err := net.Listen("tcp", addr) if err != nil { - log.Fatalf("failed to listen on :443: %v", err) + log.Fatalf("failed to listen on %s: %v", addr, err) } lis = loggingListener{Listener: lis} @@ -77,6 +79,7 @@ func startGRPC( registerServices(grpcServer, host, + grpcPort, octoURL, userStore, questEngine, @@ -104,8 +107,8 @@ func startGRPC( reflection.Register(grpcServer) - log.Printf("gRPC server listening on :443") - log.Printf("client host address: %s:443", host) + log.Printf("gRPC server listening on %s", addr) + log.Printf("client host address: %s:%d", host, grpcPort) if err := grpcServer.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) @@ -115,6 +118,7 @@ func startGRPC( func registerServices( srv *grpc.Server, host string, + grpcPort int, octoURL string, userStore interface { store.UserRepository @@ -145,7 +149,7 @@ func registerServices( pb.RegisterBannerServiceServer(srv, service.NewBannerServiceServer(gachaEntries)) pb.RegisterUserServiceServer(srv, service.NewUserServiceServer(userStore, userStore)) pb.RegisterBattleServiceServer(srv, service.NewBattleServiceServer(userStore, userStore)) - pb.RegisterConfigServiceServer(srv, service.NewConfigServiceServer(host, int32(443), octoURL)) + pb.RegisterConfigServiceServer(srv, service.NewConfigServiceServer(host, int32(grpcPort), octoURL)) pb.RegisterDataServiceServer(srv, service.NewDataServiceServer(userStore, userStore)) pb.RegisterTutorialServiceServer(srv, service.NewTutorialServiceServer(userStore, userStore, questEngine)) pb.RegisterGachaServiceServer(srv, service.NewGachaServiceServer(userStore, userStore, gachaEntries, gachaHandler)) diff --git a/server/cmd/lunar-tear/main.go b/server/cmd/lunar-tear/main.go index 5acab96..5d20bd4 100644 --- a/server/cmd/lunar-tear/main.go +++ b/server/cmd/lunar-tear/main.go @@ -16,6 +16,7 @@ import ( func main() { httpPort := flag.Int("http-port", 8080, "HTTP server port (Octo API)") + grpcPort := flag.Int("grpc-port", 443, "gRPC server port") host := flag.String("host", "127.0.0.1", "hostname the client will connect to") dbPath := flag.String("db", "db/game.db", "SQLite database path") flag.Parse() @@ -165,6 +166,7 @@ func main() { startGRPC( *host, + *grpcPort, octoURL, userStore, questHandler, diff --git a/server/docker-compose.yaml b/server/docker-compose.yaml index 1f432aa..d3b62cd 100644 --- a/server/docker-compose.yaml +++ b/server/docker-compose.yaml @@ -5,10 +5,11 @@ services: environment: LUNAR_HOST: 127.0.0.1 LUNAR_HTTP_PORT: 8080 + LUNAR_GRPC_PORT: 8003 volumes: - ./assets:/opt/lunar-tear/assets - ./db:/opt/lunar-tear/db ports: - - 443:443 # grpc, hardcoded by the client, not configurable + - 8003:8003 - 8080:8080 diff --git a/server/entrypoint.sh b/server/entrypoint.sh index 46acc15..1906180 100755 --- a/server/entrypoint.sh +++ b/server/entrypoint.sh @@ -4,4 +4,4 @@ set -e mkdir -p db goose -dir migrations sqlite3 db/game.db up -exec ./lunar-tear --host "${LUNAR_HOST}" --http-port "${LUNAR_HTTP_PORT}" +exec ./lunar-tear --host "${LUNAR_HOST}" --http-port "${LUNAR_HTTP_PORT}" --grpc-port "${LUNAR_GRPC_PORT:-443}"