LoginServerThread.java 22 KB

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