1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

3 Char Minimum Player Name Length Changed to 1

Discussion in 'Help' started by MK500, Apr 13, 2017.

  1. MK500

    MK500 Slime

    Messages:
    77
    GitHub:
    markkrueg
    Has anything changed recently with the minimum player name length? I probably need to look through the PMMP code to see if there is anything enforcing it there. I've been noticing just the last few days players have been using one character and two character player names.

    Is this something that was checked by the MCPE app before, and changed with 1.0.6?

    Sorry if I'm missing something obvious.
     
  2. MK500

    MK500 Slime

    Messages:
    77
    GitHub:
    markkrueg
    Ah, it looks like PMMP used to verify that username was 3 characters or more; but at some point it stopped. Probably this wasn't recent.

    I assume this is intended?

    Code in Player.php from a few months ago:
    PHP:
                    $valid true;
                    
    $len strlen($packet->username);
                    if(
    $len 16 or $len 3){
                        
    $valid false;
                    }
                    for(
    $i 0$i $len and $valid; ++$i){
                        
    $c ord($packet->username{$i});
                        if((
    $c >= ord("a") and $c <= ord("z")) or
                            (
    $c >= ord("A") and $c <= ord("Z")) or
                            (
    $c >= ord("0") and $c <= ord("9")) or $c === ord("_")
                        ){
                            continue;
                        }

                        
    $valid false;
                        break;
                    }
    Now replaced with:
    PHP:
        public static function isValidUserName(string $name) : bool{
            
    $lname strtolower($name);
            
    $len strlen($name);
            return 
    $lname !== "rcon" and $lname !== "console" and $len >= and $len <= 16 and preg_match("/[^A-Za-z0-9_]/"$name) === 0;
        }
     
    Last edited: Apr 13, 2017
  3. MK500

    MK500 Slime

    Messages:
    77
    GitHub:
    markkrueg
    Yeah, I was also thinking this might be "help". Thanks for moving it for me.

    Sorry about that.
     
  4. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Your best options are to make your own custom phar, or submit a PR on github.
     
  5. MK500

    MK500 Slime

    Messages:
    77
    GitHub:
    markkrueg
    Yeah, I already modified my server to force 3; as I think that's just better. But I didn't want to make a PR because maybe I'm the only one that thinks this :)

    Since it's a single character edit to the code; I'm sure if a lot of people comment in this thread someone will make the change eventually. So far it doesn't seem to be such a big deal to most people.
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    there should just be a config...
     
  7. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    This was altered to 1-16 chars to match vanilla MCPE length treatment.
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    PHP:
    public function onJoin() {
        if(
    strlen($player) < 3) {
            
    $server->sendMessage("kick " $player " Your name needs to be at least 3 letters long!");
        }
    }
     
  9. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    If that is supposed to be working code, that's not correct. Every variable is undefined, the event handler is incorrect, and ServerObject->sendMessage() isn't an existing method, as far as I know. I do think you are correct that a plugin could be used to check for a proper length name though.
     
    dktapps likes this.
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    What if their name is AL and they want to use it as their username?
     
    dktapps likes this.
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    PHP:
    public function onPreLogin(PlayerPreLoginEvent $event) {
        
    $player $event->getPlayer();
        if(
    strlen($player) < 3) {
            
    $cmd "kick " $player " Your name needs to be at least 3 letters long!";
            
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(),$cmd);
        }
    }
    Old PocketMine Forums:
    I don't know how to do that.
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    *citation Needed*
     
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Um, does my code look good? Or silly beginner mistakes...?
    I tried my own code and it didn't work. :p No idea what the problem could be.
     
    Last edited: Apr 15, 2017
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    public function onPreLogin(PlayerPreLoginEvent $event) {
        
    $player $event->getPlayer();
        if(
    strlen($player->getName()) < 3) { //function parameter must be string, not player object
            
    $event->setCancelled(); // set event to cancelled for other plugins and to prevent errors
            
    $event->setKickMessage("Your name needs to be at least 3 letters long!"); // added message for player to see on their logout
        
    }
    }
     
    Last edited: Apr 15, 2017
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    What does setCancelled() exactly do? Explain what you've changed.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.