LoginServerThread.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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. final List<String> playerList = new ArrayList<>();
  275. for (L2PcInstance player : L2World.getInstance().getPlayers())
  276. {
  277. playerList.add(player.getAccountName());
  278. }
  279. sendPacket(new PlayerInGame(playerList));
  280. }
  281. break;
  282. case 0x03:
  283. PlayerAuthResponse par = new PlayerAuthResponse(incoming);
  284. String account = par.getAccount();
  285. WaitingClient wcToRemove = null;
  286. synchronized (_waitingClients)
  287. {
  288. for (WaitingClient wc : _waitingClients)
  289. {
  290. if (wc.account.equals(account))
  291. {
  292. wcToRemove = wc;
  293. }
  294. }
  295. }
  296. if (wcToRemove != null)
  297. {
  298. if (par.isAuthed())
  299. {
  300. PlayerInGame pig = new PlayerInGame(par.getAccount());
  301. sendPacket(pig);
  302. wcToRemove.gameClient.setState(GameClientState.AUTHED);
  303. wcToRemove.gameClient.setSessionId(wcToRemove.session);
  304. CharSelectionInfo cl = new CharSelectionInfo(wcToRemove.account, wcToRemove.gameClient.getSessionId().playOkID1);
  305. wcToRemove.gameClient.getConnection().sendPacket(cl);
  306. wcToRemove.gameClient.setCharSelection(cl.getCharInfo());
  307. }
  308. else
  309. {
  310. _log.warning("Session key is not correct. Closing connection for account " + wcToRemove.account + ".");
  311. // wcToRemove.gameClient.getConnection().sendPacket(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  312. wcToRemove.gameClient.close(new LoginFail(LoginFail.SYSTEM_ERROR_LOGIN_LATER));
  313. _accountsInGameServer.remove(wcToRemove.account);
  314. }
  315. _waitingClients.remove(wcToRemove);
  316. }
  317. break;
  318. case 0x04:
  319. KickPlayer kp = new KickPlayer(incoming);
  320. doKickPlayer(kp.getAccount());
  321. break;
  322. case 0x05:
  323. RequestCharacters rc = new RequestCharacters(incoming);
  324. getCharsOnServer(rc.getAccount());
  325. break;
  326. case 0x06:
  327. new ChangePasswordResponse(incoming);
  328. break;
  329. }
  330. }
  331. }
  332. catch (UnknownHostException e)
  333. {
  334. _log.log(Level.WARNING, "", e);
  335. }
  336. catch (SocketException e)
  337. {
  338. _log.warning("LoginServer not avaible, trying to reconnect...");
  339. }
  340. catch (IOException e)
  341. {
  342. _log.log(Level.WARNING, "Disconnected from Login, Trying to reconnect: " + e.getMessage(), e);
  343. }
  344. finally
  345. {
  346. try
  347. {
  348. _loginSocket.close();
  349. if (isInterrupted())
  350. {
  351. return;
  352. }
  353. }
  354. catch (Exception e)
  355. {
  356. }
  357. }
  358. try
  359. {
  360. Thread.sleep(5000); // 5 seconds tempo.
  361. }
  362. catch (InterruptedException e)
  363. {
  364. return; // never swallow an interrupt!
  365. }
  366. }
  367. }
  368. /**
  369. * Adds the waiting client and send request.
  370. * @param acc the account
  371. * @param client the game client
  372. * @param key the session key
  373. */
  374. public void addWaitingClientAndSendRequest(String acc, L2GameClient client, SessionKey key)
  375. {
  376. WaitingClient wc = new WaitingClient(acc, client, key);
  377. synchronized (_waitingClients)
  378. {
  379. _waitingClients.add(wc);
  380. }
  381. PlayerAuthRequest par = new PlayerAuthRequest(acc, key);
  382. try
  383. {
  384. sendPacket(par);
  385. }
  386. catch (IOException e)
  387. {
  388. _log.warning("Error while sending player auth request");
  389. }
  390. }
  391. /**
  392. * Removes the waiting client.
  393. * @param client the client
  394. */
  395. public void removeWaitingClient(L2GameClient client)
  396. {
  397. WaitingClient toRemove = null;
  398. synchronized (_waitingClients)
  399. {
  400. for (WaitingClient c : _waitingClients)
  401. {
  402. if (c.gameClient == client)
  403. {
  404. toRemove = c;
  405. }
  406. }
  407. if (toRemove != null)
  408. {
  409. _waitingClients.remove(toRemove);
  410. }
  411. }
  412. }
  413. /**
  414. * Send logout for the given account.
  415. * @param account the account
  416. */
  417. public void sendLogout(String account)
  418. {
  419. if (account == null)
  420. {
  421. return;
  422. }
  423. PlayerLogout pl = new PlayerLogout(account);
  424. try
  425. {
  426. sendPacket(pl);
  427. }
  428. catch (IOException e)
  429. {
  430. _log.warning("Error while sending logout packet to login");
  431. }
  432. finally
  433. {
  434. _accountsInGameServer.remove(account);
  435. }
  436. }
  437. /**
  438. * Adds the game server login.
  439. * @param account the account
  440. * @param client the client
  441. */
  442. public void addGameServerLogin(String account, L2GameClient client)
  443. {
  444. _accountsInGameServer.put(account, client);
  445. }
  446. /**
  447. * Send access level.
  448. * @param account the account
  449. * @param level the access level
  450. */
  451. public void sendAccessLevel(String account, int level)
  452. {
  453. ChangeAccessLevel cal = new ChangeAccessLevel(account, level);
  454. try
  455. {
  456. sendPacket(cal);
  457. }
  458. catch (IOException e)
  459. {
  460. }
  461. }
  462. /**
  463. * Send client tracert.
  464. * @param account the account
  465. * @param address the address
  466. */
  467. public void sendClientTracert(String account, String[] address)
  468. {
  469. PlayerTracert ptc = new PlayerTracert(account, address[0], address[1], address[2], address[3], address[4]);
  470. try
  471. {
  472. sendPacket(ptc);
  473. }
  474. catch (IOException e)
  475. {
  476. }
  477. }
  478. /**
  479. * Send mail.
  480. * @param account the account
  481. * @param mailId the mail id
  482. * @param args the args
  483. */
  484. public void sendMail(String account, String mailId, String... args)
  485. {
  486. SendMail sem = new SendMail(account, mailId, args);
  487. try
  488. {
  489. sendPacket(sem);
  490. }
  491. catch (IOException e)
  492. {
  493. }
  494. }
  495. /**
  496. * Send temp ban.
  497. * @param account the account
  498. * @param ip the ip
  499. * @param time the time
  500. */
  501. public void sendTempBan(String account, String ip, long time)
  502. {
  503. TempBan tbn = new TempBan(account, ip, time);
  504. try
  505. {
  506. sendPacket(tbn);
  507. }
  508. catch (IOException e)
  509. {
  510. }
  511. }
  512. /**
  513. * Hex to string.
  514. * @param hex the hex value
  515. * @return the hex value as string
  516. */
  517. private String hexToString(byte[] hex)
  518. {
  519. return new BigInteger(hex).toString(16);
  520. }
  521. /**
  522. * Kick player for the given account.
  523. * @param account the account
  524. */
  525. public void doKickPlayer(String account)
  526. {
  527. L2GameClient client = _accountsInGameServer.get(account);
  528. if (client != null)
  529. {
  530. LogRecord record = new LogRecord(Level.WARNING, "Kicked by login");
  531. record.setParameters(new Object[]
  532. {
  533. client
  534. });
  535. _logAccounting.log(record);
  536. client.setAditionalClosePacket(SystemMessage.getSystemMessage(SystemMessageId.ANOTHER_LOGIN_WITH_ACCOUNT));
  537. client.closeNow();
  538. }
  539. }
  540. /**
  541. * Gets the chars on server.
  542. * @param account the account
  543. */
  544. private void getCharsOnServer(String account)
  545. {
  546. int chars = 0;
  547. List<Long> charToDel = new ArrayList<>();
  548. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  549. PreparedStatement ps = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?"))
  550. {
  551. ps.setString(1, account);
  552. try (ResultSet rs = ps.executeQuery())
  553. {
  554. while (rs.next())
  555. {
  556. chars++;
  557. long delTime = rs.getLong("deletetime");
  558. if (delTime != 0)
  559. {
  560. charToDel.add(delTime);
  561. }
  562. }
  563. }
  564. }
  565. catch (SQLException e)
  566. {
  567. _log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
  568. }
  569. ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
  570. try
  571. {
  572. sendPacket(rec);
  573. }
  574. catch (IOException e)
  575. {
  576. }
  577. }
  578. /**
  579. * Send packet.
  580. * @param sl the sendable packet
  581. * @throws IOException Signals that an I/O exception has occurred.
  582. */
  583. private void sendPacket(BaseSendablePacket sl) throws IOException
  584. {
  585. byte[] data = sl.getContent();
  586. NewCrypt.appendChecksum(data);
  587. _blowfish.crypt(data, 0, data.length);
  588. int len = data.length + 2;
  589. synchronized (_out) // avoids tow threads writing in the mean time
  590. {
  591. _out.write(len & 0xff);
  592. _out.write((len >> 8) & 0xff);
  593. _out.write(data);
  594. _out.flush();
  595. }
  596. }
  597. /**
  598. * Sets the max player.
  599. * @param maxPlayer The maxPlayer to set.
  600. */
  601. public void setMaxPlayer(int maxPlayer)
  602. {
  603. sendServerStatus(ServerStatus.MAX_PLAYERS, maxPlayer);
  604. _maxPlayer = maxPlayer;
  605. }
  606. /**
  607. * Gets the max player.
  608. * @return Returns the maxPlayer.
  609. */
  610. public int getMaxPlayer()
  611. {
  612. return _maxPlayer;
  613. }
  614. /**
  615. * Send server status.
  616. * @param id the id
  617. * @param value the value
  618. */
  619. public void sendServerStatus(int id, int value)
  620. {
  621. ServerStatus ss = new ServerStatus();
  622. ss.addAttribute(id, value);
  623. try
  624. {
  625. sendPacket(ss);
  626. }
  627. catch (IOException e)
  628. {
  629. }
  630. }
  631. /**
  632. * Send Server Type Config to LS.
  633. */
  634. public void sendServerType()
  635. {
  636. ServerStatus ss = new ServerStatus();
  637. ss.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  638. try
  639. {
  640. sendPacket(ss);
  641. }
  642. catch (IOException e)
  643. {
  644. }
  645. }
  646. /**
  647. * Send change password.
  648. * @param accountName the account name
  649. * @param charName the char name
  650. * @param oldpass the old pass
  651. * @param newpass the new pass
  652. */
  653. public void sendChangePassword(String accountName, String charName, String oldpass, String newpass)
  654. {
  655. ChangePassword cp = new ChangePassword(accountName, charName, oldpass, newpass);
  656. try
  657. {
  658. sendPacket(cp);
  659. }
  660. catch (IOException e)
  661. {
  662. }
  663. }
  664. /**
  665. * Gets the status string.
  666. * @return the status string
  667. */
  668. public String getStatusString()
  669. {
  670. return ServerStatus.STATUS_STRING[_status];
  671. }
  672. /**
  673. * Gets the server name.
  674. * @return the server name.
  675. */
  676. public String getServerName()
  677. {
  678. return _serverName;
  679. }
  680. /**
  681. * Sets the server status.
  682. * @param status the new server status
  683. */
  684. public void setServerStatus(int status)
  685. {
  686. switch (status)
  687. {
  688. case ServerStatus.STATUS_AUTO:
  689. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  690. _status = status;
  691. break;
  692. case ServerStatus.STATUS_DOWN:
  693. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_DOWN);
  694. _status = status;
  695. break;
  696. case ServerStatus.STATUS_FULL:
  697. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_FULL);
  698. _status = status;
  699. break;
  700. case ServerStatus.STATUS_GM_ONLY:
  701. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  702. _status = status;
  703. break;
  704. case ServerStatus.STATUS_GOOD:
  705. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GOOD);
  706. _status = status;
  707. break;
  708. case ServerStatus.STATUS_NORMAL:
  709. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_NORMAL);
  710. _status = status;
  711. break;
  712. default:
  713. throw new IllegalArgumentException("Status does not exists:" + status);
  714. }
  715. }
  716. public L2GameClient getClient(String name)
  717. {
  718. return name != null ? _accountsInGameServer.get(name) : null;
  719. }
  720. public static class SessionKey
  721. {
  722. public int playOkID1;
  723. public int playOkID2;
  724. public int loginOkID1;
  725. public int loginOkID2;
  726. /**
  727. * Instantiates a new session key.
  728. * @param loginOK1 the login o k1
  729. * @param loginOK2 the login o k2
  730. * @param playOK1 the play o k1
  731. * @param playOK2 the play o k2
  732. */
  733. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  734. {
  735. playOkID1 = playOK1;
  736. playOkID2 = playOK2;
  737. loginOkID1 = loginOK1;
  738. loginOkID2 = loginOK2;
  739. }
  740. @Override
  741. public String toString()
  742. {
  743. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  744. }
  745. }
  746. private static class WaitingClient
  747. {
  748. public String account;
  749. public L2GameClient gameClient;
  750. public SessionKey session;
  751. /**
  752. * Instantiates a new waiting client.
  753. * @param acc the acc
  754. * @param client the client
  755. * @param key the key
  756. */
  757. public WaitingClient(String acc, L2GameClient client, SessionKey key)
  758. {
  759. account = acc;
  760. gameClient = client;
  761. session = key;
  762. }
  763. }
  764. private static class SingletonHolder
  765. {
  766. protected static final LoginServerThread _instance = new LoginServerThread();
  767. }
  768. }