Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom Packets

Comments in 'Plugin Development' started by Samueljh1H8sLag, Dec 30, 2015.

  1. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Hey, Im trying to make some custom packets, but I have no idea what to add into the encode() or decode() functions.

    Here is a basic packet template:

    PHP:
    class PlayerListPacket extends DataPacket {

       const 
    NETWORK_ID 0xc3;

       public function 
    pid(){
          return 
    0xc3;
       }

       public function 
    decode(){ }

       public function 
    encode(){
          
    $this->buffer = \chr(self::NETWORK_ID); $this->offset 0;;
       }

    }
    Now, at the moment, the encode makes the client freeze. Im not too sure how it is formatted as each type of data value is encoded in a strange way.

    Here is an example of the encode function in the AddPlayerPacket:

    PHP:
    public function encode(){

       
    $this->buffer = \chr(self::NETWORK_ID); $this->offset 0;;
       
    $this->buffer .= Binary::writeLong($this->clientID);
       
    $this->putString($this->username);
       
    $this->buffer .= Binary::writeLong($this->eid);
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->x) : \strrev(\pack("f"$this->x)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->y) : \strrev(\pack("f"$this->y)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->z) : \strrev(\pack("f"$this->z)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->speedX) : \strrev(\pack("f"$this->speedX)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->speedY) : \strrev(\pack("f"$this->speedY)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->speedZ) : \strrev(\pack("f"$this->speedZ)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->yaw) : \strrev(\pack("f"$this->yaw)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->yaw) : \strrev(\pack("f"$this->yaw)));
       
    $this->buffer .= (\ENDIANNESS === ? \pack("f"$this->pitch) : \strrev(\pack("f"$this->pitch)));
       
    $this->buffer .= \pack("n"$this->item);$this->buffer .= \pack("n"$this->meta);
       
    $this->buffer .=    \chr($this->slim 0);
       
    $this->putString($this->skin);
       
    $meta Binary::writeMetadata($this->metadata);
       
    $this->buffer .= $meta;
    }
    Any ideas? :)
    hoyinm14mc and Legoboy0215 like this.
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I don't understand a single line XD
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't use code decompiled from phar. Use code from PocketMine source. That makes more sense.
  4. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    i did use it from the pocketmine source. Look for yourself
    hoyinm14mc likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  6. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Legoboy0215 likes this.

Share This Page

Advertisement