Create custom match plugin

Rename world_control

Fix package name

Attempt with main package

Go world_control debug

Go world_control debug

Added get world RPC method

Remove '_' from module

Nakama plugin testing

Nakama plugin testing

Nakama plugin testing

Try updated pipeline

Nakama plugin testing

Update pipeline

Rework plugin dir

Fix path

Fix imports

Fix imports

Load match

Load match work

Server changes

Server changes

Server changes

Changes basic upon helpful suggestions

Client side get match
This commit is contained in:
2020-08-15 19:26:02 -04:00
parent 0d9d05943c
commit 12ea66e4fc
11 changed files with 211 additions and 38 deletions

52
server/plugin/rpc/rpc.go Normal file
View File

@ -0,0 +1,52 @@
package rpc
import (
"context"
"database/sql"
"github.com/heroiclabs/nakama-common/runtime"
)
func getFirstWorld(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule) (string, error) {
// List existing matches
// that have been 1 & 4 players
minSize := 1
maxSize := 4
matches, listErr := nk.MatchList(ctx, 1, false, "", &minSize, &maxSize, "") //local matches = nakama.match_list()
// Return if listing error
if listErr != nil {
logger.Printf("Failed to list matches when grabing first world! Error: %v\n", listErr)
return "", listErr
}
// If no matches exist, create one
if len(matches) <= 0 {
// Create match
//params := map[string]interface{}{}
matchID, createErr := nk.MatchCreate(ctx, "control", map[string]interface{}{})
//return nakama.match_create("world_control", {})
// Return if creation error
if createErr != nil {
logger.Printf("Failed to create match when grabing first world! Error: %v\n", createErr)
return "", createErr
}
logger.Info("Successfully created new match!")
// Return newly created match
return matchID, nil
} else {
// Return first found match
return matches[0].GetMatchId(), nil
}
}
func GetWorldId(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
matchID, err := getFirstWorld(ctx, logger, nk)
return matchID, err
}