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

Too many packets in a single batch

Discussion in 'Help' started by EnteMomo, Feb 15, 2020.

  1. EnteMomo

    EnteMomo Silverfish

    Messages:
    22
    GitHub:
    Joshiiiii
    So since there is this new version of minecraft where there is no Player Movement on any server anymore we had to make an own fix.
    Here is the solution:
    PHP:
    public function onDataPacketSend(DataPacketSendEvent $event) {
       if(
    $event->getPacket() instanceof BatchPacket) {
          
    $pk $event->getPacket();
          
          
    $packets = [];
          
          foreach(
    $pk->getPackets() as $buf) {
             
    $pk1 PacketPool::getPacket($buf);
             
    $pk1->buffer $buf;
             
    $pk1->decode();
             
             if(
    $pk1 instanceof MoveActorAbsolutePacket) {
                
    $isHuman false;
                foreach(
    $this->getServer()->getLevels() as $level) {
                   
    $entity $level->getEntity($pk1->entityRuntimeId);
                   if(
    $entity instanceof Human) {
                      if(
    $entity->getId() == $event->getPlayer()->getId())
                         return;
                      
                      
    $isHuman true;
                      
    $pk2 = new MovePlayerPacket();
                      
    $pk2->entityRuntimeId $pk1->entityRuntimeId;
                      
    $pk2->position $pk1->position;
                      
    $pk2->pitch $pk1->xRot;
                      
    $pk2->headYaw $pk1->yRot;
                      
    $pk2->yaw $pk1->zRot;
                      
                      
    $event->getPlayer()->dataPacket($pk2);
                      
    $event->setCancelled(true);
                   }
                }
                if(!
    $isHuman) {
                   
    $packets[] = $pk1;
                }
             } else {
                
    $packets[] = $pk1;
             }
          }
          if(!empty(
    $packets) && $event->isCancelled()) {
             
    $this->getServer()->batchPackets([$event->getPlayer()], $packets);
          }
       }
    }
    The problem is that when a player is near to many entitys the server crashes with the error: "Too many packets in a single batch"
    Is there any limit of packets to send or is there any issue in the code?
     
  2. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    $p->sendPosition($p,$p->yaw,$p->pitch,MovePlayerPacket::MODE_NORMAL,$p->getViewers());
    You dont need all that complicated code
    put this in your PlayerMoveEvent
     
    EnteMomo likes this.
  3. EnteMomo

    EnteMomo Silverfish

    Messages:
    22
    GitHub:
    Joshiiiii
    Since Pocketmine decided to fix it on their own, I didn't had to do it anymore. Thanks anyways! :)
     
    Mr174 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.