From b3ff0795ece4f95ad8f202e49ebd53b12b1b671e Mon Sep 17 00:00:00 2001 From: Rogiel Date: Sat, 21 May 2011 22:41:27 -0300 Subject: [PATCH] Service exceptions externalized and better logging configuration Signed-off-by: Rogiel --- .../java/com/l2jserver/L2JGameServerMain.java | 8 +- .../net/handler/Lineage2PacketHandler.java | 26 ++- .../packet/client/CharacterActionPacket.java | 18 +- .../client/CharacterAttackRequestPacket.java | 4 +- .../client/CharacterChatMessagePacket.java | 7 +- .../client/CharacterRequestActionUse.java | 2 +- .../client/CharacterRequestMovePacket.java | 2 +- .../CharacterValidatePositionPacket.java | 2 +- .../game/net/packet/client/EnterWorld.java | 6 +- .../l2jserver/model/template/NPCTemplate.java | 10 +- .../npc/DwarfVillageMasterNPCTemplate.java | 1 - .../npc/KamaelVillageMasterNPCTemplate.java | 1 - .../npc/OrcVillageMasterNPCTemplate.java | 1 - .../java/com/l2jserver/model/world/NPC.java | 20 -- .../l2jserver/service/ServiceException.java | 4 +- .../com/l2jserver/service/ServiceModule.java | 11 +- .../service/core/Log4JLoggingService.java | 22 ++ .../core/log4j/TruncateToZipFileAppender.java | 203 ++++++++++++++++++ .../CannotSetTargetServiceException.java | 11 + .../CharacterInJailServiceException.java | 11 + .../CharacterNotInJailServiceException.java | 11 + .../{ => character}/CharacterService.java | 40 +--- .../character/CharacterServiceException.java} | 31 +-- .../{ => character}/CharacterServiceImpl.java | 9 +- .../CannotChatToSelfChatServiceException.java | 12 ++ .../ChatBanActiveChatServiceException.java | 13 ++ .../service/game/chat/ChatService.java | 34 --- .../game/chat/ChatServiceException.java} | 14 +- .../TargetNotFoundChatServiceException.java | 12 ++ .../game/chat/channel/ChatChannel.java | 2 +- .../game/npc/ActionServiceException.java | 23 ++ .../NPCService.java} | 29 ++- .../game/npc/NPCServiceException.java} | 14 +- .../service/game/npc/NPCServiceImpl.java | 54 +++++ .../npc/NotAttackableNPCServiceException.java | 12 ++ .../game/pathing/MapperPathingService.java | 2 +- .../game/scripting/ScriptingServiceImpl.java | 6 +- .../spawn/AlreadySpawnedServiceException.java | 12 ++ .../spawn/NotSpawnedServiceException.java | 11 + .../SpawnPointNotFoundServiceException.java | 12 ++ .../game/{ => spawn}/SpawnService.java | 32 +-- .../game/spawn/SpawnServiceException.java} | 14 +- .../game/{ => spawn}/SpawnServiceImpl.java | 2 +- .../game/world/CachedWorldIDService.java | 3 +- 44 files changed, 559 insertions(+), 215 deletions(-) create mode 100644 src/main/java/com/l2jserver/service/core/log4j/TruncateToZipFileAppender.java create mode 100644 src/main/java/com/l2jserver/service/game/character/CannotSetTargetServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/character/CharacterInJailServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/character/CharacterNotInJailServiceException.java rename src/main/java/com/l2jserver/service/game/{ => character}/CharacterService.java (77%) rename src/main/java/com/l2jserver/{util/exception/L2ServiceException.java => service/game/character/CharacterServiceException.java} (62%) rename src/main/java/com/l2jserver/service/game/{ => character}/CharacterServiceImpl.java (97%) create mode 100644 src/main/java/com/l2jserver/service/game/chat/CannotChatToSelfChatServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/chat/ChatBanActiveChatServiceException.java rename src/main/java/com/l2jserver/{util/exception/L2SpawnServiceException.java => service/game/chat/ChatServiceException.java} (72%) create mode 100644 src/main/java/com/l2jserver/service/game/chat/TargetNotFoundChatServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/npc/ActionServiceException.java rename src/main/java/com/l2jserver/service/game/{MonsterService.java => npc/NPCService.java} (54%) rename src/main/java/com/l2jserver/{util/exception/L2ChatServiceException.java => service/game/npc/NPCServiceException.java} (72%) create mode 100644 src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java create mode 100644 src/main/java/com/l2jserver/service/game/npc/NotAttackableNPCServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/spawn/AlreadySpawnedServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/spawn/NotSpawnedServiceException.java create mode 100644 src/main/java/com/l2jserver/service/game/spawn/SpawnPointNotFoundServiceException.java rename src/main/java/com/l2jserver/service/game/{ => spawn}/SpawnService.java (76%) rename src/main/java/com/l2jserver/{util/exception/L2CharacterServiceException.java => service/game/spawn/SpawnServiceException.java} (72%) rename src/main/java/com/l2jserver/service/game/{ => spawn}/SpawnServiceImpl.java (99%) diff --git a/src/main/java/com/l2jserver/L2JGameServerMain.java b/src/main/java/com/l2jserver/L2JGameServerMain.java index 6738461bc..e487817c4 100644 --- a/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -25,13 +25,13 @@ import com.l2jserver.service.ServiceManager; import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.database.DatabaseService; -import com.l2jserver.service.game.CharacterService; -import com.l2jserver.service.game.SpawnService; -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.chat.ChatService; import com.l2jserver.service.game.pathing.PathingService; import com.l2jserver.service.game.scripting.ScriptingService; +import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; +import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; +import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.world.WorldIDService; import com.l2jserver.service.network.NetworkService; diff --git a/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java b/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java index cfb58817d..a9149c35f 100644 --- a/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java +++ b/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java @@ -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", "
").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", "
").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); + } } } diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java index a0ba8b1cb..e0cc9325c 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java @@ -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 Rogiel */ @@ -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 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(); + } } } diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java index 0a5c25b1c..d2e428c78 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java @@ -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; /** diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterChatMessagePacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterChatMessagePacket.java index 5cfeee67a..5093e053f 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterChatMessagePacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterChatMessagePacket.java @@ -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 diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestActionUse.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestActionUse.java index 4009686e4..0df4a62c5 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestActionUse.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestActionUse.java @@ -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. diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java index c7dbf41e2..5491db4dd 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java @@ -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; /** diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java index c25713b8c..a8daeb154 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java @@ -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; /** diff --git a/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java b/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java index 6841e0b86..f60c2d152 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java @@ -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 diff --git a/src/main/java/com/l2jserver/model/template/NPCTemplate.java b/src/main/java/com/l2jserver/model/template/NPCTemplate.java index 49d3940db..8aa668896 100644 --- a/src/main/java/com/l2jserver/model/template/NPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/NPCTemplate.java @@ -27,10 +27,11 @@ import com.l2jserver.model.world.AbstractActor.Race; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.NPC; 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.service.network.NetworkService; import com.l2jserver.util.calculator.Calculator; +import com.l2jserver.util.exception.L2Exception; import com.l2jserver.util.html.markup.HtmlTemplate; import com.l2jserver.util.html.markup.MarkupTag; @@ -101,8 +102,11 @@ public abstract class NPCTemplate extends ActorTemplate { * the interacting character * @param action * the action performed + * @throws L2Exception + * any {@link L2Exception} */ - public void action(NPC npc, L2Character character, CharacterAction action) { + public void action(NPC npc, L2Character character, CharacterAction action) + throws L2Exception { final Lineage2Connection conn = networkService.discover(character .getID()); if (conn == null) diff --git a/src/main/java/com/l2jserver/model/template/npc/DwarfVillageMasterNPCTemplate.java b/src/main/java/com/l2jserver/model/template/npc/DwarfVillageMasterNPCTemplate.java index 680d0431c..8059ed27f 100644 --- a/src/main/java/com/l2jserver/model/template/npc/DwarfVillageMasterNPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/npc/DwarfVillageMasterNPCTemplate.java @@ -17,7 +17,6 @@ package com.l2jserver.model.template.npc; import com.l2jserver.model.id.template.NPCTemplateID; -import com.l2jserver.model.template.NPCTemplate; /** * @author Rogiel diff --git a/src/main/java/com/l2jserver/model/template/npc/KamaelVillageMasterNPCTemplate.java b/src/main/java/com/l2jserver/model/template/npc/KamaelVillageMasterNPCTemplate.java index 80bcd1f1b..1c7d1ee1c 100644 --- a/src/main/java/com/l2jserver/model/template/npc/KamaelVillageMasterNPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/npc/KamaelVillageMasterNPCTemplate.java @@ -17,7 +17,6 @@ package com.l2jserver.model.template.npc; import com.l2jserver.model.id.template.NPCTemplateID; -import com.l2jserver.model.template.NPCTemplate; /** * @author Rogiel diff --git a/src/main/java/com/l2jserver/model/template/npc/OrcVillageMasterNPCTemplate.java b/src/main/java/com/l2jserver/model/template/npc/OrcVillageMasterNPCTemplate.java index a2ae34b89..072557e6b 100644 --- a/src/main/java/com/l2jserver/model/template/npc/OrcVillageMasterNPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/npc/OrcVillageMasterNPCTemplate.java @@ -17,7 +17,6 @@ package com.l2jserver.model.template.npc; import com.l2jserver.model.id.template.NPCTemplateID; -import com.l2jserver.model.template.NPCTemplate; /** * @author Rogiel diff --git a/src/main/java/com/l2jserver/model/world/NPC.java b/src/main/java/com/l2jserver/model/world/NPC.java index 84df8a3c2..a5677d7eb 100644 --- a/src/main/java/com/l2jserver/model/world/NPC.java +++ b/src/main/java/com/l2jserver/model/world/NPC.java @@ -16,14 +16,11 @@ */ package com.l2jserver.model.world; -import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction; import com.l2jserver.model.id.TemplateID; import com.l2jserver.model.id.object.NPCID; import com.l2jserver.model.id.template.NPCTemplateID; import com.l2jserver.model.template.NPCTemplate; -import com.l2jserver.model.world.capability.Actor; import com.l2jserver.service.game.ai.AIScript; -import com.l2jserver.util.calculator.Calculator; /** * NPC stand for "Not Playable Character" and is an character that not player @@ -48,23 +45,6 @@ public class NPC extends AbstractActor { this.templateID = templateID; } - /** - * Executes an action on this NPC - * - * @param character - * the interacting character - * @param action - * the action - */ - public void action(L2Character character, CharacterAction action) { - getTemplate().action(this, character, action); - } - - public void receiveAttack(Calculator calculator, Actor attacker) { - // TODO add buffs to calculator! - getTemplate().receiveAttack(this, calculator, attacker); - } - /** * @return the NPC template ID */ diff --git a/src/main/java/com/l2jserver/service/ServiceException.java b/src/main/java/com/l2jserver/service/ServiceException.java index 1b3ca9938..e7cc38b24 100644 --- a/src/main/java/com/l2jserver/service/ServiceException.java +++ b/src/main/java/com/l2jserver/service/ServiceException.java @@ -16,12 +16,14 @@ */ package com.l2jserver.service; +import com.l2jserver.util.exception.L2Exception; + /** * Exception for an {@link Service} * * @author Rogiel */ -public class ServiceException extends Exception { +public class ServiceException extends L2Exception { private static final long serialVersionUID = 1L; public ServiceException() { diff --git a/src/main/java/com/l2jserver/service/ServiceModule.java b/src/main/java/com/l2jserver/service/ServiceModule.java index 5931c2ab1..358ed5d9f 100644 --- a/src/main/java/com/l2jserver/service/ServiceModule.java +++ b/src/main/java/com/l2jserver/service/ServiceModule.java @@ -27,16 +27,18 @@ import com.l2jserver.service.core.Log4JLoggingService; import com.l2jserver.service.core.LoggingService; import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.database.MySQLDatabaseService; -import com.l2jserver.service.game.CharacterService; -import com.l2jserver.service.game.CharacterServiceImpl; -import com.l2jserver.service.game.SpawnService; -import com.l2jserver.service.game.SpawnServiceImpl; +import com.l2jserver.service.game.character.CharacterService; +import com.l2jserver.service.game.character.CharacterServiceImpl; import com.l2jserver.service.game.chat.ChatService; import com.l2jserver.service.game.chat.SimpleChatService; +import com.l2jserver.service.game.npc.NPCService; +import com.l2jserver.service.game.npc.NPCServiceImpl; import com.l2jserver.service.game.pathing.MapperPathingService; import com.l2jserver.service.game.pathing.PathingService; import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.scripting.ScriptingServiceImpl; +import com.l2jserver.service.game.spawn.SpawnService; +import com.l2jserver.service.game.spawn.SpawnServiceImpl; import com.l2jserver.service.game.template.ScriptTemplateService; import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.world.CachedWorldIDService; @@ -87,6 +89,7 @@ public class ServiceModule extends AbstractModule { .in(Scopes.SINGLETON); bind(CharacterService.class).to(CharacterServiceImpl.class).in( Scopes.SINGLETON); + bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON); bind(WorldService.class).to(WorldServiceImpl.class) .in(Scopes.SINGLETON); diff --git a/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java b/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java index 4398a7c30..5e2cfbe37 100644 --- a/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java +++ b/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java @@ -17,6 +17,11 @@ package com.l2jserver.service.core; import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; import com.l2jserver.service.AbstractService; import com.l2jserver.service.ServiceStartException; @@ -29,9 +34,26 @@ import com.l2jserver.service.ServiceStopException; */ public class Log4JLoggingService extends AbstractService implements LoggingService { + private Logger rootLogger; + private Logger l2jLogger; + private Logger scriptLogger; + @Override protected void doStart() throws ServiceStartException { + final Layout layout = new PatternLayout( + "[%p %d{yyyy-MM-dd HH-mm-ss}] %c:%L - %m%n"); + BasicConfigurator.configure(); + rootLogger = Logger.getRootLogger(); + l2jLogger = Logger.getLogger("com.l2jserver"); + scriptLogger = Logger.getLogger("script"); + + rootLogger.removeAllAppenders(); + rootLogger.setLevel(Level.WARN); + rootLogger.addAppender(new ConsoleAppender(layout, "System.err")); + + l2jLogger.setLevel(Level.DEBUG); + scriptLogger.setLevel(Level.DEBUG); } @Override diff --git a/src/main/java/com/l2jserver/service/core/log4j/TruncateToZipFileAppender.java b/src/main/java/com/l2jserver/service/core/log4j/TruncateToZipFileAppender.java new file mode 100644 index 000000000..6c8aaf077 --- /dev/null +++ b/src/main/java/com/l2jserver/service/core/log4j/TruncateToZipFileAppender.java @@ -0,0 +1,203 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.service.core.log4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.apache.commons.io.FileUtils; +import org.apache.log4j.FileAppender; +import org.apache.log4j.helpers.LogLog; + +/** + * This class is appender that zips old file instead of appending it.
+ * File is recognized as old if it's lastModified() is < JVM startup time.
+ * So we can have per-run appending.
+ * + * Unfortunately, UNIX systems doesn't support file creation date, so we have to + * use lastModified(), windows only solution is not good. + * + * @author Rogiel + */ +public class TruncateToZipFileAppender extends FileAppender { + + /** + * String that points to root directory for backups + */ + private String backupDir = "log/backup"; + + /** + * String that represents date format for backup files + */ + private String backupDateFormat = "yyyy-MM-dd HH-mm-ss"; + + /** + * Sets and opens the file where the log output will go. The + * specified file must be writable. + *

+ * If there was already an opened file, then the previous file is closed + * first. + *

+ *

+ * Do not use this method directly. To configure a FileAppender or one of + * its subclasses, set its properties one by one and then call + * activateOptions. + *

+ *
+ * Truncation is done by {@link #truncate(java.io.File)} + * + * @param fileName + * The path to the log file. + * @param append + * If true will append to fileName. Otherwise will truncate + * fileName. + */ + @Override + public void setFile(String fileName, boolean append, boolean bufferedIO, + int bufferSize) throws IOException { + + if (!append) { + truncate(new File(fileName)); + } + + super.setFile(fileName, append, bufferedIO, bufferSize); + } + + /** + * This method creates archive with file instead of deleting it. + * + * @param file + * file to truncate + */ + protected void truncate(File file) { + LogLog.debug("Compression of file: " + file.getAbsolutePath() + + " started."); + + // Linux systems doesn't provide file creation time, so we have to hope + // that log files + // were not modified manually after server starup + // We can use here Windowns-only solution but that suck :( + if (FileUtils.isFileOlder(file, ManagementFactory.getRuntimeMXBean() + .getStartTime())) { + File backupRoot = new File(getBackupDir()); + if (!backupRoot.exists() && !backupRoot.mkdirs()) { + throw new Error("Can't create backup dir for backup storage"); + } + + SimpleDateFormat df; + try { + df = new SimpleDateFormat(getBackupDateFormat()); + } catch (Exception e) { + throw new Error("Invalid date formate for backup files: " + + getBackupDateFormat(), e); + } + String date = df.format(new Date(file.lastModified())); + + File zipFile = new File(backupRoot, file.getName() + "." + date + + ".zip"); + + ZipOutputStream zos = null; + FileInputStream fis = null; + try { + zos = new ZipOutputStream(new FileOutputStream(zipFile)); + ZipEntry entry = new ZipEntry(file.getName()); + entry.setMethod(ZipEntry.DEFLATED); + entry.setCrc(FileUtils.checksumCRC32(file)); + zos.putNextEntry(entry); + fis = FileUtils.openInputStream(file); + + byte[] buffer = new byte[1024]; + int readed; + while ((readed = fis.read(buffer)) != -1) { + zos.write(buffer, 0, readed); + } + + } catch (Exception e) { + throw new Error("Can't create zip file", e); + } finally { + if (zos != null) { + try { + zos.close(); + } catch (IOException e) { + // not critical error + LogLog.warn("Can't close zip file", e); + } + } + + if (fis != null) { + try { + // not critical error + fis.close(); + } catch (IOException e) { + LogLog.warn("Can't close zipped file", e); + } + } + } + + if (!file.delete()) { + throw new Error("Can't delete old log file " + + file.getAbsolutePath()); + } + } + } + + /** + * Returns root directory for backups + * + * @return root directory for backups + */ + public String getBackupDir() { + return backupDir; + } + + /** + * Sets root directory for backups + * + * @param backupDir + * new root directory for backups + */ + public void setBackupDir(String backupDir) { + this.backupDir = backupDir; + } + + /** + * Returns date format that should be used for backup files represented as + * string + * + * @return date formate for backup files + */ + public String getBackupDateFormat() { + return backupDateFormat; + } + + /** + * Sets date format for bakcup files represented as string + * + * @param backupDateFormat + * date format for backup files + */ + public void setBackupDateFormat(String backupDateFormat) { + this.backupDateFormat = backupDateFormat; + } +} diff --git a/src/main/java/com/l2jserver/service/game/character/CannotSetTargetServiceException.java b/src/main/java/com/l2jserver/service/game/character/CannotSetTargetServiceException.java new file mode 100644 index 000000000..ddc48cd4a --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/character/CannotSetTargetServiceException.java @@ -0,0 +1,11 @@ +package com.l2jserver.service.game.character; + +/** + * Exception thrown when the target cannot be set + * + * @author Rogiel + */ +public class CannotSetTargetServiceException extends + CharacterServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/character/CharacterInJailServiceException.java b/src/main/java/com/l2jserver/service/game/character/CharacterInJailServiceException.java new file mode 100644 index 000000000..577f44d74 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/character/CharacterInJailServiceException.java @@ -0,0 +1,11 @@ +package com.l2jserver.service.game.character; + +/** + * Exception thrown when the character is in jail + * + * @author Rogiel + */ +public class CharacterInJailServiceException extends + CharacterServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/character/CharacterNotInJailServiceException.java b/src/main/java/com/l2jserver/service/game/character/CharacterNotInJailServiceException.java new file mode 100644 index 000000000..b5764f89e --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/character/CharacterNotInJailServiceException.java @@ -0,0 +1,11 @@ +package com.l2jserver.service.game.character; + +/** + * Exception thrown when the character is not in jail + * + * @author Rogiel + */ +public class CharacterNotInJailServiceException extends + CharacterServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/CharacterService.java b/src/main/java/com/l2jserver/service/game/character/CharacterService.java similarity index 77% rename from src/main/java/com/l2jserver/service/game/CharacterService.java rename to src/main/java/com/l2jserver/service/game/character/CharacterService.java index b1b409b0f..b8778574c 100644 --- a/src/main/java/com/l2jserver/service/game/CharacterService.java +++ b/src/main/java/com/l2jserver/service/game/character/CharacterService.java @@ -14,17 +14,16 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.service.game; +package com.l2jserver.service.game.character; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.capability.Actor; import com.l2jserver.service.Service; -import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException; -import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException; -import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException; +import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; +import com.l2jserver.service.game.spawn.NotSpawnedServiceException; +import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; import com.l2jserver.util.dimensional.Coordinate; import com.l2jserver.util.dimensional.Point; -import com.l2jserver.util.exception.L2ChatServiceException; /** * This service manages {@link L2Character} instances @@ -105,7 +104,8 @@ public interface CharacterService extends Service { * @throws CharacterNotInJailServiceException * if character is not in jail */ - void unjail(L2Character character) throws CharacterNotInJailServiceException; + void unjail(L2Character character) + throws CharacterNotInJailServiceException; /** * Moves the given character to coordinate @@ -152,32 +152,4 @@ public interface CharacterService extends Service { * the character */ void run(L2Character character); - - /** - * Exception thrown when the target cannot be set - * - * @author Rogiel - */ - public class CannotSetTargetServiceException extends L2ChatServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown when the character is in jail - * - * @author Rogiel - */ - public class CharacterInJailServiceException extends L2ChatServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown when the character is not in jail - * - * @author Rogiel - */ - public class CharacterNotInJailServiceException extends - L2ChatServiceException { - private static final long serialVersionUID = 1L; - } } diff --git a/src/main/java/com/l2jserver/util/exception/L2ServiceException.java b/src/main/java/com/l2jserver/service/game/character/CharacterServiceException.java similarity index 62% rename from src/main/java/com/l2jserver/util/exception/L2ServiceException.java rename to src/main/java/com/l2jserver/service/game/character/CharacterServiceException.java index 1fe6b5fe5..90c5f6068 100644 --- a/src/main/java/com/l2jserver/util/exception/L2ServiceException.java +++ b/src/main/java/com/l2jserver/service/game/character/CharacterServiceException.java @@ -14,44 +14,29 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.exception; +package com.l2jserver.service.game.character; + +import com.l2jserver.service.ServiceException; /** - * Base exception for Lineage 2 - * * @author Rogiel */ -public class L2ServiceException extends Exception { - /** - * Default Serial Version UID - */ +public class CharacterServiceException extends ServiceException { private static final long serialVersionUID = 1L; - /** - * @see Exception#Exception() - */ - public L2ServiceException() { + public CharacterServiceException() { super(); } - /** - * @see Exception#Exception(String, Throwable) - */ - public L2ServiceException(String message, Throwable cause) { + public CharacterServiceException(String message, Throwable cause) { super(message, cause); } - /** - * @see Exception#Exception(String) - */ - public L2ServiceException(String message) { + public CharacterServiceException(String message) { super(message); } - /** - * @see Exception#Exception(Throwable) - */ - public L2ServiceException(Throwable cause) { + public CharacterServiceException(Throwable cause) { super(cause); } } diff --git a/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java similarity index 97% rename from src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java rename to src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java index f1c77f849..0f7e03985 100644 --- a/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.service.game; +package com.l2jserver.service.game.character; import com.google.common.base.Preconditions; import com.google.inject.Inject; @@ -48,13 +48,14 @@ import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent; import com.l2jserver.model.world.npc.event.NPCSpawnEvent; import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService.Depends; -import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException; -import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException; -import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException; import com.l2jserver.service.game.chat.ChatMessageDestination; import com.l2jserver.service.game.chat.ChatService; import com.l2jserver.service.game.chat.channel.ChatChannel; import com.l2jserver.service.game.chat.channel.ChatChannelListener; +import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; +import com.l2jserver.service.game.spawn.NotSpawnedServiceException; +import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; +import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.FilteredWorldListener; import com.l2jserver.service.game.world.event.WorldEvent; diff --git a/src/main/java/com/l2jserver/service/game/chat/CannotChatToSelfChatServiceException.java b/src/main/java/com/l2jserver/service/game/chat/CannotChatToSelfChatServiceException.java new file mode 100644 index 000000000..b936c94c7 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/CannotChatToSelfChatServiceException.java @@ -0,0 +1,12 @@ +package com.l2jserver.service.game.chat; + + +/** + * Exception thrown if the player is trying to chat with itself. + * + * @author Rogiel + */ +public class CannotChatToSelfChatServiceException extends + ChatServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/chat/ChatBanActiveChatServiceException.java b/src/main/java/com/l2jserver/service/game/chat/ChatBanActiveChatServiceException.java new file mode 100644 index 000000000..1338239d5 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/ChatBanActiveChatServiceException.java @@ -0,0 +1,13 @@ +package com.l2jserver.service.game.chat; + + +/** + * Exception thrown if the player trying to send a message is currently + * banned. + * + * @author Rogiel + */ +public class ChatBanActiveChatServiceException extends + ChatServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/chat/ChatService.java b/src/main/java/com/l2jserver/service/game/chat/ChatService.java index 05d32af93..c26a7d449 100644 --- a/src/main/java/com/l2jserver/service/game/chat/ChatService.java +++ b/src/main/java/com/l2jserver/service/game/chat/ChatService.java @@ -23,7 +23,6 @@ import com.l2jserver.service.Service; import com.l2jserver.service.game.chat.channel.ChatChannel; import com.l2jserver.service.game.chat.channel.PrivateChatChannel; import com.l2jserver.service.game.chat.channel.PublicChatChannel; -import com.l2jserver.util.exception.L2ChatServiceException; /** * This service chatting in the server @@ -107,37 +106,4 @@ public interface ChatService extends Service { * @return the public clan {@link ChatChannel} */ PublicChatChannel getChannel(ClanID clan); - - // TODO party chat - - /** - * Exception thrown when the target of an private chat is not found - * - * @author Rogiel - */ - public class TargetNotFoundChatServiceException extends - L2ChatServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown if the player is trying to chat with itself. - * - * @author Rogiel - */ - public class CannotChatToSelfChatServiceException extends - L2ChatServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown if the player trying to send a message is currently - * banned. - * - * @author Rogiel - */ - public class ChatBanActiveChatServiceException extends - L2ChatServiceException { - private static final long serialVersionUID = 1L; - } } diff --git a/src/main/java/com/l2jserver/util/exception/L2SpawnServiceException.java b/src/main/java/com/l2jserver/service/game/chat/ChatServiceException.java similarity index 72% rename from src/main/java/com/l2jserver/util/exception/L2SpawnServiceException.java rename to src/main/java/com/l2jserver/service/game/chat/ChatServiceException.java index b96a7d4ed..2311ebe1a 100644 --- a/src/main/java/com/l2jserver/util/exception/L2SpawnServiceException.java +++ b/src/main/java/com/l2jserver/service/game/chat/ChatServiceException.java @@ -14,27 +14,29 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.exception; +package com.l2jserver.service.game.chat; + +import com.l2jserver.service.ServiceException; /** * @author Rogiel */ -public class L2SpawnServiceException extends L2ServiceException { +public class ChatServiceException extends ServiceException { private static final long serialVersionUID = 1L; - public L2SpawnServiceException() { + public ChatServiceException() { super(); } - public L2SpawnServiceException(String message, Throwable cause) { + public ChatServiceException(String message, Throwable cause) { super(message, cause); } - public L2SpawnServiceException(String message) { + public ChatServiceException(String message) { super(message); } - public L2SpawnServiceException(Throwable cause) { + public ChatServiceException(Throwable cause) { super(cause); } } diff --git a/src/main/java/com/l2jserver/service/game/chat/TargetNotFoundChatServiceException.java b/src/main/java/com/l2jserver/service/game/chat/TargetNotFoundChatServiceException.java new file mode 100644 index 000000000..549c66177 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/TargetNotFoundChatServiceException.java @@ -0,0 +1,12 @@ +package com.l2jserver.service.game.chat; + + +/** + * Exception thrown when the target of an private chat is not found + * + * @author Rogiel + */ +public class TargetNotFoundChatServiceException extends + ChatServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java index de46c8d1c..3b2d51ff6 100644 --- a/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java +++ b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java @@ -17,7 +17,7 @@ package com.l2jserver.service.game.chat.channel; import com.l2jserver.model.id.object.CharacterID; -import com.l2jserver.service.game.chat.ChatService.ChatBanActiveChatServiceException; +import com.l2jserver.service.game.chat.ChatBanActiveChatServiceException; /** * The {@link ChatChannel} object is used to send messages to a channel. diff --git a/src/main/java/com/l2jserver/service/game/npc/ActionServiceException.java b/src/main/java/com/l2jserver/service/game/npc/ActionServiceException.java new file mode 100644 index 000000000..8f11b4222 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/npc/ActionServiceException.java @@ -0,0 +1,23 @@ +package com.l2jserver.service.game.npc; + +import com.l2jserver.util.exception.L2Exception; + +/** + * Exception thrown when the action implementation thrown an exception. Will + * always contain an cause + * + * @author Rogiel + */ +public class ActionServiceException extends NPCServiceException { + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance + * + * @param cause + * the cause + */ + public ActionServiceException(L2Exception cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/MonsterService.java b/src/main/java/com/l2jserver/service/game/npc/NPCService.java similarity index 54% rename from src/main/java/com/l2jserver/service/game/MonsterService.java rename to src/main/java/com/l2jserver/service/game/npc/NPCService.java index 23b23ba02..80f66c7c5 100644 --- a/src/main/java/com/l2jserver/service/game/MonsterService.java +++ b/src/main/java/com/l2jserver/service/game/npc/NPCService.java @@ -14,25 +14,44 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.service.game; +package com.l2jserver.service.game.npc; +import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction; +import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.NPC; import com.l2jserver.service.Service; /** - * This service controls {@link NPC}s + * This service manages {@link NPC} instances * * @author Rogiel */ -public interface MonsterService extends Service { +public interface NPCService extends Service { /** - * Interacts the given player with the given npc + * Executes an action for an NPC. Each {@link NPCTemplate} have it's own + * actions. * * @param npc * the npc * @param character * the character + * @param action + * the action type */ - void interact(NPC npc, L2Character character); + void action(NPC npc, L2Character character, CharacterAction action) + throws ActionServiceException; + + /** + * Attacks an given NPC, if possible. + * + * @param npc + * the npc + * @param attacker + * the character + * @throws NotAttackableNPCServiceException + * if {@link NPC} is not attackable + */ + void attack(NPC npc, L2Character attacker) + throws NotAttackableNPCServiceException; } diff --git a/src/main/java/com/l2jserver/util/exception/L2ChatServiceException.java b/src/main/java/com/l2jserver/service/game/npc/NPCServiceException.java similarity index 72% rename from src/main/java/com/l2jserver/util/exception/L2ChatServiceException.java rename to src/main/java/com/l2jserver/service/game/npc/NPCServiceException.java index f08e9a9ce..9a4b9d959 100644 --- a/src/main/java/com/l2jserver/util/exception/L2ChatServiceException.java +++ b/src/main/java/com/l2jserver/service/game/npc/NPCServiceException.java @@ -14,27 +14,29 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.exception; +package com.l2jserver.service.game.npc; + +import com.l2jserver.service.ServiceException; /** * @author Rogiel */ -public class L2ChatServiceException extends L2ServiceException { +public class NPCServiceException extends ServiceException { private static final long serialVersionUID = 1L; - public L2ChatServiceException() { + public NPCServiceException() { super(); } - public L2ChatServiceException(String message, Throwable cause) { + public NPCServiceException(String message, Throwable cause) { super(message, cause); } - public L2ChatServiceException(String message) { + public NPCServiceException(String message) { super(message); } - public L2ChatServiceException(Throwable cause) { + public NPCServiceException(Throwable cause) { super(cause); } } diff --git a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java new file mode 100644 index 000000000..2fb5b3ed7 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java @@ -0,0 +1,54 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.service.game.npc; + +import com.google.common.base.Preconditions; +import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction; +import com.l2jserver.model.template.NPCTemplate; +import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.world.NPC; +import com.l2jserver.service.AbstractService; +import com.l2jserver.util.exception.L2Exception; + +/** + * Default {@link NPCService} implementation + * + * @author Rogiel + */ +public class NPCServiceImpl extends AbstractService implements NPCService { + @Override + public void action(NPC npc, L2Character character, CharacterAction action) + throws ActionServiceException { + Preconditions.checkNotNull(npc, "npc"); + Preconditions.checkNotNull(character, "character"); + Preconditions.checkNotNull(action, "action"); + + final NPCTemplate template = npc.getTemplate(); + try { + template.action(npc, character, action); + } catch (L2Exception e) { + throw new ActionServiceException(e); + } + } + + @Override + public void attack(NPC npc, L2Character attacker) + throws NotAttackableNPCServiceException { + Preconditions.checkNotNull(npc, "npc"); + Preconditions.checkNotNull(attacker, "attacker"); + } +} diff --git a/src/main/java/com/l2jserver/service/game/npc/NotAttackableNPCServiceException.java b/src/main/java/com/l2jserver/service/game/npc/NotAttackableNPCServiceException.java new file mode 100644 index 000000000..93283be7a --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/npc/NotAttackableNPCServiceException.java @@ -0,0 +1,12 @@ +package com.l2jserver.service.game.npc; + +import com.l2jserver.model.world.NPC; + +/** + * Exception thrown when the {@link NPC} is not attackable + * + * @author Rogiel + */ +public class NotAttackableNPCServiceException extends NPCServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java b/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java index 803413620..93b9aa4fc 100644 --- a/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java +++ b/src/main/java/com/l2jserver/service/game/pathing/MapperPathingService.java @@ -33,7 +33,7 @@ import com.l2jserver.service.AbstractService; import com.l2jserver.service.AbstractService.Depends; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; -import com.l2jserver.service.game.CharacterService; +import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.TypedWorldListener; import com.l2jserver.service.game.world.event.WorldEventDispatcher; diff --git a/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java b/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java index 0401edf14..957399117 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java @@ -118,8 +118,7 @@ public class ScriptingServiceImpl extends AbstractService implements private ScriptContext createContext(ScriptInfo si, ScriptContext parent) throws Exception { Preconditions.checkNotNull(si, "si"); - Preconditions.checkNotNull(parent, "parent"); - + ScriptContext context = getScriptContext(si.getRoot(), parent); context.setLibraries(si.getLibraries()); context.setCompilerClassName(si.getCompilerClass()); @@ -159,8 +158,7 @@ public class ScriptingServiceImpl extends AbstractService implements private ScriptContext getScriptContext(File root, ScriptContext parent) throws InstantiationException { Preconditions.checkNotNull(root, "root"); - Preconditions.checkNotNull(parent, "parent"); - + ScriptContextImpl ctx; if (parent == null) { ctx = new ScriptContextImpl(injector, root); diff --git a/src/main/java/com/l2jserver/service/game/spawn/AlreadySpawnedServiceException.java b/src/main/java/com/l2jserver/service/game/spawn/AlreadySpawnedServiceException.java new file mode 100644 index 000000000..f716340ee --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/spawn/AlreadySpawnedServiceException.java @@ -0,0 +1,12 @@ +package com.l2jserver.service.game.spawn; + + +/** + * Exception thrown when the object is already spawned and registered in the + * world + * + * @author Rogiel + */ +public class AlreadySpawnedServiceException extends SpawnServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/spawn/NotSpawnedServiceException.java b/src/main/java/com/l2jserver/service/game/spawn/NotSpawnedServiceException.java new file mode 100644 index 000000000..7a869ec6e --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/spawn/NotSpawnedServiceException.java @@ -0,0 +1,11 @@ +package com.l2jserver.service.game.spawn; + + +/** + * Exception thrown when trying to unspawn an object that is not spawned + * + * @author Rogiel + */ +public class NotSpawnedServiceException extends SpawnServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/spawn/SpawnPointNotFoundServiceException.java b/src/main/java/com/l2jserver/service/game/spawn/SpawnPointNotFoundServiceException.java new file mode 100644 index 000000000..24b153c59 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/spawn/SpawnPointNotFoundServiceException.java @@ -0,0 +1,12 @@ +package com.l2jserver.service.game.spawn; + + +/** + * Exception thrown when the target spawn point is not found + * + * @author Rogiel + */ +public class SpawnPointNotFoundServiceException extends + SpawnServiceException { + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/service/game/SpawnService.java b/src/main/java/com/l2jserver/service/game/spawn/SpawnService.java similarity index 76% rename from src/main/java/com/l2jserver/service/game/SpawnService.java rename to src/main/java/com/l2jserver/service/game/spawn/SpawnService.java index c832e7fb0..66460b7a0 100644 --- a/src/main/java/com/l2jserver/service/game/SpawnService.java +++ b/src/main/java/com/l2jserver/service/game/spawn/SpawnService.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.service.game; +package com.l2jserver.service.game.spawn; import com.l2jserver.model.world.Player; import com.l2jserver.model.world.capability.Spawnable; @@ -23,7 +23,6 @@ import com.l2jserver.model.world.player.event.PlayerTeleportEvent; import com.l2jserver.service.Service; import com.l2jserver.util.dimensional.Coordinate; import com.l2jserver.util.dimensional.Point; -import com.l2jserver.util.exception.L2SpawnServiceException; /** * This service is responsible for spawning monsters, npcs and players. @@ -87,33 +86,4 @@ public interface SpawnService extends Service { * if the object is not spawned */ void unspawn(Spawnable spawnable) throws NotSpawnedServiceException; - - /** - * Exception thrown when the object is already spawned and registered in the - * world - * - * @author Rogiel - */ - public class AlreadySpawnedServiceException extends L2SpawnServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown when the target spawn point is not found - * - * @author Rogiel - */ - public class SpawnPointNotFoundServiceException extends - L2SpawnServiceException { - private static final long serialVersionUID = 1L; - } - - /** - * Exception thrown when trying to unspawn an object that is not spawned - * - * @author Rogiel - */ - public class NotSpawnedServiceException extends L2SpawnServiceException { - private static final long serialVersionUID = 1L; - } } diff --git a/src/main/java/com/l2jserver/util/exception/L2CharacterServiceException.java b/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceException.java similarity index 72% rename from src/main/java/com/l2jserver/util/exception/L2CharacterServiceException.java rename to src/main/java/com/l2jserver/service/game/spawn/SpawnServiceException.java index 0803b44bd..95139746a 100644 --- a/src/main/java/com/l2jserver/util/exception/L2CharacterServiceException.java +++ b/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceException.java @@ -14,27 +14,29 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.exception; +package com.l2jserver.service.game.spawn; + +import com.l2jserver.service.ServiceException; /** * @author Rogiel */ -public class L2CharacterServiceException extends L2ServiceException { +public class SpawnServiceException extends ServiceException { private static final long serialVersionUID = 1L; - public L2CharacterServiceException() { + public SpawnServiceException() { super(); } - public L2CharacterServiceException(String message, Throwable cause) { + public SpawnServiceException(String message, Throwable cause) { super(message, cause); } - public L2CharacterServiceException(String message) { + public SpawnServiceException(String message) { super(message); } - public L2CharacterServiceException(Throwable cause) { + public SpawnServiceException(Throwable cause) { super(cause); } } diff --git a/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java b/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java similarity index 99% rename from src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java rename to src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java index 2db927c44..c3277e9b9 100644 --- a/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.service.game; +package com.l2jserver.service.game.spawn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java b/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java index 9c5df2a19..28ce43070 100644 --- a/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java +++ b/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java @@ -90,8 +90,7 @@ public class CachedWorldIDService extends AbstractService implements cache = new Cache(new CacheConfiguration("id-cache", IDAllocator.ALLOCABLE_IDS) .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU) - .overflowToDisk(true).eternal(true).timeToLiveSeconds(60) - .timeToIdleSeconds(30).diskPersistent(false) + .overflowToDisk(true).eternal(true).diskPersistent(false) .diskExpiryThreadIntervalSeconds(0)); cacheService.register(cache); }