LoginServerThread.java 22 KB

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