mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Add --grpc-port support
This commit is contained in:
@@ -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
|
||||
@@ -83,16 +84,17 @@ sudo setcap cap_net_bind_service=+ep ./lunar-tear
|
||||
### Ports
|
||||
|
||||
| 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) |
|
||||
|
||||
### Flags
|
||||
|
||||
| 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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user