Commit d1dfc0488a5fff6922f6d08e9cab3bd0c8721ac2
1 parent
e068f370
fix ClientPermissions and ChatFilter
Showing
8 changed files
with
160 additions
and
7 deletions
debug/obfuscation.properties
java/client/com/mumfrey/liteloader/client/PacketEventsClient.java
| ... | ... | @@ -20,6 +20,7 @@ import com.mumfrey.liteloader.ChatListener; |
| 20 | 20 | import com.mumfrey.liteloader.JoinGameListener; |
| 21 | 21 | import com.mumfrey.liteloader.PostLoginListener; |
| 22 | 22 | import com.mumfrey.liteloader.PreJoinGameListener; |
| 23 | +import com.mumfrey.liteloader.client.util.PrivateFieldsClient; | |
| 23 | 24 | import com.mumfrey.liteloader.common.transformers.PacketEventInfo; |
| 24 | 25 | import com.mumfrey.liteloader.core.ClientPluginChannels; |
| 25 | 26 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; |
| ... | ... | @@ -32,6 +33,7 @@ import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; |
| 32 | 33 | import com.mumfrey.liteloader.core.runtime.Packets; |
| 33 | 34 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; |
| 34 | 35 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
| 36 | +import com.mumfrey.liteloader.util.ChatUtilities; | |
| 35 | 37 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 36 | 38 | |
| 37 | 39 | /** |
| ... | ... | @@ -205,7 +207,8 @@ public class PacketEventsClient extends PacketEvents |
| 205 | 207 | if (packet.func_148915_c() == null) |
| 206 | 208 | return; |
| 207 | 209 | |
| 208 | - IChatComponent chat = packet.func_148915_c(); | |
| 210 | + IChatComponent originalChat = packet.func_148915_c(); | |
| 211 | + IChatComponent chat = originalChat; | |
| 209 | 212 | String message = chat.getFormattedText(); |
| 210 | 213 | |
| 211 | 214 | // Chat filters get a stab at the chat first, if any filter returns false the chat is discarded |
| ... | ... | @@ -232,6 +235,19 @@ public class PacketEventsClient extends PacketEvents |
| 232 | 235 | } |
| 233 | 236 | } |
| 234 | 237 | |
| 238 | + if (chat != originalChat) | |
| 239 | + { | |
| 240 | + try | |
| 241 | + { | |
| 242 | + chat = ChatUtilities.convertLegacyCodes(chat); | |
| 243 | + PrivateFieldsClient.chatMessage.set(packet, chat); | |
| 244 | + } | |
| 245 | + catch (Exception ex) | |
| 246 | + { | |
| 247 | + ex.printStackTrace(); | |
| 248 | + } | |
| 249 | + } | |
| 250 | + | |
| 235 | 251 | // Chat listeners get the chat if no filter removed it |
| 236 | 252 | this.chatListeners.all().onChat(chat, message); |
| 237 | 253 | } | ... | ... |
java/client/com/mumfrey/liteloader/client/util/PrivateFieldsClient.java
| ... | ... | @@ -10,7 +10,9 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; |
| 10 | 10 | import net.minecraft.client.resources.IResourceManagerReloadListener; |
| 11 | 11 | import net.minecraft.client.resources.SimpleReloadableResourceManager; |
| 12 | 12 | import net.minecraft.network.NetworkManager; |
| 13 | +import net.minecraft.network.play.server.S02PacketChat; | |
| 13 | 14 | import net.minecraft.tileentity.TileEntity; |
| 15 | +import net.minecraft.util.IChatComponent; | |
| 14 | 16 | import net.minecraft.util.ObjectIntIdentityMap; |
| 15 | 17 | import net.minecraft.util.RegistryNamespaced; |
| 16 | 18 | import net.minecraft.util.RegistrySimple; |
| ... | ... | @@ -35,6 +37,7 @@ public class PrivateFieldsClient<P, T> extends PrivateFields<P, T> |
| 35 | 37 | public static final PrivateFieldsClient<TileEntityRendererDispatcher, Map> specialRendererMap = new PrivateFieldsClient<TileEntityRendererDispatcher, Map> (TileEntityRendererDispatcher.class, Obf.mapSpecialRenderers); |
| 36 | 38 | public static final PrivateFieldsClient<TileEntity, Map> tileEntityNameToClassMap = new PrivateFieldsClient<TileEntity, Map> (TileEntity.class, Obf.tileEntityNameToClassMap); |
| 37 | 39 | public static final PrivateFieldsClient<TileEntity, Map> tileEntityClassToNameMap = new PrivateFieldsClient<TileEntity, Map> (TileEntity.class, Obf.tileEntityClassToNameMap); |
| 40 | + public static final PrivateFieldsClient<S02PacketChat, IChatComponent> chatMessage = new PrivateFieldsClient<S02PacketChat, IChatComponent> (S02PacketChat.class, Obf.chatComponent); | |
| 38 | 41 | |
| 39 | 42 | public static final PrivateFieldsClient<SimpleReloadableResourceManager, List<IResourceManagerReloadListener>> reloadListeners = |
| 40 | 43 | new PrivateFieldsClient<SimpleReloadableResourceManager, List<IResourceManagerReloadListener>>(SimpleReloadableResourceManager.class, Obf.reloadListeners); | ... | ... |
java/common/com/mumfrey/liteloader/core/PacketEvents.java
| ... | ... | @@ -280,9 +280,5 @@ public abstract class PacketEvents implements InterfaceProvider |
| 280 | 280 | { |
| 281 | 281 | LiteLoaderEventBroker.broker.onPlayerSettingsReceived(((NetHandlerPlayServer)netHandler).playerEntity, packet); |
| 282 | 282 | } |
| 283 | - else | |
| 284 | - { | |
| 285 | - System.err.println("ACTUALLY: handler is " + netHandler); | |
| 286 | - } | |
| 287 | 283 | } |
| 288 | 284 | } | ... | ... |
java/common/com/mumfrey/liteloader/core/runtime/Obf.java
| ... | ... | @@ -104,6 +104,7 @@ public class Obf |
| 104 | 104 | public static final Obf useShader = new Obf("field_175083_ad", "ad" ); |
| 105 | 105 | public static final Obf viewDistance = new Obf("field_149528_b", "b" ); |
| 106 | 106 | public static final Obf entityPosY = new Obf("field_70163_u", "t" ); |
| 107 | + public static final Obf chatComponent = new Obf("field_148919_a", "a" ); | |
| 107 | 108 | |
| 108 | 109 | // Methods |
| 109 | 110 | // ----------------------------------------------------------------------------------------- | ... | ... |
java/common/com/mumfrey/liteloader/permissions/PermissionsManagerClient.java
| ... | ... | @@ -239,7 +239,7 @@ public class PermissionsManagerClient implements PermissionsManager, PluginChann |
| 239 | 239 | { |
| 240 | 240 | byte[] data = query.getBytes(); |
| 241 | 241 | PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); |
| 242 | - buffer.writeByteArray(data); | |
| 242 | + buffer.writeBytes(data); | |
| 243 | 243 | ClientPluginChannels.sendMessage(ReplicatedPermissionsContainer.CHANNEL, buffer, ChannelPolicy.DISPATCH_ALWAYS); |
| 244 | 244 | } |
| 245 | 245 | } | ... | ... |
java/common/com/mumfrey/liteloader/util/ChatUtilities.java
0 โ 100644
| 1 | +package com.mumfrey.liteloader.util; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +import net.minecraft.util.ChatComponentText; | |
| 6 | +import net.minecraft.util.ChatStyle; | |
| 7 | +import net.minecraft.util.EnumChatFormatting; | |
| 8 | +import net.minecraft.util.IChatComponent; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Utility functions for chat | |
| 12 | + * | |
| 13 | + * @author Adam Mummery-Smith | |
| 14 | + */ | |
| 15 | +public abstract class ChatUtilities | |
| 16 | +{ | |
| 17 | + private static String formattingCodeLookup; | |
| 18 | + | |
| 19 | + static | |
| 20 | + { | |
| 21 | + StringBuilder formattingCodes = new StringBuilder(); | |
| 22 | + | |
| 23 | + for (EnumChatFormatting chatFormat : EnumChatFormatting.values()) | |
| 24 | + { | |
| 25 | + formattingCodes.append(chatFormat.toString().charAt(1)); | |
| 26 | + } | |
| 27 | + | |
| 28 | + ChatUtilities.formattingCodeLookup = formattingCodes.toString(); | |
| 29 | + } | |
| 30 | + | |
| 31 | + private ChatUtilities() {} | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Get a chat style from a legacy formatting code | |
| 35 | + * | |
| 36 | + * @param code Code | |
| 37 | + * @return | |
| 38 | + */ | |
| 39 | + public static ChatStyle getChatStyleFromCode(char code) | |
| 40 | + { | |
| 41 | + int pos = ChatUtilities.formattingCodeLookup.indexOf(code); | |
| 42 | + if (pos < 0) return null; | |
| 43 | + EnumChatFormatting format = EnumChatFormatting.values()[pos]; | |
| 44 | + | |
| 45 | + ChatStyle style = new ChatStyle(); | |
| 46 | + if (format.isColor()) | |
| 47 | + { | |
| 48 | + style.setColor(format); | |
| 49 | + } | |
| 50 | + else if (format.isFancyStyling()) | |
| 51 | + { | |
| 52 | + switch (format) | |
| 53 | + { | |
| 54 | + case BOLD: style.setBold(true); break; | |
| 55 | + case ITALIC: style.setItalic(true); break; | |
| 56 | + case STRIKETHROUGH: style.setStrikethrough(true); break; | |
| 57 | + case UNDERLINE: style.setUnderlined(true); break; | |
| 58 | + case OBFUSCATED: style.setObfuscated(true); break; | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + return style; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Convert a component containing text formatted with legacy codes to a native ChatComponent structure | |
| 67 | + */ | |
| 68 | + public static IChatComponent convertLegacyCodes(IChatComponent chat) | |
| 69 | + { | |
| 70 | + return ChatUtilities.covertCodesInPlace(chat); | |
| 71 | + } | |
| 72 | + | |
| 73 | + private static List<IChatComponent> covertCodesInPlace(List<IChatComponent> siblings) | |
| 74 | + { | |
| 75 | + for (int index = 0; index < siblings.size(); index++) | |
| 76 | + { | |
| 77 | + siblings.set(index, ChatUtilities.covertCodesInPlace(siblings.get(index))); | |
| 78 | + } | |
| 79 | + | |
| 80 | + return siblings; | |
| 81 | + } | |
| 82 | + | |
| 83 | + @SuppressWarnings("unchecked") | |
| 84 | + private static IChatComponent covertCodesInPlace(IChatComponent component) | |
| 85 | + { | |
| 86 | + IChatComponent newComponent = null; | |
| 87 | + if (component instanceof ChatComponentText) | |
| 88 | + { | |
| 89 | + ChatComponentText textComponent = (ChatComponentText)component; | |
| 90 | + ChatStyle style = textComponent.getChatStyle(); | |
| 91 | + String text = textComponent.getChatComponentText_TextValue(); | |
| 92 | + | |
| 93 | + int pos = text.indexOf('\247'); | |
| 94 | + while (pos > -1 && text != null) | |
| 95 | + { | |
| 96 | + if (pos < text.length() - 1) | |
| 97 | + { | |
| 98 | + IChatComponent head = new ChatComponentText(pos > 0 ? text.substring(0, pos) : "").setChatStyle(style); | |
| 99 | + style = ChatUtilities.getChatStyleFromCode(text.charAt(pos + 1)); | |
| 100 | + text = text.substring(pos + 2); | |
| 101 | + newComponent = (newComponent == null) ? head : newComponent.appendSibling(head); | |
| 102 | + pos = text.indexOf('\247'); | |
| 103 | + } | |
| 104 | + else | |
| 105 | + { | |
| 106 | + text = null; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + if (text != null) | |
| 111 | + { | |
| 112 | + IChatComponent tail = new ChatComponentText(text).setChatStyle(style); | |
| 113 | + newComponent = (newComponent == null) ? tail : newComponent.appendSibling(tail); | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + if (newComponent == null) | |
| 118 | + { | |
| 119 | + ChatUtilities.covertCodesInPlace(component.getSiblings()); | |
| 120 | + return component; | |
| 121 | + } | |
| 122 | + | |
| 123 | + for (IChatComponent oldSibling : ChatUtilities.covertCodesInPlace(component.getSiblings())) | |
| 124 | + { | |
| 125 | + newComponent.appendSibling(oldSibling); | |
| 126 | + } | |
| 127 | + | |
| 128 | + return newComponent; | |
| 129 | + } | |
| 130 | +} | ... | ... |
java/common/net/eq2online/permissions/ReplicatedPermissionsContainer.java
| ... | ... | @@ -98,7 +98,13 @@ public class ReplicatedPermissionsContainer implements Serializable |
| 98 | 98 | { |
| 99 | 99 | try |
| 100 | 100 | { |
| 101 | - ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(data.readByteArray())); | |
| 101 | + int readableBytes = data.readableBytes(); | |
| 102 | + if (readableBytes == 0) return null; | |
| 103 | + | |
| 104 | + byte[] payload = new byte[readableBytes]; | |
| 105 | + data.readBytes(payload); | |
| 106 | + | |
| 107 | + ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(payload)); | |
| 102 | 108 | ReplicatedPermissionsContainer object = (ReplicatedPermissionsContainer)inputStream.readObject(); |
| 103 | 109 | return object; |
| 104 | 110 | } | ... | ... |