1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

Added in-game message for exception in server

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-21 01:07:11 -03:00
parent c3c7277dd9
commit 6efce6615f
5 changed files with 46 additions and 73 deletions

View File

@@ -17,13 +17,9 @@
package com.l2jserver;
import com.google.inject.Injector;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.provider.NPCIDProvider;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.cache.CacheService;
@@ -95,16 +91,5 @@ public class L2JGameServerMain {
npc.setPoint(Point.fromXYZ(-71301, 258259, -3134));
spawnService.spawn(npc, null);
final ObjectIDResolver resolver = injector
.getInstance(ObjectIDResolver.class);
final ObjectID<L2Character> cid = resolver.resolve(268437456);
L2Character c = cid.getObject();
System.out
.println(injector.getInstance(ItemDAO.class).loadInventory(c));
System.out.println(injector.getInstance(ObjectIDResolver.class)
.resolve(268635457).getObject());
}
}

View File

@@ -1,41 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
final HtmlTemplate template = new HtmlTemplate("Notice") {
@Override
public void build(MarkupTag body) {
body.text("This NPC is not yet implemented!").br();
body.text("This NPC is not yet implemented!", "000000").br();
body.text("This NPC is not yet implemented!", "ffffff").p();
body.addLink("Click me!", "test");
}
};
System.out.println(template.toHtmlString());
}
}

View File

@@ -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));
}
}

View File

@@ -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
}

View File

@@ -107,20 +107,21 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
if (conn == null)
return;
// target this npc
charService.target(character, npc);
// generate not implemented message
final HtmlTemplate template = new HtmlTemplate(name) {
@Override
public void build(MarkupTag body) {
body.text("The NPC ${name} is not yet implemented!", "ff0000")
.p();
body.addLink("Click me!", "test");
}
};
template.register("name", name);
conn.write(new NPCHtmlMessagePacket(npc, template));
throw new RuntimeException("Testing...");
// // target this npc
// charService.target(character, npc);
//
// // generate not implemented message
// final HtmlTemplate template = new HtmlTemplate(name) {
// @Override
// public void build(MarkupTag body) {
// body.text("The NPC ${name} is not yet implemented!", "ff0000")
// .p();
// body.addLink("Click me!", "test");
// }
// };
// template.register("name", name);
// conn.write(new NPCHtmlMessagePacket(npc, template));
}
/**