Anmelden
DE
apps/caramail-chat / src / Chat / TempId.php · commit 6eebcdb
<?phpnamespace App\Chat;/** * The applet's "tempid": the one-time key the web site gave it. The server of this project (caramail-server) reads * the profile from it: n=Nickname&a=25&s=1&v=City (sex 0 man / 1 woman), &k=<moderator key>. */final class TempId{    /** The "provenance" of a site (the last field of the ids): 0 jumphp.net, 1 caramail.tv, else a number of the domain. */    public static function origin(string $site): int    {        $site = strtolower(preg_replace('/^www\./', '', trim($site)) ?? '');        return match ($site) {            '', 'jumphp.net' => 0,            'caramail.tv' => 1,            default => 2 + (int)(sprintf('%u', crc32($site)) % 90),        };    }    /** $role: the role asked (0 normal, 1 moderator, 2 administrator), honoured by the server from the owner's address only */    public static function make(string $nickname, int $age, int $sex, string $city, string $key = '', int $origin = 0, ?int $role = null): string    {        $q = ['n' => $nickname, 'a' => $age, 's' => $sex, 'v' => $city];        if ($role !== null) {            $q['r'] = $role;        }        if ($origin > 0) {            $q['p'] = $origin;        }        if ($key !== '') {            $q['k'] = $key;        }        return http_build_query($q);    }}