2
0

L2GameClient.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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.network;
  16. import java.net.InetAddress;
  17. import java.nio.ByteBuffer;
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.util.List;
  22. import java.util.concurrent.RejectedExecutionException;
  23. import java.util.concurrent.ScheduledFuture;
  24. import java.util.concurrent.locks.ReentrantLock;
  25. import java.util.logging.Level;
  26. import java.util.logging.LogRecord;
  27. import java.util.logging.Logger;
  28. import javolution.util.FastList;
  29. import org.mmocore.network.MMOClient;
  30. import org.mmocore.network.MMOConnection;
  31. import com.l2jserver.Config;
  32. import com.l2jserver.L2DatabaseFactory;
  33. import com.l2jserver.gameserver.LoginServerThread;
  34. import com.l2jserver.gameserver.ThreadPoolManager;
  35. import com.l2jserver.gameserver.LoginServerThread.SessionKey;
  36. import com.l2jserver.gameserver.datatables.CharNameTable;
  37. import com.l2jserver.gameserver.datatables.ClanTable;
  38. import com.l2jserver.gameserver.model.CharSelectInfoPackage;
  39. import com.l2jserver.gameserver.model.L2Clan;
  40. import com.l2jserver.gameserver.model.L2World;
  41. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  42. import com.l2jserver.gameserver.model.entity.L2Event;
  43. import com.l2jserver.gameserver.model.entity.TvTEvent;
  44. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  45. import com.l2jserver.gameserver.network.serverpackets.ServerClose;
  46. import com.l2jserver.gameserver.util.FloodProtectors;
  47. import com.l2jserver.gameserver.util.Util;
  48. import com.l2jserver.util.EventData;
  49. /**
  50. * Represents a client connected on Game Server
  51. * @author KenM
  52. */
  53. public final class L2GameClient extends MMOClient<MMOConnection<L2GameClient>>
  54. {
  55. protected static final Logger _log = Logger.getLogger(L2GameClient.class.getName());
  56. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  57. /**
  58. * CONNECTED - client has just connected
  59. * AUTHED - client has authed but doesnt has character attached to it yet
  60. * IN_GAME - client has selected a char and is in game
  61. * @author KenM
  62. */
  63. public static enum GameClientState { CONNECTED, AUTHED, IN_GAME }
  64. public GameClientState state;
  65. // Info
  66. private String _accountName;
  67. private SessionKey _sessionId;
  68. private L2PcInstance _activeChar;
  69. private ReentrantLock _activeCharLock = new ReentrantLock();
  70. private boolean _isAuthedGG;
  71. private long _connectionStartTime;
  72. private List<Integer> _charSlotMapping = new FastList<Integer>();
  73. // floodprotectors
  74. private final FloodProtectors _floodProtectors = new FloodProtectors(this);
  75. // Task
  76. protected final ScheduledFuture<?> _autoSaveInDB;
  77. protected ScheduledFuture<?> _cleanupTask = null;
  78. // Crypt
  79. private GameCrypt _crypt;
  80. // Flood protection
  81. public byte packetsSentInSec = 0;
  82. public int packetsSentStartTick = 0;
  83. public byte underflowReadsInMin = 0;
  84. public int underflowReadStartTick = 0;
  85. private boolean _isDetached = false;
  86. private boolean _protocol;
  87. private int[][] trace;
  88. public L2GameClient(MMOConnection<L2GameClient> con)
  89. {
  90. super(con);
  91. state = GameClientState.CONNECTED;
  92. _connectionStartTime = System.currentTimeMillis();
  93. _crypt = new GameCrypt();
  94. if (Config.CHAR_STORE_INTERVAL > 0)
  95. {
  96. _autoSaveInDB = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(
  97. new AutoSaveTask(), 300000L, (Config.CHAR_STORE_INTERVAL*60000L)
  98. );
  99. }
  100. else
  101. {
  102. _autoSaveInDB = null;
  103. }
  104. }
  105. public byte[] enableCrypt()
  106. {
  107. byte[] key = BlowFishKeygen.getRandomKey();
  108. _crypt.setKey(key);
  109. return key;
  110. }
  111. public GameClientState getState()
  112. {
  113. return state;
  114. }
  115. public void setState(GameClientState pState)
  116. {
  117. state = pState;
  118. }
  119. public long getConnectionStartTime()
  120. {
  121. return _connectionStartTime;
  122. }
  123. @Override
  124. public boolean decrypt(ByteBuffer buf, int size)
  125. {
  126. _crypt.decrypt(buf.array(), buf.position(), size);
  127. return true;
  128. }
  129. @Override
  130. public boolean encrypt(final ByteBuffer buf, final int size)
  131. {
  132. _crypt.encrypt(buf.array(), buf.position(), size);
  133. buf.position(buf.position() + size);
  134. return true;
  135. }
  136. public L2PcInstance getActiveChar()
  137. {
  138. return _activeChar;
  139. }
  140. public void setActiveChar(L2PcInstance pActiveChar)
  141. {
  142. _activeChar = pActiveChar;
  143. if (_activeChar != null)
  144. {
  145. L2World.getInstance().storeObject(getActiveChar());
  146. }
  147. }
  148. public ReentrantLock getActiveCharLock()
  149. {
  150. return _activeCharLock;
  151. }
  152. public FloodProtectors getFloodProtectors()
  153. {
  154. return _floodProtectors;
  155. }
  156. public void setGameGuardOk(boolean val)
  157. {
  158. _isAuthedGG = val;
  159. }
  160. public boolean isAuthedGG()
  161. {
  162. return _isAuthedGG;
  163. }
  164. public void setAccountName(String pAccountName)
  165. {
  166. _accountName = pAccountName;
  167. }
  168. public String getAccountName()
  169. {
  170. return _accountName;
  171. }
  172. public void setSessionId(SessionKey sk)
  173. {
  174. _sessionId = sk;
  175. }
  176. public SessionKey getSessionId()
  177. {
  178. return _sessionId;
  179. }
  180. public void sendPacket(L2GameServerPacket gsp)
  181. {
  182. if (_isDetached) return;
  183. // Packets from invisible chars sends only to GMs
  184. if (gsp.isInvisible() && getActiveChar() != null && !getActiveChar().isGM())
  185. return;
  186. getConnection().sendPacket(gsp);
  187. gsp.runImpl();
  188. }
  189. public boolean isDetached()
  190. {
  191. return _isDetached;
  192. }
  193. public void setDetached(boolean b)
  194. {
  195. _isDetached = b;
  196. }
  197. /**
  198. * Method to handle character deletion
  199. *
  200. * @return a byte:
  201. * <li>-1: Error: No char was found for such charslot, caught exception, etc...
  202. * <li> 0: character is not member of any clan, proceed with deletion
  203. * <li> 1: character is member of a clan, but not clan leader
  204. * <li> 2: character is clan leader
  205. */
  206. public byte markToDeleteChar(int charslot)
  207. {
  208. int objid = getObjectIdForSlot(charslot);
  209. if (objid < 0)
  210. return -1;
  211. Connection con = null;
  212. try
  213. {
  214. con = L2DatabaseFactory.getInstance().getConnection();
  215. PreparedStatement statement = con.prepareStatement("SELECT clanId FROM characters WHERE charId=?");
  216. statement.setInt(1, objid);
  217. ResultSet rs = statement.executeQuery();
  218. rs.next();
  219. int clanId = rs.getInt(1);
  220. byte answer = 0;
  221. if (clanId != 0)
  222. {
  223. L2Clan clan = ClanTable.getInstance().getClan(clanId);
  224. if (clan == null)
  225. answer = 0; // jeezes!
  226. else if (clan.getLeaderId() == objid)
  227. answer = 2;
  228. else
  229. answer = 1;
  230. }
  231. rs.close();
  232. statement.close();
  233. // Setting delete time
  234. if (answer == 0)
  235. {
  236. if (Config.DELETE_DAYS == 0)
  237. deleteCharByObjId(objid);
  238. else
  239. {
  240. statement = con.prepareStatement("UPDATE characters SET deletetime=? WHERE charId=?");
  241. statement.setLong(1, System.currentTimeMillis() + Config.DELETE_DAYS*86400000L); // 24*60*60*1000 = 86400000
  242. statement.setInt(2, objid);
  243. statement.execute();
  244. statement.close();
  245. }
  246. LogRecord record = new LogRecord(Level.WARNING, "Delete");
  247. record.setParameters(new Object[]{objid, L2GameClient.this});
  248. _logAccounting.log(record);
  249. }
  250. return answer;
  251. }
  252. catch (Exception e)
  253. {
  254. _log.log(Level.SEVERE, "Error updating delete time of character.", e);
  255. return -1;
  256. }
  257. finally
  258. {
  259. L2DatabaseFactory.close(con);
  260. }
  261. }
  262. /**
  263. * Save the L2PcInstance to the database.
  264. */
  265. public static void saveCharToDisk(L2PcInstance cha, boolean storeItems)
  266. {
  267. try
  268. {
  269. cha.store();
  270. if (Config.UPDATE_ITEMS_ON_CHAR_STORE && storeItems)
  271. {
  272. cha.getInventory().updateDatabase();
  273. cha.getWarehouse().updateDatabase();
  274. }
  275. }
  276. catch (Exception e)
  277. {
  278. _log.log(Level.SEVERE, "Error saving character..", e);
  279. }
  280. }
  281. public void markRestoredChar(int charslot) throws Exception
  282. {
  283. //have to make sure active character must be nulled
  284. /*if (getActiveChar() != null)
  285. {
  286. saveCharToDisk (getActiveChar());
  287. if (Config.DEBUG) _log.fine("active Char saved");
  288. this.setActiveChar(null);
  289. }*/
  290. int objid = getObjectIdForSlot(charslot);
  291. if (objid < 0)
  292. return;
  293. Connection con = null;
  294. try
  295. {
  296. con = L2DatabaseFactory.getInstance().getConnection();
  297. PreparedStatement statement = con.prepareStatement("UPDATE characters SET deletetime=0 WHERE charId=?");
  298. statement.setInt(1, objid);
  299. statement.execute();
  300. statement.close();
  301. }
  302. catch (Exception e)
  303. {
  304. _log.log(Level.SEVERE, "Error restoring character.", e);
  305. }
  306. finally
  307. {
  308. L2DatabaseFactory.close(con);
  309. }
  310. LogRecord record = new LogRecord(Level.WARNING, "Restore");
  311. record.setParameters(new Object[]{objid, L2GameClient.this});
  312. _logAccounting.log(record);
  313. }
  314. public static void deleteCharByObjId(int objid)
  315. {
  316. if (objid < 0)
  317. return;
  318. CharNameTable.getInstance().removeName(objid);
  319. Connection con = null;
  320. try
  321. {
  322. con = L2DatabaseFactory.getInstance().getConnection();
  323. PreparedStatement statement ;
  324. statement = con.prepareStatement("DELETE FROM character_friends WHERE charId=? OR friendId=?");
  325. statement.setInt(1, objid);
  326. statement.setInt(2, objid);
  327. statement.execute();
  328. statement.close();
  329. statement = con.prepareStatement("DELETE FROM character_hennas WHERE charId=?");
  330. statement.setInt(1, objid);
  331. statement.execute();
  332. statement.close();
  333. statement = con.prepareStatement("DELETE FROM character_macroses WHERE charId=?");
  334. statement.setInt(1, objid);
  335. statement.execute();
  336. statement.close();
  337. statement = con.prepareStatement("DELETE FROM character_quests WHERE charId=?");
  338. statement.setInt(1, objid);
  339. statement.execute();
  340. statement.close();
  341. statement = con.prepareStatement("DELETE FROM character_quest_global_data WHERE charId=?");
  342. statement.setInt(1, objid);
  343. statement.executeUpdate();
  344. statement.close();
  345. statement = con.prepareStatement("DELETE FROM character_recipebook WHERE charId=?");
  346. statement.setInt(1, objid);
  347. statement.execute();
  348. statement.close();
  349. statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
  350. statement.setInt(1, objid);
  351. statement.execute();
  352. statement.close();
  353. statement = con.prepareStatement("DELETE FROM character_skills WHERE charId=?");
  354. statement.setInt(1, objid);
  355. statement.execute();
  356. statement.close();
  357. statement = con.prepareStatement("DELETE FROM character_skills_save WHERE charId=?");
  358. statement.setInt(1, objid);
  359. statement.execute();
  360. statement.close();
  361. statement = con.prepareStatement("DELETE FROM character_subclasses WHERE charId=?");
  362. statement.setInt(1, objid);
  363. statement.execute();
  364. statement.close();
  365. statement = con.prepareStatement("DELETE FROM heroes WHERE charId=?");
  366. statement.setInt(1, objid);
  367. statement.execute();
  368. statement.close();
  369. statement = con.prepareStatement("DELETE FROM olympiad_nobles WHERE charId=?");
  370. statement.setInt(1, objid);
  371. statement.execute();
  372. statement.close();
  373. statement = con.prepareStatement("DELETE FROM seven_signs WHERE charId=?");
  374. statement.setInt(1, objid);
  375. statement.execute();
  376. statement.close();
  377. statement = con.prepareStatement("DELETE FROM pets WHERE item_obj_id IN (SELECT object_id FROM items WHERE items.owner_id=?)");
  378. statement.setInt(1, objid);
  379. statement.execute();
  380. statement.close();
  381. statement = con.prepareStatement("DELETE FROM item_attributes WHERE itemId IN (SELECT object_id FROM items WHERE items.owner_id=?)");
  382. statement.setInt(1, objid);
  383. statement.execute();
  384. statement.close();
  385. statement = con.prepareStatement("DELETE FROM items WHERE owner_id=?");
  386. statement.setInt(1, objid);
  387. statement.execute();
  388. statement.close();
  389. statement = con.prepareStatement("DELETE FROM merchant_lease WHERE player_id=?");
  390. statement.setInt(1, objid);
  391. statement.execute();
  392. statement.close();
  393. statement = con.prepareStatement("DELETE FROM character_raid_points WHERE charId=?");
  394. statement.setInt(1, objid);
  395. statement.execute();
  396. statement.close();
  397. statement = con.prepareStatement("DELETE FROM character_recommends WHERE charId=? OR target_id=?");
  398. statement.setInt(1, objid);
  399. statement.setInt(2, objid);
  400. statement.execute();
  401. statement.close();
  402. statement = con.prepareStatement("DELETE FROM character_instance_time WHERE charId=?");
  403. statement.setInt(1, objid);
  404. statement.execute();
  405. statement.close();
  406. statement = con.prepareStatement("DELETE FROM characters WHERE charId=?");
  407. statement.setInt(1, objid);
  408. statement.execute();
  409. statement.close();
  410. }
  411. catch (Exception e)
  412. {
  413. _log.log(Level.SEVERE, "Error deleting character.", e);
  414. }
  415. finally
  416. {
  417. L2DatabaseFactory.close(con);
  418. }
  419. }
  420. public L2PcInstance loadCharFromDisk(int charslot)
  421. {
  422. L2PcInstance character = L2PcInstance.load(getObjectIdForSlot(charslot));
  423. if (character != null)
  424. {
  425. // preinit some values for each login
  426. character.setRunning(); // running is default
  427. character.standUp(); // standing is default
  428. character.refreshOverloaded();
  429. character.refreshExpertisePenalty();
  430. character.setOnlineStatus(true);
  431. }
  432. else
  433. {
  434. _log.severe("could not restore in slot: "+ charslot);
  435. }
  436. //setCharacter(character);
  437. return character;
  438. }
  439. /**
  440. * @param chars
  441. */
  442. public void setCharSelection(CharSelectInfoPackage[] chars)
  443. {
  444. _charSlotMapping.clear();
  445. for (int i = 0; i < chars.length; i++)
  446. {
  447. int objectId = chars[i].getObjectId();
  448. _charSlotMapping.add(Integer.valueOf(objectId));
  449. }
  450. }
  451. public void close(L2GameServerPacket gsp)
  452. {
  453. getConnection().close(gsp);
  454. }
  455. /**
  456. * @param charslot
  457. * @return
  458. */
  459. private int getObjectIdForSlot(int charslot)
  460. {
  461. if (charslot < 0 || charslot >= _charSlotMapping.size())
  462. {
  463. _log.warning(toString()+" tried to delete Character in slot "+charslot+" but no characters exits at that slot.");
  464. return -1;
  465. }
  466. Integer objectId = _charSlotMapping.get(charslot);
  467. return objectId.intValue();
  468. }
  469. @Override
  470. protected void onForcedDisconnection()
  471. {
  472. LogRecord record = new LogRecord(Level.WARNING, "Disconnected abnormally");
  473. record.setParameters(new Object[]{L2GameClient.this});
  474. _logAccounting.log(record);
  475. }
  476. @Override
  477. protected void onDisconnection()
  478. {
  479. // no long running tasks here, do it async
  480. try
  481. {
  482. ThreadPoolManager.getInstance().executeTask(new DisconnectTask());
  483. }
  484. catch (RejectedExecutionException e)
  485. {
  486. // server is closing
  487. }
  488. }
  489. public void closeNow()
  490. {
  491. super.getConnection().close(ServerClose.STATIC_PACKET);
  492. cleanMe(true);
  493. }
  494. /**
  495. * Produces the best possible string representation of this client.
  496. */
  497. @Override
  498. public String toString()
  499. {
  500. try
  501. {
  502. InetAddress address = getConnection().getInetAddress();
  503. switch (getState())
  504. {
  505. case CONNECTED:
  506. return "[IP: "+(address == null ? "disconnected" : address.getHostAddress())+"]";
  507. case AUTHED:
  508. return "[Account: "+getAccountName()+" - IP: "+(address == null ? "disconnected" : address.getHostAddress())+"]";
  509. case IN_GAME:
  510. return "[Character: "+(getActiveChar() == null ? "disconnected" : getActiveChar().getName()+"["+getActiveChar().getObjectId()+"]")+" - Account: "+getAccountName()+" - IP: "+(address == null ? "disconnected" : address.getHostAddress())+"]";
  511. default:
  512. throw new IllegalStateException("Missing state on switch");
  513. }
  514. }
  515. catch (NullPointerException e)
  516. {
  517. return "[Character read failed due to disconnect]";
  518. }
  519. }
  520. class DisconnectTask implements Runnable
  521. {
  522. /**
  523. * @see java.lang.Runnable#run()
  524. */
  525. public void run()
  526. {
  527. boolean fast = true;
  528. try
  529. {
  530. final L2PcInstance player = L2GameClient.this.getActiveChar();
  531. if (player != null && !isDetached())
  532. {
  533. setDetached(true);
  534. if (!player.isInOlympiadMode()
  535. && !player.isFestivalParticipant()
  536. && !TvTEvent.isPlayerParticipant(player.getObjectId())
  537. && !player.isInJail()
  538. && player.getVehicle() == null)
  539. {
  540. if ((player.isInStoreMode() && Config.OFFLINE_TRADE_ENABLE)
  541. || (player.isInCraftMode() && Config.OFFLINE_CRAFT_ENABLE))
  542. {
  543. player.leaveParty();
  544. if (Config.OFFLINE_SET_NAME_COLOR)
  545. {
  546. player.getAppearance().setNameColor(Config.OFFLINE_NAME_COLOR);
  547. player.broadcastUserInfo();
  548. }
  549. if (player.getOfflineStartTime() == 0)
  550. player.setOfflineStartTime(System.currentTimeMillis());
  551. LogRecord record = new LogRecord(Level.INFO, "Entering offline mode");
  552. record.setParameters(new Object[]{L2GameClient.this});
  553. _logAccounting.log(record);
  554. return;
  555. }
  556. }
  557. if (player.isInCombat() || player.isLocked())
  558. {
  559. fast = false;
  560. }
  561. }
  562. cleanMe(fast);
  563. }
  564. catch (Exception e1)
  565. {
  566. _log.log(Level.WARNING, "Error while disconnecting client.", e1);
  567. }
  568. }
  569. }
  570. public void cleanMe(boolean fast)
  571. {
  572. try
  573. {
  574. synchronized(this)
  575. {
  576. if (_cleanupTask == null)
  577. {
  578. _cleanupTask = ThreadPoolManager.getInstance().scheduleGeneral(new CleanupTask(), fast ? 5 : 15000L);
  579. }
  580. }
  581. }
  582. catch (Exception e1)
  583. {
  584. _log.log(Level.WARNING, "Error during cleanup.", e1);
  585. }
  586. }
  587. class CleanupTask implements Runnable
  588. {
  589. /**
  590. * @see java.lang.Runnable#run()
  591. */
  592. public void run()
  593. {
  594. try
  595. {
  596. // we are going to manually save the char bellow thus we can force the cancel
  597. if (_autoSaveInDB != null)
  598. {
  599. _autoSaveInDB.cancel(true);
  600. ThreadPoolManager.getInstance().removeGeneral((Runnable) _autoSaveInDB);
  601. }
  602. L2PcInstance player = L2GameClient.this.getActiveChar();
  603. if (player != null) // this should only happen on connection loss
  604. {
  605. if (player.isLocked())
  606. {
  607. _log.log(Level.WARNING, "Player "+player.getName()+" still performing subclass actions during disconnect.");
  608. }
  609. // we store all data from players who are disconnected while in an event in order to restore it in the next login
  610. if (player.atEvent)
  611. {
  612. EventData data = new EventData(player.eventX, player.eventY, player.eventZ, player.eventkarma, player.eventpvpkills, player.eventpkkills, player.eventTitle, player.kills,
  613. player.eventSitForced);
  614. L2Event.connectionLossData.put(player.getName(), data);
  615. }
  616. // to prevent call cleanMe() again
  617. setDetached(false);
  618. // prevent closing again
  619. player.setClient(null);
  620. if (player.isOnline() > 0)
  621. player.logout();
  622. }
  623. L2GameClient.this.setActiveChar(null);
  624. }
  625. catch (Exception e1)
  626. {
  627. _log.log(Level.WARNING, "Error while cleanup client.", e1);
  628. }
  629. finally
  630. {
  631. LoginServerThread.getInstance().sendLogout(L2GameClient.this.getAccountName());
  632. }
  633. }
  634. }
  635. class AutoSaveTask implements Runnable
  636. {
  637. public void run()
  638. {
  639. try
  640. {
  641. L2PcInstance player = L2GameClient.this.getActiveChar();
  642. if (player != null && player.isOnline() > 0) // safety precaution
  643. {
  644. saveCharToDisk(player, true);
  645. if (player.getPet() != null)
  646. player.getPet().store();
  647. }
  648. }
  649. catch (Exception e)
  650. {
  651. _log.log(Level.SEVERE, "Error on AutoSaveTask.", e);
  652. }
  653. }
  654. }
  655. public boolean isProtocolOk()
  656. {
  657. return _protocol;
  658. }
  659. public void setProtocolOk(boolean b)
  660. {
  661. _protocol = b;
  662. }
  663. public boolean handleCheat(String punishment)
  664. {
  665. if (_activeChar != null)
  666. {
  667. Util.handleIllegalPlayerAction(_activeChar, toString()+": "+punishment, Config.DEFAULT_PUNISH);
  668. return true;
  669. }
  670. Logger _logAudit = Logger.getLogger("audit");
  671. _logAudit.log(Level.INFO, "AUDIT: Client "+toString()+" kicked for reason: "+punishment);
  672. closeNow();
  673. return false;
  674. }
  675. public void setClientTracert(int[][] tracert)
  676. {
  677. trace = tracert;
  678. }
  679. public int[][] getTrace()
  680. {
  681. return trace;
  682. }
  683. }