server

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2017 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const CALLBACKS = "runtime_callbacks"

Variables

View Source
var (
	VerboseLogging = true
	StdoutLogging  = false
)

By default, log all messages with Warn and Error messages to a log file inside Data/Log/<name>.log file. The content will be in JSON. if --verbose is passed, log messages with Debug and higher levels. if --logtostdout is passed, logs are only printed to stdout. In all cases, Error messages trigger the stacktrace to be dumped as well.

Functions

func ConvertLuaTable added in v0.13.0

func ConvertLuaTable(lv *lua.LTable) map[string]interface{}

func ConvertMap added in v0.13.0

func ConvertMap(l *lua.LState, data map[string]interface{}) *lua.LTable

func NewAuthenticationService

func NewAuthenticationService(logger *zap.Logger, config Config, db *sql.DB, statService StatsService, registry *SessionRegistry, socialClient *social.Client, pipeline *pipeline, runtime *Runtime) *authenticationService

NewAuthenticationService creates a new AuthenticationService

func NewConfig

func NewConfig() *config

NewConfig constructs a Config struct which represents server settings.

func NewConsoleLogger added in v0.12.2

func NewConsoleLogger(output *os.File) *zap.Logger

func NewJSONLogger added in v0.12.2

func NewJSONLogger(output *os.File) *zap.Logger

func NewLogger added in v0.12.2

func NewLogger(consoleLogger *zap.Logger, config Config) *zap.Logger

func NewLuaContext added in v0.13.0

func NewLuaContext(l *lua.LState, env *lua.LTable, mode ExecutionMode, uid uuid.UUID, handle string, sessionExpiry int64) *lua.LTable

func NewMessageRouterService

func NewMessageRouterService(registry *SessionRegistry) *messageRouterService

func NewMultiLogger added in v0.12.2

func NewMultiLogger(loggers ...*zap.Logger) *zap.Logger

func NewOpsService

func NewOpsService(logger *zap.Logger, multiLogger *zap.Logger, version string, config Config, statsService StatsService) *opsService

NewOpsService creates a new opsService

func NewPipeline

func NewPipeline(config Config, db *sql.DB, tracker Tracker, matchmaker Matchmaker, messageRouter MessageRouter, registry *SessionRegistry, socialClient *social.Client, runtime *Runtime) *pipeline

NewPipeline creates a new Pipeline

func NewPresenceNotifier

func NewPresenceNotifier(logger *zap.Logger, name string, tracker Tracker, messageRouter MessageRouter) *presenceNotifier

NewPresenceNotifier creates a new PresenceNotifier

func NewSession

func NewSession(logger *zap.Logger, config Config, userID uuid.UUID, handle string, lang string, expiry int64, websocketConn *websocket.Conn, unregister func(s *session)) *session

NewSession creates a new session which encapsulates a socket connection

func OpenOs added in v0.13.0

func OpenOs(L *lua.LState) int

func RuntimeAfterHook added in v0.13.0

func RuntimeAfterHook(logger *zap.Logger, runtime *Runtime, jsonpbMarshaler *jsonpb.Marshaler, messageType string, envelope *Envelope, session *session)

func RuntimeAfterHookAuthentication added in v0.13.0

func RuntimeAfterHookAuthentication(logger *zap.Logger, runtime *Runtime, jsonpbMarshaler *jsonpb.Marshaler, envelope *AuthenticateRequest)

func StorageFetch added in v0.13.0

func StorageFetch(logger *zap.Logger, db *sql.DB, caller uuid.UUID, keys []*StorageKey) ([]*StorageData, Error_Code, error)

func StorageWrite added in v0.13.0

func StorageWrite(logger *zap.Logger, db *sql.DB, caller uuid.UUID, data []*StorageData) ([]*StorageKey, Error_Code, error)

Types

type BuiltinModule added in v0.13.0

type BuiltinModule interface {
	Loader(l *lua.LState) int
}

type Callbacks added in v0.13.0

type Callbacks struct {
	HTTP   map[string]*lua.LFunction
	RPC    map[string]*lua.LFunction
	Before map[string]*lua.LFunction
	After  map[string]*lua.LFunction
}

type Config

type Config interface {
	GetName() string
	GetDataDir() string
	GetPort() int
	GetOpsPort() int
	GetDSNS() []string
	GetSession() *SessionConfig
	GetTransport() *TransportConfig
	GetDatabase() *DatabaseConfig
	GetSocial() *SocialConfig
	GetRuntime() *RuntimeConfig
}

Config interface is the Nakama Core configuration

type DatabaseConfig

type DatabaseConfig struct {
	ConnMaxLifetimeMs int `yaml:"conn_max_lifetime_ms" json:"conn_max_lifetime_ms"`
	MaxOpenConns      int `yaml:"max_open_conns" json:"max_open_conns"`
	MaxIdleConns      int `yaml:"max_idle_conns" json:"max_idle_conns"`
}

DatabaseConfig is configuration relevant to the Database storage

func NewDatabaseConfig

func NewDatabaseConfig() *DatabaseConfig

NewDatabaseConfig creates a new DatabaseConfig struct

type ExecutionMode added in v0.13.0

type ExecutionMode int
const (
	RPC ExecutionMode = iota
	BEFORE
	AFTER
	HTTP
	JOB
	LEADERBOARD_RESET
)

func (ExecutionMode) String added in v0.13.0

func (e ExecutionMode) String() string

type Matchmaker added in v0.13.0

type Matchmaker interface {
	Add(sessionID uuid.UUID, userID uuid.UUID, meta PresenceMeta, requiredCount int64) (uuid.UUID, map[MatchmakerKey]*MatchmakerProfile)
	Remove(sessionID uuid.UUID, userID uuid.UUID, ticket uuid.UUID) error
	RemoveAll(sessionID uuid.UUID)
	UpdateAll(sessionID uuid.UUID, meta PresenceMeta)
}

type MatchmakerKey added in v0.13.0

type MatchmakerKey struct {
	ID     PresenceID
	UserID uuid.UUID
	Ticket uuid.UUID
}

type MatchmakerProfile added in v0.13.0

type MatchmakerProfile struct {
	Meta          PresenceMeta
	RequiredCount int64
}

type MatchmakerService added in v0.13.0

type MatchmakerService struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMatchmakerService added in v0.13.0

func NewMatchmakerService(name string) *MatchmakerService

func (*MatchmakerService) Add added in v0.13.0

func (m *MatchmakerService) Add(sessionID uuid.UUID, userID uuid.UUID, meta PresenceMeta, requiredCount int64) (uuid.UUID, map[MatchmakerKey]*MatchmakerProfile)

func (*MatchmakerService) Remove added in v0.13.0

func (m *MatchmakerService) Remove(sessionID uuid.UUID, userID uuid.UUID, ticket uuid.UUID) error

func (*MatchmakerService) RemoveAll added in v0.13.0

func (m *MatchmakerService) RemoveAll(sessionID uuid.UUID)

func (*MatchmakerService) UpdateAll added in v0.13.0

func (m *MatchmakerService) UpdateAll(sessionID uuid.UUID, meta PresenceMeta)

type MessageRouter

type MessageRouter interface {
	Send(*zap.Logger, []Presence, proto.Message)
}

MessageRouter is responsible for sending a message to a list of presences

type NakamaModule added in v0.13.0

type NakamaModule struct {
	// contains filtered or unexported fields
}

func NewNakamaModule added in v0.13.0

func NewNakamaModule(logger *zap.Logger, db *sql.DB, l *lua.LState) *NakamaModule

func (*NakamaModule) Loader added in v0.13.0

func (n *NakamaModule) Loader(l *lua.LState) int

type NakamaxModule added in v0.13.0

type NakamaxModule struct {
	// contains filtered or unexported fields
}

func NewNakamaxModule added in v0.13.0

func NewNakamaxModule(logger *zap.Logger) *NakamaxModule

func (*NakamaxModule) Loader added in v0.13.0

func (nx *NakamaxModule) Loader(l *lua.LState) int

type Presence

type Presence struct {
	ID     PresenceID
	Topic  string
	UserID uuid.UUID
	Meta   PresenceMeta
}

type PresenceID

type PresenceID struct {
	Node      string
	SessionID uuid.UUID
}

type PresenceMeta

type PresenceMeta struct {
	Handle string
}

type Runtime added in v0.13.0

type Runtime struct {
	// contains filtered or unexported fields
}

func NewRuntime added in v0.13.0

func NewRuntime(logger *zap.Logger, multiLogger *zap.Logger, db *sql.DB, config *RuntimeConfig) (*Runtime, error)

func (*Runtime) GetRuntimeCallback added in v0.13.0

func (r *Runtime) GetRuntimeCallback(e ExecutionMode, key string) *lua.LFunction

func (*Runtime) InvokeFunctionAfter added in v0.13.0

func (r *Runtime) InvokeFunctionAfter(fn *lua.LFunction, uid uuid.UUID, handle string, sessionExpiry int64, payload map[string]interface{}) error

func (*Runtime) InvokeFunctionBefore added in v0.13.0

func (r *Runtime) InvokeFunctionBefore(fn *lua.LFunction, uid uuid.UUID, handle string, sessionExpiry int64, payload map[string]interface{}) (map[string]interface{}, error)

func (*Runtime) InvokeFunctionHTTP added in v0.13.0

func (r *Runtime) InvokeFunctionHTTP(fn *lua.LFunction, uid uuid.UUID, handle string, sessionExpiry int64, payload map[string]interface{}) (map[string]interface{}, error)

func (*Runtime) InvokeFunctionRPC added in v0.13.0

func (r *Runtime) InvokeFunctionRPC(fn *lua.LFunction, uid uuid.UUID, handle string, sessionExpiry int64, payload []byte) ([]byte, error)

func (*Runtime) NewStateThread added in v0.13.0

func (r *Runtime) NewStateThread() (*lua.LState, context.CancelFunc)

func (*Runtime) Stop added in v0.13.0

func (r *Runtime) Stop()

type RuntimeConfig added in v0.13.0

type RuntimeConfig struct {
	Environment map[string]interface{} `yaml:"env" json:"env"`
	Path        string                 `yaml:"path" json:"path"`
	HTTPKey     string                 `yaml:"http_key" json:"http_key"`
}

RuntimeConfig is configuration relevant to the Runtime Lua VM

func NewRuntimeConfig added in v0.13.0

func NewRuntimeConfig() *RuntimeConfig

NewRuntimeConfig creates a new RuntimeConfig struct

type SessionConfig

type SessionConfig struct {
	EncryptionKey string `yaml:"encryption_key" json:"encryption_key"`
	TokenExpiryMs int64  `yaml:"token_expiry_ms" json:"token_expiry_ms"`
}

SessionConfig is configuration relevant to the session

func NewSessionConfig

func NewSessionConfig() *SessionConfig

NewSessionConfig creates a new SessionConfig struct

type SessionRegistry

type SessionRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SessionRegistry maintains a list of sessions to their IDs. This is thread-safe.

func NewSessionRegistry

func NewSessionRegistry(logger *zap.Logger, config Config, tracker Tracker, matchmaker Matchmaker) *SessionRegistry

NewSessionRegistry creates a new SessionRegistry

func (*SessionRegistry) Get

func (a *SessionRegistry) Get(sessionID uuid.UUID) *session

Get returns a session matching the sessionID

type SocialConfig

type SocialConfig struct {
	Steam *SocialConfigSteam `yaml:"steam" json:"steam"`
}

SocialConfig is configuration relevant to the Social providers

func NewSocialConfig

func NewSocialConfig() *SocialConfig

NewSocialConfig creates a new SocialConfig struct

type SocialConfigSteam

type SocialConfigSteam struct {
	PublisherKey string `yaml:"publisher_key" json:"publisher_key"`
	AppID        int    `yaml:"app_id" json:"app_id"`
}

SocialConfigSteam is configuration relevant to Steam

type StatsService

type StatsService interface {
	GetStats() []map[string]interface{}
	GetHealthStatus() int
}

StatsService is responsible for gathering and reading stats information from metrics

func NewStatsService

func NewStatsService(logger *zap.Logger, config Config, version string, tracker Tracker, startedAt int64) StatsService

NewStatsService creates a new StatsService

type StorageData added in v0.13.0

type StorageData struct {
	Bucket          string
	Collection      string
	Record          string
	UserId          []byte // this must be UserId not UserID
	Value           []byte
	Version         []byte
	PermissionRead  int64
	PermissionWrite int64
	CreatedAt       int64
	UpdatedAt       int64
	ExpiresAt       int64
}

type StorageKey added in v0.13.0

type StorageKey struct {
	Bucket     string
	Collection string
	Record     string
	UserId     []byte // this must be UserId not UserID
	// Version is used when returning results from write ops, does not apply to fetch ops.
	Version []byte
}

type Tracker

type Tracker interface {
	AddDiffListener(func([]Presence, []Presence))
	Stop()

	Track(sessionID uuid.UUID, topic string, userID uuid.UUID, meta PresenceMeta)
	Untrack(sessionID uuid.UUID, topic string, userID uuid.UUID)
	UntrackAll(sessionID uuid.UUID)
	Update(sessionID uuid.UUID, topic string, userID uuid.UUID, meta PresenceMeta) error
	UpdateAll(sessionID uuid.UUID, meta PresenceMeta)

	// Get current total number of presences.
	Count() int
	// Check if a single presence on the current node exists.
	CheckLocalByIDTopicUser(sessionID uuid.UUID, topic string, userID uuid.UUID) bool
	// List presences by topic.
	ListByTopic(topic string) []Presence
	// List presences on the current node by topic.
	ListLocalByTopic(topic string) []Presence
}

type TrackerService

type TrackerService struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTrackerService

func NewTrackerService(name string) *TrackerService

func (*TrackerService) AddDiffListener

func (t *TrackerService) AddDiffListener(f func([]Presence, []Presence))

func (*TrackerService) CheckLocalByIDTopicUser

func (t *TrackerService) CheckLocalByIDTopicUser(sessionID uuid.UUID, topic string, userID uuid.UUID) bool

func (*TrackerService) Count

func (t *TrackerService) Count() int

func (*TrackerService) ListByTopic

func (t *TrackerService) ListByTopic(topic string) []Presence

func (*TrackerService) ListLocalByTopic

func (t *TrackerService) ListLocalByTopic(topic string) []Presence

func (*TrackerService) Stop

func (t *TrackerService) Stop()

func (*TrackerService) Track

func (t *TrackerService) Track(sessionID uuid.UUID, topic string, userID uuid.UUID, meta PresenceMeta)

func (*TrackerService) Untrack

func (t *TrackerService) Untrack(sessionID uuid.UUID, topic string, userID uuid.UUID)

func (*TrackerService) UntrackAll

func (t *TrackerService) UntrackAll(sessionID uuid.UUID)

func (*TrackerService) Update

func (t *TrackerService) Update(sessionID uuid.UUID, topic string, userID uuid.UUID, meta PresenceMeta) error

func (*TrackerService) UpdateAll added in v0.12.0

func (t *TrackerService) UpdateAll(sessionID uuid.UUID, meta PresenceMeta)

type TransportConfig

type TransportConfig struct {
	ServerKey           string `yaml:"server_key" json:"server_key"`
	MaxMessageSizeBytes int64  `yaml:"max_message_size_bytes" json:"max_message_size_bytes"`
	WriteWaitMs         int    `yaml:"write_wait_ms" json:"write_wait_ms"`
	PongWaitMs          int    `yaml:"pong_wait_ms" json:"pong_wait_ms"`
	PingPeriodMs        int    `yaml:"ping_period_ms" json:"ping_period_ms"`
}

TransportConfig is configuration relevant to the transport socket and protocol

func NewTransportConfig

func NewTransportConfig() *TransportConfig

NewTransportConfig creates a new TransportConfig struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL