LoginServerThread.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. * Copyright (C) 2004-2013 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.Connection;
  34. import java.sql.PreparedStatement;
  35. import java.sql.ResultSet;
  36. import java.sql.SQLException;
  37. import java.util.ArrayList;
  38. import java.util.List;
  39. import java.util.logging.Level;
  40. import java.util.logging.LogRecord;
  41. import java.util.logging.Logger;
  42. import javolution.util.FastList;
  43. import javolution.util.FastMap;
  44. import com.l2jserver.Config;
  45. import com.l2jserver.L2DatabaseFactory;
  46. import com.l2jserver.gameserver.model.L2World;
  47. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  48. import com.l2jserver.gameserver.network.L2GameClient;
  49. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  50. import com.l2jserver.gameserver.network.SystemMessageId;
  51. import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
  52. import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
  53. import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
  54. import com.l2jserver.gameserver.network.gameserverpackets.ChangePassword;
  55. import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
  56. import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
  57. import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
  58. import com.l2jserver.gameserver.network.gameserverpackets.PlayerTracert;
  59. import com.l2jserver.gameserver.network.gameserverpackets.ReplyCharacters;
  60. import com.l2jserver.gameserver.network.gameserverpackets.SendMail;
  61. import com.l2jserver.gameserver.network.gameserverpackets.ServerStatus;
  62. import com.l2jserver.gameserver.network.gameserverpackets.TempBan;
  63. import com.l2jserver.gameserver.network.loginserverpackets.AuthResponse;
  64. import com.l2jserver.gameserver.network.loginserverpackets.ChangePasswordResponse;
  65. import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
  66. import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
  67. import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
  68. import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
  69. import com.l2jserver.gameserver.network.loginserverpackets.RequestCharacters;
  70. import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  71. import com.l2jserver.gameserver.network.serverpackets.LoginFail;
  72. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  73. import com.l2jserver.util.Util;
  74. import com.l2jserver.util.crypt.NewCrypt;
  75. import com.l2jserver.util.network.BaseSendablePacket;
  76. public class LoginServerThread extends Thread
  77. {
  78. protected static final Logger _log = Logger.getLogger(LoginServerThread.class.getName());
  79. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  80. /** @see com.l2jserver.loginserver.L2LoginServer#PROTOCOL_REV */
  81. private static final int REVISION = 0x0106;
  82. private RSAPublicKey _publicKey;
  83. private final String _hostname;
  84. private final int _port;
  85. private final int _gamePort;
  86. private Socket _loginSocket;
  87. private InputStream _in;
  88. private OutputStream _out;
  89. /**
  90. * The BlowFish engine used to encrypt packets<br>
  91. * It is first initialized with a unified key:<br>
  92. * "_;v.]05-31!|+-%xT!^[$\00"<br>
  93. * <br>
  94. * and then after handshake, with a new key sent by<br>
  95. * login server during the handshake. This new key is stored<br>
  96. * in {@link #_blowfishKey}
  97. */
  98. private NewCrypt _blowfish;
  99. private byte[] _blowfishKey;
  100. private byte[] _hexID;
  101. private final boolean _acceptAlternate;
  102. private int _requestID;
  103. private int _serverID;
  104. private final boolean _reserveHost;
  105. private int _maxPlayer;
  106. private final List<WaitingClient> _waitingClients;
  107. private final FastMap<String, L2GameClient> _accountsInGameServer = new FastMap<>();
  108. private int _status;
  109. private String _serverName;
  110. private final List<String> _subnets;
  111. private final List<String> _hosts;
  112. /**
  113. * Instantiates a new login server thread.
  114. */
  115. protected LoginServerThread()
  116. {
  117. super("LoginServerThread");
  118. _port = Config.GAME_SERVER_LOGIN_PORT;
  119. _gamePort = Config.PORT_GAME;
  120. _hostname = Config.GAME_SERVER_LOGIN_HOST;
  121. _hexID = Config.HEX_ID;
  122. if (_hexID == null)
  123. {
  124. _requestID = Config.REQUEST_ID;
  125. _hexID = Util.generateHex(16);
  126. }
  127. else
  128. {
  129. _requestID = Config.SERVER_ID;
  130. }
  131. _acceptAlternate = Config.ACCEPT_ALTERNATE_ID;
  132. _reserveHost = Config.RESERVE_HOST_ON_LOGIN;
  133. _subnets = Config.GAME_SERVER_SUBNETS;
  134. _hosts = Config.GAME_SERVER_HOSTS;
  135. _waitingClients = new FastList<>();
  136. _accountsInGameServer.shared();
  137. _maxPlayer = Config.MAXIMUM_ONLINE_USERS;
  138. }
  139. /**
  140. * Gets the single instance of LoginServerThread.
  141. * @return single instance of LoginServerThread
  142. */
  143. public static LoginServerThread getInstance()
  144. {
  145. return SingletonHolder._instance;
  146. }
  147. @Override
  148. public void run()
  149. {
  150. while (!isInterrupted())
  151. {
  152. int lengthHi = 0;
  153. int lengthLo = 0;
  154. int length = 0;
  155. boolean checksumOk = false;
  156. try
  157. {
  158. // Connection
  159. _log.info("Connecting to login on " + _hostname + ":" + _port);
  160. _loginSocket = new Socket(_hostname, _port);
  161. _in = _loginSocket.getInputStream();
  162. _out = new BufferedOutputStream(_loginSocket.getOutputStream());
  163. // init Blowfish
  164. _blowfishKey = Util.generateHex(40);
  165. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  166. while (!isInterrupted())
  167. {
  168. lengthLo = _in.read();
  169. lengthHi = _in.read();
  170. length = (lengthHi * 256) + lengthLo;
  171. if (lengthHi < 0)
  172. {
  173. _log.finer("LoginServerThread: Login terminated the connection.");
  174. break;
  175. }
  176. byte[] incoming = new byte[length - 2];
  177. int receivedBytes = 0;
  178. int newBytes = 0;
  179. int left = length - 2;
  180. while ((newBytes != -1) && (receivedBytes < (length - 2)))
  181. {
  182. newBytes = _in.read(incoming, receivedBytes, left);
  183. receivedBytes = receivedBytes + newBytes;
  184. left -= newBytes;
  185. }
  186. if (receivedBytes != (length - 2))
  187. {
  188. _log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
  189. break;
  190. }
  191. // decrypt if we have a key
  192. _blowfish.decrypt(incoming, 0, incoming.length);
  193. checksumOk = NewCrypt.verifyChecksum(incoming);
  194. if (!checksumOk)
  195. {
  196. _log.warning("Incorrect packet checksum, ignoring packet (LS)");
  197. break;
  198. }
  199. int packetType = incoming[0] & 0xff;
  200. switch (packetType)
  201. {
  202. case 0x00:
  203. InitLS init = new InitLS(incoming);
  204. if (init.getRevision() != REVISION)
  205. {
  206. // TODO: revision mismatch
  207. _log.warning("/!\\ Revision mismatch between LS and GS /!\\");
  208. break;
  209. }
  210. try
  211. {
  212. KeyFactory kfac = KeyFactory.getInstance("RSA");
  213. BigInteger modulus = new BigInteger(init.getRSAKey());
  214. RSAPublicKeySpec kspec1 = new RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4);
  215. _publicKey = (RSAPublicKey) kfac.generatePublic(kspec1);
  216. }
  217. catch (GeneralSecurityException e)
  218. {
  219. _log.warning("Troubles while init the public key send by login");
  220. break;
  221. }
  222. // send the blowfish key through the rsa encryption
  223. BlowFishKey bfk = new BlowFishKey(_blowfishKey, _publicKey);
  224. sendPacket(bfk);
  225. // now, only accept packet with the new encryption
  226. _blowfish = new NewCrypt(_blowfishKey);
  227. AuthRequest ar = new AuthRequest(_requestID, _acceptAlternate, _hexID, _gamePort, _reserveHost, _maxPlayer, _subnets, _hosts);
  228. sendPacket(ar);
  229. break;
  230. case 0x01:
  231. LoginServerFail lsf = new LoginServerFail(incoming);
  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(incoming);
  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<>();
  275. for (L2PcInstance player : L2World.getInstance().getAllPlayersArray())
  276. {
  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(incoming);
  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. PlayerInGame pig = new PlayerInGame(par.getAccount());
  302. sendPacket(pig);
  303. wcToRemove.gameClient.setState(GameClientState.AUTHED);
  304. wcToRemove.gameClient.setSessionId(wcToRemove.session);
  305. CharSelectionInfo cl = new CharSelectionInfo(wcToRemove.account, wcToRemove.gameClient.getSessionId().playOkID1);
  306. wcToRemove.gameClient.getConnection().sendPacket(cl);
  307. wcToRemove.gameClient.setCharSelection(cl.getCharInfo());
  308. }
  309. else
  310. {
  311. _log.warning("Session key is not correct. Closing connection for account " + wcToRemove.account + ".");
  312. // wcToRemove.gameClient.getConnection().sendPacket(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  313. wcToRemove.gameClient.close(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  314. _accountsInGameServer.remove(wcToRemove.account);
  315. }
  316. _waitingClients.remove(wcToRemove);
  317. }
  318. break;
  319. case 0x04:
  320. KickPlayer kp = new KickPlayer(incoming);
  321. doKickPlayer(kp.getAccount());
  322. break;
  323. case 0x05:
  324. RequestCharacters rc = new RequestCharacters(incoming);
  325. getCharsOnServer(rc.getAccount());
  326. break;
  327. case 0x06:
  328. new ChangePasswordResponse(incoming);
  329. break;
  330. }
  331. }
  332. }
  333. catch (UnknownHostException e)
  334. {
  335. _log.log(Level.WARNING, "", e);
  336. }
  337. catch (SocketException e)
  338. {
  339. _log.warning("LoginServer not avaible, trying to reconnect...");
  340. }
  341. catch (IOException e)
  342. {
  343. _log.log(Level.WARNING, "Disconnected from Login, Trying to reconnect: " + e.getMessage(), e);
  344. }
  345. finally
  346. {
  347. try
  348. {
  349. _loginSocket.close();
  350. if (isInterrupted())
  351. {
  352. return;
  353. }
  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. /**
  370. * Adds the waiting client and send request.
  371. * @param acc the account
  372. * @param client the game client
  373. * @param key the session key
  374. */
  375. public void addWaitingClientAndSendRequest(String acc, L2GameClient client, SessionKey key)
  376. {
  377. WaitingClient wc = new WaitingClient(acc, client, key);
  378. synchronized (_waitingClients)
  379. {
  380. _waitingClients.add(wc);
  381. }
  382. PlayerAuthRequest par = new PlayerAuthRequest(acc, key);
  383. try
  384. {
  385. sendPacket(par);
  386. }
  387. catch (IOException e)
  388. {
  389. _log.warning("Error while sending player auth request");
  390. }
  391. }
  392. /**
  393. * Removes the waiting client.
  394. * @param client the client
  395. */
  396. public void removeWaitingClient(L2GameClient client)
  397. {
  398. WaitingClient toRemove = null;
  399. synchronized (_waitingClients)
  400. {
  401. for (WaitingClient c : _waitingClients)
  402. {
  403. if (c.gameClient == client)
  404. {
  405. toRemove = c;
  406. }
  407. }
  408. if (toRemove != null)
  409. {
  410. _waitingClients.remove(toRemove);
  411. }
  412. }
  413. }
  414. /**
  415. * Send logout for the given account.
  416. * @param account the account
  417. */
  418. public void sendLogout(String account)
  419. {
  420. if (account == null)
  421. {
  422. return;
  423. }
  424. PlayerLogout pl = new PlayerLogout(account);
  425. try
  426. {
  427. sendPacket(pl);
  428. }
  429. catch (IOException e)
  430. {
  431. _log.warning("Error while sending logout packet to login");
  432. }
  433. finally
  434. {
  435. _accountsInGameServer.remove(account);
  436. }
  437. }
  438. /**
  439. * Adds the game server login.
  440. * @param account the account
  441. * @param client the client
  442. */
  443. public void addGameServerLogin(String account, L2GameClient client)
  444. {
  445. _accountsInGameServer.put(account, client);
  446. }
  447. /**
  448. * Send access level.
  449. * @param account the account
  450. * @param level the access level
  451. */
  452. public void sendAccessLevel(String account, int level)
  453. {
  454. ChangeAccessLevel cal = new ChangeAccessLevel(account, level);
  455. try
  456. {
  457. sendPacket(cal);
  458. }
  459. catch (IOException e)
  460. {
  461. }
  462. }
  463. /**
  464. * Send client tracert.
  465. * @param account the account
  466. * @param address the address
  467. */
  468. public void sendClientTracert(String account, String[] address)
  469. {
  470. PlayerTracert ptc = new PlayerTracert(account, address[0], address[1], address[2], address[3], address[4]);
  471. try
  472. {
  473. sendPacket(ptc);
  474. }
  475. catch (IOException e)
  476. {
  477. }
  478. }
  479. /**
  480. * Send mail.
  481. * @param account the account
  482. * @param mailId the mail id
  483. * @param args the args
  484. */
  485. public void sendMail(String account, String mailId, String... args)
  486. {
  487. SendMail sem = new SendMail(account, mailId, args);
  488. try
  489. {
  490. sendPacket(sem);
  491. }
  492. catch (IOException e)
  493. {
  494. }
  495. }
  496. /**
  497. * Send temp ban.
  498. * @param account the account
  499. * @param ip the ip
  500. * @param time the time
  501. */
  502. public void sendTempBan(String account, String ip, long time)
  503. {
  504. TempBan tbn = new TempBan(account, ip, time);
  505. try
  506. {
  507. sendPacket(tbn);
  508. }
  509. catch (IOException e)
  510. {
  511. }
  512. }
  513. /**
  514. * Hex to string.
  515. * @param hex the hex value
  516. * @return the hex value as string
  517. */
  518. private String hexToString(byte[] hex)
  519. {
  520. return new BigInteger(hex).toString(16);
  521. }
  522. /**
  523. * Kick player for the given account.
  524. * @param account the account
  525. */
  526. public void doKickPlayer(String account)
  527. {
  528. L2GameClient client = _accountsInGameServer.get(account);
  529. if (client != null)
  530. {
  531. LogRecord record = new LogRecord(Level.WARNING, "Kicked by login");
  532. record.setParameters(new Object[]
  533. {
  534. client
  535. });
  536. _logAccounting.log(record);
  537. client.setAditionalClosePacket(SystemMessage.getSystemMessage(SystemMessageId.ANOTHER_LOGIN_WITH_ACCOUNT));
  538. client.closeNow();
  539. }
  540. }
  541. /**
  542. * Gets the chars on server.
  543. * @param account the account
  544. */
  545. private void getCharsOnServer(String account)
  546. {
  547. int chars = 0;
  548. List<Long> charToDel = new ArrayList<>();
  549. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  550. PreparedStatement ps = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?"))
  551. {
  552. ps.setString(1, account);
  553. try (ResultSet rs = ps.executeQuery())
  554. {
  555. while (rs.next())
  556. {
  557. chars++;
  558. long delTime = rs.getLong("deletetime");
  559. if (delTime != 0)
  560. {
  561. charToDel.add(delTime);
  562. }
  563. }
  564. }
  565. }
  566. catch (SQLException e)
  567. {
  568. _log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
  569. }
  570. ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
  571. try
  572. {
  573. sendPacket(rec);
  574. }
  575. catch (IOException e)
  576. {
  577. }
  578. }
  579. /**
  580. * Send packet.
  581. * @param sl the sendable packet
  582. * @throws IOException Signals that an I/O exception has occurred.
  583. */
  584. private void sendPacket(BaseSendablePacket sl) throws IOException
  585. {
  586. byte[] data = sl.getContent();
  587. NewCrypt.appendChecksum(data);
  588. _blowfish.crypt(data, 0, data.length);
  589. int len = data.length + 2;
  590. synchronized (_out) // avoids tow threads writing in the mean time
  591. {
  592. _out.write(len & 0xff);
  593. _out.write((len >> 8) & 0xff);
  594. _out.write(data);
  595. _out.flush();
  596. }
  597. }
  598. /**
  599. * Sets the max player.
  600. * @param maxPlayer The maxPlayer to set.
  601. */
  602. public void setMaxPlayer(int maxPlayer)
  603. {
  604. sendServerStatus(ServerStatus.MAX_PLAYERS, maxPlayer);
  605. _maxPlayer = maxPlayer;
  606. }
  607. /**
  608. * Gets the max player.
  609. * @return Returns the maxPlayer.
  610. */
  611. public int getMaxPlayer()
  612. {
  613. return _maxPlayer;
  614. }
  615. /**
  616. * Send server status.
  617. * @param id the id
  618. * @param value the value
  619. */
  620. public void sendServerStatus(int id, int value)
  621. {
  622. ServerStatus ss = new ServerStatus();
  623. ss.addAttribute(id, value);
  624. try
  625. {
  626. sendPacket(ss);
  627. }
  628. catch (IOException e)
  629. {
  630. }
  631. }
  632. /**
  633. * Send Server Type Config to LS.
  634. */
  635. public void sendServerType()
  636. {
  637. ServerStatus ss = new ServerStatus();
  638. ss.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  639. try
  640. {
  641. sendPacket(ss);
  642. }
  643. catch (IOException e)
  644. {
  645. }
  646. }
  647. /**
  648. * Send change password.
  649. * @param accountName the account name
  650. * @param charName the char name
  651. * @param oldpass the old pass
  652. * @param newpass the new pass
  653. */
  654. public void sendChangePassword(String accountName, String charName, String oldpass, String newpass)
  655. {
  656. ChangePassword cp = new ChangePassword(accountName, charName, oldpass, newpass);
  657. try
  658. {
  659. sendPacket(cp);
  660. }
  661. catch (IOException e)
  662. {
  663. }
  664. }
  665. /**
  666. * Gets the status string.
  667. * @return the status string
  668. */
  669. public String getStatusString()
  670. {
  671. return ServerStatus.STATUS_STRING[_status];
  672. }
  673. /**
  674. * Gets the server name.
  675. * @return the server name.
  676. */
  677. public String getServerName()
  678. {
  679. return _serverName;
  680. }
  681. /**
  682. * Sets the server status.
  683. * @param status the new server status
  684. */
  685. public void setServerStatus(int status)
  686. {
  687. switch (status)
  688. {
  689. case ServerStatus.STATUS_AUTO:
  690. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  691. _status = status;
  692. break;
  693. case ServerStatus.STATUS_DOWN:
  694. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_DOWN);
  695. _status = status;
  696. break;
  697. case ServerStatus.STATUS_FULL:
  698. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_FULL);
  699. _status = status;
  700. break;
  701. case ServerStatus.STATUS_GM_ONLY:
  702. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  703. _status = status;
  704. break;
  705. case ServerStatus.STATUS_GOOD:
  706. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GOOD);
  707. _status = status;
  708. break;
  709. case ServerStatus.STATUS_NORMAL:
  710. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_NORMAL);
  711. _status = status;
  712. break;
  713. default:
  714. throw new IllegalArgumentException("Status does not exists:" + status);
  715. }
  716. }
  717. public L2GameClient getClient(String name)
  718. {
  719. return name != null ? _accountsInGameServer.get(name) : null;
  720. }
  721. public static class SessionKey
  722. {
  723. public int playOkID1;
  724. public int playOkID2;
  725. public int loginOkID1;
  726. public int loginOkID2;
  727. /**
  728. * Instantiates a new session key.
  729. * @param loginOK1 the login o k1
  730. * @param loginOK2 the login o k2
  731. * @param playOK1 the play o k1
  732. * @param playOK2 the play o k2
  733. */
  734. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  735. {
  736. playOkID1 = playOK1;
  737. playOkID2 = playOK2;
  738. loginOkID1 = loginOK1;
  739. loginOkID2 = loginOK2;
  740. }
  741. @Override
  742. public String toString()
  743. {
  744. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  745. }
  746. }
  747. private static class WaitingClient
  748. {
  749. public String account;
  750. public L2GameClient gameClient;
  751. public SessionKey session;
  752. /**
  753. * Instantiates a new waiting client.
  754. * @param acc the acc
  755. * @param client the client
  756. * @param key the key
  757. */
  758. public WaitingClient(String acc, L2GameClient client, SessionKey key)
  759. {
  760. account = acc;
  761. gameClient = client;
  762. session = key;
  763. }
  764. }
  765. private static class SingletonHolder
  766. {
  767. protected static final LoginServerThread _instance = new LoginServerThread();
  768. }
  769. }