Examples of GameserverConfiguration


Examples of be.demmel.jgws.cfg.jaxb.GameserverConfiguration

  public static void main(String... parameters) {
    Thread.currentThread().setName("Startup");
    LOGGER.info("The \"Java Guild Wars (Game)Server\" (version {}) is starting", Version.getVersion());
    try {
      GameserverConfiguration gameServerConfiguration = getGameServerConfiguration();

      // Retrieve the PacketDeserializers for every outgoing (game) packet
      Map<Integer, PacketDeserializer> packetDeserializers = GeneralUtils.getPacketDeserializers("be.demmel.jgws.packets.gameserver.inbound");
      // Retrieve the PacketSerializers for every incoming (game) packet
      Map<Class<? extends Packet>, PacketSerializer> packetSerializers = GeneralUtils.getPacketSerializers("be.demmel.jgws.packets.gameserver.outbound");

      // Retrieve the PacketHandlers for every incoming (login) packet
      Map<Class<? extends Packet>, PacketHandler> packetHandlers = GeneralUtils.getPacketHandlers("be.demmel.jgws.packets.handlers");

      // Create the ActionQueue that processes actions
      ActionQueue actionQueue = new ActionQueue();
      Thread actionQueueThread = new Thread(actionQueue);
      actionQueueThread.start();

      Jpa jpaConfiguration = gameServerConfiguration.getJpa();

      Map<String, String> properties = new HashMap<>();
      properties.put("javax.persistence.jdbc.driver", jpaConfiguration.getDriver());
      properties.put("javax.persistence.jdbc.url", jpaConfiguration.getUrl());
      properties.put("javax.persistence.jdbc.user", jpaConfiguration.getUser());
      properties.put("javax.persistence.jdbc.password", jpaConfiguration.getPassword());

      entityManagerFactory = Persistence.createEntityManagerFactory("jgws", properties);
     
      EntityManagerFactoryTool.setEntityManagerFactory(entityManagerFactory);

      // build all maps for this GS
      loadedMaps = loadMaps();

      LOGGER.info("Registering Game Server to Login Server");
      // Register this Game Server with the Login Server
      String portalUri = gameServerConfiguration.getPortalUri();
      URI serviceRmiUri = new URI(portalUri);

      LoginServerPortal remoteObject = null;
      // get the remote object from the registry
      try {
        remoteObject = (LoginServerPortal) Naming.lookup(serviceRmiUri.toASCIIString());
      } catch (Exception e) {
        // Add some understandable string
        throw new Exception("RMI connection failed : ", e);
      }

      Binding bindingConfiguration = gameServerConfiguration.getBinding();
      String bindingIp = bindingConfiguration.getIp();
      int bindingPort = bindingConfiguration.getPort();

      try {
        InetSocketAddress hostAndPort = new InetSocketAddress(InetAddress.getByName(bindingIp), bindingPort);
        GameServerPortalImpl gameServerPortal = new GameServerPortalImpl();
        int portalCallbackPort = gameServerConfiguration.getPortalCallbackPort();
        UnicastRemoteObject.exportObject(gameServerPortal, portalCallbackPort);

        be.demmel.jgws.rmi.GameServer gameServer = new be.demmel.jgws.rmi.GameServerImpl(gameServerPortal, hostAndPort);

        remoteObject.registerGameServer(gameServer);
      } catch (Exception e) {
        // Add some understandable string
        throw new Exception("Registering this Game Server to the Login Server failed : ", e);
      }
      LOGGER.info("Registered Game Server to Login Server");

      // TODO: SSL (with certificates) for RMI
      // TODO: also add an option to disable SSL, because listening on an interface which is NOT available to the public could also work
      // (intranet IP...) :)
     
      ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
     
      final InboundPacketHandler<GameServerSession> inboundPacketHandler = new InboundPacketHandler<GameServerSession>(channels, packetHandlers, SessionKey.SESSION_KEY, actionQueue);
     
      LogBlackList logBlackList = gameServerConfiguration.getLogBlackList();
      if(gameServerConfiguration.getLogBlackList() != null) { // don't log some inbound and outbound packets
        Set<Class<? extends Packet>> inboundPacketsLogBlackList = new HashSet<Class<? extends Packet>>(), outboundPacketsLogBlackList = new HashSet<Class<? extends Packet>>();
       
        for(String packet : logBlackList.getInbound().getPacket()) {
          inboundPacketsLogBlackList.add( (Class<? extends Packet>)Class.forName(packet));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.