GameServerThread.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.loginserver;
  16. import java.io.BufferedOutputStream;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.OutputStream;
  20. import java.net.InetAddress;
  21. import java.net.Socket;
  22. import java.net.UnknownHostException;
  23. import java.security.KeyPair;
  24. import java.security.interfaces.RSAPrivateKey;
  25. import java.security.interfaces.RSAPublicKey;
  26. import java.util.Arrays;
  27. import java.util.List;
  28. import java.util.Set;
  29. import java.util.logging.Logger;
  30. import com.l2jserver.Config;
  31. import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
  32. import com.l2jserver.loginserver.gameserverpackets.BlowFishKey;
  33. import com.l2jserver.loginserver.gameserverpackets.ChangeAccessLevel;
  34. import com.l2jserver.loginserver.gameserverpackets.GameServerAuth;
  35. import com.l2jserver.loginserver.gameserverpackets.PlayerAuthRequest;
  36. import com.l2jserver.loginserver.gameserverpackets.PlayerInGame;
  37. import com.l2jserver.loginserver.gameserverpackets.PlayerLogout;
  38. import com.l2jserver.loginserver.gameserverpackets.PlayerTracert;
  39. import com.l2jserver.loginserver.gameserverpackets.ServerStatus;
  40. import com.l2jserver.loginserver.loginserverpackets.AuthResponse;
  41. import com.l2jserver.loginserver.loginserverpackets.InitLS;
  42. import com.l2jserver.loginserver.loginserverpackets.KickPlayer;
  43. import com.l2jserver.loginserver.loginserverpackets.LoginServerFail;
  44. import com.l2jserver.loginserver.loginserverpackets.PlayerAuthResponse;
  45. import com.l2jserver.util.Util;
  46. import com.l2jserver.util.crypt.NewCrypt;
  47. import com.l2jserver.util.network.BaseSendablePacket;
  48. import javolution.util.FastSet;
  49. /**
  50. * @author -Wooden-
  51. * @author KenM
  52. *
  53. */
  54. public class GameServerThread extends Thread
  55. {
  56. protected static final Logger _log = Logger.getLogger(GameServerThread.class.getName());
  57. private Socket _connection;
  58. private InputStream _in;
  59. private OutputStream _out;
  60. private RSAPublicKey _publicKey;
  61. private RSAPrivateKey _privateKey;
  62. private NewCrypt _blowfish;
  63. private byte[] _blowfishKey;
  64. private String _connectionIp;
  65. private GameServerInfo _gsi;
  66. /** Authed Clients on a GameServer*/
  67. private Set<String> _accountsOnGameServer = new FastSet<String>();
  68. private String _connectionIPAddress;
  69. @Override
  70. public void run()
  71. {
  72. _connectionIPAddress = _connection.getInetAddress().getHostAddress();
  73. if (GameServerThread.isBannedGameserverIP(_connectionIPAddress))
  74. {
  75. _log.info("GameServerRegistration: IP Address " + _connectionIPAddress + " is on Banned IP list.");
  76. forceClose(LoginServerFail.REASON_IP_BANNED);
  77. // ensure no further processing for this connection
  78. return;
  79. }
  80. InitLS startPacket = new InitLS(_publicKey.getModulus().toByteArray());
  81. try
  82. {
  83. sendPacket(startPacket);
  84. int lengthHi = 0;
  85. int lengthLo = 0;
  86. int length = 0;
  87. boolean checksumOk = false;
  88. for (;;)
  89. {
  90. lengthLo = _in.read();
  91. lengthHi = _in.read();
  92. length= lengthHi*256 + lengthLo;
  93. if (lengthHi < 0 || _connection.isClosed())
  94. {
  95. _log.finer("LoginServerThread: Login terminated the connection.");
  96. break;
  97. }
  98. byte[] data = new byte[length - 2];
  99. int receivedBytes = 0;
  100. int newBytes = 0;
  101. int left = length - 2;
  102. while (newBytes != -1 && receivedBytes < length - 2)
  103. {
  104. newBytes = _in.read(data, receivedBytes, left);
  105. receivedBytes = receivedBytes + newBytes;
  106. left -= newBytes;
  107. }
  108. if (receivedBytes != length-2)
  109. {
  110. _log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
  111. break;
  112. }
  113. // decrypt if we have a key
  114. data = _blowfish.decrypt(data);
  115. checksumOk = NewCrypt.verifyChecksum(data);
  116. if (!checksumOk)
  117. {
  118. _log.warning("Incorrect packet checksum, closing connection (LS)");
  119. return;
  120. }
  121. if (Config.DEBUG)
  122. {
  123. _log.warning("[C]\n"+Util.printData(data));
  124. }
  125. int packetType = data[0] & 0xff;
  126. switch (packetType)
  127. {
  128. case 00:
  129. onReceiveBlowfishKey(data);
  130. break;
  131. case 01:
  132. onGameServerAuth(data);
  133. break;
  134. case 02:
  135. onReceivePlayerInGame(data);
  136. break;
  137. case 03:
  138. onReceivePlayerLogOut(data);
  139. break;
  140. case 04:
  141. onReceiveChangeAccessLevel(data);
  142. break;
  143. case 05:
  144. onReceivePlayerAuthRequest(data);
  145. break;
  146. case 06:
  147. onReceiveServerStatus(data);
  148. break;
  149. case 07:
  150. onReceivePlayerTracert(data);
  151. break;
  152. default:
  153. _log.warning("Unknown Opcode ("+Integer.toHexString(packetType).toUpperCase()+") from GameServer, closing connection.");
  154. forceClose(LoginServerFail.NOT_AUTHED);
  155. }
  156. }
  157. }
  158. catch (IOException e)
  159. {
  160. String serverName = (getServerId() != -1 ? "["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId()) : "("+_connectionIPAddress+")");
  161. String msg = "GameServer "+serverName+": Connection lost: "+e.getMessage();
  162. _log.info(msg);
  163. broadcastToTelnet(msg);
  164. }
  165. finally
  166. {
  167. if (isAuthed())
  168. {
  169. _gsi.setDown();
  170. _log.info("Server ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId())+" is now set as disconnected");
  171. }
  172. L2LoginServer.getInstance().getGameServerListener().removeGameServer(this);
  173. L2LoginServer.getInstance().getGameServerListener().removeFloodProtection(_connectionIp);
  174. }
  175. }
  176. private void onReceiveBlowfishKey(byte[] data)
  177. {
  178. /*if (_blowfish == null)
  179. {*/
  180. BlowFishKey bfk = new BlowFishKey(data,_privateKey);
  181. _blowfishKey = bfk.getKey();
  182. _blowfish = new NewCrypt(_blowfishKey);
  183. if (Config.DEBUG)
  184. {
  185. _log.info("New BlowFish key received, Blowfih Engine initialized:");
  186. }
  187. /*}
  188. else
  189. {
  190. _log.warning("GameServer attempted to re-initialize the blowfish key.");
  191. // TODO get a better reason
  192. this.forceClose(LoginServerFail.NOT_AUTHED);
  193. }*/
  194. }
  195. private void onGameServerAuth(byte[] data) throws IOException
  196. {
  197. GameServerAuth gsa = new GameServerAuth(data);
  198. if (Config.DEBUG)
  199. {
  200. _log.info("Auth request received");
  201. }
  202. handleRegProcess(gsa);
  203. if (isAuthed())
  204. {
  205. AuthResponse ar = new AuthResponse(getGameServerInfo().getId());
  206. sendPacket(ar);
  207. if (Config.DEBUG)
  208. {
  209. _log.info("Authed: id: "+getGameServerInfo().getId());
  210. }
  211. broadcastToTelnet("GameServer ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId())+" is connected");
  212. }
  213. }
  214. private void onReceivePlayerInGame(byte[] data)
  215. {
  216. if (isAuthed())
  217. {
  218. PlayerInGame pig = new PlayerInGame(data);
  219. List<String> newAccounts = pig.getAccounts();
  220. for (String account : newAccounts)
  221. {
  222. _accountsOnGameServer.add(account);
  223. if (Config.DEBUG)
  224. {
  225. _log.info("Account "+account+" logged in GameServer: ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId()));
  226. }
  227. broadcastToTelnet("Account "+account+" logged in GameServer "+getServerId());
  228. }
  229. }
  230. else
  231. {
  232. forceClose(LoginServerFail.NOT_AUTHED);
  233. }
  234. }
  235. private void onReceivePlayerLogOut(byte[] data)
  236. {
  237. if (isAuthed())
  238. {
  239. PlayerLogout plo = new PlayerLogout(data);
  240. _accountsOnGameServer.remove(plo.getAccount());
  241. if (Config.DEBUG)
  242. {
  243. _log.info("Player "+plo.getAccount()+" logged out from gameserver ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId()));
  244. }
  245. broadcastToTelnet("Player "+plo.getAccount()+" disconnected from GameServer "+getServerId());
  246. }
  247. else
  248. {
  249. forceClose(LoginServerFail.NOT_AUTHED);
  250. }
  251. }
  252. private void onReceiveChangeAccessLevel(byte[] data)
  253. {
  254. if (isAuthed())
  255. {
  256. ChangeAccessLevel cal = new ChangeAccessLevel(data);
  257. LoginController.getInstance().setAccountAccessLevel(cal.getAccount(),cal.getLevel());
  258. _log.info("Changed "+cal.getAccount()+" access level to "+cal.getLevel());
  259. }
  260. else
  261. {
  262. forceClose(LoginServerFail.NOT_AUTHED);
  263. }
  264. }
  265. private void onReceivePlayerAuthRequest(byte[] data) throws IOException
  266. {
  267. if (isAuthed())
  268. {
  269. PlayerAuthRequest par = new PlayerAuthRequest(data);
  270. PlayerAuthResponse authResponse;
  271. if (Config.DEBUG)
  272. {
  273. _log.info("auth request received for Player "+par.getAccount());
  274. }
  275. SessionKey key = LoginController.getInstance().getKeyForAccount(par.getAccount());
  276. if (key != null && key.equals(par.getKey()))
  277. {
  278. if (Config.DEBUG)
  279. {
  280. _log.info("auth request: OK");
  281. }
  282. LoginController.getInstance().removeAuthedLoginClient(par.getAccount());
  283. authResponse = new PlayerAuthResponse(par.getAccount(), true);
  284. }
  285. else
  286. {
  287. if (Config.DEBUG)
  288. {
  289. _log.info("auth request: NO");
  290. _log.info("session key from self: "+key);
  291. _log.info("session key sent: "+par.getKey());
  292. }
  293. authResponse = new PlayerAuthResponse(par.getAccount(), false);
  294. }
  295. sendPacket(authResponse);
  296. }
  297. else
  298. {
  299. forceClose(LoginServerFail.NOT_AUTHED);
  300. }
  301. }
  302. private void onReceiveServerStatus(byte[] data)
  303. {
  304. if (isAuthed())
  305. {
  306. if (Config.DEBUG)
  307. {
  308. _log.info("ServerStatus received");
  309. }
  310. new ServerStatus(data,getServerId()); //will do the actions by itself
  311. }
  312. else
  313. {
  314. forceClose(LoginServerFail.NOT_AUTHED);
  315. }
  316. }
  317. private void onReceivePlayerTracert(byte[] data)
  318. {
  319. if (isAuthed())
  320. {
  321. PlayerTracert plt = new PlayerTracert(data);
  322. LoginController.getInstance().setAccountLastTracert(plt.getAccount(),
  323. plt.getPcIp(), plt.getFirstHop(), plt.getSecondHop(),
  324. plt.getThirdHop(), plt.getFourthHop());
  325. if (Config.DEBUG)
  326. {
  327. _log.info("Saved "+plt.getAccount()+" last tracert");
  328. }
  329. }
  330. else
  331. {
  332. forceClose(LoginServerFail.NOT_AUTHED);
  333. }
  334. }
  335. private void handleRegProcess(GameServerAuth gameServerAuth)
  336. {
  337. GameServerTable gameServerTable = GameServerTable.getInstance();
  338. int id = gameServerAuth.getDesiredID();
  339. byte[] hexId = gameServerAuth.getHexID();
  340. GameServerInfo gsi = gameServerTable.getRegisteredGameServerById(id);
  341. // is there a gameserver registered with this id?
  342. if (gsi != null)
  343. {
  344. // does the hex id match?
  345. if (Arrays.equals(gsi.getHexId(), hexId))
  346. {
  347. // check to see if this GS is already connected
  348. synchronized (gsi)
  349. {
  350. if (gsi.isAuthed())
  351. {
  352. forceClose(LoginServerFail.REASON_ALREADY_LOGGED8IN);
  353. }
  354. else
  355. {
  356. attachGameServerInfo(gsi, gameServerAuth);
  357. }
  358. }
  359. }
  360. else
  361. {
  362. // there is already a server registered with the desired id and different hex id
  363. // try to register this one with an alternative id
  364. if (Config.ACCEPT_NEW_GAMESERVER && gameServerAuth.acceptAlternateID())
  365. {
  366. gsi = new GameServerInfo(id, hexId, this);
  367. if (gameServerTable.registerWithFirstAvaliableId(gsi))
  368. {
  369. attachGameServerInfo(gsi, gameServerAuth);
  370. gameServerTable.registerServerOnDB(gsi);
  371. }
  372. else
  373. {
  374. forceClose(LoginServerFail.REASON_NO_FREE_ID);
  375. }
  376. }
  377. else
  378. {
  379. // server id is already taken, and we cant get a new one for you
  380. forceClose(LoginServerFail.REASON_WRONG_HEXID);
  381. }
  382. }
  383. }
  384. else
  385. {
  386. // can we register on this id?
  387. if (Config.ACCEPT_NEW_GAMESERVER)
  388. {
  389. gsi = new GameServerInfo(id, hexId, this);
  390. if (gameServerTable.register(id, gsi))
  391. {
  392. attachGameServerInfo(gsi, gameServerAuth);
  393. gameServerTable.registerServerOnDB(gsi);
  394. }
  395. else
  396. {
  397. // some one took this ID meanwhile
  398. forceClose(LoginServerFail.REASON_ID_RESERVED);
  399. }
  400. }
  401. else
  402. {
  403. forceClose(LoginServerFail.REASON_WRONG_HEXID);
  404. }
  405. }
  406. }
  407. public boolean hasAccountOnGameServer(String account)
  408. {
  409. return _accountsOnGameServer.contains(account);
  410. }
  411. public int getPlayerCount()
  412. {
  413. return _accountsOnGameServer.size();
  414. }
  415. /**
  416. * Attachs a GameServerInfo to this Thread
  417. * <li>Updates the GameServerInfo values based on GameServerAuth packet</li>
  418. * <li><b>Sets the GameServerInfo as Authed</b></li>
  419. * @param gsi The GameServerInfo to be attached.
  420. * @param gameServerAuth The server info.
  421. */
  422. private void attachGameServerInfo(GameServerInfo gsi, GameServerAuth gameServerAuth)
  423. {
  424. setGameServerInfo(gsi);
  425. gsi.setGameServerThread(this);
  426. gsi.setPort(gameServerAuth.getPort());
  427. setGameHosts(gameServerAuth.getExternalHost(), gameServerAuth.getInternalHost());
  428. gsi.setMaxPlayers(gameServerAuth.getMaxPlayers());
  429. gsi.setAuthed(true);
  430. }
  431. private void forceClose(int reason)
  432. {
  433. LoginServerFail lsf = new LoginServerFail(reason);
  434. try
  435. {
  436. sendPacket(lsf);
  437. }
  438. catch (IOException e)
  439. {
  440. _log.finer("GameServerThread: Failed kicking banned server. Reason: "+e.getMessage());
  441. }
  442. try
  443. {
  444. _connection.close();
  445. }
  446. catch (IOException e)
  447. {
  448. _log.finer("GameServerThread: Failed disconnecting banned server, server already disconnected.");
  449. }
  450. }
  451. /*private void handleRegisterationProcess(GameServerAuth gameServerauth)
  452. {
  453. try
  454. {
  455. GameServerTable gsTableInstance = GameServerTable.getInstance();
  456. if (gsTableInstance.isARegisteredServer(gameServerauth.getHexID()))
  457. {
  458. if (Config.DEBUG)
  459. {
  460. _log.info("Valid HexID");
  461. }
  462. _server_id = gsTableInstance.getServerIDforHex(gameServerauth.getHexID());
  463. if (gsTableInstance.isServerAuthed(_server_id))
  464. {
  465. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_ALREADY_LOGGED8IN);
  466. sendPacket(lsf);
  467. _connection.close();
  468. return;
  469. }
  470. _gamePort = gameServerauth.getPort();
  471. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  472. _max_players = gameServerauth.getMaxPlayers();
  473. _hexID = gameServerauth.getHexID();
  474. //gsTableInstance.addServer(this);
  475. }
  476. else if (Config.ACCEPT_NEW_GAMESERVER)
  477. {
  478. if (Config.DEBUG)
  479. {
  480. _log.info("New HexID");
  481. }
  482. if(!gameServerauth.acceptAlternateID())
  483. {
  484. if(gsTableInstance.isIDfree(gameServerauth.getDesiredID()))
  485. {
  486. if (Config.DEBUG)_log.info("Desired ID is Valid");
  487. _server_id = gameServerauth.getDesiredID();
  488. _gamePort = gameServerauth.getPort();
  489. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  490. _max_players = gameServerauth.getMaxPlayers();
  491. _hexID = gameServerauth.getHexID();
  492. gsTableInstance.createServer(this);
  493. //gsTableInstance.addServer(this);
  494. }
  495. else
  496. {
  497. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_ID_RESERVED);
  498. sendPacket(lsf);
  499. _connection.close();
  500. return;
  501. }
  502. }
  503. else
  504. {
  505. int id;
  506. if(!gsTableInstance.isIDfree(gameServerauth.getDesiredID()))
  507. {
  508. id = gsTableInstance.findFreeID();
  509. if (Config.DEBUG)_log.info("Affected New ID:"+id);
  510. if(id < 0)
  511. {
  512. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_NO_FREE_ID);
  513. sendPacket(lsf);
  514. _connection.close();
  515. return;
  516. }
  517. }
  518. else
  519. {
  520. id = gameServerauth.getDesiredID();
  521. if (Config.DEBUG)_log.info("Desired ID is Valid");
  522. }
  523. _server_id = id;
  524. _gamePort = gameServerauth.getPort();
  525. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  526. _max_players = gameServerauth.getMaxPlayers();
  527. _hexID = gameServerauth.getHexID();
  528. gsTableInstance.createServer(this);
  529. //gsTableInstance.addServer(this);
  530. }
  531. }
  532. else
  533. {
  534. _log.info("Wrong HexID");
  535. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_WRONG_HEXID);
  536. sendPacket(lsf);
  537. _connection.close();
  538. return;
  539. }
  540. }
  541. catch (IOException e)
  542. {
  543. _log.info("Error while registering GameServer "+GameServerTable.getInstance().serverNames.get(_server_id)+" (ID:"+_server_id+")");
  544. }
  545. }*/
  546. /**
  547. * @param ipAddress
  548. * @return
  549. */
  550. public static boolean isBannedGameserverIP(String ipAddress)
  551. {
  552. return false;
  553. }
  554. public GameServerThread(Socket con)
  555. {
  556. _connection = con;
  557. _connectionIp = con.getInetAddress().getHostAddress();
  558. try
  559. {
  560. _in = _connection.getInputStream();
  561. _out = new BufferedOutputStream(_connection.getOutputStream());
  562. }
  563. catch (IOException e)
  564. {
  565. e.printStackTrace();
  566. }
  567. KeyPair pair = GameServerTable.getInstance().getKeyPair();
  568. _privateKey = (RSAPrivateKey) pair.getPrivate();
  569. _publicKey = (RSAPublicKey) pair.getPublic();
  570. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  571. setName(getClass().getSimpleName()+"-"+getId()+"@"+_connectionIp);
  572. start();
  573. }
  574. /**
  575. * @param sl
  576. * @throws IOException
  577. */
  578. private void sendPacket(BaseSendablePacket sl) throws IOException
  579. {
  580. byte[] data = sl.getContent();
  581. NewCrypt.appendChecksum(data);
  582. if (Config.DEBUG)
  583. {
  584. _log.finest("[S] "+sl.getClass().getSimpleName()+":\n"+Util.printData(data));
  585. }
  586. data = _blowfish.crypt(data);
  587. int len = data.length+2;
  588. synchronized(_out)
  589. {
  590. _out.write(len & 0xff);
  591. _out.write(len >> 8 &0xff);
  592. _out.write(data);
  593. _out.flush();
  594. }
  595. }
  596. private void broadcastToTelnet(String msg)
  597. {
  598. if (L2LoginServer.getInstance().getStatusServer() != null)
  599. {
  600. L2LoginServer.getInstance().getStatusServer().sendMessageToTelnets(msg);
  601. }
  602. }
  603. public void kickPlayer(String account)
  604. {
  605. KickPlayer kp = new KickPlayer(account);
  606. try
  607. {
  608. sendPacket(kp);
  609. }
  610. catch (IOException e)
  611. {
  612. e.printStackTrace();
  613. }
  614. }
  615. /**
  616. * @param gameHost The gameHost to set.
  617. */
  618. public void setGameHosts(String gameExternalHost, String gameInternalHost)
  619. {
  620. String oldInternal = _gsi.getInternalHost();
  621. String oldExternal = _gsi.getExternalHost();
  622. _gsi.setExternalHost(gameExternalHost);
  623. _gsi.setInternalIp(gameInternalHost);
  624. if (!gameExternalHost.equals("*"))
  625. {
  626. try
  627. {
  628. _gsi.setExternalIp(InetAddress.getByName(gameExternalHost).getHostAddress());
  629. }
  630. catch (UnknownHostException e)
  631. {
  632. _log.warning("Couldn't resolve hostname \""+gameExternalHost+"\"");
  633. }
  634. }
  635. else
  636. {
  637. _gsi.setExternalIp(_connectionIp);
  638. }
  639. if(!gameInternalHost.equals("*"))
  640. {
  641. try
  642. {
  643. _gsi.setInternalIp(InetAddress.getByName(gameInternalHost).getHostAddress());
  644. }
  645. catch (UnknownHostException e)
  646. {
  647. _log.warning("Couldn't resolve hostname \""+gameInternalHost+"\"");
  648. }
  649. }
  650. else
  651. {
  652. _gsi.setInternalIp(_connectionIp);
  653. }
  654. _log.info("Updated Gameserver ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId())+" IP's:");
  655. if (oldInternal == null || !oldInternal.equalsIgnoreCase(gameInternalHost))
  656. _log.info("InternalIP: "+gameInternalHost);
  657. if (oldExternal == null || !oldExternal.equalsIgnoreCase(gameExternalHost))
  658. _log.info("ExternalIP: "+gameExternalHost);
  659. }
  660. /**
  661. * @return Returns the isAuthed.
  662. */
  663. public boolean isAuthed()
  664. {
  665. if (getGameServerInfo() == null)
  666. return false;
  667. return getGameServerInfo().isAuthed();
  668. }
  669. public void setGameServerInfo(GameServerInfo gsi)
  670. {
  671. _gsi = gsi;
  672. }
  673. public GameServerInfo getGameServerInfo()
  674. {
  675. return _gsi;
  676. }
  677. /**
  678. * @return Returns the connectionIpAddress.
  679. */
  680. public String getConnectionIpAddress()
  681. {
  682. return _connectionIPAddress;
  683. }
  684. private int getServerId()
  685. {
  686. if (getGameServerInfo() != null)
  687. {
  688. return getGameServerInfo().getId();
  689. }
  690. return -1;
  691. }
  692. }