Skip to content

Commit

Permalink
Add runtime API to read Nakama config values
Browse files Browse the repository at this point in the history
  • Loading branch information
sesposito committed Nov 22, 2024
1 parent e24311a commit 0ba5e80
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Add new runtime function to get a list of user's friend status.
- Add new Follow/Unfollow runtime APIs.
- Add new NotificationsUpdate runtime API.
- Add new GetConf runtime API.

## [1.34.0] - 2024-10-21
### Added
Expand Down
115 changes: 115 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,113 @@ declare namespace nkruntime {
persistent: boolean
}

export interface Config {
name: string
shutdown_grace_sec: number
logger: ConfigLogger
session: ConfigSession
socket: ConfigSocket
social: ConfigSocial
runtime: ConfigRuntime
iap: ConfigIAP
google_auth: ConfigGoogleAuth
satori: ConfigSatori
}

export interface ConfigLogger {
level: string
}

export interface ConfigSession {
encryption_key: string
token_expiry_sec: number
refresh_encryption_key: string
refresh_token_expiry_sec: number
single_socket: boolean
single_match: boolean
single_party: boolean
single_session: boolean
}

export interface ConfigSocket {
server_key: string
port: number
address: string
protocol: string
}

export interface ConfigSocial {
steam: ConfigSteam
facebookInstantGame: ConfigFacebookInstantGame
facebookLimitedLogin: ConfigFacebookLimitedLogin
apple: ConfigApple
}

export interface ConfigSteam {
publisher_key: string
app_id: string
}

export interface ConfigFacebookInstantGame {
app_secret: string
}

export interface ConfigFacebookLimitedLogin {
app_id: string
}

export interface ConfigApple {
bundle_id: string
}

export interface ConfigRuntime {
env: string[]
http_key: string
}

export interface ConfigIAP {
apple: ConfigIAPApple
google: ConfigIAPGoogle
huawei: ConfigIAPHuawei
facebook_instant: ConfigIAPFacebookInstant
}

export interface ConfigIAPApple {
shared_password: string
notifications_endpoint_id: string
}

export interface ConfigIAPGoogle {
client_email: string
private_key: string
notifications_endpoint_id: string
refund_check_period_min: number
package_name: string
}

export interface ConfigIAPHuawei {
public_key: string
client_id: string
client_secret: string
}

export interface ConfigIAPFacebookInstant {
public_key: string
client_id: string
client_secret: string
}

export interface ConfigGoogleAuth {
credentials_json: string
}

export interface ConfigSatori {
url: string
api_key_name: string
api_key: string
signing_key: string
}

const enum PresenceReason {
PresenceReasonUnknown = 0,
PresenceReasonJoin = 1,
Expand All @@ -3257,6 +3364,14 @@ declare namespace nkruntime {
* The server APIs available in the game server.
*/
export interface Nakama {
/**
* Get subset of Nakama configs.
*
* @returns Object containing config values.
* @throws {TypeError}
*/
getConfig(): Config;

/**
* Convert binary data to string.
*
Expand Down
130 changes: 130 additions & 0 deletions runtime/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright 2024 The Nakama Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package runtime

// Config interface is the Nakama core configuration.
type Config interface {
GetName() string
GetShutdownGraceSec() int
GetLogger() LoggerConfig
GetSession() SessionConfig
GetSocket() SocketConfig
GetSocial() SocialConfig
GetRuntime() RuntimeConfig
GetIAP() IAPConfig
GetGoogleAuth() GoogleAuthConfig
GetSatori() SatoriConfig
}

// LoggerConfig is configuration relevant to logging levels and output.
type LoggerConfig interface {
GetLevel() string
}

// SessionConfig is configuration relevant to the session.
type SessionConfig interface {
GetEncryptionKey() string
GetTokenExpirySec() int64
GetRefreshEncryptionKey() string
GetRefreshTokenExpirySec() int64
GetSingleSocket() bool
GetSingleMatch() bool
GetSingleParty() bool
GetSingleSession() bool
}

// SocketConfig is configuration relevant to the transport socket and protocol.
type SocketConfig interface {
GetServerKey() string
GetPort() int
GetAddress() string
GetProtocol() string
}

// SocialConfig is configuration relevant to the social authentication providers.
type SocialConfig interface {
GetSteam() SocialConfigSteam
GetFacebookInstantGame() SocialConfigFacebookInstantGame
GetFacebookLimitedLogin() SocialConfigFacebookLimitedLogin
GetApple() SocialConfigApple
}

// SocialConfigSteam is configuration relevant to Steam.
type SocialConfigSteam interface {
GetPublisherKey() string
GetAppID() int
}

// SocialConfigFacebookInstantGame is configuration relevant to Facebook Instant Games.
type SocialConfigFacebookInstantGame interface {
GetAppSecret() string
}

// SocialConfigFacebookLimitedLogin is configuration relevant to Facebook Limited Login.
type SocialConfigFacebookLimitedLogin interface {
GetAppId() string
}

// SocialConfigApple is configuration relevant to Apple Sign In.
type SocialConfigApple interface {
GetBundleId() string
}

// RuntimeConfig is configuration relevant to the Runtimes.
type RuntimeConfig interface {
GetEnv() []string
GetHTTPKey() string
}

type IAPConfig interface {
GetApple() IAPAppleConfig
GetGoogle() IAPGoogleConfig
GetHuawei() IAPHuaweiConfig
GetFacebookInstant() IAPFacebookInstantConfig
}

type IAPAppleConfig interface {
GetSharedPassword() string
GetNotificationsEndpointId() string
}

type IAPGoogleConfig interface {
GetClientEmail() string
GetPrivateKey() string
GetNotificationsEndpointId() string
GetRefundCheckPeriodMin() int
GetPackageName() string
}

type SatoriConfig interface {
GetUrl() string
GetApiKeyName() string
GetApiKey() string
GetSigningKey() string
}

type IAPHuaweiConfig interface {
GetPublicKey() string
GetClientID() string
GetClientSecret() string
}

type IAPFacebookInstantConfig interface {
GetAppSecret() string
}

type GoogleAuthConfig interface {
GetCredentialsJSON() string
}
1 change: 1 addition & 0 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ type NakamaModule interface {
StatusFollow(sessionID string, userIDs []string) error
StatusUnfollow(sessionID string, userIDs []string) error

GetConfig() (Config, error)
GetSatori() Satori
GetFleetManager() FleetManager
}
Expand Down

0 comments on commit 0ba5e80

Please sign in to comment.