GameServerThread.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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.crypt.NewCrypt;
  33. import com.l2jserver.loginserver.gameserverpackets.BlowFishKey;
  34. import com.l2jserver.loginserver.gameserverpackets.ChangeAccessLevel;
  35. import com.l2jserver.loginserver.gameserverpackets.GameServerAuth;
  36. import com.l2jserver.loginserver.gameserverpackets.PlayerAuthRequest;
  37. import com.l2jserver.loginserver.gameserverpackets.PlayerInGame;
  38. import com.l2jserver.loginserver.gameserverpackets.PlayerLogout;
  39. import com.l2jserver.loginserver.gameserverpackets.PlayerTracert;
  40. import com.l2jserver.loginserver.gameserverpackets.ServerStatus;
  41. import com.l2jserver.loginserver.loginserverpackets.AuthResponse;
  42. import com.l2jserver.loginserver.loginserverpackets.InitLS;
  43. import com.l2jserver.loginserver.loginserverpackets.KickPlayer;
  44. import com.l2jserver.loginserver.loginserverpackets.LoginServerFail;
  45. import com.l2jserver.loginserver.loginserverpackets.PlayerAuthResponse;
  46. import com.l2jserver.util.Util;
  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. @SuppressWarnings("unused")
  309. ServerStatus ss = new ServerStatus(data,getServerId()); //will do the actions by itself
  310. }
  311. else
  312. {
  313. forceClose(LoginServerFail.NOT_AUTHED);
  314. }
  315. }
  316. private void onReceivePlayerTracert(byte[] data)
  317. {
  318. if (isAuthed())
  319. {
  320. PlayerTracert plt = new PlayerTracert(data);
  321. LoginController.getInstance().setAccountLastTracert(plt.getAccount(),
  322. plt.getPcIp(), plt.getFirstHop(), plt.getSecondHop(),
  323. plt.getThirdHop(), plt.getFourthHop());
  324. if (Config.DEBUG)
  325. {
  326. _log.info("Saved "+plt.getAccount()+" last tracert");
  327. }
  328. }
  329. else
  330. {
  331. forceClose(LoginServerFail.NOT_AUTHED);
  332. }
  333. }
  334. private void handleRegProcess(GameServerAuth gameServerAuth)
  335. {
  336. GameServerTable gameServerTable = GameServerTable.getInstance();
  337. int id = gameServerAuth.getDesiredID();
  338. byte[] hexId = gameServerAuth.getHexID();
  339. GameServerInfo gsi = gameServerTable.getRegisteredGameServerById(id);
  340. // is there a gameserver registered with this id?
  341. if (gsi != null)
  342. {
  343. // does the hex id match?
  344. if (Arrays.equals(gsi.getHexId(), hexId))
  345. {
  346. // check to see if this GS is already connected
  347. synchronized (gsi)
  348. {
  349. if (gsi.isAuthed())
  350. {
  351. forceClose(LoginServerFail.REASON_ALREADY_LOGGED8IN);
  352. }
  353. else
  354. {
  355. attachGameServerInfo(gsi, gameServerAuth);
  356. }
  357. }
  358. }
  359. else
  360. {
  361. // there is already a server registered with the desired id and different hex id
  362. // try to register this one with an alternative id
  363. if (Config.ACCEPT_NEW_GAMESERVER && gameServerAuth.acceptAlternateID())
  364. {
  365. gsi = new GameServerInfo(id, hexId, this);
  366. if (gameServerTable.registerWithFirstAvaliableId(gsi))
  367. {
  368. attachGameServerInfo(gsi, gameServerAuth);
  369. gameServerTable.registerServerOnDB(gsi);
  370. }
  371. else
  372. {
  373. forceClose(LoginServerFail.REASON_NO_FREE_ID);
  374. }
  375. }
  376. else
  377. {
  378. // server id is already taken, and we cant get a new one for you
  379. forceClose(LoginServerFail.REASON_WRONG_HEXID);
  380. }
  381. }
  382. }
  383. else
  384. {
  385. // can we register on this id?
  386. if (Config.ACCEPT_NEW_GAMESERVER)
  387. {
  388. gsi = new GameServerInfo(id, hexId, this);
  389. if (gameServerTable.register(id, gsi))
  390. {
  391. attachGameServerInfo(gsi, gameServerAuth);
  392. gameServerTable.registerServerOnDB(gsi);
  393. }
  394. else
  395. {
  396. // some one took this ID meanwhile
  397. forceClose(LoginServerFail.REASON_ID_RESERVED);
  398. }
  399. }
  400. else
  401. {
  402. forceClose(LoginServerFail.REASON_WRONG_HEXID);
  403. }
  404. }
  405. }
  406. public boolean hasAccountOnGameServer(String account)
  407. {
  408. return _accountsOnGameServer.contains(account);
  409. }
  410. public int getPlayerCount()
  411. {
  412. return _accountsOnGameServer.size();
  413. }
  414. /**
  415. * Attachs a GameServerInfo to this Thread
  416. * <li>Updates the GameServerInfo values based on GameServerAuth packet</li>
  417. * <li><b>Sets the GameServerInfo as Authed</b></li>
  418. * @param gsi The GameServerInfo to be attached.
  419. * @param gameServerAuth The server info.
  420. */
  421. private void attachGameServerInfo(GameServerInfo gsi, GameServerAuth gameServerAuth)
  422. {
  423. setGameServerInfo(gsi);
  424. gsi.setGameServerThread(this);
  425. gsi.setPort(gameServerAuth.getPort());
  426. setGameHosts(gameServerAuth.getExternalHost(), gameServerAuth.getInternalHost());
  427. gsi.setMaxPlayers(gameServerAuth.getMaxPlayers());
  428. gsi.setAuthed(true);
  429. }
  430. private void forceClose(int reason)
  431. {
  432. LoginServerFail lsf = new LoginServerFail(reason);
  433. try
  434. {
  435. sendPacket(lsf);
  436. }
  437. catch (IOException e)
  438. {
  439. _log.finer("GameServerThread: Failed kicking banned server. Reason: "+e.getMessage());
  440. }
  441. try
  442. {
  443. _connection.close();
  444. }
  445. catch (IOException e)
  446. {
  447. _log.finer("GameServerThread: Failed disconnecting banned server, server already disconnected.");
  448. }
  449. }
  450. /**
  451. *
  452. * @param gameServerauth
  453. */
  454. /*private void handleRegisterationProcess(GameServerAuth gameServerauth)
  455. {
  456. try
  457. {
  458. GameServerTable gsTableInstance = GameServerTable.getInstance();
  459. if (gsTableInstance.isARegisteredServer(gameServerauth.getHexID()))
  460. {
  461. if (Config.DEBUG)
  462. {
  463. _log.info("Valid HexID");
  464. }
  465. _server_id = gsTableInstance.getServerIDforHex(gameServerauth.getHexID());
  466. if (gsTableInstance.isServerAuthed(_server_id))
  467. {
  468. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_ALREADY_LOGGED8IN);
  469. sendPacket(lsf);
  470. _connection.close();
  471. return;
  472. }
  473. _gamePort = gameServerauth.getPort();
  474. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  475. _max_players = gameServerauth.getMaxPlayers();
  476. _hexID = gameServerauth.getHexID();
  477. //gsTableInstance.addServer(this);
  478. }
  479. else if (Config.ACCEPT_NEW_GAMESERVER)
  480. {
  481. if (Config.DEBUG)
  482. {
  483. _log.info("New HexID");
  484. }
  485. if(!gameServerauth.acceptAlternateID())
  486. {
  487. if(gsTableInstance.isIDfree(gameServerauth.getDesiredID()))
  488. {
  489. if (Config.DEBUG)_log.info("Desired ID is Valid");
  490. _server_id = gameServerauth.getDesiredID();
  491. _gamePort = gameServerauth.getPort();
  492. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  493. _max_players = gameServerauth.getMaxPlayers();
  494. _hexID = gameServerauth.getHexID();
  495. gsTableInstance.createServer(this);
  496. //gsTableInstance.addServer(this);
  497. }
  498. else
  499. {
  500. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_ID_RESERVED);
  501. sendPacket(lsf);
  502. _connection.close();
  503. return;
  504. }
  505. }
  506. else
  507. {
  508. int id;
  509. if(!gsTableInstance.isIDfree(gameServerauth.getDesiredID()))
  510. {
  511. id = gsTableInstance.findFreeID();
  512. if (Config.DEBUG)_log.info("Affected New ID:"+id);
  513. if(id < 0)
  514. {
  515. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_NO_FREE_ID);
  516. sendPacket(lsf);
  517. _connection.close();
  518. return;
  519. }
  520. }
  521. else
  522. {
  523. id = gameServerauth.getDesiredID();
  524. if (Config.DEBUG)_log.info("Desired ID is Valid");
  525. }
  526. _server_id = id;
  527. _gamePort = gameServerauth.getPort();
  528. setGameHosts(gameServerauth.getExternalHost(), gameServerauth.getInternalHost());
  529. _max_players = gameServerauth.getMaxPlayers();
  530. _hexID = gameServerauth.getHexID();
  531. gsTableInstance.createServer(this);
  532. //gsTableInstance.addServer(this);
  533. }
  534. }
  535. else
  536. {
  537. _log.info("Wrong HexID");
  538. LoginServerFail lsf = new LoginServerFail(LoginServerFail.REASON_WRONG_HEXID);
  539. sendPacket(lsf);
  540. _connection.close();
  541. return;
  542. }
  543. }
  544. catch (IOException e)
  545. {
  546. _log.info("Error while registering GameServer "+GameServerTable.getInstance().serverNames.get(_server_id)+" (ID:"+_server_id+")");
  547. }
  548. }*/
  549. /**
  550. * @param ipAddress
  551. * @return
  552. */
  553. public static boolean isBannedGameserverIP(String ipAddress)
  554. {
  555. // TODO Auto-generated method stub
  556. return false;
  557. }
  558. public GameServerThread(Socket con)
  559. {
  560. _connection = con;
  561. _connectionIp = con.getInetAddress().getHostAddress();
  562. try
  563. {
  564. _in = _connection.getInputStream();
  565. _out = new BufferedOutputStream(_connection.getOutputStream());
  566. }
  567. catch (IOException e)
  568. {
  569. e.printStackTrace();
  570. }
  571. KeyPair pair = GameServerTable.getInstance().getKeyPair();
  572. _privateKey = (RSAPrivateKey) pair.getPrivate();
  573. _publicKey = (RSAPublicKey) pair.getPublic();
  574. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  575. start();
  576. }
  577. /**
  578. * @param sl
  579. * @throws IOException
  580. */
  581. private void sendPacket(BaseSendablePacket sl) throws IOException
  582. {
  583. byte[] data = sl.getContent();
  584. NewCrypt.appendChecksum(data);
  585. if (Config.DEBUG)
  586. {
  587. _log.finest("[S] "+sl.getClass().getSimpleName()+":\n"+Util.printData(data));
  588. }
  589. data = _blowfish.crypt(data);
  590. int len = data.length+2;
  591. synchronized(_out)
  592. {
  593. _out.write(len & 0xff);
  594. _out.write(len >> 8 &0xff);
  595. _out.write(data);
  596. _out.flush();
  597. }
  598. }
  599. private void broadcastToTelnet(String msg)
  600. {
  601. if (L2LoginServer.getInstance().getStatusServer() != null)
  602. {
  603. L2LoginServer.getInstance().getStatusServer().sendMessageToTelnets(msg);
  604. }
  605. }
  606. public void kickPlayer(String account)
  607. {
  608. KickPlayer kp = new KickPlayer(account);
  609. try
  610. {
  611. sendPacket(kp);
  612. }
  613. catch (IOException e)
  614. {
  615. e.printStackTrace();
  616. }
  617. }
  618. /**
  619. * @param gameHost The gameHost to set.
  620. */
  621. public void setGameHosts(String gameExternalHost, String gameInternalHost)
  622. {
  623. String oldInternal = _gsi.getInternalHost();
  624. String oldExternal = _gsi.getExternalHost();
  625. _gsi.setExternalHost(gameExternalHost);
  626. _gsi.setInternalIp(gameInternalHost);
  627. if (!gameExternalHost.equals("*"))
  628. {
  629. try
  630. {
  631. _gsi.setExternalIp(InetAddress.getByName(gameExternalHost).getHostAddress());
  632. }
  633. catch (UnknownHostException e)
  634. {
  635. _log.warning("Couldn't resolve hostname \""+gameExternalHost+"\"");
  636. }
  637. }
  638. else
  639. {
  640. _gsi.setExternalIp(_connectionIp);
  641. }
  642. if(!gameInternalHost.equals("*"))
  643. {
  644. try
  645. {
  646. _gsi.setInternalIp(InetAddress.getByName(gameInternalHost).getHostAddress());
  647. }
  648. catch (UnknownHostException e)
  649. {
  650. _log.warning("Couldn't resolve hostname \""+gameInternalHost+"\"");
  651. }
  652. }
  653. else
  654. {
  655. _gsi.setInternalIp(_connectionIp);
  656. }
  657. _log.info("Updated Gameserver ["+getServerId()+"] "+GameServerTable.getInstance().getServerNameById(getServerId())+" IP's:");
  658. if (oldInternal == null || !oldInternal.equalsIgnoreCase(gameInternalHost))
  659. _log.info("InternalIP: "+gameInternalHost);
  660. if (oldExternal == null || !oldExternal.equalsIgnoreCase(gameExternalHost))
  661. _log.info("ExternalIP: "+gameExternalHost);
  662. }
  663. /**
  664. * @return Returns the isAuthed.
  665. */
  666. public boolean isAuthed()
  667. {
  668. if (getGameServerInfo() == null)
  669. return false;
  670. return getGameServerInfo().isAuthed();
  671. }
  672. public void setGameServerInfo(GameServerInfo gsi)
  673. {
  674. _gsi = gsi;
  675. }
  676. public GameServerInfo getGameServerInfo()
  677. {
  678. return _gsi;
  679. }
  680. /**
  681. * @return Returns the connectionIpAddress.
  682. */
  683. public String getConnectionIpAddress()
  684. {
  685. return _connectionIPAddress;
  686. }
  687. private int getServerId()
  688. {
  689. if (getGameServerInfo() != null)
  690. {
  691. return getGameServerInfo().getId();
  692. }
  693. return -1;
  694. }
  695. }