Commit a5d95d2f authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Allow passing lists of presences as match init parameters to Go runtime matches.

parent d5d12997
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
## [Unreleased]
### Fixed
- Fix data returned by StreamUserList in JS runtime.
- Allow passing lists of presences as match init parameters to Go runtime matches.
- Fix devconsole counts when database statistics are not available.
- Generate missing username in runtime token generator.

## [3.11.0] - 2022-03-21
### Added
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ func init() {
	// Ensure gob can deal with typical types that might be used in match parameters.
	gob.Register(map[string]interface{}(nil))
	gob.Register([]interface{}(nil))
	gob.Register([]runtime.Presence(nil))
	gob.Register(&Presence{})
	gob.Register([]runtime.MatchmakerEntry(nil))
	gob.Register(&MatchmakerEntry{})
	gob.Register([]*api.User(nil))
+46 −0
Original line number Diff line number Diff line
@@ -60,6 +60,52 @@ func TestEncodeDecode(t *testing.T) {
	t.Log("ok")
}

func TestEncodeDecodePresences(t *testing.T) {
	presences := []runtime.Presence{
		&Presence{
			ID: PresenceID{
				Node:      "nakama",
				SessionID: uuid.Must(uuid.NewV4()),
			},
			Stream: PresenceStream{
				Mode:    StreamModeMatchAuthoritative,
				Subject: uuid.Must(uuid.NewV4()),
				Label:   "nakama",
			},
			UserID: uuid.Must(uuid.NewV4()),
			Meta: PresenceMeta{
				Username: "username1",
			},
		},
		&Presence{
			ID: PresenceID{
				Node:      "nakama",
				SessionID: uuid.Must(uuid.NewV4()),
			},
			Stream: PresenceStream{
				Mode:    StreamModeMatchAuthoritative,
				Subject: uuid.Must(uuid.NewV4()),
				Label:   "nakama",
			},
			UserID: uuid.Must(uuid.NewV4()),
			Meta: PresenceMeta{
				Username: "username2",
			},
		},
	}
	params := map[string]interface{}{
		"presences": presences,
	}
	buf := &bytes.Buffer{}
	if err := gob.NewEncoder(buf).Encode(params); err != nil {
		t.Fatalf("error: %v", err)
	}
	if err := gob.NewDecoder(buf).Decode(&params); err != nil {
		t.Fatalf("error: %v", err)
	}
	t.Log("ok")
}

// should create authoritative match, and join with metadata
func TestMatchRegistryAuthoritativeMatchAndJoin(t *testing.T) {
	consoleLogger := loggerForTest(t)
+1 −1
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ func (n *RuntimeGoNakamaModule) AuthenticateSteam(ctx context.Context, token, us
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param userId(type=string) User ID to use to generate the token.
// @param username(type=string, optional=true) The user's username. If left empty, one is generated.
// @param expiresAt(type=int64, optional=true) Number of seconds the token should be valid for. Defaults to server configured expiry time.
// @param expiresAt(type=int64, optional=true) UTC time in seconds when the token must expire. Defaults to server configured expiry time.
// @return token(string) The Nakama session token.
// @return validity(int64) The period for which the token remains valid.
// @return create(bool) Value indicating if this account was just created or already existed.
+2 −2
Original line number Diff line number Diff line
@@ -1562,7 +1562,7 @@ func (n *runtimeJavascriptNakamaModule) authenticateSteam(r *goja.Runtime) func(
// @summary Generate a Nakama session token from a user ID.
// @param userId(type=string) User ID to use to generate the token.
// @param username(type=string, optional=true) The user's username. If left empty, one is generated.
// @param expiresAt(type=number, optional=true) Number of seconds the token should be valid for. Defaults to server configured expiry time.
// @param expiresAt(type=number, optional=true) UTC time in seconds when the token must expire. Defaults to server configured expiry time.
// @return token(string) The Nakama session token.
// @return validity(number) The period for which the token remains valid.
// @return error(error) An optional error value if an error occurred.
@@ -1581,7 +1581,7 @@ func (n *runtimeJavascriptNakamaModule) authenticateTokenGenerate(r *goja.Runtim

		username := getJsString(r, f.Argument(1))
		if username == "" {
			panic(r.NewTypeError("expects username"))
			username = generateUsername()
		}

		exp := time.Now().UTC().Add(time.Duration(n.config.GetSession().TokenExpirySec) * time.Second).Unix()
Loading