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

check cApS

Discussion in 'Development' started by Levi, Jul 31, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    public function onJoin(PlayerJoinEvent $e){
    $player $e->getPlayer();
    if(
    $player->getName() == "dumbass"){

    $player->close("""bad name");
    }
    }
    I want to block users with bad usernames but they can bypass it by just adding one capital word or removing one
     
    Last edited: Jul 31, 2017
  2. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    strtolower it. Don't trust caps.

    And you could create an array with known usernames from a specific player and then
    see if it's alike to it.
     
  3. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    To check if they have any amount of capitals in their name:
    PHP:
    public function onJoin(PlayerJoinEvent $e){
    $player $e->getPlayer();
    if(
    $player->getName() !== "dumbass"){ // they have caps

    $player->close("""bad name");
    }
    This is a very simple example. Provided you have the bad name lowercase, checking the player name against it (player: "dumBass", bad name: "dumbass) will work without the use of strtolower
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    will

    PHP:
    public function onJoin(PlayerJoinEvent $e){
    $player $e->getPlayer();
    if(
    $player->getName() !== "dumbass"){ // they have caps

    $player->close("""bad name");
    }
    kick players even with caps in "dumbass"?
     
  5. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    if you don't understand what hes trying say just use this
    PHP:
     if(strtolower($player->getName()) == "dumbass"){ 
    you don't have to use this example ;-;
     
    Levi likes this.
  6. Aviv

    Aviv Baby Zombie

    Messages:
    156
  7. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
  8. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    thanks, I'll try it
     
  9. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    it worked perfectly but I get error

    CODE:
    PHP:
    <?php

    namespace KD;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listener{
        
        public function 
    onEnable(){
            
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
        }
        
        public function 
    onJoin(PlayerLoginEvent $e){
    $player $e->getPlayer();
     if(
    strtolower($player->getName()) == "dumbass"){

    $player->close("""bad name!");
        
     }
        }
    }
    ERROR:

    Code:
    01:06:04 [INFO] DumBaSs[/x.1x.x.7x:53xx8] logged out due to bad name
    01:06:04 [CRITICAL] Error: "Call to a member function sendTime() on null" (EXCEPTION) in "/src/pocketmine/Player" at line 2142
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Just a tip, replace the event with PlayerPreLoginEvent. If you kick the player on PlayerJoinEvent, the player has already requested for chunks and the server has already done pointless calculations. Save on performance.
     
    Levi likes this.
  11. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    DON'T KICK THEM. Cancel the event.
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Oh yeah. Call PlayerPreLoginEvent::setLeaveMessage("bad name!") instead of kicking the player. Then cancel the event.
     
    Levi likes this.
  13. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    it's ever so slightly faster to use !== instead of strtolower() === dumbass
     
    Levi likes this.
  14. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    final product?
    PHP:
    public function prelogin(PlayerPreLoginEvent $ev){
    if(
    $ev->getPlayer()->getName() !== "dumbass"){
    return 
    true;
    }
    $ev->setCancelled(true);
    $ev->setLeaveMessage("bad name");
    }
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
     
  16. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Two tips:
    - use stripos to make sure the text is included, in case their username is something like: "_dumbass_".
    - use Regex to replace all characters between letters, in case their username is something like: "dumb_ass".
     
    Levi likes this.
  17. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    how'd you do that in this case?
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Maybe read the documentation of these functions and figure it out yourself?
     
    Last edited: Aug 4, 2017
  19. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    cool idea my friend
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I must admit my grammar is worsening sharply.
     
    Levi likes this.
  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.