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

Discussion in 'Resources' started by Comphenix, 16, 2012.

Thread Status:
Not open for further replies.
  1. So they at least show up there. Okay, what about the server and client packet list:
    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. }
  2. http://pastie.org/8223059
    Looks like client and server are switched:
    Server: [103, ...]
    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.
  3. 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.
  4. The problem is that I am using one adapter to modify all the itemstacks to keep things smaller:
  5. I don't suppose it is possible to send a packet that changes how far a bow is drawn?
  6. Sadly, that is client side. I also tried to make the bow charging slower/faster but it isn't possible. :/
  7. :/ I kinda figured, but there are quite a few things we used to think were only client side.
  8. 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.
  9. Forgot that link, thank you.
  10. ProtocolLib 2.7.0

    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

    Bug fixes
    API changes
  11. Offline


    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 :)
  12. 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. :)
  13. Offline


    GamePhase seems doesn't to work.

    My code actually (without GamePhase)
    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));
    8. if(MessUp.getMessages().containsKey(message)) {
    9. event.setCancelled(true);
    10. return;
    11. }
    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);
    18. if(matcher.matches()) {
    19. event.setCancelled(true);
    20. return;
    21. }
    22. }
    23. }
    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 :/
  14. 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.
  15. Offline


    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 ;)
  16. 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)
  17. 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.
  18. Offline


    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 ...
  19. 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:

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


    Sorry, sames results, can get the messages :/
  21. And you're using GamePhase.LOGIN?

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


    Yeah, I use login GamePhase ...

    I run Bukkit with Forge (using MCPC+), maybe there is a problem with it :/
  23. 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?
  24. ProtocolLib 2.7.3

    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
    Bug fixes
    Small fixes
    EDIT: Silly mistake. Had to bump to 2.7.3 from 2.7.2.
  25. 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:
Thread Status:
Not open for further replies.

Share This Page