GameServerThread.java 20 KB

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