/** * Handles a trade request for {@code player}. * * @param player the player to handle this for. * @param payload the payloadfer for reading the sent data. */ private void tradeRequest(Player player, MessageBuilder payload) { int index = payload.getShort(true, ByteOrder.LITTLE); Player other = World.getPlayers().get(index); if (other == null || !validate(player, other)) return; player.setSkillAction(false); if (!MinigameHandler.execute(player, true, m -> m.canTrade(player, other))) return; player.getTradeSession().request(other); }
/** * Disconnects this session from the server by canceling the registered key and closing the socket * channel. * * @param forced if the session must be disconnected because of an IO issue. */ public void disconnect(boolean forced) { try { if (!forced && player.getCombatBuilder().inCombat()) { combatLogout = true; key.attach(null); key.cancel(); channel.close(); World.submit( new Task(150, false) { @Override public void execute() { if (!player.getCombatBuilder().inCombat()) { disconnect(true); this.cancel(); } } }); return; } packetDisconnect = forced; if (state == IOState.LOGGED_IN) { if (player.getOpenShop() != null) Shop.SHOPS.get(player.getOpenShop()).getPlayers().remove(player); World.getTaskQueue().cancel(player.getCombatBuilder()); World.getTaskQueue().cancel(player); player.setSkillAction(false); World.getPlayers().remove(player); MinigameHandler.execute(player, m -> m.onLogout(player)); player.getTradeSession().reset(false); player.getPrivateMessage().updateOtherList(false); if (FightCavesHandler.remove(player)) player.move(new Position(2399, 5177)); player.save(); } key.attach(null); key.cancel(); channel.close(); ConnectionHandler.remove(host); logger.info( state == IOState.LOGGED_IN ? player + " has logged " + "out." : this + " has logged out."); state = IOState.LOGGED_OUT; } catch (Exception e) { e.printStackTrace(); } }