Dropped UPnP service. Whoever needs it, can re-adapt from l2j.
This commit is contained in:
@@ -1006,7 +1006,6 @@ public final class Config
|
||||
// --------------------------------------------------
|
||||
// Server Settings
|
||||
// --------------------------------------------------
|
||||
public static boolean ENABLE_UPNP;
|
||||
public static int PORT_GAME;
|
||||
public static int PORT_LOGIN;
|
||||
public static String LOGIN_BIND_ADDRESS;
|
||||
@@ -1212,7 +1211,6 @@ public final class Config
|
||||
|
||||
final PropertiesParser serverSettings = new PropertiesParser(CONFIGURATION_FILE);
|
||||
|
||||
ENABLE_UPNP = serverSettings.getBoolean("EnableUPnP", true);
|
||||
GAMESERVER_HOSTNAME = serverSettings.getString("GameserverHostname", "*");
|
||||
PORT_GAME = serverSettings.getInt("GameserverPort", 7777);
|
||||
|
||||
@@ -3012,7 +3010,6 @@ public final class Config
|
||||
{
|
||||
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIGURATION_FILE);
|
||||
|
||||
ENABLE_UPNP = ServerSettings.getBoolean("EnableUPnP", true);
|
||||
GAME_SERVER_LOGIN_HOST = ServerSettings.getString("LoginHostname", "127.0.0.1");
|
||||
GAME_SERVER_LOGIN_PORT = ServerSettings.getInt("LoginPort", 9013);
|
||||
|
||||
|
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server 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.
|
||||
*
|
||||
* L2J Server 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bitlet.weupnp.GatewayDevice;
|
||||
import org.bitlet.weupnp.GatewayDiscover;
|
||||
import org.bitlet.weupnp.PortMappingEntry;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class UPnPService
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(UPnPService.class.getName());
|
||||
private static final String PROTOCOL = "TCP";
|
||||
|
||||
private final GatewayDiscover _gatewayDiscover = new GatewayDiscover();
|
||||
private GatewayDevice _activeGW;
|
||||
|
||||
protected UPnPService()
|
||||
{
|
||||
try
|
||||
{
|
||||
load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, getClass().getSimpleName() + ": error while initializing: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void load() throws Exception
|
||||
{
|
||||
if (!Config.ENABLE_UPNP)
|
||||
{
|
||||
_log.log(Level.WARNING, "UPnP Service is disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
_log.log(Level.INFO, "Looking for UPnP Gateway Devices...");
|
||||
|
||||
final Map<InetAddress, GatewayDevice> gateways = _gatewayDiscover.discover();
|
||||
if (gateways.isEmpty())
|
||||
{
|
||||
_log.log(Level.INFO, "No UPnP gateways found");
|
||||
return;
|
||||
}
|
||||
|
||||
// choose the first active gateway for the tests
|
||||
_activeGW = _gatewayDiscover.getValidGateway();
|
||||
if (_activeGW != null)
|
||||
{
|
||||
_log.log(Level.INFO, "Using UPnP gateway: " + _activeGW.getFriendlyName());
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.log(Level.INFO, "No active UPnP gateway found");
|
||||
return;
|
||||
}
|
||||
|
||||
_log.log(Level.INFO, "Using local address: " + _activeGW.getLocalAddress().getHostAddress() + " External address: " + _activeGW.getExternalIPAddress());
|
||||
|
||||
if (Server.serverMode == Server.MODE_GAMESERVER)
|
||||
{
|
||||
addPortMapping(Config.PORT_GAME, "L2j Game Server");
|
||||
}
|
||||
else if (Server.serverMode == Server.MODE_LOGINSERVER)
|
||||
{
|
||||
addPortMapping(Config.PORT_LOGIN, "L2j Login Server");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllPorts() throws Exception
|
||||
{
|
||||
if (_activeGW != null)
|
||||
{
|
||||
if (Server.serverMode == Server.MODE_GAMESERVER)
|
||||
{
|
||||
deletePortMapping(Config.PORT_GAME);
|
||||
}
|
||||
else if (Server.serverMode == Server.MODE_LOGINSERVER)
|
||||
{
|
||||
deletePortMapping(Config.PORT_LOGIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPortMapping(int port, String description) throws IOException, SAXException
|
||||
{
|
||||
final PortMappingEntry portMapping = new PortMappingEntry();
|
||||
final InetAddress localAddress = _activeGW.getLocalAddress();
|
||||
|
||||
// Attempt to re-map
|
||||
if (_activeGW.getSpecificPortMappingEntry(port, PROTOCOL, portMapping))
|
||||
{
|
||||
_activeGW.deletePortMapping(port, PROTOCOL);
|
||||
}
|
||||
|
||||
if (_activeGW.addPortMapping(port, port, localAddress.getHostAddress(), PROTOCOL, description))
|
||||
{
|
||||
_log.log(Level.INFO, "Mapping successfull on [" + localAddress.getHostAddress() + ":" + port + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.log(Level.INFO, "Mapping failed on [" + localAddress.getHostAddress() + ":" + port + "] - Already mapped?");
|
||||
}
|
||||
}
|
||||
|
||||
private void deletePortMapping(int port) throws IOException, SAXException
|
||||
{
|
||||
if (_activeGW.deletePortMapping(port, PROTOCOL))
|
||||
{
|
||||
_log.log(Level.INFO, "Mapping was deleted from [" + _activeGW.getLocalAddress().getHostAddress() + ":" + port + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public static UPnPService getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final UPnPService _instance = new UPnPService();
|
||||
}
|
||||
}
|
@@ -33,7 +33,6 @@ import java.util.logging.Logger;
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.Server;
|
||||
import com.l2jserver.UPnPService;
|
||||
import com.l2jserver.commons.mmocore.SelectorConfig;
|
||||
import com.l2jserver.commons.mmocore.SelectorThread;
|
||||
import com.l2jserver.gameserver.cache.HtmCache;
|
||||
@@ -463,9 +462,6 @@ public class GameServer
|
||||
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": Maximum numbers of connected players: " + Config.MAXIMUM_ONLINE_USERS);
|
||||
_log.log(Level.INFO, getClass().getSimpleName() + ": Server loaded in " + ((System.currentTimeMillis() - serverLoadStart) / 1000) + " seconds.");
|
||||
|
||||
printSection("UPnP");
|
||||
UPnPService.getInstance();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
|
@@ -23,7 +23,6 @@ import java.util.logging.Logger;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.UPnPService;
|
||||
import com.l2jserver.gameserver.data.sql.impl.ClanTable;
|
||||
import com.l2jserver.gameserver.data.sql.impl.OfflineTradersTable;
|
||||
import com.l2jserver.gameserver.datatables.BotReportTable;
|
||||
@@ -189,16 +188,6 @@ public class Shutdown extends Thread
|
||||
TimeCounter tc = new TimeCounter();
|
||||
TimeCounter tc1 = new TimeCounter();
|
||||
|
||||
try
|
||||
{
|
||||
UPnPService.getInstance().removeAllPorts();
|
||||
_log.info("UPnP Service: All ports mappings deleted (" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while removing UPnP port mappings: ", t);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS && !Config.STORE_OFFLINE_TRADE_IN_REALTIME)
|
||||
|
@@ -35,7 +35,6 @@ import java.util.logging.Logger;
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.L2DatabaseFactory;
|
||||
import com.l2jserver.Server;
|
||||
import com.l2jserver.UPnPService;
|
||||
import com.l2jserver.commons.mmocore.SelectorConfig;
|
||||
import com.l2jserver.commons.mmocore.SelectorThread;
|
||||
import com.l2jserver.loginserver.network.L2LoginClient;
|
||||
@@ -189,8 +188,6 @@ public final class L2LoginServer
|
||||
_log.log(Level.SEVERE, "FATAL: Failed to open server socket. Reason: " + e.getMessage(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
UPnPService.getInstance();
|
||||
}
|
||||
|
||||
public Status getStatusServer()
|
||||
|
Reference in New Issue
Block a user