LoginServerThread.java 22 KB

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