config->get('tribes.notice_hours', 24) * 3600 / $this->config->speed())); } public function maxMembers(): int { return (int) $this->config->get('tribes.max_members', 25); } /** * The relation between two tribes, from the rows between them (both directions). * * @param iterable $rows */ public static function relation(?int $mine, ?int $theirs, iterable $rows, CarbonImmutable $now): string { if ($mine === null || $theirs === null) { return self::NONE; } if ($mine === $theirs) { return self::TRIBE; } $ours = $their = null; foreach ($rows as $row) { if ($row['tribe_id'] === $mine && $row['other_tribe_id'] === $theirs) { $ours = $row; } elseif ($row['tribe_id'] === $theirs && $row['other_tribe_id'] === $mine) { $their = $row; } } $holds = fn (?array $r, string $state) => $r && $r['state'] === $state && $r['confirmed'] && ($r['ends_at'] === null || $r['ends_at']->greaterThan($now)); foreach (self::PACTS as $pact) { if ($holds($ours, $pact) && $holds($their, $pact)) { return $pact; } } if (($ours['state'] ?? null) === self::ENEMY || ($their['state'] ?? null) === self::ENEMY) { return self::ENEMY; } return self::NONE; } /** Whether a relation forbids attacks between the two. */ public static function protects(string $relation): bool { return in_array($relation, [self::TRIBE, self::ALLY, self::NAP], true); } /** 3 to 32 characters, letters, digits, spaces and a few marks. */ public static function validName(string $name): bool { return (bool) preg_match('/^[\p{L}\p{N}][\p{L}\p{N} \'\-_.&]{1,30}[\p{L}\p{N}.]$/u', $name); } /** 2 to 6 characters, letters, digits and - _ . */ public static function validTag(string $tag): bool { return (bool) preg_match('/^[\p{L}\p{N}\-_.]{2,6}$/u', $tag); } }