Add --grpc-port support

This commit is contained in:
Ilya Groshev
2026-04-20 11:46:42 +03:00
parent c33e738fd5
commit 43d6527b42
5 changed files with 28 additions and 19 deletions
+14 -12
View File
@@ -67,12 +67,13 @@ go run ./cmd/import-snapshot \
```bash ```bash
cd server cd server
sudo go run ./cmd/lunar-tear \ go run ./cmd/lunar-tear \
--host 10.0.2.2 \ --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 ```bash
go build -o lunar-tear ./cmd/lunar-tear go build -o lunar-tear ./cmd/lunar-tear
@@ -82,18 +83,19 @@ sudo setcap cap_net_bind_service=+ep ./lunar-tear
### Ports ### Ports
| Protocol | Port | Notes | | Protocol | Port | Notes |
| -------- | ---- | ---------------------------------------------------- | | -------- | ---- | ----------------------------------------------------------- |
| gRPC | 443 | hardcoded by the client, not configurable | | gRPC | 443 | default; configurable with `--grpc-port` (requires patched client) |
| HTTP | 8080 | Octo asset API + game web pages (`--http-port` flag) | | HTTP | 8080 | Octo asset API + game web pages (`--http-port` flag) |
### Flags ### Flags
| Flag | Default | Description | | Flag | Default | Description |
| ------------- | ------------ | ------------------------------- | | ------------- | ------------ | ---------------------------------------------------- |
| `--host` | `127.0.0.1` | hostname/IP given to the client | | `--host` | `127.0.0.1` | hostname/IP given to the client |
| `--http-port` | `8080` | HTTP/Octo server port | | `--http-port` | `8080` | HTTP/Octo server port |
| `--db` | `db/game.db` | SQLite database path | | `--grpc-port` | `443` | gRPC server port (client must be patched to match) |
| `--db` | `db/game.db` | SQLite database path |
### Docker ### Docker
+9 -5
View File
@@ -37,6 +37,7 @@ func (l loggingListener) Accept() (net.Conn, error) {
func startGRPC( func startGRPC(
host string, host string,
grpcPort int,
octoURL string, octoURL string,
userStore interface { userStore interface {
store.UserRepository store.UserRepository
@@ -64,9 +65,10 @@ func startGRPC(
sideStoryCatalog *masterdata.SideStoryCatalog, sideStoryCatalog *masterdata.SideStoryCatalog,
bigHuntCatalog *masterdata.BigHuntCatalog, bigHuntCatalog *masterdata.BigHuntCatalog,
) { ) {
lis, err := net.Listen("tcp", ":443") addr := fmt.Sprintf(":%d", grpcPort)
lis, err := net.Listen("tcp", addr)
if err != nil { 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} lis = loggingListener{Listener: lis}
@@ -77,6 +79,7 @@ func startGRPC(
registerServices(grpcServer, registerServices(grpcServer,
host, host,
grpcPort,
octoURL, octoURL,
userStore, userStore,
questEngine, questEngine,
@@ -104,8 +107,8 @@ func startGRPC(
reflection.Register(grpcServer) reflection.Register(grpcServer)
log.Printf("gRPC server listening on :443") log.Printf("gRPC server listening on %s", addr)
log.Printf("client host address: %s:443", host) log.Printf("client host address: %s:%d", host, grpcPort)
if err := grpcServer.Serve(lis); err != nil { if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err) log.Fatalf("failed to serve: %v", err)
@@ -115,6 +118,7 @@ func startGRPC(
func registerServices( func registerServices(
srv *grpc.Server, srv *grpc.Server,
host string, host string,
grpcPort int,
octoURL string, octoURL string,
userStore interface { userStore interface {
store.UserRepository store.UserRepository
@@ -145,7 +149,7 @@ func registerServices(
pb.RegisterBannerServiceServer(srv, service.NewBannerServiceServer(gachaEntries)) pb.RegisterBannerServiceServer(srv, service.NewBannerServiceServer(gachaEntries))
pb.RegisterUserServiceServer(srv, service.NewUserServiceServer(userStore, userStore)) pb.RegisterUserServiceServer(srv, service.NewUserServiceServer(userStore, userStore))
pb.RegisterBattleServiceServer(srv, service.NewBattleServiceServer(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.RegisterDataServiceServer(srv, service.NewDataServiceServer(userStore, userStore))
pb.RegisterTutorialServiceServer(srv, service.NewTutorialServiceServer(userStore, userStore, questEngine)) pb.RegisterTutorialServiceServer(srv, service.NewTutorialServiceServer(userStore, userStore, questEngine))
pb.RegisterGachaServiceServer(srv, service.NewGachaServiceServer(userStore, userStore, gachaEntries, gachaHandler)) pb.RegisterGachaServiceServer(srv, service.NewGachaServiceServer(userStore, userStore, gachaEntries, gachaHandler))
+2
View File
@@ -16,6 +16,7 @@ import (
func main() { func main() {
httpPort := flag.Int("http-port", 8080, "HTTP server port (Octo API)") 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") host := flag.String("host", "127.0.0.1", "hostname the client will connect to")
dbPath := flag.String("db", "db/game.db", "SQLite database path") dbPath := flag.String("db", "db/game.db", "SQLite database path")
flag.Parse() flag.Parse()
@@ -165,6 +166,7 @@ func main() {
startGRPC( startGRPC(
*host, *host,
*grpcPort,
octoURL, octoURL,
userStore, userStore,
questHandler, questHandler,
+2 -1
View File
@@ -5,10 +5,11 @@ services:
environment: environment:
LUNAR_HOST: 127.0.0.1 LUNAR_HOST: 127.0.0.1
LUNAR_HTTP_PORT: 8080 LUNAR_HTTP_PORT: 8080
LUNAR_GRPC_PORT: 8003
volumes: volumes:
- ./assets:/opt/lunar-tear/assets - ./assets:/opt/lunar-tear/assets
- ./db:/opt/lunar-tear/db - ./db:/opt/lunar-tear/db
ports: ports:
- 443:443 # grpc, hardcoded by the client, not configurable - 8003:8003
- 8080:8080 - 8080:8080
+1 -1
View File
@@ -4,4 +4,4 @@ set -e
mkdir -p db mkdir -p db
goose -dir migrations sqlite3 db/game.db up 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}"