mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-10 09:22:49 +00:00
Added in-game message for exception in server
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -18,13 +18,18 @@ package com.l2jserver.game.net.handler;
|
||||
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelStateEvent;
|
||||
import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelHandler;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.ClientPacket;
|
||||
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.network.NettyNetworkService;
|
||||
import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||
import com.l2jserver.util.html.markup.MarkupTag;
|
||||
|
||||
/**
|
||||
* This handler dispatches the {@link ClientPacket#process(Lineage2Connection)}
|
||||
@@ -87,4 +92,21 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
|
||||
ChannelStateEvent e) throws Exception {
|
||||
nettyNetworkService.unregister(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||
throws Exception {
|
||||
// TODO only send exception stack trace in development mode!
|
||||
// TODO ignore netty exceptions or it could cause stack overflow
|
||||
final String exception = Throwables.getStackTraceAsString(e.getCause())
|
||||
.replaceAll("\n", "<br>").replace(" ", "");
|
||||
|
||||
final HtmlTemplate template = new HtmlTemplate("Java Exception") {
|
||||
@Override
|
||||
public void build(MarkupTag body) {
|
||||
body.text(exception);
|
||||
}
|
||||
};
|
||||
connection.write(new NPCHtmlMessagePacket(null, template));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,13 @@ public class NPCHtmlMessagePacket extends AbstractServerPacket {
|
||||
*/
|
||||
public static final int OPCODE = 0x19;
|
||||
|
||||
/**
|
||||
* The saying NPC
|
||||
*/
|
||||
private final NPC npc;
|
||||
/**
|
||||
* The HTML contents
|
||||
*/
|
||||
private final String html;
|
||||
|
||||
public NPCHtmlMessagePacket(NPC npc, Html html) {
|
||||
@@ -45,15 +51,15 @@ public class NPCHtmlMessagePacket extends AbstractServerPacket {
|
||||
this.html = html.toHtml();
|
||||
}
|
||||
|
||||
public NPCHtmlMessagePacket(NPC npc, HtmlTemplate markup) {
|
||||
public NPCHtmlMessagePacket(NPC npc, HtmlTemplate template) {
|
||||
super(OPCODE);
|
||||
this.npc = npc;
|
||||
this.html = markup.toHtmlString();
|
||||
this.html = template.toHtmlString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(npc.getID().getID());
|
||||
buffer.writeInt((npc != null ? npc.getID().getID() : 0x01));
|
||||
BufferUtils.writeString(buffer, html);
|
||||
buffer.writeInt(0x00); // item id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user