2019-12-22 11:50:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
|
|
|
|
class PlayerName implements Rule
|
|
|
|
{
|
|
|
|
public function passes($attribute, $value)
|
|
|
|
{
|
|
|
|
$regexp = '/.*/';
|
|
|
|
|
|
|
|
switch (option('player_name_rule')) {
|
|
|
|
case 'official':
|
|
|
|
// Mojang's official username rule
|
2019-12-22 14:25:22 +08:00
|
|
|
$regexp = '/^[A-Za-z0-9_]+$/';
|
2019-12-22 11:50:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cjk':
|
|
|
|
// CJK Unified Ideographs
|
|
|
|
$regexp = '/^[A-Za-z0-9_§\x{4e00}-\x{9fff}]+$/u';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'custom':
|
|
|
|
$regexp = option('custom_player_name_regexp') ?: $regexp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-12-22 14:25:22 +08:00
|
|
|
return (bool) preg_match($regexp, $value);
|
2019-12-22 11:50:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function message()
|
|
|
|
{
|
|
|
|
return trans('user.player.player-name-rule.'.option('player_name_rule'));
|
|
|
|
}
|
|
|
|
}
|