2
0

GameServerThread.java 20 KB

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