Commit 2f188238 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Add support for optional client IP address passthrough to runtime Satori client.

parent 3980ebc7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Added JavaScript runtime function to clear all localcache data.
- Added support for per-key TTL in Lua runtime localcache.
- Added support for per-key TTL in JavaScript runtime localcache.
- Add support for optional client IP address passthrough to runtime Satori client.

### Changed
- Remove unused config 'matchmaker.batch_pool_size'.
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ require (
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
	github.com/heroiclabs/nakama-common v0.0.0-20231110231506-a6d791dbc20f
	github.com/heroiclabs/nakama-common v0.0.0-20231111182915-5206c3ece9b0
	github.com/jackc/pgconn v1.14.0
	github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
	github.com/jackc/pgtype v1.14.0
+2 −2
+10 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"errors"
	"fmt"
	"io"
	"net"
	"net/http"
	"net/url"
	"strings"
@@ -141,8 +142,9 @@ type authenticateBody struct {
// @summary Create a new identity.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param id(type=string) The identifier of the identity.
// @param ipAddress(type=string, optional=true) An optional client IP address to pass on to Satori for geo-IP lookup.
// @return error(error) An optional error value if an error occurred.
func (s *SatoriClient) Authenticate(ctx context.Context, id string) error {
func (s *SatoriClient) Authenticate(ctx context.Context, id string, ipAddress ...string) error {
	if s.invalidConfig {
		return runtime.ErrSatoriConfigurationInvalid
	}
@@ -162,6 +164,13 @@ func (s *SatoriClient) Authenticate(ctx context.Context, id string) error {
	}
	req.Header.Set("Content-Type", "application/json")
	req.SetBasicAuth(s.apiKey, "")
	if len(ipAddress) > 0 && ipAddress[0] != "" {
		if ipAddr := net.ParseIP(ipAddress[0]); ipAddr != nil {
			req.Header.Set("X-Forwarded-For", ipAddr.String())
		}
	} else if ipAddr, ok := ctx.Value(runtime.RUNTIME_CTX_CLIENT_IP).(string); ok {
		req.Header.Set("X-Forwarded-For", ipAddr)
	}

	res, err := s.httpc.Do(req)
	if err != nil {
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ var (
		DiscardUnknown: false,
	}
	metrics       = NewLocalMetrics(logger, logger, nil, cfg)
	storageIdx, _ = NewLocalStorageIndex(logger, nil, &StorageConfig{DisableIndexOnly: false})
	storageIdx, _ = NewLocalStorageIndex(logger, nil, &StorageConfig{DisableIndexOnly: false}, metrics)
	_             = CheckConfig(logger, cfg)
)

Loading