# Crash Service Bootstrap

The Crash game requires a running service loop to progress through the
`waiting → started → busted` cycle. Hosts can bootstrap the service with the
`initializeCrashService` helper exposed by the original games package.

```js
const OriginalGames = require('path-to-packages/original-games');
const { GamePlatformAdapter } = OriginalGames;

class MyAdapter extends GamePlatformAdapter {
  // ... implement required abstract methods ...
}

const crashService = OriginalGames.initializeCrashService({
  io, // socket.io server instance
  platformAdapter: new MyAdapter(),
  registerShutdown: (stop) => {
    ['SIGINT', 'SIGTERM'].forEach((signal) => {
      process.once(signal, () => {
        stop();
        process.exit(0);
      });
    });
  },
});
```

## Dependency checks

`initializeCrashService` verifies that:

- A platform adapter is registered and implements bankroll, balance, and bet
  bookkeeping methods.
- The legacy `Rule` module is present, ensuring bankroll checks succeed.
- The PostgreSQL client exposes `query()` so history lookups function.

If any dependency is missing, the initializer throws before the game loop
starts. This guarantees auto-cashout timers and history queries have the
resources they need.

## Lifecycle control

The initializer returns a controller with `{ start, stop }` helpers:

- `start()` restarts the wait/start/bust cycle (it is invoked automatically
  unless `autoStart` is set to `false`).
- `stop()` clears all timers, resets the in-memory player lists, and marks the
  game as stopped.

Use the `registerShutdown` option to hook the `stop()` handler into your
process shutdown logic so that timers are cleaned up gracefully when the host
service exits.
