L2GameClient.java 21 KB

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