How do packets work?

Discussion in 'Plugin Development' started by Regenwurm97, Sep 27, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Regenwurm97

    Hey!

    I often hear that many cool things would not be possible without the usage of packets, such as playing client animations or adjusting several values etc.
    As I never worked with packets before, I thought to look up some information on them on the internet but well - theres neither a wiki thread nor any bukkit resources on this topic :(

    So could anybody awnser me some (or all :D) of the following questions so I get a better view on them and know what's possible and what not? Would be really great guys...

    1) What are packets? (I heard they're like those 0x15 codes and send to players to make them see something but thats only very roughly explained I think...)

    2) What do packets allow you? (Rather a simple overview of the best functions)

    3) How to use packets? How do I send packets to a player and (VERY IMPORTANT) what values etc. do I have to adjust (some guys out there modified fileds like "a" or "b" on packages...)

    4) What's the (main) difference between those 0x00 Codes (Hexadecimal?) and the classes like PacketArmAnimation18.java

    I really hope to find someone here to help me :)
    Thx in advance!
     
  2. Offline

    nisovin

    When people talk about packets, they're talking about the protocol that Minecraft uses to communicate information between the server and client. All information is passed between server and client through packets. When people say that you have to "use packets", they mean you either need to send a packet manually, intercept a packet as it's being sent or received, or both.

    What they allow you to do is a very broad subject. If you're really interested in it, you will use this as a resource pretty much constantly: http://wiki.vg/Protocol

    You will also probably want to use ProtocolLib, which allows you to intercept and process packets before they reach the server. http://dev.bukkit.org/bukkit-plugins/protocollib/
     
  3. Offline

    chasechocolate

  4. Offline

    Janmm14

    Regenwurm97
    1) Packets are used for the communication between minecraft client and server. Every packet has an identifier code, for example 0x15.
    2) Changing tab list of a player, rename every basic item easily, hiding enchantments, letting falling blocks fly (maybe). I don't know what other things are possible too.
    3) For sending packets easily I like ProtocolLib. Check it out at bukkitdev. It also allowes modifying incoming and leaving packets and also sending packet sto the server for the client. You can get some classes out of his packetwrapper to easily set some values.
    There is also a good wiki: http://wiki.vg/Protocol
    4) You are right. 0x?? is a hexadecimal number, and Packet18ArmAnimation, the 18 is decimal. There are many converters in the internet.
     
  5. Offline

    xTrollxDudex

    Regenwurm97
    Resources section, check out my Packets Explained thread
     
  6. Offline

    Cirno

    1) Basically information sent to and from the server and client.
    2) Anything that you can think of; besides new items and the like.
    3) To use them directly, add CraftBukkit to your libraries and do the following:
    ((CraftPlayer)a).getHandle().playerConnection.sendPacket(packetobj);
    You can also use PacketProtocol.
    4) Yes; that's hexadecimal.

    That's my shot at explaining it.
     
  7. Offline

    Regenwurm97

    xTrollxDudex could you give me the link please? I searched in the resources section but could't find any topics with the word "packet" inside its title that fit to my questions :l

    @Janmm14
    Ah that sounds great! :D I will propably use ProtocolLibrary too if it's easier. But I can imagine I would use packets only in some cases (like three times in my plugin) so is another library really a better way than just sending packets normally via the playerConnection?

    Cirno
    Short and understandable :D But what is the Packetobj? Is it a new instance of any packetXX class? Would be nice if you could post a quick code example of sending someone a packet :)
     
  8. Offline

    Janmm14

    Regenwurm97
    Bukkit changes the packet of all non-bukkit files every beta / release, so you would have to update your plugin every beta / release, when you are not using Reflection, what ProtocolLib uses for example. With ProtocolLib you can also change the contents of packets sent by minecraft for example or stop sending them.
     
  9. Offline

    Regenwurm97

    Janmm14 Allright but I would always have to wait for an update of protocolLib to come out wouldn't I? :)
     
  10. Regenwurm97 Not necessarly, you can always use reflection. In my animation lib I never make use of any library, just pure reflection.
     
  11. Offline

    Scizzr

    I was juuuuust about to mention this. It's a shame how many people don't even look there...




    First page, 5th link down (at the time of posting this)
    http://forums.bukkit.org/threads/packets-nms-explained.177955/
     
    xTrollxDudex likes this.
  12. Offline

    Regenwurm97

  13. Offline

    Cirno

    PacketObj is just an instance of any packet; an example of one would be a Packet20NamedEntitySpawn .
    Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn();
    packet.a = 957192; //Some random number. This is the entity id.
    packet.b = "This is my name!"; //Limit of 16 characters.
    packet.c = x;
    packet.d = y;
    packet.e = z;
    packet.f = (byte)0;
    packet.g = (byte)0;
    packet.h = 0;
    packet.i = //A data watcher instance? I forgot how to make/get one.
    ((CraftPlayer)aPlayer).getHandle().playerConnection.sendPacket(packet);

    Note that if you play with packets a lot, there is a slight chance of always crashing the client or kicking them.
     
  14. Offline

    Scizzr

    Why are you making an instance of Packet3Chat but instantiating it as a Packet20NamedEntitySpawn?
    Code:
    Type mismatch: cannot convert from Packet20NamedEntitySpawn to Packet3Chat
     
  15. Offline

    Cirno

    Oopse :p
    Editing now.
     
Thread Status:
Not open for further replies.

Share This Page