LoginServerThread.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver;
  16. import java.io.BufferedOutputStream;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.OutputStream;
  20. import java.math.BigInteger;
  21. import java.net.Socket;
  22. import java.net.SocketException;
  23. import java.net.UnknownHostException;
  24. import java.security.GeneralSecurityException;
  25. import java.security.KeyFactory;
  26. import java.security.interfaces.RSAPublicKey;
  27. import java.security.spec.RSAKeyGenParameterSpec;
  28. import java.security.spec.RSAPublicKeySpec;
  29. import java.sql.Connection;
  30. import java.sql.PreparedStatement;
  31. import java.sql.ResultSet;
  32. import java.sql.SQLException;
  33. import java.util.ArrayList;
  34. import java.util.List;
  35. import java.util.Map;
  36. import java.util.logging.Level;
  37. import java.util.logging.LogRecord;
  38. import java.util.logging.Logger;
  39. import javolution.util.FastList;
  40. import javolution.util.FastMap;
  41. import com.l2jserver.Config;
  42. import com.l2jserver.L2DatabaseFactory;
  43. import com.l2jserver.gameserver.model.L2World;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.network.L2GameClient;
  46. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  47. import com.l2jserver.gameserver.network.SystemMessageId;
  48. import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
  49. import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
  50. import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
  51. import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
  52. import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
  53. import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
  54. import com.l2jserver.gameserver.network.gameserverpackets.PlayerTracert;
  55. import com.l2jserver.gameserver.network.gameserverpackets.ReplyCharacters;
  56. import com.l2jserver.gameserver.network.gameserverpackets.SendMail;
  57. import com.l2jserver.gameserver.network.gameserverpackets.ServerStatus;
  58. import com.l2jserver.gameserver.network.gameserverpackets.TempBan;
  59. import com.l2jserver.gameserver.network.loginserverpackets.AuthResponse;
  60. import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
  61. import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
  62. import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
  63. import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
  64. import com.l2jserver.gameserver.network.loginserverpackets.RequestCharacters;
  65. import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  66. import com.l2jserver.gameserver.network.serverpackets.LoginFail;
  67. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  68. import com.l2jserver.util.Util;
  69. import com.l2jserver.util.crypt.NewCrypt;
  70. import com.l2jserver.util.network.BaseSendablePacket;
  71. public class LoginServerThread extends Thread
  72. {
  73. protected static final Logger _log = Logger.getLogger(LoginServerThread.class.getName());
  74. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  75. /** {@see com.l2jserver.loginserver.LoginServer#PROTOCOL_REV } */
  76. private static final int REVISION = 0x0106;
  77. private RSAPublicKey _publicKey;
  78. private String _hostname;
  79. private int _port;
  80. private int _gamePort;
  81. private Socket _loginSocket;
  82. private InputStream _in;
  83. private OutputStream _out;
  84. /**
  85. * The BlowFish engine used to encrypt packets<br>
  86. * It is first initialized with a unified key:<br>
  87. * "_;v.]05-31!|+-%xT!^[$\00"<br>
  88. * <br>
  89. * and then after handshake, with a new key sent by<br>
  90. * loginserver during the handshake. This new key is stored<br>
  91. * in {@link #_blowfishKey}
  92. */
  93. private NewCrypt _blowfish;
  94. private byte[] _blowfishKey;
  95. private byte[] _hexID;
  96. private boolean _acceptAlternate;
  97. private int _requestID;
  98. private int _serverID;
  99. private boolean _reserveHost;
  100. private int _maxPlayer;
  101. private List<WaitingClient> _waitingClients;
  102. private Map<String, L2GameClient> _accountsInGameServer;
  103. private int _status;
  104. private String _serverName;
  105. private String[] _subnets;
  106. private String[] _hosts;
  107. private LoginServerThread()
  108. {
  109. super("LoginServerThread");
  110. _port = Config.GAME_SERVER_LOGIN_PORT;
  111. _gamePort = Config.PORT_GAME;
  112. _hostname = Config.GAME_SERVER_LOGIN_HOST;
  113. _hexID = Config.HEX_ID;
  114. if (_hexID == null)
  115. {
  116. _requestID = Config.REQUEST_ID;
  117. _hexID = Util.generateHex(16);
  118. }
  119. else
  120. {
  121. _requestID = Config.SERVER_ID;
  122. }
  123. _acceptAlternate = Config.ACCEPT_ALTERNATE_ID;
  124. _reserveHost = Config.RESERVE_HOST_ON_LOGIN;
  125. _subnets = Config.GAME_SERVER_SUBNETS;
  126. _hosts = Config.GAME_SERVER_HOSTS;
  127. _waitingClients = new FastList<WaitingClient>();
  128. _accountsInGameServer = new FastMap<String, L2GameClient>().shared();
  129. _maxPlayer = Config.MAXIMUM_ONLINE_USERS;
  130. }
  131. public static LoginServerThread getInstance()
  132. {
  133. return SingletonHolder._instance;
  134. }
  135. @Override
  136. public void run()
  137. {
  138. while (!isInterrupted())
  139. {
  140. int lengthHi = 0;
  141. int lengthLo = 0;
  142. int length = 0;
  143. boolean checksumOk = false;
  144. try
  145. {
  146. // Connection
  147. _log.info("Connecting to login on " + _hostname + ":" + _port);
  148. _loginSocket = new Socket(_hostname, _port);
  149. _in = _loginSocket.getInputStream();
  150. _out = new BufferedOutputStream(_loginSocket.getOutputStream());
  151. //init Blowfish
  152. _blowfishKey = Util.generateHex(40);
  153. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  154. while (!isInterrupted())
  155. {
  156. lengthLo = _in.read();
  157. lengthHi = _in.read();
  158. length = lengthHi * 256 + lengthLo;
  159. if (lengthHi < 0)
  160. {
  161. _log.finer("LoginServerThread: Login terminated the connection.");
  162. break;
  163. }
  164. byte[] incoming = new byte[length - 2];
  165. int receivedBytes = 0;
  166. int newBytes = 0;
  167. int left = length - 2;
  168. while (newBytes != -1 && receivedBytes < length - 2)
  169. {
  170. newBytes = _in.read(incoming, receivedBytes, left);
  171. receivedBytes = receivedBytes + newBytes;
  172. left -= newBytes;
  173. }
  174. if (receivedBytes != length - 2)
  175. {
  176. _log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
  177. break;
  178. }
  179. // decrypt if we have a key
  180. byte[] decrypt = _blowfish.decrypt(incoming);
  181. checksumOk = NewCrypt.verifyChecksum(decrypt);
  182. if (!checksumOk)
  183. {
  184. _log.warning("Incorrect packet checksum, ignoring packet (LS)");
  185. break;
  186. }
  187. if (Config.DEBUG)
  188. _log.warning("[C]\n" + Util.printData(decrypt));
  189. int packetType = decrypt[0] & 0xff;
  190. switch (packetType)
  191. {
  192. case 0x00:
  193. InitLS init = new InitLS(decrypt);
  194. if (Config.DEBUG)
  195. _log.info("Init received");
  196. if (init.getRevision() != REVISION)
  197. {
  198. //TODO: revision mismatch
  199. _log.warning("/!\\ Revision mismatch between LS and GS /!\\");
  200. break;
  201. }
  202. try
  203. {
  204. KeyFactory kfac = KeyFactory.getInstance("RSA");
  205. BigInteger modulus = new BigInteger(init.getRSAKey());
  206. RSAPublicKeySpec kspec1 = new RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4);
  207. _publicKey = (RSAPublicKey) kfac.generatePublic(kspec1);
  208. if (Config.DEBUG)
  209. _log.info("RSA key set up");
  210. }
  211. catch (GeneralSecurityException e)
  212. {
  213. _log.warning("Troubles while init the public key send by login");
  214. break;
  215. }
  216. //send the blowfish key through the rsa encryption
  217. BlowFishKey bfk = new BlowFishKey(_blowfishKey, _publicKey);
  218. sendPacket(bfk);
  219. if (Config.DEBUG)
  220. _log.info("Sent new blowfish key");
  221. //now, only accept paket with the new encryption
  222. _blowfish = new NewCrypt(_blowfishKey);
  223. if (Config.DEBUG)
  224. _log.info("Changed blowfish key");
  225. AuthRequest ar = new AuthRequest(_requestID, _acceptAlternate, _hexID, _gamePort, _reserveHost, _maxPlayer, _subnets, _hosts);
  226. sendPacket(ar);
  227. if (Config.DEBUG)
  228. _log.info("Sent AuthRequest to login");
  229. break;
  230. case 0x01:
  231. LoginServerFail lsf = new LoginServerFail(decrypt);
  232. _log.info("Damn! Registeration Failed: " + lsf.getReasonString());
  233. // login will close the connection here
  234. break;
  235. case 0x02:
  236. AuthResponse aresp = new AuthResponse(decrypt);
  237. _serverID = aresp.getServerId();
  238. _serverName = aresp.getServerName();
  239. Config.saveHexid(_serverID, hexToString(_hexID));
  240. _log.info("Registered on login as Server " + _serverID + " : " + _serverName);
  241. ServerStatus st = new ServerStatus();
  242. if (Config.SERVER_LIST_BRACKET)
  243. {
  244. st.addAttribute(ServerStatus.SERVER_LIST_SQUARE_BRACKET, ServerStatus.ON);
  245. }
  246. else
  247. {
  248. st.addAttribute(ServerStatus.SERVER_LIST_SQUARE_BRACKET, ServerStatus.OFF);
  249. }
  250. st.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  251. if (Config.SERVER_GMONLY)
  252. {
  253. st.addAttribute(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  254. }
  255. else
  256. {
  257. st.addAttribute(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  258. }
  259. if (Config.SERVER_LIST_AGE == 15)
  260. {
  261. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_15);
  262. }
  263. else if (Config.SERVER_LIST_AGE == 18)
  264. {
  265. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_18);
  266. }
  267. else
  268. {
  269. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_ALL);
  270. }
  271. sendPacket(st);
  272. if (L2World.getInstance().getAllPlayersCount() > 0)
  273. {
  274. FastList<String> playerList = new FastList<String>();
  275. //synchronized (L2World.getInstance().getAllPlayers())
  276. {
  277. for (L2PcInstance player : L2World.getInstance().getAllPlayersArray())
  278. playerList.add(player.getAccountName());
  279. }
  280. PlayerInGame pig = new PlayerInGame(playerList);
  281. sendPacket(pig);
  282. }
  283. break;
  284. case 0x03:
  285. PlayerAuthResponse par = new PlayerAuthResponse(decrypt);
  286. String account = par.getAccount();
  287. WaitingClient wcToRemove = null;
  288. synchronized (_waitingClients)
  289. {
  290. for (WaitingClient wc : _waitingClients)
  291. {
  292. if (wc.account.equals(account))
  293. {
  294. wcToRemove = wc;
  295. }
  296. }
  297. }
  298. if (wcToRemove != null)
  299. {
  300. if (par.isAuthed())
  301. {
  302. if (Config.DEBUG)
  303. _log.info("Login accepted player " + wcToRemove.account + " waited("
  304. + (GameTimeController.getGameTicks() - wcToRemove.timestamp) + "ms)");
  305. PlayerInGame pig = new PlayerInGame(par.getAccount());
  306. sendPacket(pig);
  307. wcToRemove.gameClient.setState(GameClientState.AUTHED);
  308. wcToRemove.gameClient.setSessionId(wcToRemove.session);
  309. CharSelectionInfo cl = new CharSelectionInfo(wcToRemove.account, wcToRemove.gameClient.getSessionId().playOkID1);
  310. wcToRemove.gameClient.getConnection().sendPacket(cl);
  311. wcToRemove.gameClient.setCharSelection(cl.getCharInfo());
  312. }
  313. else
  314. {
  315. _log.warning("Session key is not correct. Closing connection for account " + wcToRemove.account + ".");
  316. //wcToRemove.gameClient.getConnection().sendPacket(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  317. wcToRemove.gameClient.close(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  318. _accountsInGameServer.remove(wcToRemove.account);
  319. }
  320. _waitingClients.remove(wcToRemove);
  321. }
  322. break;
  323. case 0x04:
  324. KickPlayer kp = new KickPlayer(decrypt);
  325. doKickPlayer(kp.getAccount());
  326. break;
  327. case 0x05:
  328. RequestCharacters rc = new RequestCharacters(decrypt);
  329. getCharsOnServer(rc.getAccount());
  330. break;
  331. }
  332. }
  333. }
  334. catch (UnknownHostException e)
  335. {
  336. if (Config.DEBUG)
  337. _log.log(Level.WARNING, "", e);
  338. }
  339. catch (SocketException e)
  340. {
  341. _log.warning("LoginServer not avaible, trying to reconnect...");
  342. }
  343. catch (IOException e)
  344. {
  345. _log.log(Level.WARNING, "Disconnected from Login, Trying to reconnect: " + e.getMessage(), e);
  346. }
  347. finally
  348. {
  349. try
  350. {
  351. _loginSocket.close();
  352. if (isInterrupted())
  353. return;
  354. }
  355. catch (Exception e)
  356. {
  357. }
  358. }
  359. try
  360. {
  361. Thread.sleep(5000); // 5 seconds tempo.
  362. }
  363. catch (InterruptedException e)
  364. {
  365. return; // never swallow an interrupt!
  366. }
  367. }
  368. }
  369. public void addWaitingClientAndSendRequest(String acc, L2GameClient client, SessionKey key)
  370. {
  371. if (Config.DEBUG)
  372. _log.info(String.valueOf(key));
  373. WaitingClient wc = new WaitingClient(acc, client, key);
  374. synchronized (_waitingClients)
  375. {
  376. _waitingClients.add(wc);
  377. }
  378. PlayerAuthRequest par = new PlayerAuthRequest(acc, key);
  379. try
  380. {
  381. sendPacket(par);
  382. }
  383. catch (IOException e)
  384. {
  385. _log.warning("Error while sending player auth request");
  386. if (Config.DEBUG)
  387. _log.log(Level.WARNING, "", e);
  388. }
  389. }
  390. public void removeWaitingClient(L2GameClient client)
  391. {
  392. WaitingClient toRemove = null;
  393. synchronized (_waitingClients)
  394. {
  395. for (WaitingClient c : _waitingClients)
  396. {
  397. if (c.gameClient == client)
  398. {
  399. toRemove = c;
  400. }
  401. }
  402. if (toRemove != null)
  403. _waitingClients.remove(toRemove);
  404. }
  405. }
  406. public void sendLogout(String account)
  407. {
  408. if (account == null)
  409. return;
  410. PlayerLogout pl = new PlayerLogout(account);
  411. try
  412. {
  413. sendPacket(pl);
  414. }
  415. catch (IOException e)
  416. {
  417. _log.warning("Error while sending logout packet to login");
  418. if (Config.DEBUG)
  419. _log.log(Level.WARNING, "", e);
  420. }
  421. finally
  422. {
  423. _accountsInGameServer.remove(account);
  424. }
  425. }
  426. public void addGameServerLogin(String account, L2GameClient client)
  427. {
  428. _accountsInGameServer.put(account, client);
  429. }
  430. public void sendAccessLevel(String account, int level)
  431. {
  432. ChangeAccessLevel cal = new ChangeAccessLevel(account, level);
  433. try
  434. {
  435. sendPacket(cal);
  436. }
  437. catch (IOException e)
  438. {
  439. if (Config.DEBUG)
  440. _log.log(Level.WARNING, "", e);
  441. }
  442. }
  443. public void sendClientTracert(String account, String[] adress)
  444. {
  445. PlayerTracert ptc = new PlayerTracert(account, adress[0], adress[1], adress[2], adress[3], adress[4]);
  446. try
  447. {
  448. sendPacket(ptc);
  449. }
  450. catch (IOException e)
  451. {
  452. if (Config.DEBUG)
  453. _log.log(Level.WARNING, "", e);
  454. }
  455. }
  456. public void sendMail(String account, String mailId, String... args)
  457. {
  458. SendMail sem = new SendMail(account, mailId, args);
  459. try
  460. {
  461. sendPacket(sem);
  462. }
  463. catch (IOException e)
  464. {
  465. if (Config.DEBUG)
  466. _log.log(Level.WARNING, "", e);
  467. }
  468. }
  469. public void sendTempBan(String account, String ip, long time)
  470. {
  471. TempBan tbn = new TempBan(account, ip, time);
  472. try
  473. {
  474. sendPacket(tbn);
  475. }
  476. catch (IOException e)
  477. {
  478. if (Config.DEBUG)
  479. _log.log(Level.WARNING, "", e);
  480. }
  481. }
  482. private String hexToString(byte[] hex)
  483. {
  484. return new BigInteger(hex).toString(16);
  485. }
  486. public void doKickPlayer(String account)
  487. {
  488. L2GameClient client = _accountsInGameServer.get(account);
  489. if (client != null)
  490. {
  491. LogRecord record = new LogRecord(Level.WARNING, "Kicked by login");
  492. record.setParameters(new Object[]{client});
  493. _logAccounting.log(record);
  494. client.setAditionalClosePacket(SystemMessage.getSystemMessage(SystemMessageId.ANOTHER_LOGIN_WITH_ACCOUNT));
  495. client.closeNow();
  496. }
  497. }
  498. private void getCharsOnServer(String account)
  499. {
  500. Connection con = null;
  501. int chars = 0;
  502. List<Long> charToDel = new ArrayList<Long>();
  503. try
  504. {
  505. con = L2DatabaseFactory.getInstance().getConnection();
  506. PreparedStatement statement = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?");
  507. statement.setString(1, account);
  508. ResultSet rset = statement.executeQuery();
  509. while (rset.next())
  510. {
  511. chars++;
  512. long delTime = rset.getLong("deletetime");
  513. if (delTime != 0)
  514. charToDel.add(delTime);
  515. }
  516. rset.close();
  517. statement.close();
  518. }
  519. catch (SQLException e)
  520. {
  521. _log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
  522. }
  523. finally
  524. {
  525. L2DatabaseFactory.close(con);
  526. }
  527. ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
  528. try
  529. {
  530. sendPacket(rec);
  531. }
  532. catch (IOException e)
  533. {
  534. if (Config.DEBUG)
  535. _log.log(Level.WARNING, "", e);
  536. }
  537. }
  538. /**
  539. * @param sl
  540. * @throws IOException
  541. */
  542. private void sendPacket(BaseSendablePacket sl) throws IOException
  543. {
  544. byte[] data = sl.getContent();
  545. NewCrypt.appendChecksum(data);
  546. if (Config.DEBUG)
  547. _log.finest("[S]\n" + Util.printData(data));
  548. data = _blowfish.crypt(data);
  549. int len = data.length + 2;
  550. synchronized (_out) //avoids tow threads writing in the mean time
  551. {
  552. _out.write(len & 0xff);
  553. _out.write(len >> 8 & 0xff);
  554. _out.write(data);
  555. _out.flush();
  556. }
  557. }
  558. /**
  559. * @param maxPlayer The maxPlayer to set.
  560. */
  561. public void setMaxPlayer(int maxPlayer)
  562. {
  563. sendServerStatus(ServerStatus.MAX_PLAYERS, maxPlayer);
  564. _maxPlayer = maxPlayer;
  565. }
  566. /**
  567. * @return Returns the maxPlayer.
  568. */
  569. public int getMaxPlayer()
  570. {
  571. return _maxPlayer;
  572. }
  573. /**
  574. * @param server_gm_only
  575. */
  576. public void sendServerStatus(int id, int value)
  577. {
  578. ServerStatus ss = new ServerStatus();
  579. ss.addAttribute(id, value);
  580. try
  581. {
  582. sendPacket(ss);
  583. }
  584. catch (IOException e)
  585. {
  586. if (Config.DEBUG)
  587. _log.log(Level.WARNING, "", e);
  588. }
  589. }
  590. /**
  591. * Send Server Type Config to LS
  592. */
  593. public void sendServerType()
  594. {
  595. ServerStatus ss = new ServerStatus();
  596. ss.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  597. try
  598. {
  599. sendPacket(ss);
  600. }
  601. catch (IOException e)
  602. {
  603. if (Config.DEBUG)
  604. _log.log(Level.WARNING, "", e);
  605. }
  606. }
  607. /**
  608. * @return
  609. */
  610. public String getStatusString()
  611. {
  612. return ServerStatus.STATUS_STRING[_status];
  613. }
  614. /**
  615. * @return
  616. */
  617. public boolean isBracketShown()
  618. {
  619. return Config.SERVER_LIST_BRACKET;
  620. }
  621. /**
  622. * @return Returns the serverName.
  623. */
  624. public String getServerName()
  625. {
  626. return _serverName;
  627. }
  628. public void setServerStatus(int status)
  629. {
  630. switch (status)
  631. {
  632. case ServerStatus.STATUS_AUTO:
  633. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  634. _status = status;
  635. break;
  636. case ServerStatus.STATUS_DOWN:
  637. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_DOWN);
  638. _status = status;
  639. break;
  640. case ServerStatus.STATUS_FULL:
  641. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_FULL);
  642. _status = status;
  643. break;
  644. case ServerStatus.STATUS_GM_ONLY:
  645. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  646. _status = status;
  647. break;
  648. case ServerStatus.STATUS_GOOD:
  649. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GOOD);
  650. _status = status;
  651. break;
  652. case ServerStatus.STATUS_NORMAL:
  653. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_NORMAL);
  654. _status = status;
  655. break;
  656. default:
  657. throw new IllegalArgumentException("Status does not exists:" + status);
  658. }
  659. }
  660. public static class SessionKey
  661. {
  662. public int playOkID1;
  663. public int playOkID2;
  664. public int loginOkID1;
  665. public int loginOkID2;
  666. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  667. {
  668. playOkID1 = playOK1;
  669. playOkID2 = playOK2;
  670. loginOkID1 = loginOK1;
  671. loginOkID2 = loginOK2;
  672. }
  673. @Override
  674. public String toString()
  675. {
  676. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  677. }
  678. }
  679. private static class WaitingClient
  680. {
  681. public int timestamp;
  682. public String account;
  683. public L2GameClient gameClient;
  684. public SessionKey session;
  685. public WaitingClient(String acc, L2GameClient client, SessionKey key)
  686. {
  687. account = acc;
  688. timestamp = GameTimeController.getGameTicks();
  689. gameClient = client;
  690. session = key;
  691. }
  692. }
  693. @SuppressWarnings("synthetic-access")
  694. private static class SingletonHolder
  695. {
  696. protected static final LoginServerThread _instance = new LoginServerThread();
  697. }
  698. }