LoginServerThread.java 20 KB

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