Archived
1
0
Fork 0
This repository has been archived on 2026-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
Danmaku/server/main.go

39 lines
1.3 KiB
Go

package main
import (
"context"
"database/sql"
"danmaku/game-modes/battle-royale"
"github.com/heroiclabs/nakama-common/runtime"
)
// RPC for force-creating a match for debugging/development, separate from the matchmaking process
func ManualForceCreateBRMatchRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
modulename := "battle-royale"
if matchId, err := nk.MatchCreate(ctx, modulename, make(map[string]interface{})); err != nil {
return "", err
} else {
return matchId, nil
}
}
// main function for hooking into the nakama runtime, responsible for setting up all handlers
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
// Register handlers for match lifecycle
if err := initializer.RegisterMatch("battle-royale", func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error) {
return &battleroyale.Match{}, nil
}); err != nil {
logger.Error("Unable to register match handler: %v", nil)
return err
}
// Register RPCs
if err := initializer.RegisterRpc("manual_force_create_br_match_rpc", ManualForceCreateBRMatchRPC); err != nil {
logger.Error("Unable to register: %v", err)
return err
}
return nil
}