Advertisement
BezneR

L2Proxy_update_1

Apr 21st, 2021
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 25.81 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/loginserver/data/xml/L2ProxyData.java
  4. ===================================================================
  5. --- java/net/sf/l2j/loginserver/data/xml/L2ProxyData.java   (revision 10)
  6. +++ java/net/sf/l2j/loginserver/data/xml/L2ProxyData.java   (nonexistent)
  7. @@ -1,77 +0,0 @@
  8. -package net.sf.l2j.loginserver.data.xml;
  9. -
  10. -import net.sf.l2j.commons.data.xml.IXmlReader;
  11. -import net.sf.l2j.commons.logging.CLogger;
  12. -import net.sf.l2j.loginserver.model.L2Proxy;
  13. -import org.w3c.dom.Document;
  14. -
  15. -import java.net.UnknownHostException;
  16. -import java.nio.file.Path;
  17. -import java.util.Collection;
  18. -import java.util.HashMap;
  19. -import java.util.Map;
  20. -
  21. -public class L2ProxyData implements IXmlReader
  22. -{    
  23. -    private static final CLogger LOGGER = new CLogger(L2ProxyData.class.getName());
  24. -    private final Map<Integer, L2Proxy> _proxyServers = new HashMap<>();
  25. -    
  26. -    public L2Proxy getProxyById(int proxyId)
  27. -    {
  28. -        return _proxyServers.get(proxyId);
  29. -    }
  30. -    
  31. -    public Collection<L2Proxy> getProxies()
  32. -    {
  33. -        return _proxyServers.values();
  34. -    }
  35. -    
  36. -    @Override
  37. -    public void load()
  38. -    {
  39. -        parseFile("./config/proxy.xml");
  40. -        LOGGER.info("Loaded {} proxy servers.", _proxyServers.size());
  41. -    }
  42. -
  43. -    @Override
  44. -    public void parseDocument(Document doc, Path path)
  45. -    {
  46. -        forEach(doc, "list", listNode ->
  47. -        {
  48. -            forEach(listNode, "gameserver", gameserverNode ->
  49. -            {
  50. -                final var gameserverSet = parseAttributes(gameserverNode);
  51. -                var serverId = gameserverSet.getInteger("serverId");
  52. -                var hidesGameserver = gameserverSet.getBool("hide");
  53. -                
  54. -                forEach(gameserverNode, "proxy", proxyNode -> {
  55. -                    final var proxySet = parseAttributes(proxyNode);
  56. -                    try
  57. -                    {
  58. -                        final var proxy = new L2Proxy(
  59. -                                serverId,
  60. -                                proxySet.getInteger("proxyServerId"),
  61. -                                proxySet.getString("proxyHost"),
  62. -                                proxySet.getInteger("proxyPort"),
  63. -                                hidesGameserver);
  64. -                        _proxyServers.put(proxySet.getInteger("proxyServerId"), proxy);
  65. -                    }
  66. -                    catch (UnknownHostException ex)
  67. -                    {
  68. -                        LOGGER.warn("Failed to process proxy due to badly formatted proxy host", ex);
  69. -                    }
  70. -                });                
  71. -            });
  72. -        });
  73. -    }
  74. -    
  75. -    public static L2ProxyData getInstance()
  76. -    {
  77. -        return L2ProxyData.SingletonHolder.INSTANCE;
  78. -    }
  79. -
  80. -    private static class SingletonHolder
  81. -    {
  82. -        protected static final L2ProxyData INSTANCE = new L2ProxyData();
  83. -    }
  84. -}
  85. \ No newline at end of file
  86. Index: java/net/sf/l2j/loginserver/model/L2ProxyInfo.java
  87. ===================================================================
  88. --- java/net/sf/l2j/loginserver/model/L2ProxyInfo.java  (nonexistent)
  89. +++ java/net/sf/l2j/loginserver/model/L2ProxyInfo.java  (working copy)
  90. @@ -0,0 +1,30 @@
  91. +package net.sf.l2j.loginserver.model;
  92. +
  93. +public class L2ProxyInfo
  94. +{
  95. +    private final int _gameserverId;
  96. +    private final boolean _hidesGameserver;
  97. +    private final boolean _fallbackToGameserver;
  98. +    
  99. +    public L2ProxyInfo(int gameserverId, boolean hidesGameserver, boolean fallbackToGameserver)
  100. +    {
  101. +        _gameserverId = gameserverId;
  102. +        _hidesGameserver = hidesGameserver;
  103. +        _fallbackToGameserver = fallbackToGameserver;
  104. +    }
  105. +
  106. +    public boolean hidesGameserver()
  107. +    {
  108. +        return _hidesGameserver;
  109. +    }
  110. +
  111. +    public int getGameserverId()
  112. +    {
  113. +        return _gameserverId;
  114. +    }
  115. +
  116. +    public boolean isFallbackToGameserver()
  117. +    {
  118. +        return _fallbackToGameserver;
  119. +    }
  120. +}
  121. \ No newline at end of file
  122. Index: config/proxy.xml
  123. ===================================================================
  124. --- config/proxy.xml    (revision 10)
  125. +++ config/proxy.xml    (working copy)
  126. @@ -1,6 +1,18 @@
  127.  <?xml version='1.0' encoding='utf-8'?>
  128.  <list>
  129. -    <gameserver serverId="1" hide="true">
  130. -        <proxy proxyServerId="2" proxyHost="127.0.0.1" proxyPort="7778"/>
  131. +    <config />
  132. +    <!--
  133. +        serverId: The true id of the gameserver
  134. +        hide: When enabled, the true gameserver will not appear in the server list
  135. +        fallbackToGameserver: When the proxy server is down, when true, the real gameserver will appear
  136. +        proxyServerId: The gameserver id that the proxy will use to be listed in the server list
  137. +        proxyHost: The host of the proxy
  138. +        proxyPort: The port of the proxy
  139. +        apiPort: The port of the API for the proxy
  140. +        apiKey: The api key for the proxy api
  141. +    -->
  142. +    <gameserver serverId="1" hide="true" fallbackToGameserver="false">
  143. +        <proxy proxyServerId="2" proxyHost="127.0.0.1" proxyPort="7778" validateHealth="true" apiPort="6969" apiKey="changeit"/>
  144. +        <proxy proxyServerId="3" proxyHost="127.0.0.1" proxyPort="7779" validateHealth="true" apiPort="6969" apiKey="changeit"/>
  145.      </gameserver>
  146.  </list>
  147. \ No newline at end of file
  148. Index: java/net/sf/l2j/Config.java
  149. ===================================================================
  150. --- java/net/sf/l2j/Config.java (revision 10)
  151. +++ java/net/sf/l2j/Config.java (working copy)
  152. @@ -1424,6 +1424,11 @@
  153.         NORMAL_CONNECTION_TIME = server.getProperty("NormalConnectionTime", 700);
  154.         FAST_CONNECTION_TIME = server.getProperty("FastConnectionTime", 350);
  155.         MAX_CONNECTION_PER_IP = server.getProperty("MaxConnectionPerIP", 50);
  156. +      
  157. +       SCHEDULED_THREAD_POOL_COUNT = server.getProperty("ScheduledThreadPoolCount", -1);
  158. +       THREADS_PER_SCHEDULED_THREAD_POOL = server.getProperty("ThreadsPerScheduledThreadPool", 4);
  159. +       INSTANT_THREAD_POOL_COUNT = server.getProperty("InstantThreadPoolCount", -1);
  160. +       THREADS_PER_INSTANT_THREAD_POOL = server.getProperty("ThreadsPerInstantThreadPool", 2);
  161.     }
  162.    
  163.     public static final void loadGameServer()
  164. Index: config/loginserver.properties
  165. ===================================================================
  166. --- config/loginserver.properties   (revision 10)
  167. +++ config/loginserver.properties   (working copy)
  168. @@ -50,4 +50,20 @@
  169.  FastConnectionLimit = 15
  170.  NormalConnectionTime = 700
  171.  FastConnectionTime = 350
  172. -MaxConnectionPerIP = 50
  173. \ No newline at end of file
  174. +MaxConnectionPerIP = 50
  175. +
  176. +# =================================================================
  177. +#                            Threadpool
  178. +# =================================================================
  179. +
  180. +# Determines the amount of scheduled thread pools. If set to -1, the server will decide the amount depending on the available processors.
  181. +ScheduledThreadPoolCount = -1
  182. +
  183. +# Specifies how many threads will be in a single scheduled pool.
  184. +ThreadsPerScheduledThreadPool = 4
  185. +
  186. +# Determines the amount of instant thread pools. If set to -1, the server will decide the amount depending on the available processors.
  187. +InstantThreadPoolCount = -1
  188. +
  189. +# Specifies how many threads will be in a single instant pool.
  190. +ThreadsPerInstantThreadPool = 2
  191. \ No newline at end of file
  192. Index: java/net/sf/l2j/loginserver/data/manager/L2ProxyManager.java
  193. ===================================================================
  194. --- java/net/sf/l2j/loginserver/data/manager/L2ProxyManager.java    (nonexistent)
  195. +++ java/net/sf/l2j/loginserver/data/manager/L2ProxyManager.java    (working copy)
  196. @@ -0,0 +1,98 @@
  197. +package net.sf.l2j.loginserver.data.manager;
  198. +
  199. +import net.sf.l2j.commons.logging.CLogger;
  200. +import net.sf.l2j.commons.pool.ThreadPool;
  201. +import net.sf.l2j.loginserver.data.xml.L2ProxyDataLoader;
  202. +import net.sf.l2j.loginserver.model.L2Proxy;
  203. +import net.sf.l2j.loginserver.model.L2ProxyInfo;
  204. +import net.sf.l2j.util.PredicateHelpers;
  205. +
  206. +import java.io.IOException;
  207. +import java.net.URI;
  208. +import java.net.http.HttpClient;
  209. +import java.net.http.HttpRequest;
  210. +import java.net.http.HttpResponse;
  211. +import java.time.Duration;
  212. +import java.util.Collection;
  213. +import java.util.HashMap;
  214. +import java.util.Map;
  215. +import java.util.concurrent.ScheduledFuture;
  216. +import java.util.stream.Collectors;
  217. +
  218. +public enum L2ProxyManager
  219. +{
  220. +    INSTANCE;
  221. +
  222. +    private final CLogger _logger = new CLogger(L2ProxyDataLoader.class.getName());
  223. +    private ScheduledFuture<?> _statusUpdateTask;
  224. +    private Map<Integer, L2ProxyInfo> _proxyInfo = new HashMap<>();
  225. +    private Map<Integer, L2Proxy> _proxyServers = new HashMap<>();
  226. +    private final HttpClient _httpClient = HttpClient.newHttpClient();
  227. +
  228. +    public synchronized void initialise(Map<Integer, L2ProxyInfo> proxyInfoList, Map<Integer, L2Proxy> proxies)
  229. +    {
  230. +        _proxyInfo = proxyInfoList;
  231. +        _proxyServers = proxies;
  232. +        _logger.info("Loaded {} proxy servers.", _proxyServers.size());
  233. +        
  234. +        if(_statusUpdateTask != null)
  235. +        {
  236. +            _statusUpdateTask.cancel(true);
  237. +        }
  238. +        _statusUpdateTask = ThreadPool.scheduleAtFixedRate(updateProxyHealthTask(), 0, 10000);
  239. +    }
  240. +    
  241. +    public L2Proxy getProxyById(int proxyId)
  242. +    {
  243. +        return _proxyServers.get(proxyId);
  244. +    }
  245. +
  246. +    public Collection<L2Proxy> getProxies()
  247. +    {
  248. +        return _proxyServers.values();
  249. +    }
  250. +
  251. +    public L2ProxyInfo getProxyInfoByGameserverId(int gameserverId)
  252. +    {
  253. +        return _proxyInfo.get(gameserverId);
  254. +    }
  255. +
  256. +    private Runnable updateProxyHealthTask()
  257. +    {
  258. +        return () ->
  259. +        {
  260. +            var distinctProxyHosts = _proxyServers.values().stream()
  261. +                    .filter(L2Proxy::shouldValidateHealth)
  262. +                    .filter(PredicateHelpers.distinctByKeys(L2Proxy::getProxyAddress, L2Proxy::getProxyPort))
  263. +                    .map(x -> new Object() {
  264. +                public final Integer proxyId = x.getProxyServerId();
  265. +                public final String apiHost = x.getProxyAddress().getHostAddress();
  266. +                public final Integer apiPort = x.getApiPort();
  267. +            }).collect(Collectors.toList());
  268. +
  269. +            for (var host : distinctProxyHosts)
  270. +            {
  271. +                var request = HttpRequest.newBuilder(
  272. +                        URI.create(String.format("http://%s:%s/_ping", host.apiHost, host.apiPort)))
  273. +                        .header("accept", "application/json")
  274. +                        .timeout(Duration.ofSeconds(5))
  275. +                        .build();
  276. +
  277. +                try
  278. +                {
  279. +                    var response = _httpClient.send(request, HttpResponse.BodyHandlers.ofString());
  280. +                    if (response.statusCode() == 200 && response.body().equals("pong"))
  281. +                    {
  282. +                        _proxyServers.get(host.proxyId).setHealthy(true);
  283. +                        continue;
  284. +                    }
  285. +                    _proxyServers.get(host.proxyId).setHealthy(false);
  286. +                }
  287. +                catch (IOException | InterruptedException e)
  288. +                {
  289. +                    _proxyServers.get(host.proxyId).setHealthy(false);
  290. +                }
  291. +            }
  292. +        };
  293. +    }
  294. +}
  295. \ No newline at end of file
  296. Index: build.xml
  297. ===================================================================
  298. --- build.xml   (revision 10)
  299. +++ build.xml   (working copy)
  300. @@ -47,6 +47,7 @@
  301.         <mkdir dir="${build.dist.game}/config/en" />
  302.         <mkdir dir="${build.dist.game}/config/en/customs" />
  303.         <mkdir dir="${build.dist.login}/config" />
  304. +       <mkdir dir="${build.dist.login}/config/en" />
  305.         <copy todir="${build.dist.game}/config">
  306.             <fileset dir="config">
  307.                 <include name="*.properties" />
  308. @@ -62,6 +63,8 @@
  309.         <copy todir="${build.dist.game}/config/en">
  310.             <fileset dir="config/en">  
  311.                 <include name="*.properties" />
  312. +               <exclude name="banned_ips.properties" />
  313. +               <exclude name="loginserver.properties" />
  314.             </fileset> 
  315.         </copy>
  316.         <copy todir="${build.dist.game}/config/en/customs">
  317. @@ -77,6 +80,14 @@
  318.                 <include name="proxy.xml" />
  319.             </fileset>
  320.         </copy>
  321. +       <copy todir="${build.dist.login}/config/en">
  322. +           <fileset dir="config/en">
  323. +               <include name="banned_ips.properties" />
  324. +               <include name="logging.properties" />
  325. +               <include name="loginserver.properties" />
  326. +               <include name="proxy.xml" />
  327. +           </fileset>
  328. +       </copy>
  329.         <mkdir dir="${build.dist.game}/data" />
  330.     </target>
  331.  
  332. Index: config/en/proxy.xml
  333. ===================================================================
  334. --- config/en/proxy.xml (nonexistent)
  335. +++ config/en/proxy.xml (working copy)
  336. @@ -0,0 +1,18 @@
  337. +<?xml version='1.0' encoding='utf-8'?>
  338. +<list>
  339. +    <config />
  340. +    <!--
  341. +        serverId: The true id of the gameserver
  342. +        hide: When enabled, the true gameserver will not appear in the server list
  343. +        fallbackToGameserver: When the proxy server is down, when true, the real gameserver will appear
  344. +        proxyServerId: The gameserver id that the proxy will use to be listed in the server list
  345. +        proxyHost: The host of the proxy
  346. +        proxyPort: The port of the proxy
  347. +        apiPort: The port of the API for the proxy
  348. +        apiKey: The api key for the proxy api
  349. +    -->
  350. +    <gameserver serverId="1" hide="true" fallbackToGameserver="false">
  351. +        <proxy proxyServerId="2" proxyHost="127.0.0.1" proxyPort="7778" validateHealth="true" apiPort="6969" apiKey="changeit"/>
  352. +        <proxy proxyServerId="3" proxyHost="127.0.0.1" proxyPort="7779" validateHealth="true" apiPort="6969" apiKey="changeit"/>
  353. +    </gameserver>
  354. +</list>
  355. \ No newline at end of file
  356. Index: java/net/sf/l2j/util/PredicateHelpers.java
  357. ===================================================================
  358. --- java/net/sf/l2j/util/PredicateHelpers.java  (nonexistent)
  359. +++ java/net/sf/l2j/util/PredicateHelpers.java  (working copy)
  360. @@ -0,0 +1,25 @@
  361. +package net.sf.l2j.util;
  362. +
  363. +import java.util.Arrays;
  364. +import java.util.List;
  365. +import java.util.Map;
  366. +import java.util.concurrent.ConcurrentHashMap;
  367. +import java.util.function.Function;
  368. +import java.util.function.Predicate;
  369. +import java.util.stream.Collectors;
  370. +
  371. +public class PredicateHelpers
  372. +{
  373. +    @SafeVarargs
  374. +    public static <T> Predicate<T> distinctByKeys(Function<? super T, ?>... keyExtractors)
  375. +    {
  376. +        final Map<List<?>, Boolean> seen = new ConcurrentHashMap<>();
  377. +        return t ->
  378. +        {
  379. +            final List<?> keys = Arrays.stream(keyExtractors)
  380. +                    .map(ke -> ke.apply(t))
  381. +                    .collect(Collectors.toList());
  382. +            return seen.putIfAbsent(keys, Boolean.TRUE) == null;
  383. +        };
  384. +    }
  385. +}
  386. \ No newline at end of file
  387. Index: java/net/sf/l2j/loginserver/data/xml/L2ProxyDataLoader.java
  388. ===================================================================
  389. --- java/net/sf/l2j/loginserver/data/xml/L2ProxyDataLoader.java (nonexistent)
  390. +++ java/net/sf/l2j/loginserver/data/xml/L2ProxyDataLoader.java (working copy)
  391. @@ -0,0 +1,74 @@
  392. +package net.sf.l2j.loginserver.data.xml;
  393. +
  394. +import net.sf.l2j.commons.data.xml.IXmlReader;
  395. +import net.sf.l2j.commons.logging.CLogger;
  396. +import net.sf.l2j.loginserver.data.manager.L2ProxyManager;
  397. +import net.sf.l2j.loginserver.model.L2Proxy;
  398. +import net.sf.l2j.loginserver.model.L2ProxyInfo;
  399. +import org.w3c.dom.Document;
  400. +
  401. +import java.net.UnknownHostException;
  402. +import java.nio.file.Path;
  403. +import java.util.HashMap;
  404. +
  405. +public class L2ProxyDataLoader implements IXmlReader
  406. +{
  407. +    private static final CLogger LOGGER = new CLogger(L2ProxyDataLoader.class.getName());
  408. +    
  409. +    @Override
  410. +    public void load()
  411. +    {
  412. +        parseFile("./config/proxy.xml");        
  413. +    }
  414. +
  415. +    @Override
  416. +    public void parseDocument(Document doc, Path path)
  417. +    {        
  418. +        var proxyInfoList = new HashMap<Integer, L2ProxyInfo>();
  419. +        var proxies = new HashMap<Integer, L2Proxy>();
  420. +        forEach(doc, "list", listNode ->
  421. +        {
  422. +            forEach(listNode, "gameserver", gameserverNode ->
  423. +            {
  424. +                final var gameserverSet = parseAttributes(gameserverNode);
  425. +                var serverId = gameserverSet.getInteger("serverId");
  426. +                var hidesGameserver = gameserverSet.getBool("hide");
  427. +                var fallbackToGameserver = gameserverSet.getBool("fallbackToGameserver");
  428. +                var proxyInfo = new L2ProxyInfo(serverId, hidesGameserver, fallbackToGameserver);
  429. +                proxyInfoList.put(serverId, proxyInfo);
  430. +                
  431. +                forEach(gameserverNode, "proxy", proxyNode ->
  432. +                {
  433. +                    final var proxySet = parseAttributes(proxyNode);
  434. +                    try
  435. +                    {
  436. +                        final var proxy = new L2Proxy(
  437. +                                serverId,
  438. +                                proxySet.getInteger("proxyServerId"),
  439. +                                proxySet.getString("proxyHost"),
  440. +                                proxySet.getInteger("proxyPort"),
  441. +                                proxySet.getString("apiKey"),
  442. +                                proxySet.getInteger("apiPort"),
  443. +                                proxySet.getBool("validateHealth"));
  444. +                        proxies.put(proxySet.getInteger("proxyServerId"), proxy);
  445. +                    }
  446. +                    catch (UnknownHostException ex)
  447. +                    {
  448. +                        LOGGER.warn("Failed to process proxy due to badly formatted proxy host", ex);
  449. +                    }
  450. +                });                
  451. +            });
  452. +        });
  453. +        L2ProxyManager.INSTANCE.initialise(proxyInfoList, proxies);
  454. +    }
  455. +    
  456. +    public static L2ProxyDataLoader getInstance()
  457. +    {
  458. +        return SingletonHolder.INSTANCE;
  459. +    }
  460. +
  461. +    private static class SingletonHolder
  462. +    {
  463. +        protected static final L2ProxyDataLoader INSTANCE = new L2ProxyDataLoader();
  464. +    }
  465. +}
  466. \ No newline at end of file
  467. Index: java/net/sf/l2j/loginserver/LoginServer.java
  468. ===================================================================
  469. --- java/net/sf/l2j/loginserver/LoginServer.java    (revision 10)
  470. +++ java/net/sf/l2j/loginserver/LoginServer.java    (working copy)
  471. @@ -13,12 +13,13 @@
  472.  import net.sf.l2j.commons.mmocore.SelectorConfig;
  473.  import net.sf.l2j.commons.mmocore.SelectorThread;
  474.  import net.sf.l2j.commons.pool.ConnectionPool;
  475. +import net.sf.l2j.commons.pool.ThreadPool;
  476.  
  477.  import net.sf.l2j.Config;
  478.  import net.sf.l2j.loginserver.data.manager.GameServerManager;
  479.  import net.sf.l2j.loginserver.data.manager.IpBanManager;
  480.  import net.sf.l2j.loginserver.data.sql.AccountTable;
  481. -import net.sf.l2j.loginserver.data.xml.L2ProxyData;
  482. +import net.sf.l2j.loginserver.data.xml.L2ProxyDataLoader;
  483.  import net.sf.l2j.loginserver.network.LoginClient;
  484.  import net.sf.l2j.loginserver.network.LoginPacketHandler;
  485.  
  486. @@ -56,6 +57,7 @@
  487.        
  488.         StringUtil.printSection("Poolers");
  489.         ConnectionPool.init();
  490. +       ThreadPool.init();
  491.        
  492.         AccountTable.getInstance();
  493.        
  494. @@ -66,7 +68,7 @@
  495.         GameServerManager.getInstance();
  496.        
  497.         StringUtil.printSection("L2Proxy");
  498. -       L2ProxyData.getInstance().load();
  499. +       L2ProxyDataLoader.getInstance().load();
  500.        
  501.         StringUtil.printSection("Ban List");
  502.         IpBanManager.getInstance();
  503. Index: config/en/loginserver.properties
  504. ===================================================================
  505. --- config/en/loginserver.properties    (revision 10)
  506. +++ config/en/loginserver.properties    (working copy)
  507. @@ -53,4 +53,20 @@
  508.  FastConnectionLimit = 15
  509.  NormalConnectionTime = 700
  510.  FastConnectionTime = 350
  511. -MaxConnectionPerIP = 50
  512. \ No newline at end of file
  513. +MaxConnectionPerIP = 50
  514. +
  515. +# =================================================================
  516. +#                            Threadpool
  517. +# =================================================================
  518. +
  519. +# Determines the amount of scheduled thread pools. If set to -1, the server will decide the amount depending on the available processors.
  520. +ScheduledThreadPoolCount = -1
  521. +
  522. +# Specifies how many threads will be in a single scheduled pool.
  523. +ThreadsPerScheduledThreadPool = 4
  524. +
  525. +# Determines the amount of instant thread pools. If set to -1, the server will decide the amount depending on the available processors.
  526. +InstantThreadPoolCount = -1
  527. +
  528. +# Specifies how many threads will be in a single instant pool.
  529. +ThreadsPerInstantThreadPool = 2
  530. \ No newline at end of file
  531. Index: java/net/sf/l2j/loginserver/model/Account.java
  532. ===================================================================
  533. --- java/net/sf/l2j/loginserver/model/Account.java  (revision 10)
  534. +++ java/net/sf/l2j/loginserver/model/Account.java  (working copy)
  535. @@ -3,8 +3,8 @@
  536.  import net.sf.l2j.commons.network.ServerType;
  537.  
  538.  import net.sf.l2j.loginserver.data.manager.GameServerManager;
  539. +import net.sf.l2j.loginserver.data.manager.L2ProxyManager;
  540.  import net.sf.l2j.loginserver.data.sql.AccountTable;
  541. -import net.sf.l2j.loginserver.data.xml.L2ProxyData;
  542.  
  543.  public final class Account
  544.  {
  545. @@ -44,7 +44,7 @@
  546.     public final boolean isLoginPossible(int serverId)
  547.     {
  548.         GameServerInfo gsi = GameServerManager.getInstance().getRegisteredGameServers().get(serverId);
  549. -       L2Proxy proxy = L2ProxyData.getInstance().getProxyById(serverId);
  550. +       L2Proxy proxy = L2ProxyManager.INSTANCE.getProxyById(serverId);
  551.                
  552.         if(gsi == null && proxy != null)
  553.             gsi = GameServerManager.getInstance().getRegisteredGameServers().get(proxy.getGameserverId());
  554. Index: java/net/sf/l2j/loginserver/network/serverpackets/ServerList.java
  555. ===================================================================
  556. --- java/net/sf/l2j/loginserver/network/serverpackets/ServerList.java   (revision 10)
  557. +++ java/net/sf/l2j/loginserver/network/serverpackets/ServerList.java   (working copy)
  558. @@ -10,7 +10,7 @@
  559.  import net.sf.l2j.commons.network.ServerType;
  560.  
  561.  import net.sf.l2j.loginserver.data.manager.GameServerManager;
  562. -import net.sf.l2j.loginserver.data.xml.L2ProxyData;
  563. +import net.sf.l2j.loginserver.data.manager.L2ProxyManager;
  564.  import net.sf.l2j.loginserver.model.Account;
  565.  import net.sf.l2j.loginserver.model.GameServerInfo;
  566.  import net.sf.l2j.loginserver.model.L2Proxy;
  567. @@ -33,21 +33,35 @@
  568.             final ServerType type = (account.getAccessLevel() < 0 || (gsi.getType() == ServerType.GM_ONLY && account.getAccessLevel() <= 0)) ? ServerType.DOWN : gsi.getType();
  569.             final String hostName = gsi.getHostName();
  570.            
  571. -           var proxiesForGameserver = L2ProxyData.getInstance().getProxies().stream()
  572. +           var proxyInfo = L2ProxyManager.INSTANCE.getProxyInfoByGameserverId(gsi.getId());
  573. +                      
  574. +           if(proxyInfo == null)
  575. +           {
  576. +               _servers.add(new ServerData(type, hostName, gsi));
  577. +               continue;
  578. +           }
  579. +                      
  580. +           var proxiesForGameserver = L2ProxyManager.INSTANCE.getProxies().stream()
  581.                 .filter(x -> x.getGameserverId() == gsi.getId()).collect(Collectors.toList());
  582. -                          
  583. -           if(proxiesForGameserver.stream().noneMatch(L2Proxy::hidesGameserver))
  584. +                      
  585. +           if(!proxyInfo.hidesGameserver())
  586.             {
  587.                 _servers.add(new ServerData(type, hostName, gsi));
  588.             }
  589. -              
  590. +          
  591. +           if(proxyInfo.isFallbackToGameserver() && proxiesForGameserver.stream().noneMatch(L2Proxy::isHealthy))
  592. +           {
  593. +               _servers.add(new ServerData(type, hostName, gsi));
  594. +           }
  595. +                      
  596.             proxiesForGameserver.forEach(l2Proxy ->
  597.             {
  598. -               _servers.add(new ServerData(type, l2Proxy.getProxyServerId(), l2Proxy.getProxyAddress().getHostAddress(), l2Proxy.getProxyPort(), gsi));
  599. +               var newType = l2Proxy.isHealthy() ? ServerType.GOOD : ServerType.DOWN;                
  600. +               _servers.add(new ServerData(newType, l2Proxy.getProxyServerId(), l2Proxy.getProxyAddress().getHostAddress(), l2Proxy.getProxyPort(), gsi));
  601.             });
  602. -                      
  603. -           _servers.sort(SERVER_DATA_COMPARATOR);
  604.         }
  605. +                  
  606. +       _servers.sort(SERVER_DATA_COMPARATOR);
  607.     }
  608.    
  609.     @Override
  610. Index: java/net/sf/l2j/loginserver/model/L2Proxy.java
  611. ===================================================================
  612. --- java/net/sf/l2j/loginserver/model/L2Proxy.java  (revision 10)
  613. +++ java/net/sf/l2j/loginserver/model/L2Proxy.java  (working copy)
  614. @@ -9,15 +9,21 @@
  615.      private final int _proxyServerId;
  616.      private final InetAddress _proxyAddress;
  617.      private final int _proxyPort;
  618. -    private final boolean _hidesGameserver;
  619. +    private final String _apiKey;
  620. +    private final int _apiPort;
  621. +    private final boolean _validateHealth;
  622. +    private boolean _isHealthy = true;
  623. +    private int _maxConnections = -1;
  624.  
  625. -    public L2Proxy(int gameserverId, int proxyServerId, String proxyHost, int proxyPort, boolean hidesGameserver) throws UnknownHostException
  626. +    public L2Proxy(int gameserverId, int proxyServerId, String proxyHost, int proxyPort, String apiKey, int apiPort, boolean validateHealth) throws UnknownHostException
  627.      {
  628.          _gameserverId = gameserverId;
  629.          _proxyServerId = proxyServerId;
  630.          _proxyAddress = InetAddress.getByName(proxyHost);
  631.          _proxyPort = proxyPort;
  632. -        _hidesGameserver = hidesGameserver;
  633. +        _apiKey = apiKey;
  634. +        _apiPort = apiPort;
  635. +        _validateHealth = validateHealth;
  636.      }
  637.  
  638.      public int getGameserverId()
  639. @@ -40,8 +46,38 @@
  640.          return _proxyPort;
  641.      }
  642.  
  643. -    public boolean hidesGameserver()
  644. +    public boolean isHealthy()
  645.      {
  646. -        return _hidesGameserver;
  647. +        return _isHealthy;
  648.      }
  649. +
  650. +    public void setHealthy(boolean healthy)
  651. +    {
  652. +        _isHealthy = healthy;
  653. +    }
  654. +
  655. +    public int getMaxConnections()
  656. +    {
  657. +        return _maxConnections;
  658. +    }
  659. +
  660. +    public void setMaxConnections(int maxConnections)
  661. +    {
  662. +        _maxConnections = maxConnections;
  663. +    }
  664. +
  665. +    public String getApiKey()
  666. +    {
  667. +        return _apiKey;
  668. +    }
  669. +
  670. +    public int getApiPort()
  671. +    {
  672. +        return _apiPort;
  673. +    }
  674. +
  675. +    public boolean shouldValidateHealth()
  676. +    {
  677. +        return _validateHealth;
  678. +    }
  679.  }
  680. \ No newline at end of file
  681.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement