LoginServerThread.java 22 KB

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