[Lib] [1.7.9] ProtocolLib 3.4.0 - Safely and easily modify sent and recieved packets

Discussion in 'Resources' started by Comphenix, Sep 15, 2012.

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

    Cybermaxke

  2. Offline

    Comphenix

    So they at least show up there. Okay, what about the server and client packet list:
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. // Remember to depend on ProtocolLib
    3. @Override
    4. public void onEnable() {
    5. System.out.println("Server: " + PacketRegistry.getServerPackets());
    6. System.out.println("Client: " + PacketRegistry.getClientPackets());
    7. }
    8. }
     
  3. Offline

    Cybermaxke

    http://pastie.org/8223059
    Looks like client and server are switched:
    Code:
    Server: [103, ...]
    Code:
    Unsupported client packet ID in current Minecraft version: 103
    EDIT: It is working in the normal inventory, but not in thr creative one. I still don't know why its throwing the unsupported exceptions.
     
  4. Offline

    Comphenix

    Ah, now I see - you're not just registering a WINDOW_CLICK listener, you're also registering listeners for a range of other packets. Next time, remember to post all the relevant code, not just a snippet that happens to work fine by itself ...

    The problem here is that you can only register listeners for packet IDs that actually exist. I suggest registering two separate packet listeners, one for every server packet your interested in, and one for every client packet. Then use the correct ConnectionSide (not ConnectionSide.BOTH - which really should be depreciated), and things should work again.
     
  5. Offline

    Cybermaxke

    The problem is that I am using one adapter to modify all the itemstacks to keep things smaller:
    http://pastie.org/8223945
     
  6. Offline

    Comphenix

  7. Offline

    Cybermaxke

  8. Offline

    Ultimate_n00b

    I don't suppose it is possible to send a packet that changes how far a bow is drawn?
     
  9. Offline

    Cybermaxke

    Sadly, that is client side. I also tried to make the bow charging slower/faster but it isn't possible. :/
     
  10. Offline

    Ultimate_n00b

    :/ I kinda figured, but there are quite a few things we used to think were only client side.
     
  11. Offline

    desht

    The basic rule of thumb for knowing if something is purely client side or not is to look at the packet reference here: http://www.wiki.vg/Protocol - if there's a packet for what you want to do, then you can control it from the server, either via Bukkit, direct NMS calls, or via ProtocolLib. It's well worth reading that page and getting at least somewhat familiar with all the packets and what they can do.
     
  12. Offline

    Ultimate_n00b

    Forgot that link, thank you.
     
  13. Offline

    Comphenix

    ProtocolLib 2.7.0

    Download:
    It's been a month, and it's time for yet another bug fix release - this time to address a couple of issues with the INTERCEPT_BUFFER feature introduced in 2.5.0 regarding certain plugins and Spigot, along with some API improvements. Spigot users are advised to upgrade.

    An interesting bug was reported in issue 118 - asynchronous listeners, which were introduced way back in 1.2.0, can actually player actions to be performed twice. If you have noticed problems such as doors closing and opening, blocks being double-placed, etc., I urge you to upgrade.

    Finally, I've added a new convenience method to PacketManager - broadcastServerPacket(), with three different overloads that allow you to broadcast a packet to every player on the server, every player tracking a given entity or every player within a certain radius.

    Change log

    Features
    Bug fixes
    API changes
     
  14. Offline

    Comphenix

  15. Offline

    bsymon

    Hi, I'm using ProtoLib to make a plugin that mask the messages listed in a file. If the server send a message, and if this message is contained in the file, the message is not sended. This work pretty well :)

    BUT (yeah, is not fun when everything work for the first try), all the messages sended from PlayerJoinEvent are not intercepted ... And it's very annoying :/ Is not normal ?

    If yes, there is a way to still get the messages ?


    Thank you, and sorry if my english is not perfect, I'm french :)
     
  16. Offline

    Comphenix

    Yeah, it's an unfortunate design decision, but ProtocolLib will only intercept "login packets" if you tell it to, for performance reasons.

    Essentially, you have to set the packet adapters GamePhase to LOGIN. Take a look at this example for more information.

    You don't have to apologize, your English is fine. :)
     
  17. Offline

    bsymon

    GamePhase seems doesn't to work.

    My code actually (without GamePhase)
    Code:java
    1. private static PacketAdapter onServerSendMessage =
    2. new PacketAdapter(MessUp.plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST, Packets.Server.CHAT) {
    3. @Override
    4. public void onPacketSending(PacketEvent event) {
    5. PacketContainer packet = event.getPacket();
    6. String message = ChatColor.stripColor(packet.getStrings().read(0));
    7.  
    8. if(MessUp.getMessages().containsKey(message)) {
    9. event.setCancelled(true);
    10. return;
    11. }
    12.  
    13. for(String regex : MessUp.getMessages().keySet()) {
    14. if(MessUp.getMessages().get(regex)) {
    15. Pattern pattern = Pattern.compile(regex);
    16. Matcher matcher = pattern.matcher(message);
    17.  
    18. if(matcher.matches()) {
    19. event.setCancelled(true);
    20. return;
    21. }
    22. }
    23. }
    24.  
    25. /* Si rien n'a été trouvé, le message est envoyé. */
    26. }
    27. };


    I added GamePhase.LOGIN, but message from PlayerJoinEvent are still not intercepted :/
     
  18. Offline

    Comphenix

    Did you try printing the message to the console too, to check that you at least see these messages?

    Keep in mind that the server doesn't send raw messages anymore (after 1.6.1). They're encoded in JSON form.
     
  19. Offline

    bsymon

    Yeah, I already try to print the message in the console, but there is nothing from PlayerJoinEvent. And, I forget to precise, I run a 1.5.2 bukkit ;)
     
  20. Offline

    DevRosemberg

    How could i disguise players as Mobs with this? And how can i use it not showing it in the /pl (importing it into plugin or something like that)
     
  21. Offline

    Comphenix

    What kind of message are you trying to intercept anyways? Not all messages can be modified, some are entirely client side.

    Take a look at Lib's Disguises for some inspiration.

    As for somehow merging ProtocoLib with your plugin ... don't. It may prevent other plugins from intercepting packets. But you can do your own packet interception if ProtocoLib is not present. Take a look at Orebfuscator or BkCommonLib for some concrete implementation, or read my take on the matter.
     
  22. Offline

    bsymon

    I just want intercept messages sent by the server or plugins. But if a plugin send a message to a player in a PlayerJoinEvent (like that : player.sendMessage("Hello world!")), I can't get it ...
     
  23. Offline

    Comphenix

    Ah, I see what you mean.

    I guess that comes down to how ProtocolLib actually performs its "code injection" for intercepting packets, which is actually done using two separate methods - one for players before they have properly logged in (NetworkManager), and one after that (PlayerConnection).

    Due to other conflicting plugins (such as SpoutPlugin and the like), I decided to undo the login injection in a LOWEST PlayerLoginEvent listener, and apply the PlayerConnection injection in a MONITOR PlayerLoginEvent listener. Unfortunately, that does mean ProtocolLib miss any packets sent by plugins in between these two listeners, which is why you're not seeing any of those chat packets.

    I've tried to correct this by moving everything to the MONITOR listener, which hopefully shouldn't screw things up too much. You can get this updated version on my Jenkins server:
    http://assets.comphenix.net/jenkins/job/ProtocolLib/lastStableBuild/

    See if that works any better. :)
     
  24. Offline

    bsymon

    Sorry, sames results, can get the messages :/
     
  25. Offline

    Comphenix

    And you're using GamePhase.LOGIN?

    I did manage to get the message from the following plugin, using the latest snapshot:
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. @Override
    3. public void onEnable() {
    4. getServer().getPluginManager().registerEvents(this, this);
    5. }
    6.  
    7. @EventHandler
    8. public void onPlayerJoinEvent(PlayerJoinEvent e) {
    9. e.getPlayer().sendMessage("This is a test.");
    10. }
    11. }
     
  26. Offline

    bsymon

    Yeah, I use login GamePhase ...

    I run Bukkit with Forge (using MCPC+), maybe there is a problem with it :/
     
  27. Offline

    Comphenix

    Hm, no, I still can't reproduce it. The plugin above works fine with MCPC+ Plus 1.5.2 #64 (no mods though). But I don't think we will get any further, at least not unless you could send a full server setup that reproduces this problem?

    In any case ... have you thought about simply recompiling whatever plugin is causing your trouble? Or ask the author nicely to add a configuration for disabling that message?
     
  28. Offline

    Comphenix

    ProtocolLib 2.7.3

    Download:
    There's a couple of new things worth upgrading in this update - first, there's a number of bug fixes mainly addressed at Spigot, such as a server-crash during reloading (ticket 127), a PlayerLoggedOutException (ticket 131) and support for snapshot protocol versions. But I've also added some very needed volatile keywords, where multiple threads were reading and updating the same variable. That should make the infamous "Unknown origin" error message less likely.
    In addition, I've also added a way to measure the time taken by each packet listener:
    Change log
    Features
    Bug fixes
    Small fixes
    EDIT: Silly mistake. Had to bump to 2.7.3 from 2.7.2.
     
  29. Offline

    p000ison

    Heyhey,

    I'm currently experimenting with nbt data bukkit :/ Is there any way I could save nbt data persistent? Currently I have the problem that bukkit overrides my nbt data if I drop the item for example. It's really annoying that craftbukkit is not able to handle this properly.


    I think this here is the main problem. Craftbukkit always overrides the whole item nbt data:
    https://github.com/Bukkit/CraftBukk...raftbukkit/inventory/CraftItemStack.java#L355
     
Thread Status:
Not open for further replies.

Share This Page