refactor(scum): use runtime capability probes
This commit is contained in:
@@ -21,14 +21,13 @@ type SafeAdapter interface {
|
||||
SpawnVehicle(context.Context, map[string]any) (map[string]any, error)
|
||||
}
|
||||
|
||||
// ServerBoundAdapter lets a versioned adapter prove that it is configured for
|
||||
// ServerBoundAdapter lets a runtime adapter prove that it is configured for
|
||||
// the same server as the registration which declared handler availability.
|
||||
// Generic test adapters do not need this optional assertion.
|
||||
type ServerBoundAdapter interface{ ServerBinding() string }
|
||||
|
||||
type HandlerAvailability struct {
|
||||
BoundServerID string
|
||||
ServerVersion string
|
||||
Capabilities map[string]bool
|
||||
Approved bool
|
||||
}
|
||||
@@ -85,7 +84,7 @@ func (registry *HandlerRegistry) Execute(ctx context.Context, command ClaimedCom
|
||||
return unsupportedResult("unsupported"), nil
|
||||
}
|
||||
handler, exists := registry.handlers[command.CommandType]
|
||||
if !exists || strings.TrimSpace(registry.availability.ServerVersion) == "" {
|
||||
if !exists {
|
||||
return unsupportedResult("unsupported"), nil
|
||||
}
|
||||
payload, err := handler(ctx, command.Payload)
|
||||
@@ -171,15 +170,14 @@ func validateCommandPayload(commandType string, payload map[string]any) error {
|
||||
}
|
||||
return nil
|
||||
case "game-state.patch":
|
||||
if err := require("playerId", "gameVersion", "expectedStateVersion", "safetyWindow", "reason", "changes"); err != nil {
|
||||
if err := require("playerId", "expectedStateVersion", "safetyWindow", "reason", "changes"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := noUnknown("playerId", "gameVersion", "expectedStateVersion", "safetyWindow", "reason", "changes"); err != nil {
|
||||
if err := noUnknown("playerId", "expectedStateVersion", "safetyWindow", "reason", "changes"); err != nil {
|
||||
return err
|
||||
}
|
||||
version, ok := payload["gameVersion"].(string)
|
||||
changes, changesOK := payload["changes"].([]any)
|
||||
if !ok || version == "" || !changesOK || len(changes) == 0 || len(changes) > 8 {
|
||||
if !changesOK || len(changes) == 0 || len(changes) > 8 {
|
||||
return fmt.Errorf("state patch payload is invalid")
|
||||
}
|
||||
return nil
|
||||
@@ -337,7 +335,7 @@ func (dispatcher Dispatcher) Run(ctx context.Context) error {
|
||||
|
||||
// Runtime keeps the registered companion alive with bounded heartbeat and
|
||||
// polling intervals. It owns no host connection or game credential; handlers
|
||||
// are the only route to a version-bound adapter.
|
||||
// are the only route to runtime capability adapters.
|
||||
type RuntimeGateway interface {
|
||||
CommandGateway
|
||||
Register(context.Context) (Registration, error)
|
||||
|
||||
Reference in New Issue
Block a user