1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

Service exceptions externalized and better logging configuration

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-21 22:41:27 -03:00
parent ab38e7d5ba
commit b3ff0795ec
44 changed files with 559 additions and 215 deletions

View File

@@ -16,6 +16,9 @@
*/
package com.l2jserver.game.net.handler;
import java.io.IOException;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
@@ -94,13 +97,20 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event)
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 Throwable e = event.getCause();
if (e instanceof ChannelException)
return;
if (e instanceof IOException)
return;
if (!connection.isConnected())
// no point sending error messages if the client is disconnected
return;
// TODO only send exception stack trace in development mode!
final String exception = Throwables.getStackTraceAsString(e)
.replaceAll("\n", "<br>").replace(" ", "");
final HtmlTemplate template = new HtmlTemplate("Java Exception") {
@Override
public void build(MarkupTag body) {
@@ -108,5 +118,11 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
}
};
connection.write(new NPCHtmlMessagePacket(null, template));
connection.sendActionFailed(); // order client not to wait any packet
final String[] lines = Throwables.getStackTraceAsString(e).split("\n");
for(final String line : lines) {
connection.sendMessage(line);
}
}
}

View File

@@ -25,11 +25,12 @@ import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
* Executes an action from an character to an NPC
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@@ -40,8 +41,10 @@ public class CharacterActionPacket extends AbstractClientPacket {
public static final int OPCODE = 0x1f;
private final ObjectIDResolver idResolver;
private final NPCService npcService;
private int objectId;
@SuppressWarnings("unused")
private Coordinate origin;
private CharacterAction action;
@@ -67,8 +70,10 @@ public class CharacterActionPacket extends AbstractClientPacket {
}
@Inject
public CharacterActionPacket(ObjectIDResolver idResolver) {
public CharacterActionPacket(ObjectIDResolver idResolver,
NPCService npcService) {
this.idResolver = idResolver;
this.npcService = npcService;
}
@Override
@@ -84,11 +89,14 @@ public class CharacterActionPacket extends AbstractClientPacket {
// since this is an erasure type, this is safe.
final ObjectID<NPC> id = idResolver.resolve(objectId);
if (!(id instanceof NPCID)) {
System.out.println("Incorrect type: " + id);
conn.sendActionFailed();
return;
}
final NPC npc = id.getObject();
npc.action(conn.getCharacter(), action);
try {
npcService.action(npc, conn.getCharacter(), action);
} catch (ActionServiceException e) {
conn.sendActionFailed();
}
}
}

View File

@@ -29,8 +29,8 @@ import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.CharacterService.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.util.dimensional.Coordinate;
/**

View File

@@ -22,13 +22,12 @@ import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
import com.l2jserver.service.game.chat.CannotChatToSelfChatServiceException;
import com.l2jserver.service.game.chat.ChatBanActiveChatServiceException;
import com.l2jserver.service.game.chat.ChatMessageDestination;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.chat.ChatService.CannotChatToSelfChatServiceException;
import com.l2jserver.service.game.chat.ChatService.ChatBanActiveChatServiceException;
import com.l2jserver.service.game.chat.ChatService.TargetNotFoundChatServiceException;
import com.l2jserver.service.game.chat.TargetNotFoundChatServiceException;
import com.l2jserver.util.BufferUtils;
import com.l2jserver.util.exception.L2ChatServiceException;
/**
* Completes the creation of an character. Creates the object, inserts into the

View File

@@ -23,7 +23,7 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterMoveType;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.character.CharacterService;
/**
* This packet notifies the server which character the player has chosen to use.

View File

@@ -25,7 +25,7 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.CharacterStopMovePacket;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.util.dimensional.Coordinate;
/**

View File

@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.util.dimensional.Point;
/**

View File

@@ -24,9 +24,9 @@ import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
/**
* The client is requesting a logout. Currently, when this packet is received