GameServerThread.java 19 KB

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