LoginServerThread.java 22 KB

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