isValidServerEvent function

bool isValidServerEvent(
  1. ServerWorldEvent event,
  2. WorldState state
)

Implementation

bool isValidServerEvent(ServerWorldEvent event, WorldState state) =>
    switch (event) {
      WorldInitialized() =>
        event.info?.packs.length == event.packsSignature?.length &&
            (event.info?.packs.every((e) =>
                    event.packsSignature?.any((p) => p.id == e) ?? false) ??
                true),
      TeamJoined() => state.info.teams.containsKey(event.team),
      TeamLeft() => state.info.teams.containsKey(event.team),
      CellShuffled() => event.positions.every((e) => e.inRange(
          0,
          state
                  .getTableOrDefault(event.cell.table)
                  .getCell(event.cell.position)
                  .objects
                  .length -
              1)),
      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),
      DialogOpened() => event.dialog.isValid(),
      _ => true,
    };