Commit d1dfc0488a5fff6922f6d08e9cab3bd0c8721ac2
1 parent
e068f370
fix ClientPermissions and ChatFilter
Showing
8 changed files
with
160 additions
and
7 deletions
debug/obfuscation.properties
| @@ -20,6 +20,7 @@ field_147713_ae=shaderIndex | @@ -20,6 +20,7 @@ field_147713_ae=shaderIndex | ||
| 20 | field_175083_ad=useShader | 20 | field_175083_ad=useShader |
| 21 | field_149528_b=view | 21 | field_149528_b=view |
| 22 | field_70163_u=posY | 22 | field_70163_u=posY |
| 23 | +field_148919_a=chatComponent | ||
| 23 | func_148833_a=processPacket | 24 | func_148833_a=processPacket |
| 24 | func_71411_J=runGameLoop | 25 | func_71411_J=runGameLoop |
| 25 | func_71407_l=runTick | 26 | func_71407_l=runTick |
java/client/com/mumfrey/liteloader/client/PacketEventsClient.java
| @@ -20,6 +20,7 @@ import com.mumfrey.liteloader.ChatListener; | @@ -20,6 +20,7 @@ import com.mumfrey.liteloader.ChatListener; | ||
| 20 | import com.mumfrey.liteloader.JoinGameListener; | 20 | import com.mumfrey.liteloader.JoinGameListener; |
| 21 | import com.mumfrey.liteloader.PostLoginListener; | 21 | import com.mumfrey.liteloader.PostLoginListener; |
| 22 | import com.mumfrey.liteloader.PreJoinGameListener; | 22 | import com.mumfrey.liteloader.PreJoinGameListener; |
| 23 | +import com.mumfrey.liteloader.client.util.PrivateFieldsClient; | ||
| 23 | import com.mumfrey.liteloader.common.transformers.PacketEventInfo; | 24 | import com.mumfrey.liteloader.common.transformers.PacketEventInfo; |
| 24 | import com.mumfrey.liteloader.core.ClientPluginChannels; | 25 | import com.mumfrey.liteloader.core.ClientPluginChannels; |
| 25 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; | 26 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; |
| @@ -32,6 +33,7 @@ import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; | @@ -32,6 +33,7 @@ import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; | ||
| 32 | import com.mumfrey.liteloader.core.runtime.Packets; | 33 | import com.mumfrey.liteloader.core.runtime.Packets; |
| 33 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; | 34 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; |
| 34 | import com.mumfrey.liteloader.transformers.event.EventInfo; | 35 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
| 36 | +import com.mumfrey.liteloader.util.ChatUtilities; | ||
| 35 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | 37 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 36 | 38 | ||
| 37 | /** | 39 | /** |
| @@ -205,7 +207,8 @@ public class PacketEventsClient extends PacketEvents | @@ -205,7 +207,8 @@ public class PacketEventsClient extends PacketEvents | ||
| 205 | if (packet.func_148915_c() == null) | 207 | if (packet.func_148915_c() == null) |
| 206 | return; | 208 | return; |
| 207 | 209 | ||
| 208 | - IChatComponent chat = packet.func_148915_c(); | 210 | + IChatComponent originalChat = packet.func_148915_c(); |
| 211 | + IChatComponent chat = originalChat; | ||
| 209 | String message = chat.getFormattedText(); | 212 | String message = chat.getFormattedText(); |
| 210 | 213 | ||
| 211 | // Chat filters get a stab at the chat first, if any filter returns false the chat is discarded | 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,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 | // Chat listeners get the chat if no filter removed it | 251 | // Chat listeners get the chat if no filter removed it |
| 236 | this.chatListeners.all().onChat(chat, message); | 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,7 +10,9 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; | ||
| 10 | import net.minecraft.client.resources.IResourceManagerReloadListener; | 10 | import net.minecraft.client.resources.IResourceManagerReloadListener; |
| 11 | import net.minecraft.client.resources.SimpleReloadableResourceManager; | 11 | import net.minecraft.client.resources.SimpleReloadableResourceManager; |
| 12 | import net.minecraft.network.NetworkManager; | 12 | import net.minecraft.network.NetworkManager; |
| 13 | +import net.minecraft.network.play.server.S02PacketChat; | ||
| 13 | import net.minecraft.tileentity.TileEntity; | 14 | import net.minecraft.tileentity.TileEntity; |
| 15 | +import net.minecraft.util.IChatComponent; | ||
| 14 | import net.minecraft.util.ObjectIntIdentityMap; | 16 | import net.minecraft.util.ObjectIntIdentityMap; |
| 15 | import net.minecraft.util.RegistryNamespaced; | 17 | import net.minecraft.util.RegistryNamespaced; |
| 16 | import net.minecraft.util.RegistrySimple; | 18 | import net.minecraft.util.RegistrySimple; |
| @@ -35,6 +37,7 @@ public class PrivateFieldsClient<P, T> extends PrivateFields<P, T> | @@ -35,6 +37,7 @@ public class PrivateFieldsClient<P, T> extends PrivateFields<P, T> | ||
| 35 | public static final PrivateFieldsClient<TileEntityRendererDispatcher, Map> specialRendererMap = new PrivateFieldsClient<TileEntityRendererDispatcher, Map> (TileEntityRendererDispatcher.class, Obf.mapSpecialRenderers); | 37 | public static final PrivateFieldsClient<TileEntityRendererDispatcher, Map> specialRendererMap = new PrivateFieldsClient<TileEntityRendererDispatcher, Map> (TileEntityRendererDispatcher.class, Obf.mapSpecialRenderers); |
| 36 | public static final PrivateFieldsClient<TileEntity, Map> tileEntityNameToClassMap = new PrivateFieldsClient<TileEntity, Map> (TileEntity.class, Obf.tileEntityNameToClassMap); | 38 | public static final PrivateFieldsClient<TileEntity, Map> tileEntityNameToClassMap = new PrivateFieldsClient<TileEntity, Map> (TileEntity.class, Obf.tileEntityNameToClassMap); |
| 37 | public static final PrivateFieldsClient<TileEntity, Map> tileEntityClassToNameMap = new PrivateFieldsClient<TileEntity, Map> (TileEntity.class, Obf.tileEntityClassToNameMap); | 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 | public static final PrivateFieldsClient<SimpleReloadableResourceManager, List<IResourceManagerReloadListener>> reloadListeners = | 42 | public static final PrivateFieldsClient<SimpleReloadableResourceManager, List<IResourceManagerReloadListener>> reloadListeners = |
| 40 | new PrivateFieldsClient<SimpleReloadableResourceManager, List<IResourceManagerReloadListener>>(SimpleReloadableResourceManager.class, Obf.reloadListeners); | 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,9 +280,5 @@ public abstract class PacketEvents implements InterfaceProvider | ||
| 280 | { | 280 | { |
| 281 | LiteLoaderEventBroker.broker.onPlayerSettingsReceived(((NetHandlerPlayServer)netHandler).playerEntity, packet); | 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,6 +104,7 @@ public class Obf | ||
| 104 | public static final Obf useShader = new Obf("field_175083_ad", "ad" ); | 104 | public static final Obf useShader = new Obf("field_175083_ad", "ad" ); |
| 105 | public static final Obf viewDistance = new Obf("field_149528_b", "b" ); | 105 | public static final Obf viewDistance = new Obf("field_149528_b", "b" ); |
| 106 | public static final Obf entityPosY = new Obf("field_70163_u", "t" ); | 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 | // Methods | 109 | // Methods |
| 109 | // ----------------------------------------------------------------------------------------- | 110 | // ----------------------------------------------------------------------------------------- |
java/common/com/mumfrey/liteloader/permissions/PermissionsManagerClient.java
| @@ -239,7 +239,7 @@ public class PermissionsManagerClient implements PermissionsManager, PluginChann | @@ -239,7 +239,7 @@ public class PermissionsManagerClient implements PermissionsManager, PluginChann | ||
| 239 | { | 239 | { |
| 240 | byte[] data = query.getBytes(); | 240 | byte[] data = query.getBytes(); |
| 241 | PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); | 241 | PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); |
| 242 | - buffer.writeByteArray(data); | 242 | + buffer.writeBytes(data); |
| 243 | ClientPluginChannels.sendMessage(ReplicatedPermissionsContainer.CHANNEL, buffer, ChannelPolicy.DISPATCH_ALWAYS); | 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,7 +98,13 @@ public class ReplicatedPermissionsContainer implements Serializable | ||
| 98 | { | 98 | { |
| 99 | try | 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 | ReplicatedPermissionsContainer object = (ReplicatedPermissionsContainer)inputStream.readObject(); | 108 | ReplicatedPermissionsContainer object = (ReplicatedPermissionsContainer)inputStream.readObject(); |
| 103 | return object; | 109 | return object; |
| 104 | } | 110 | } |