LoginServerThread.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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.Collection;
  35. import java.util.List;
  36. import java.util.Map;
  37. import java.util.logging.Level;
  38. import java.util.logging.LogRecord;
  39. import java.util.logging.Logger;
  40. import javolution.util.FastList;
  41. import javolution.util.FastMap;
  42. import com.l2jserver.Config;
  43. import com.l2jserver.L2DatabaseFactory;
  44. import com.l2jserver.gameserver.model.L2World;
  45. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  46. import com.l2jserver.gameserver.network.L2GameClient;
  47. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  48. import com.l2jserver.gameserver.network.SystemMessageId;
  49. import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
  50. import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
  51. import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
  52. import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
  53. import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
  54. import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
  55. import com.l2jserver.gameserver.network.gameserverpackets.PlayerTracert;
  56. import com.l2jserver.gameserver.network.gameserverpackets.ReplyCharacters;
  57. import com.l2jserver.gameserver.network.gameserverpackets.SendMail;
  58. import com.l2jserver.gameserver.network.gameserverpackets.ServerStatus;
  59. import com.l2jserver.gameserver.network.gameserverpackets.TempBan;
  60. import com.l2jserver.gameserver.network.loginserverpackets.AuthResponse;
  61. import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
  62. import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
  63. import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
  64. import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
  65. import com.l2jserver.gameserver.network.loginserverpackets.RequestCharacters;
  66. import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  67. import com.l2jserver.gameserver.network.serverpackets.LoginFail;
  68. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  69. import com.l2jserver.util.Util;
  70. import com.l2jserver.util.crypt.NewCrypt;
  71. import com.l2jserver.util.network.BaseSendablePacket;
  72. public class LoginServerThread extends Thread
  73. {
  74. protected static final Logger _log = Logger.getLogger(LoginServerThread.class.getName());
  75. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  76. /** {@see com.l2jserver.loginserver.LoginServer#PROTOCOL_REV } */
  77. private static final int REVISION = 0x0106;
  78. private RSAPublicKey _publicKey;
  79. private String _hostname;
  80. private int _port;
  81. private int _gamePort;
  82. private Socket _loginSocket;
  83. private InputStream _in;
  84. private OutputStream _out;
  85. /**
  86. * The BlowFish engine used to encrypt packets<br>
  87. * It is first initialized with a unified key:<br>
  88. * "_;v.]05-31!|+-%xT!^[$\00"<br>
  89. * <br>
  90. * and then after handshake, with a new key sent by<br>
  91. * loginserver during the handshake. This new key is stored<br>
  92. * in {@link #_blowfishKey}
  93. */
  94. private NewCrypt _blowfish;
  95. private byte[] _blowfishKey;
  96. private byte[] _hexID;
  97. private boolean _acceptAlternate;
  98. private int _requestID;
  99. private int _serverID;
  100. private boolean _reserveHost;
  101. private int _maxPlayer;
  102. private List<WaitingClient> _waitingClients;
  103. private Map<String, L2GameClient> _accountsInGameServer;
  104. private int _status;
  105. private String _serverName;
  106. private String[] _subnets;
  107. private String[] _hosts;
  108. private LoginServerThread()
  109. {
  110. super("LoginServerThread");
  111. _port = Config.GAME_SERVER_LOGIN_PORT;
  112. _gamePort = Config.PORT_GAME;
  113. _hostname = Config.GAME_SERVER_LOGIN_HOST;
  114. _hexID = Config.HEX_ID;
  115. if (_hexID == null)
  116. {
  117. _requestID = Config.REQUEST_ID;
  118. _hexID = Util.generateHex(16);
  119. }
  120. else
  121. {
  122. _requestID = Config.SERVER_ID;
  123. }
  124. _acceptAlternate = Config.ACCEPT_ALTERNATE_ID;
  125. _reserveHost = Config.RESERVE_HOST_ON_LOGIN;
  126. _subnets = Config.GAME_SERVER_SUBNETS;
  127. _hosts = Config.GAME_SERVER_HOSTS;
  128. _waitingClients = new FastList<WaitingClient>();
  129. _accountsInGameServer = new FastMap<String, L2GameClient>().shared();
  130. _maxPlayer = Config.MAXIMUM_ONLINE_USERS;
  131. }
  132. public static LoginServerThread getInstance()
  133. {
  134. return SingletonHolder._instance;
  135. }
  136. @Override
  137. public void run()
  138. {
  139. while (!isInterrupted())
  140. {
  141. int lengthHi = 0;
  142. int lengthLo = 0;
  143. int length = 0;
  144. boolean checksumOk = false;
  145. try
  146. {
  147. // Connection
  148. _log.info("Connecting to login on " + _hostname + ":" + _port);
  149. _loginSocket = new Socket(_hostname, _port);
  150. _in = _loginSocket.getInputStream();
  151. _out = new BufferedOutputStream(_loginSocket.getOutputStream());
  152. //init Blowfish
  153. _blowfishKey = Util.generateHex(40);
  154. _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00");
  155. while (!isInterrupted())
  156. {
  157. lengthLo = _in.read();
  158. lengthHi = _in.read();
  159. length = lengthHi * 256 + lengthLo;
  160. if (lengthHi < 0)
  161. {
  162. _log.finer("LoginServerThread: Login terminated the connection.");
  163. break;
  164. }
  165. byte[] incoming = new byte[length - 2];
  166. int receivedBytes = 0;
  167. int newBytes = 0;
  168. int left = length - 2;
  169. while (newBytes != -1 && receivedBytes < length - 2)
  170. {
  171. newBytes = _in.read(incoming, receivedBytes, left);
  172. receivedBytes = receivedBytes + newBytes;
  173. left -= newBytes;
  174. }
  175. if (receivedBytes != length - 2)
  176. {
  177. _log.warning("Incomplete Packet is sent to the server, closing connection.(LS)");
  178. break;
  179. }
  180. // decrypt if we have a key
  181. byte[] decrypt = _blowfish.decrypt(incoming);
  182. checksumOk = NewCrypt.verifyChecksum(decrypt);
  183. if (!checksumOk)
  184. {
  185. _log.warning("Incorrect packet checksum, ignoring packet (LS)");
  186. break;
  187. }
  188. if (Config.DEBUG)
  189. _log.warning("[C]\n" + Util.printData(decrypt));
  190. int packetType = decrypt[0] & 0xff;
  191. switch (packetType)
  192. {
  193. case 0x00:
  194. InitLS init = new InitLS(decrypt);
  195. if (Config.DEBUG)
  196. _log.info("Init received");
  197. if (init.getRevision() != REVISION)
  198. {
  199. //TODO: revision mismatch
  200. _log.warning("/!\\ Revision mismatch between LS and GS /!\\");
  201. break;
  202. }
  203. try
  204. {
  205. KeyFactory kfac = KeyFactory.getInstance("RSA");
  206. BigInteger modulus = new BigInteger(init.getRSAKey());
  207. RSAPublicKeySpec kspec1 = new RSAPublicKeySpec(modulus, RSAKeyGenParameterSpec.F4);
  208. _publicKey = (RSAPublicKey) kfac.generatePublic(kspec1);
  209. if (Config.DEBUG)
  210. _log.info("RSA key set up");
  211. }
  212. catch (GeneralSecurityException e)
  213. {
  214. _log.warning("Troubles while init the public key send by login");
  215. break;
  216. }
  217. //send the blowfish key through the rsa encryption
  218. BlowFishKey bfk = new BlowFishKey(_blowfishKey, _publicKey);
  219. sendPacket(bfk);
  220. if (Config.DEBUG)
  221. _log.info("Sent new blowfish key");
  222. //now, only accept paket with the new encryption
  223. _blowfish = new NewCrypt(_blowfishKey);
  224. if (Config.DEBUG)
  225. _log.info("Changed blowfish key");
  226. AuthRequest ar = new AuthRequest(_requestID, _acceptAlternate, _hexID, _gamePort, _reserveHost, _maxPlayer, _subnets, _hosts);
  227. sendPacket(ar);
  228. if (Config.DEBUG)
  229. _log.info("Sent AuthRequest to login");
  230. break;
  231. case 0x01:
  232. LoginServerFail lsf = new LoginServerFail(decrypt);
  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(decrypt);
  238. _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. FastList<String> playerList = new FastList<String>();
  276. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  277. //synchronized (L2World.getInstance().getAllPlayers())
  278. {
  279. for (L2PcInstance player : pls)
  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);
  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. }
  334. }
  335. }
  336. catch (UnknownHostException e)
  337. {
  338. if (Config.DEBUG)
  339. _log.log(Level.WARNING, "", e);
  340. }
  341. catch (SocketException e)
  342. {
  343. _log.warning("LoginServer not avaible, trying to reconnect...");
  344. }
  345. catch (IOException e)
  346. {
  347. _log.log(Level.WARNING, "Disconnected from Login, Trying to reconnect: " + e.getMessage(), e);
  348. }
  349. finally
  350. {
  351. try
  352. {
  353. _loginSocket.close();
  354. if (isInterrupted())
  355. return;
  356. }
  357. catch (Exception e)
  358. {
  359. }
  360. }
  361. try
  362. {
  363. Thread.sleep(5000); // 5 seconds tempo.
  364. }
  365. catch (InterruptedException e)
  366. {
  367. return; // never swallow an interrupt!
  368. }
  369. }
  370. }
  371. public void addWaitingClientAndSendRequest(String acc, L2GameClient client, SessionKey key)
  372. {
  373. if (Config.DEBUG)
  374. _log.info(String.valueOf(key));
  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. if (Config.DEBUG)
  389. _log.log(Level.WARNING, "", e);
  390. }
  391. }
  392. public void removeWaitingClient(L2GameClient client)
  393. {
  394. WaitingClient toRemove = null;
  395. synchronized (_waitingClients)
  396. {
  397. for (WaitingClient c : _waitingClients)
  398. {
  399. if (c.gameClient == client)
  400. {
  401. toRemove = c;
  402. }
  403. }
  404. if (toRemove != null)
  405. _waitingClients.remove(toRemove);
  406. }
  407. }
  408. public void sendLogout(String account)
  409. {
  410. if (account == null)
  411. return;
  412. PlayerLogout pl = new PlayerLogout(account);
  413. try
  414. {
  415. sendPacket(pl);
  416. }
  417. catch (IOException e)
  418. {
  419. _log.warning("Error while sending logout packet to login");
  420. if (Config.DEBUG)
  421. _log.log(Level.WARNING, "", e);
  422. }
  423. finally
  424. {
  425. _accountsInGameServer.remove(account);
  426. }
  427. }
  428. public void addGameServerLogin(String account, L2GameClient client)
  429. {
  430. _accountsInGameServer.put(account, client);
  431. }
  432. public void sendAccessLevel(String account, int level)
  433. {
  434. ChangeAccessLevel cal = new ChangeAccessLevel(account, level);
  435. try
  436. {
  437. sendPacket(cal);
  438. }
  439. catch (IOException e)
  440. {
  441. if (Config.DEBUG)
  442. _log.log(Level.WARNING, "", e);
  443. }
  444. }
  445. public void sendClientTracert(String account, String[] adress)
  446. {
  447. PlayerTracert ptc = new PlayerTracert(account, adress[0], adress[1], adress[2], adress[3], adress[4]);
  448. try
  449. {
  450. sendPacket(ptc);
  451. }
  452. catch (IOException e)
  453. {
  454. if (Config.DEBUG)
  455. _log.log(Level.WARNING, "", e);
  456. }
  457. }
  458. public void sendMail(String account, String mailId, String... args)
  459. {
  460. SendMail sem = new SendMail(account, mailId, args);
  461. try
  462. {
  463. sendPacket(sem);
  464. }
  465. catch (IOException e)
  466. {
  467. if (Config.DEBUG)
  468. _log.log(Level.WARNING, "", e);
  469. }
  470. }
  471. public void sendTempBan(String account, String ip, long time)
  472. {
  473. TempBan tbn = new TempBan(account, ip, time);
  474. try
  475. {
  476. sendPacket(tbn);
  477. }
  478. catch (IOException e)
  479. {
  480. if (Config.DEBUG)
  481. _log.log(Level.WARNING, "", e);
  482. }
  483. }
  484. private String hexToString(byte[] hex)
  485. {
  486. return new BigInteger(hex).toString(16);
  487. }
  488. public void doKickPlayer(String account)
  489. {
  490. L2GameClient client = _accountsInGameServer.get(account);
  491. if (client != null)
  492. {
  493. LogRecord record = new LogRecord(Level.WARNING, "Kicked by login");
  494. record.setParameters(new Object[]{client});
  495. _logAccounting.log(record);
  496. client.setAditionalClosePacket(SystemMessage.getSystemMessage(SystemMessageId.ANOTHER_LOGIN_WITH_ACCOUNT));
  497. client.closeNow();
  498. }
  499. }
  500. private void getCharsOnServer(String account)
  501. {
  502. Connection con = null;
  503. int chars = 0;
  504. List<Long> charToDel = new ArrayList<Long>();
  505. try
  506. {
  507. con = L2DatabaseFactory.getInstance().getConnection();
  508. PreparedStatement statement = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?");
  509. statement.setString(1, account);
  510. ResultSet rset = statement.executeQuery();
  511. while (rset.next())
  512. {
  513. chars++;
  514. long delTime = rset.getLong("deletetime");
  515. if (delTime != 0)
  516. charToDel.add(delTime);
  517. }
  518. rset.close();
  519. statement.close();
  520. }
  521. catch (SQLException e)
  522. {
  523. _log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
  524. }
  525. finally
  526. {
  527. L2DatabaseFactory.close(con);
  528. }
  529. ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
  530. try
  531. {
  532. sendPacket(rec);
  533. }
  534. catch (IOException e)
  535. {
  536. if (Config.DEBUG)
  537. _log.log(Level.WARNING, "", e);
  538. }
  539. }
  540. /**
  541. * @param sl
  542. * @throws IOException
  543. */
  544. private void sendPacket(BaseSendablePacket sl) throws IOException
  545. {
  546. byte[] data = sl.getContent();
  547. NewCrypt.appendChecksum(data);
  548. if (Config.DEBUG)
  549. _log.finest("[S]\n" + Util.printData(data));
  550. data = _blowfish.crypt(data);
  551. int len = data.length + 2;
  552. synchronized (_out) //avoids tow threads writing in the mean time
  553. {
  554. _out.write(len & 0xff);
  555. _out.write(len >> 8 & 0xff);
  556. _out.write(data);
  557. _out.flush();
  558. }
  559. }
  560. /**
  561. * @param maxPlayer The maxPlayer to set.
  562. */
  563. public void setMaxPlayer(int maxPlayer)
  564. {
  565. sendServerStatus(ServerStatus.MAX_PLAYERS, maxPlayer);
  566. _maxPlayer = maxPlayer;
  567. }
  568. /**
  569. * @return Returns the maxPlayer.
  570. */
  571. public int getMaxPlayer()
  572. {
  573. return _maxPlayer;
  574. }
  575. /**
  576. * @param server_gm_only
  577. */
  578. public void sendServerStatus(int id, int value)
  579. {
  580. ServerStatus ss = new ServerStatus();
  581. ss.addAttribute(id, value);
  582. try
  583. {
  584. sendPacket(ss);
  585. }
  586. catch (IOException e)
  587. {
  588. if (Config.DEBUG)
  589. _log.log(Level.WARNING, "", e);
  590. }
  591. }
  592. /**
  593. * Send Server Type Config to LS
  594. */
  595. public void sendServerType()
  596. {
  597. ServerStatus ss = new ServerStatus();
  598. ss.addAttribute(ServerStatus.SERVER_TYPE, Config.SERVER_LIST_TYPE);
  599. try
  600. {
  601. sendPacket(ss);
  602. }
  603. catch (IOException e)
  604. {
  605. if (Config.DEBUG)
  606. _log.log(Level.WARNING, "", e);
  607. }
  608. }
  609. /**
  610. * @return
  611. */
  612. public String getStatusString()
  613. {
  614. return ServerStatus.STATUS_STRING[_status];
  615. }
  616. /**
  617. * @return
  618. */
  619. public boolean isBracketShown()
  620. {
  621. return Config.SERVER_LIST_BRACKET;
  622. }
  623. /**
  624. * @return Returns the serverName.
  625. */
  626. public String getServerName()
  627. {
  628. return _serverName;
  629. }
  630. public void setServerStatus(int status)
  631. {
  632. switch (status)
  633. {
  634. case ServerStatus.STATUS_AUTO:
  635. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_AUTO);
  636. _status = status;
  637. break;
  638. case ServerStatus.STATUS_DOWN:
  639. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_DOWN);
  640. _status = status;
  641. break;
  642. case ServerStatus.STATUS_FULL:
  643. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_FULL);
  644. _status = status;
  645. break;
  646. case ServerStatus.STATUS_GM_ONLY:
  647. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GM_ONLY);
  648. _status = status;
  649. break;
  650. case ServerStatus.STATUS_GOOD:
  651. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_GOOD);
  652. _status = status;
  653. break;
  654. case ServerStatus.STATUS_NORMAL:
  655. sendServerStatus(ServerStatus.SERVER_LIST_STATUS, ServerStatus.STATUS_NORMAL);
  656. _status = status;
  657. break;
  658. default:
  659. throw new IllegalArgumentException("Status does not exists:" + status);
  660. }
  661. }
  662. public static class SessionKey
  663. {
  664. public int playOkID1;
  665. public int playOkID2;
  666. public int loginOkID1;
  667. public int loginOkID2;
  668. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  669. {
  670. playOkID1 = playOK1;
  671. playOkID2 = playOK2;
  672. loginOkID1 = loginOK1;
  673. loginOkID2 = loginOK2;
  674. }
  675. @Override
  676. public String toString()
  677. {
  678. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  679. }
  680. }
  681. private static class WaitingClient
  682. {
  683. public int timestamp;
  684. public String account;
  685. public L2GameClient gameClient;
  686. public SessionKey session;
  687. public WaitingClient(String acc, L2GameClient client, SessionKey key)
  688. {
  689. account = acc;
  690. timestamp = GameTimeController.getGameTicks();
  691. gameClient = client;
  692. session = key;
  693. }
  694. }
  695. @SuppressWarnings("synthetic-access")
  696. private static class SingletonHolder
  697. {
  698. protected static final LoginServerThread _instance = new LoginServerThread();
  699. }
  700. }