diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java index 3b61ede57..8b0526a7d 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -32,6 +32,7 @@ import com.l2jserver.service.game.scripting.ScriptingService; import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.world.WorldIDService; import com.l2jserver.service.network.NetworkService; +import com.l2jserver.service.network.gameguard.GameGuardService; import com.l2jserver.service.network.keygen.BlowfishKeygenService; /** @@ -40,13 +41,18 @@ import com.l2jserver.service.network.keygen.BlowfishKeygenService; * @author Rogiel */ public class L2JGameServerMain { - public static final Class[] SERVICES = { CacheService.class, - ConfigurationService.class, DatabaseService.class, - WorldIDService.class, ScriptingService.class, - TemplateService.class, ChatService.class, NPCService.class, - ItemService.class, CharacterService.class, ShortcutService.class, - PathingService.class, BlowfishKeygenService.class, - NetworkService.class }; + public static final Class[][] SERVICES = { + // core services + { CacheService.class, ConfigurationService.class, + DatabaseService.class, WorldIDService.class, + ScriptingService.class, TemplateService.class }, + // game services + { ChatService.class, NPCService.class, ItemService.class, + CharacterService.class, ShortcutService.class, + PathingService.class }, + // network services - should be started at last! + { BlowfishKeygenService.class, GameGuardService.class, + NetworkService.class } }; /** * Main method @@ -61,18 +67,22 @@ public class L2JGameServerMain { final ServiceManager serviceManager = server.getInjector() .getInstance(ServiceManager.class); - for (final Class service : SERVICES) { - serviceManager.start((Class) service); + for (final Class[] category : SERVICES) { + for (final Class service : category) { + serviceManager.start((Class) service); + } } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { - for (final Class service : SERVICES) { - try { - serviceManager - .stop((Class) service); - } catch (ServiceStopException e) { + for (final Class[] category : SERVICES) { + for (final Class service : category) { + try { + serviceManager + .stop((Class) service); + } catch (ServiceStopException e) { + } } } } @@ -84,44 +94,4 @@ public class L2JGameServerMain { System.exit(0); } } - // - // /** - // * This method does an static spawn for an object - // * - // * @throws AlreadySpawnedServiceException - // * @throws SpawnPointNotFoundServiceException - // */ - // private static void staticSpawn(Injector injector) - // throws SpawnPointNotFoundServiceException, - // AlreadySpawnedServiceException { - // final NPCTemplateIDProvider templateProvider = injector - // .getInstance(NPCTemplateIDProvider.class); - // final NPCIDProvider provider = injector - // .getInstance(NPCIDProvider.class); - // final SpawnService spawnService = injector - // .getInstance(SpawnService.class); - // - // final NPCTemplateID id = templateProvider.createID(12077); - // final NPC npc = id.getTemplate().create(); - // - // npc.setID(provider.createID()); - // // close to char spawn - // npc.setPoint(Point.fromXYZ(-71301, 258259, -3134)); - // - // spawnService.spawn(npc, null); - // - // // close spawn gatekepper - // final NPCTemplateID gid = templateProvider.createID(30006); - // final NPC gatekeeper = gid.getTemplate().create(); - // gatekeeper.setID(provider.createID()); - // gatekeeper.setPoint(Point.fromXYZ(-71301, 258559, -3134)); - // spawnService.spawn(gatekeeper, null); - // - // // spawn tamil - orc village - // final NPCTemplateID tamilId = templateProvider.createID(30576); - // final NPC tamil = tamilId.getTemplate().create(); - // tamil.setID(provider.createID()); - // tamil.setPoint(Point.fromXYZ(-45264, -112512, -240)); - // spawnService.spawn(tamil, null); - // } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/L2Character.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/L2Character.java index 3bb1b95dc..2a0037327 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/L2Character.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/L2Character.java @@ -94,10 +94,6 @@ public class L2Character extends Player { */ private double CP; - /** - * The character's status - */ - private boolean online; /** * Date of character's last access */ @@ -326,22 +322,6 @@ public class L2Character extends Player { this.CP = CP; } - /** - * @return the online - */ - public boolean isOnline() { - return online; - } - - /** - * @param online - * the online to set - */ - public void setOnline(boolean online) { - desireUpdate(); - this.online = online; - } - /** * @return the lastAccess */ diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterService.java index 1fe97f9de..07a3fc355 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterService.java @@ -102,6 +102,24 @@ public interface CharacterService extends Service { */ void leaveWorld(L2Character character) throws NotSpawnedServiceException; + /** + * Checks whether the character is currently online or not + * + * @param character + * the character + * @return true if the character is online right now + */ + boolean isOnline(L2Character character); + + /** + * Checks if this account has an character that is currently online + * + * @param accountID + * the account id + * @return true if the account is online right now + */ + boolean isOnline(AccountID accountID); + /** * Set the target of this character * diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java index 4a3b2a899..dc2f89a5c 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java @@ -16,6 +16,8 @@ */ package com.l2jserver.service.game.character; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +63,7 @@ import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.WorldEventDispatcher; import com.l2jserver.service.network.broadcast.BroadcastService; import com.l2jserver.service.network.gameguard.GameGuardService; +import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Point3D; @@ -69,8 +72,7 @@ import com.l2jserver.util.geometry.Point3D; * * @author Rogiel */ -@Depends({ WorldService.class, SpawnService.class, AttackService.class, - GameGuardService.class, BroadcastService.class }) +@Depends({ WorldService.class, SpawnService.class, AttackService.class }) public class CharacterServiceImpl extends AbstractService implements CharacterService { /** @@ -122,6 +124,12 @@ public class CharacterServiceImpl extends AbstractService implements */ private final CharacterTemplateIDProvider charTemplateIdProvider; + /** + * An map containing all currently online characters + */ + private final Map onlineCharacters = CollectionFactory + .newMap(); + // /** // * The {@link AIService} // */ @@ -239,7 +247,7 @@ public class CharacterServiceImpl extends AbstractService implements character.getInventory().load(itemDao.selectByCharacter(character)); character.getShortcuts().load(shortcutDao.selectByCharacter(character)); - character.setOnline(true); + onlineCharacters.put(character.getID(), character); // inventory interfere on calculators character.getStats().updateCalculator(); @@ -276,11 +284,25 @@ public class CharacterServiceImpl extends AbstractService implements spawnService.unspawn(character); eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character)); - character.setOnline(false); + onlineCharacters.remove(character.getID()); characterDao.saveObjectsAsync(character); } + @Override + public boolean isOnline(L2Character character) { + return onlineCharacters.containsKey(character.getID()); + } + + @Override + public boolean isOnline(AccountID accountID) { + for (final L2Character character : onlineCharacters.values()) { + if (character.getAccountID().equals(accountID)) + return true; + } + return false; + } + @Override public void target(L2Character character, Actor target) throws CannotSetTargetServiceException { diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java index f3359495c..c77041f2c 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/spawn/SpawnServiceImpl.java @@ -41,7 +41,6 @@ import com.l2jserver.service.core.threading.AsyncFuture; import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.event.WorldEventDispatcher; -import com.l2jserver.service.network.NetworkService; import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Point3D; @@ -50,7 +49,7 @@ import com.l2jserver.util.geometry.Point3D; * * @author Rogiel */ -@Depends({ WorldService.class, NetworkService.class, ThreadService.class }) +@Depends({ WorldService.class, ThreadService.class }) public class SpawnServiceImpl extends AbstractService implements SpawnService { /** * The logger