package com.jonathan.citrus; import com.jonathan.citrus.game.GameBase; import com.jonathan.citrus.game.cache.Library; import com.jonathan.citrus.game.protocol.BasicPacketProtocol; import com.jonathan.citrus.network.ServiceManager; import com.jonathan.citrus.network.game.HandshakeDecoder; import com.jonathan.citrus.network.handler.BasicMessageDecoder; import com.jonathan.citrus.network.handler.BasicServiceHandler; import com.jonathan.citrus.network.world.CommercialProtocol; import java.io.IOException; import java.util.logging.Level; import com.jonathan.citrus.network.world.CommercialServiceHandler; /** * * @author Jonathan */ public class WorldModule extends Module { private static String commercialAddress = null; public WorldModule(int id, int revision) { super(Module.Type.WORLD, new GameBase(id, revision)); } public WorldModule(int id, int revision, String commercialAddress) { this(id, revision); WorldModule.commercialAddress = commercialAddress; } public static boolean isCommercial() { return commercialAddress != null; } @Override protected final void _load() { try { Library.start(); System.out.println("Loaded cache."); } catch (IOException e) { e.printStackTrace(); } } @Override public final void start() { try { manager.setNetwork(new BasicPacketProtocol(), moduleBase.getReferencePort()) .setHandlers(new BasicServiceHandler(), new HandshakeDecoder()); if (isCommercial()) { manager.setCommercialNetwork(new CommercialProtocol(), commercialAddress, 40000) .setHandlers(new CommercialServiceHandler(), new BasicMessageDecoder(1)); } } catch (Exception ex) { java.util.logging.Logger.getLogger(WorldModule.class.getName()).log(Level.SEVERE, null, ex); } } public static GameBase getLogic() { return (GameBase) moduleBase; } }