LoginServerThread.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*
  2. * Copyright (C) 2004-2015 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.Map;
  40. import java.util.concurrent.ConcurrentHashMap;
  41. import java.util.concurrent.CopyOnWriteArrayList;
  42. import java.util.logging.Level;
  43. import java.util.logging.LogRecord;
  44. import java.util.logging.Logger;
  45. import com.l2jserver.Config;
  46. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  47. import com.l2jserver.gameserver.model.L2World;
  48. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  49. import com.l2jserver.gameserver.network.L2GameClient;
  50. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  51. import com.l2jserver.gameserver.network.SystemMessageId;
  52. import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
  53. import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
  54. import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
  55. import com.l2jserver.gameserver.network.gameserverpackets.ChangePassword;
  56. import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
  57. import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
  58. import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
  59. import com.l2jserver.gameserver.network.gameserverpackets.PlayerTracert;
  60. import com.l2jserver.gameserver.network.gameserverpackets.ReplyCharacters;
  61. import com.l2jserver.gameserver.network.gameserverpackets.SendMail;
  62. import com.l2jserver.gameserver.network.gameserverpackets.ServerStatus;
  63. import com.l2jserver.gameserver.network.gameserverpackets.TempBan;
  64. import com.l2jserver.gameserver.network.loginserverpackets.AuthResponse;
  65. import com.l2jserver.gameserver.network.loginserverpackets.ChangePasswordResponse;
  66. import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
  67. import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
  68. import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
  69. import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
  70. import com.l2jserver.gameserver.network.loginserverpackets.RequestCharacters;
  71. import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  72. import com.l2jserver.gameserver.network.serverpackets.LoginFail;
  73. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  74. import com.l2jserver.util.Rnd;
  75. import com.l2jserver.util.Util;
  76. import com.l2jserver.util.crypt.NewCrypt;
  77. import com.l2jserver.util.network.BaseSendablePacket;
  78. public class LoginServerThread extends Thread
  79. {
  80. protected static final Logger _log = Logger.getLogger(LoginServerThread.class.getName());
  81. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  82. /** @see com.l2jserver.loginserver.L2LoginServer#PROTOCOL_REV */
  83. private static final int REVISION = 0x0106;
  84. private final String _hostname;
  85. private final int _port;
  86. private final int _gamePort;
  87. private Socket _loginSocket;
  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 blowfishKey
  97. */
  98. private NewCrypt _blowfish;
  99. private byte[] _hexID;
  100. private final boolean _acceptAlternate;
  101. private int _requestID;
  102. private final boolean _reserveHost;
  103. private int _maxPlayer;
  104. private final List<WaitingClient> _waitingClients;
  105. private final Map<String, L2GameClient> _accountsInGameServer = new ConcurrentHashMap<>();
  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 CopyOnWriteArrayList<>();
  134. _maxPlayer = Config.MAXIMUM_ONLINE_USERS;
  135. }
  136. /**
  137. * Gets the single instance of LoginServerThread.
  138. * @return single instance of LoginServerThread
  139. */
  140. public static LoginServerThread getInstance()
  141. {
  142. return SingletonHolder._instance;
  143. }
  144. @Override
  145. public void run()
  146. {
  147. while (!isInterrupted())
  148. {
  149. int lengthHi = 0;
  150. int lengthLo = 0;
  151. int length = 0;
  152. boolean checksumOk = false;
  153. try
  154. {
  155. // Connection
  156. _log.info("Connecting to login on " + _hostname + ":" + _port);
  157. _loginSocket = new Socket(_hostname, _port);
  158. InputStream in = _loginSocket.getInputStream();
  159. _out = new BufferedOutputStream(_loginSocket.getOutputStream());
  160. // init Blowfish
  161. byte[] blowfishKey = Util.generateHex(40);
  162. // Protect the new blowfish key what cannot begin with zero
  163. if (blowfishKey[0] == 0)
  164. {
  165. blowfishKey[0] = (byte) Rnd.get(32, 64);
  166. }
  167. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  168. while (!isInterrupted())
  169. {
  170. lengthLo = in.read();
  171. lengthHi = in.read();
  172. length = (lengthHi * 256) + lengthLo;
  173. if (lengthHi < 0)
  174. {
  175. _log.finer("LoginServerThread: Login terminated the connection.");
  176. break;
  177. }
  178. byte[] incoming = new byte[length - 2];
  179. int receivedBytes = 0;
  180. int newBytes = 0;
  181. int left = length - 2;
  182. while ((newBytes != -1) && (receivedBytes < (length - 2)))
  183. {
  184. newBytes = in.read(incoming, receivedBytes, left);
  185. receivedBytes = receivedBytes + newBytes;
  186. left -= newBytes;
  187. }
  188. if (receivedBytes != (length - 2))
  189. {
  190. _log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
  191. break;
  192. }
  193. // decrypt if we have a key
  194. _blowfish.decrypt(incoming, 0, incoming.length);
  195. checksumOk = NewCrypt.verifyChecksum(incoming);
  196. if (!checksumOk)
  197. {
  198. _log.warning("Incorrect packet checksum, ignoring packet (LS)");
  199. break;
  200. }
  201. int packetType = incoming[0] & 0xff;
  202. switch (packetType)
  203. {
  204. case 0x00:
  205. InitLS init = new InitLS(incoming);
  206. if (init.getRevision() != REVISION)
  207. {
  208. // TODO: revision mismatch
  209. _log.warning("/!\\ Revision mismatch between LS and GS /!\\");
  210. break;
  211. }
  212. RSAPublicKey publicKey;
  213. try
  214. {
  215. KeyFactory kfac = KeyFactory.getInstance("RSA");
  216. BigInteger modulus = new BigInteger(init.getRSAKey());
  217. RSAPublicKeySpec kspec1 = new RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4);
  218. publicKey = (RSAPublicKey) kfac.generatePublic(kspec1);
  219. }
  220. catch (GeneralSecurityException e)
  221. {
  222. _log.warning("Trouble while init the public key send by login");
  223. break;
  224. }
  225. // send the blowfish key through the rsa encryption
  226. sendPacket(new BlowFishKey(blowfishKey, publicKey));
  227. // now, only accept packet with the new encryption
  228. _blowfish = new NewCrypt(blowfishKey);
  229. sendPacket(new AuthRequest(_requestID, _acceptAlternate, _hexID, _gamePort, _reserveHost, _maxPlayer, _subnets, _hosts));
  230. break;
  231. case 0x01:
  232. LoginServerFail lsf = new LoginServerFail(incoming);
  233. _log.info("Damn! Registeration Failed: " + lsf.getReasonString());
  234. // login will close the connection here
  235. break;
  236. case 0x02:
  237. AuthResponse aresp = new AuthResponse(incoming);
  238. int serverID = aresp.getServerId();
  239. _serverName = aresp.getServerName();
  240. Config.saveHexid(serverID, hexToString(_hexID));
  241. _log.info("Registered on login as Server " + serverID + " : " + _serverName);
  242. ServerStatus st = new ServerStatus();
  243. if (Config.SERVER_LIST_BRACKET)
  244. {
  245. st.addAttribute(ServerStatus.SERVER_LIST_SQUARE_BRACKET, ServerStatus.ON);
  246. }
  247. else
  248. {
  249. st.addAttribute(ServerStatus.SERVER_LIST_SQUARE_BRACKET, ServerStatus.OFF);
  250. }
  251. st.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  252. if (Config.SERVER_GMONLY)
  253. {
  254. st.addAttribute(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  255. }
  256. else
  257. {
  258. st.addAttribute(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  259. }
  260. if (Config.SERVER_LIST_AGE == 15)
  261. {
  262. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_15);
  263. }
  264. else if (Config.SERVER_LIST_AGE == 18)
  265. {
  266. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_18);
  267. }
  268. else
  269. {
  270. st.addAttribute(ServerStatus.SERVER_AGE, ServerStatus.SERVER_AGE_ALL);
  271. }
  272. sendPacket(st);
  273. if (L2World.getInstance().getAllPlayersCount() > 0)
  274. {
  275. final List<String> playerList = new ArrayList<>();
  276. for (L2PcInstance player : L2World.getInstance().getPlayers())
  277. {
  278. playerList.add(player.getAccountName());
  279. }
  280. sendPacket(new PlayerInGame(playerList));
  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. * @return {@code true} if account was not already logged in, {@code false} otherwise
  443. */
  444. public boolean addGameServerLogin(String account, L2GameClient client)
  445. {
  446. return _accountsInGameServer.putIfAbsent(account, client) == null;
  447. }
  448. /**
  449. * Send access level.
  450. * @param account the account
  451. * @param level the access level
  452. */
  453. public void sendAccessLevel(String account, int level)
  454. {
  455. ChangeAccessLevel cal = new ChangeAccessLevel(account, level);
  456. try
  457. {
  458. sendPacket(cal);
  459. }
  460. catch (IOException e)
  461. {
  462. }
  463. }
  464. /**
  465. * Send client tracert.
  466. * @param account the account
  467. * @param address the address
  468. */
  469. public void sendClientTracert(String account, String[] address)
  470. {
  471. PlayerTracert ptc = new PlayerTracert(account, address[0], address[1], address[2], address[3], address[4]);
  472. try
  473. {
  474. sendPacket(ptc);
  475. }
  476. catch (IOException e)
  477. {
  478. }
  479. }
  480. /**
  481. * Send mail.
  482. * @param account the account
  483. * @param mailId the mail id
  484. * @param args the args
  485. */
  486. public void sendMail(String account, String mailId, String... args)
  487. {
  488. SendMail sem = new SendMail(account, mailId, args);
  489. try
  490. {
  491. sendPacket(sem);
  492. }
  493. catch (IOException e)
  494. {
  495. }
  496. }
  497. /**
  498. * Send temp ban.
  499. * @param account the account
  500. * @param ip the ip
  501. * @param time the time
  502. */
  503. public void sendTempBan(String account, String ip, long time)
  504. {
  505. TempBan tbn = new TempBan(account, ip, time);
  506. try
  507. {
  508. sendPacket(tbn);
  509. }
  510. catch (IOException e)
  511. {
  512. }
  513. }
  514. /**
  515. * Hex to string.
  516. * @param hex the hex value
  517. * @return the hex value as string
  518. */
  519. private String hexToString(byte[] hex)
  520. {
  521. return new BigInteger(hex).toString(16);
  522. }
  523. /**
  524. * Kick player for the given account.
  525. * @param account the account
  526. */
  527. public void doKickPlayer(String account)
  528. {
  529. L2GameClient client = _accountsInGameServer.get(account);
  530. if (client != null)
  531. {
  532. LogRecord record = new LogRecord(Level.WARNING, "Kicked by login");
  533. record.setParameters(new Object[]
  534. {
  535. client
  536. });
  537. _logAccounting.log(record);
  538. client.setAditionalClosePacket(SystemMessage.getSystemMessage(SystemMessageId.ANOTHER_LOGIN_WITH_ACCOUNT));
  539. client.closeNow();
  540. }
  541. }
  542. /**
  543. * Gets the chars on server.
  544. * @param account the account
  545. */
  546. private void getCharsOnServer(String account)
  547. {
  548. int chars = 0;
  549. List<Long> charToDel = new ArrayList<>();
  550. try (Connection con = ConnectionFactory.getInstance().getConnection();
  551. PreparedStatement ps = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?"))
  552. {
  553. ps.setString(1, account);
  554. try (ResultSet rs = ps.executeQuery())
  555. {
  556. while (rs.next())
  557. {
  558. chars++;
  559. long delTime = rs.getLong("deletetime");
  560. if (delTime != 0)
  561. {
  562. charToDel.add(delTime);
  563. }
  564. }
  565. }
  566. }
  567. catch (SQLException e)
  568. {
  569. _log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
  570. }
  571. ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
  572. try
  573. {
  574. sendPacket(rec);
  575. }
  576. catch (IOException e)
  577. {
  578. }
  579. }
  580. /**
  581. * Send packet.
  582. * @param sl the sendable packet
  583. * @throws IOException Signals that an I/O exception has occurred.
  584. */
  585. private void sendPacket(BaseSendablePacket sl) throws IOException
  586. {
  587. byte[] data = sl.getContent();
  588. NewCrypt.appendChecksum(data);
  589. _blowfish.crypt(data, 0, data.length);
  590. int len = data.length + 2;
  591. synchronized (_out) // avoids tow threads writing in the mean time
  592. {
  593. _out.write(len & 0xff);
  594. _out.write((len >> 8) & 0xff);
  595. _out.write(data);
  596. _out.flush();
  597. }
  598. }
  599. /**
  600. * Sets the max player.
  601. * @param maxPlayer The maxPlayer to set.
  602. */
  603. public void setMaxPlayer(int maxPlayer)
  604. {
  605. sendServerStatus(ServerStatus.MAX_PLAYERS, maxPlayer);
  606. _maxPlayer = maxPlayer;
  607. }
  608. /**
  609. * Gets the max player.
  610. * @return Returns the maxPlayer.
  611. */
  612. public int getMaxPlayer()
  613. {
  614. return _maxPlayer;
  615. }
  616. /**
  617. * Send server status.
  618. * @param id the id
  619. * @param value the value
  620. */
  621. public void sendServerStatus(int id, int value)
  622. {
  623. ServerStatus ss = new ServerStatus();
  624. ss.addAttribute(id, value);
  625. try
  626. {
  627. sendPacket(ss);
  628. }
  629. catch (IOException e)
  630. {
  631. }
  632. }
  633. /**
  634. * Send Server Type Config to LS.
  635. */
  636. public void sendServerType()
  637. {
  638. ServerStatus ss = new ServerStatus();
  639. ss.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  640. try
  641. {
  642. sendPacket(ss);
  643. }
  644. catch (IOException e)
  645. {
  646. }
  647. }
  648. /**
  649. * Send change password.
  650. * @param accountName the account name
  651. * @param charName the char name
  652. * @param oldpass the old pass
  653. * @param newpass the new pass
  654. */
  655. public void sendChangePassword(String accountName, String charName, String oldpass, String newpass)
  656. {
  657. ChangePassword cp = new ChangePassword(accountName, charName, oldpass, newpass);
  658. try
  659. {
  660. sendPacket(cp);
  661. }
  662. catch (IOException e)
  663. {
  664. }
  665. }
  666. /**
  667. * Gets the status string.
  668. * @return the status string
  669. */
  670. public String getStatusString()
  671. {
  672. return ServerStatus.STATUS_STRING[_status];
  673. }
  674. /**
  675. * Gets the server name.
  676. * @return the server name.
  677. */
  678. public String getServerName()
  679. {
  680. return _serverName;
  681. }
  682. /**
  683. * Sets the server status.
  684. * @param status the new server status
  685. */
  686. public void setServerStatus(int status)
  687. {
  688. switch (status)
  689. {
  690. case ServerStatus.STATUS_AUTO:
  691. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  692. _status = status;
  693. break;
  694. case ServerStatus.STATUS_DOWN:
  695. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_DOWN);
  696. _status = status;
  697. break;
  698. case ServerStatus.STATUS_FULL:
  699. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_FULL);
  700. _status = status;
  701. break;
  702. case ServerStatus.STATUS_GM_ONLY:
  703. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  704. _status = status;
  705. break;
  706. case ServerStatus.STATUS_GOOD:
  707. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GOOD);
  708. _status = status;
  709. break;
  710. case ServerStatus.STATUS_NORMAL:
  711. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_NORMAL);
  712. _status = status;
  713. break;
  714. default:
  715. throw new IllegalArgumentException("Status does not exists:" + status);
  716. }
  717. }
  718. public L2GameClient getClient(String name)
  719. {
  720. return name != null ? _accountsInGameServer.get(name) : null;
  721. }
  722. public static class SessionKey
  723. {
  724. public int playOkID1;
  725. public int playOkID2;
  726. public int loginOkID1;
  727. public int loginOkID2;
  728. /**
  729. * Instantiates a new session key.
  730. * @param loginOK1 the login o k1
  731. * @param loginOK2 the login o k2
  732. * @param playOK1 the play o k1
  733. * @param playOK2 the play o k2
  734. */
  735. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  736. {
  737. playOkID1 = playOK1;
  738. playOkID2 = playOK2;
  739. loginOkID1 = loginOK1;
  740. loginOkID2 = loginOK2;
  741. }
  742. @Override
  743. public String toString()
  744. {
  745. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  746. }
  747. }
  748. private static class WaitingClient
  749. {
  750. public String account;
  751. public L2GameClient gameClient;
  752. public SessionKey session;
  753. /**
  754. * Instantiates a new waiting client.
  755. * @param acc the acc
  756. * @param client the client
  757. * @param key the key
  758. */
  759. public WaitingClient(String acc, L2GameClient client, SessionKey key)
  760. {
  761. account = acc;
  762. gameClient = client;
  763. session = key;
  764. }
  765. }
  766. private static class SingletonHolder
  767. {
  768. protected static final LoginServerThread _instance = new LoginServerThread();
  769. }
  770. }