isValidClientEvent function

bool isValidClientEvent(
  1. WorldEvent event,
  2. Channel channel,
  3. WorldState state, {
  4. required AssetManager assetManager,
})

Implementation

bool isValidClientEvent(
  WorldEvent event,
  Channel channel,
  WorldState state, {
  required AssetManager assetManager,
}) =>
    switch (event) {
      TeamJoinRequest() => state.info.teams.containsKey(event.team),
      TeamLeaveRequest() => state.info.teams.containsKey(event.team),
      CellRollRequest() => event.object?.inRange(
              0,
              state
                      .getTableOrDefault(event.cell.table)
                      .getCell(event.cell.position)
                      .objects
                      .length -
                  1) ??
          true,
      ShuffleCellRequest() => state
          .getTableOrDefault(event.cell.table)
          .cells
          .containsKey(event.cell.position),
      ObjectsSpawned() => event.objects.values.expand((e) => e).every((e) {
          final figure = assetManager.getFigure(e.asset);
          return figure != null &&
              (e.variation == null ||
                  figure.variations.containsKey(e.variation));
        }),
      ObjectsMoved() => event.from != event.to &&
          event.objects.every((e) => e.inRange(
              0,
              state
                      .getTableOrDefault(event.table)
                      .getCell(event.from)
                      .objects
                      .length -
                  1)),
      CellHideChanged() => event.object?.inRange(
              0,
              state
                      .getTableOrDefault(event.cell.table)
                      .getCell(event.cell.position)
                      .objects
                      .length -
                  1) ??
          true,
      ObjectIndexChanged() => event.index.inRange(
          0,
          state
                  .getTableOrDefault(event.cell.table)
                  .getCell(event.cell.position)
                  .objects
                  .length -
              1),
      TeamRemoved() => state.info.teams.containsKey(event.team),
      PacksChangeRequest() => channel == kAuthorityChannel,
      BoardMoveRequest() => event.from != event.to &&
          event.index.inRange(
              0,
              state
                      .getTableOrDefault(event.table)
                      .getCell(event.from)
                      .tiles
                      .length -
                  1),
      _ => true,
    };