Files
tic-tac-toe/plugins/main.go
Vishesh 'ironeagle' Bangotra ea1a70b212 feat(matchmaking): replace legacy rpc_find_match with Nakama native matchmaking
### Summary
This update removes the old RPC-driven matchmaking flow and replaces it
with proper Nakama matchmaker integration. Players now queue using
`matchmaker_add` over WebSockets, and matches are created via
`MatchmakerMatched` callback.

### Changes
- Removed `rpc_find_match` and MatchList polling logic
- Added `MatchmakerMatched` handler to auto-create TicTacToe matches
- Added RPC stubs `join_matchmaking` & `leave_matchmaking` only for
  optional validation (no server-side queueing)
- Updated `main.go` to register:
   `tictactoe` authoritative match
   `matchmaker_matched` callback
   removed obsolete rpc_find_match registration
- Ensured module loads successfully with cleaner InitModule
- Cleaned unused imports and outdated Nakama calls

### Benefits
- Fully scalable & production-ready matchmaking flow
- Eliminates race conditions & manual match assignment
- Supports multiple queues (classic / blitz) via string properties
- Aligns plugin with Nakama best practices
- Enables Python/WebSocket simulation without RPC dependencies
2025-11-26 16:34:55 +05:30

51 lines
1.2 KiB
Go

package main
import (
"context"
"database/sql"
"github.com/heroiclabs/nakama-common/runtime"
)
// Example RPC
func HelloWorld(
ctx context.Context,
logger runtime.Logger,
db *sql.DB,
nk runtime.NakamaModule,
payload string,
) (string, error) {
logger.Info("HelloWorld RPC called — payload: %s", payload)
return `{"message": "Hello from Go RPC!"}`, nil
}
// Required module initializer
func InitModule(
ctx context.Context,
logger runtime.Logger,
db *sql.DB,
nk runtime.NakamaModule,
initializer runtime.Initializer,
) error {
if err := initializer.RegisterRpc("hello_world", HelloWorld); err != nil {
logger.Error("Failed to register RPC: %v", err)
return err
}
if err := initializer.RegisterMatch("tictactoe", NewMatch); err != nil {
logger.Error("Failed to register RPC: %v", err)
return err
}
// Match making
if err := initializer.RegisterRpc("leave_matchmaking", rpcLeaveMatchmaking); err != nil {
logger.Error("RegisterRpc leave_matchmaking failed: %v", err)
return err
}
if err := initializer.RegisterMatchmakerMatched(MatchmakerMatched); err != nil {
logger.Error("RegisterMatchmakerMatched failed: %v", err)
return err
}
logger.Info("Go module loaded successfully!")
return nil
}