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

Fixes network services start order

This commit is contained in:
2011-12-26 15:30:46 -02:00
parent b562920831
commit 3286488f6e
5 changed files with 69 additions and 80 deletions

View File

@@ -32,6 +32,7 @@ import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService; import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldIDService; import com.l2jserver.service.game.world.WorldIDService;
import com.l2jserver.service.network.NetworkService; import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.network.gameguard.GameGuardService;
import com.l2jserver.service.network.keygen.BlowfishKeygenService; import com.l2jserver.service.network.keygen.BlowfishKeygenService;
/** /**
@@ -40,13 +41,18 @@ import com.l2jserver.service.network.keygen.BlowfishKeygenService;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class L2JGameServerMain { public class L2JGameServerMain {
public static final Class<?>[] SERVICES = { CacheService.class, public static final Class<?>[][] SERVICES = {
ConfigurationService.class, DatabaseService.class, // core services
WorldIDService.class, ScriptingService.class, { CacheService.class, ConfigurationService.class,
TemplateService.class, ChatService.class, NPCService.class, DatabaseService.class, WorldIDService.class,
ItemService.class, CharacterService.class, ShortcutService.class, ScriptingService.class, TemplateService.class },
PathingService.class, BlowfishKeygenService.class, // game services
NetworkService.class }; { 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 * Main method
@@ -61,14 +67,17 @@ public class L2JGameServerMain {
final ServiceManager serviceManager = server.getInjector() final ServiceManager serviceManager = server.getInjector()
.getInstance(ServiceManager.class); .getInstance(ServiceManager.class);
for (final Class<?> service : SERVICES) { for (final Class<?>[] category : SERVICES) {
for (final Class<?> service : category) {
serviceManager.start((Class<? extends Service>) service); serviceManager.start((Class<? extends Service>) service);
} }
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
for (final Class<?> service : SERVICES) { for (final Class<?>[] category : SERVICES) {
for (final Class<?> service : category) {
try { try {
serviceManager serviceManager
.stop((Class<? extends Service>) service); .stop((Class<? extends Service>) service);
@@ -76,6 +85,7 @@ public class L2JGameServerMain {
} }
} }
} }
}
})); }));
} catch (Exception e) { } catch (Exception e) {
@@ -84,44 +94,4 @@ public class L2JGameServerMain {
System.exit(0); 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);
// }
} }

View File

@@ -94,10 +94,6 @@ public class L2Character extends Player {
*/ */
private double CP; private double CP;
/**
* The character's status
*/
private boolean online;
/** /**
* Date of character's last access * Date of character's last access
*/ */
@@ -326,22 +322,6 @@ public class L2Character extends Player {
this.CP = CP; 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 * @return the lastAccess
*/ */

View File

@@ -102,6 +102,24 @@ public interface CharacterService extends Service {
*/ */
void leaveWorld(L2Character character) throws NotSpawnedServiceException; void leaveWorld(L2Character character) throws NotSpawnedServiceException;
/**
* Checks whether the character is currently online or not
*
* @param character
* the character
* @return <code>true</code> 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 <code>true</code> if the account is online right now
*/
boolean isOnline(AccountID accountID);
/** /**
* Set the target of this <tt>character</tt> * Set the target of this <tt>character</tt>
* *

View File

@@ -16,6 +16,8 @@
*/ */
package com.l2jserver.service.game.character; package com.l2jserver.service.game.character;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.network.broadcast.BroadcastService; import com.l2jserver.service.network.broadcast.BroadcastService;
import com.l2jserver.service.network.gameguard.GameGuardService; import com.l2jserver.service.network.gameguard.GameGuardService;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.geometry.Coordinate; import com.l2jserver.util.geometry.Coordinate;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -69,8 +72,7 @@ import com.l2jserver.util.geometry.Point3D;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ WorldService.class, SpawnService.class, AttackService.class, @Depends({ WorldService.class, SpawnService.class, AttackService.class })
GameGuardService.class, BroadcastService.class })
public class CharacterServiceImpl extends AbstractService implements public class CharacterServiceImpl extends AbstractService implements
CharacterService { CharacterService {
/** /**
@@ -122,6 +124,12 @@ public class CharacterServiceImpl extends AbstractService implements
*/ */
private final CharacterTemplateIDProvider charTemplateIdProvider; private final CharacterTemplateIDProvider charTemplateIdProvider;
/**
* An map containing all currently online characters
*/
private final Map<CharacterID, L2Character> onlineCharacters = CollectionFactory
.newMap();
// /** // /**
// * The {@link AIService} // * The {@link AIService}
// */ // */
@@ -239,7 +247,7 @@ public class CharacterServiceImpl extends AbstractService implements
character.getInventory().load(itemDao.selectByCharacter(character)); character.getInventory().load(itemDao.selectByCharacter(character));
character.getShortcuts().load(shortcutDao.selectByCharacter(character)); character.getShortcuts().load(shortcutDao.selectByCharacter(character));
character.setOnline(true); onlineCharacters.put(character.getID(), character);
// inventory interfere on calculators // inventory interfere on calculators
character.getStats().updateCalculator(); character.getStats().updateCalculator();
@@ -276,11 +284,25 @@ public class CharacterServiceImpl extends AbstractService implements
spawnService.unspawn(character); spawnService.unspawn(character);
eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character)); eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character));
character.setOnline(false); onlineCharacters.remove(character.getID());
characterDao.saveObjectsAsync(character); 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 @Override
public void target(L2Character character, Actor target) public void target(L2Character character, Actor target)
throws CannotSetTargetServiceException { throws CannotSetTargetServiceException {

View File

@@ -41,7 +41,6 @@ import com.l2jserver.service.core.threading.AsyncFuture;
import com.l2jserver.service.core.threading.ThreadService; import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher; 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.Coordinate;
import com.l2jserver.util.geometry.Point3D; import com.l2jserver.util.geometry.Point3D;
@@ -50,7 +49,7 @@ import com.l2jserver.util.geometry.Point3D;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
@Depends({ WorldService.class, NetworkService.class, ThreadService.class }) @Depends({ WorldService.class, ThreadService.class })
public class SpawnServiceImpl extends AbstractService implements SpawnService { public class SpawnServiceImpl extends AbstractService implements SpawnService {
/** /**
* The logger * The logger