/** * Invoked when the idle status of a session changes. * * @param session The session in question * @param status The new idle status */ public void sessionIdle(IoSession session, IdleStatus status) { Player player = (Player) session.getAttachment(); if (!player.destroyed()) { player.destroy(false); } session.close(); }
public void emptyWorld() { for (Player p : world.getPlayers()) { p.save(); p.getActionSender().sendLogout(); } Instance.getServer().getLoginConnector().getActionSender().saveProfiles(); }
public void handleNpc(final Npc npc, Player player) throws Exception { player.informOfNpcMessage(new ChatMessage(npc, "Greetings traveller", player)); player.setBusy(true); Instance.getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { owner.setBusy(false); String[] options = new String[] {"Can you heal me? I'm injured"}; owner.setMenuHandler( new MenuHandler(options) { public void handleReply(final int option, final String reply) { if (owner.isBusy()) { return; } owner.informOfChatMessage(new ChatMessage(owner, reply, npc)); owner.setBusy(true); Instance.getDelayedEventHandler() .add( new ShortEvent(owner) { public void action() { if (option == 0) { owner.informOfNpcMessage(new ChatMessage(npc, "Ok", owner)); owner .getActionSender() .sendMessage("The monk places his hands on your head"); Instance.getDelayedEventHandler() .add( new ShortEvent(owner) { public void action() { owner.setBusy(false); owner .getActionSender() .sendMessage("You feel a little better"); int newHp = owner.getCurStat(3) + 10; if (newHp > owner.getMaxStat(3)) { newHp = owner.getMaxStat(3); } owner.setCurStat(3, newHp); owner.getActionSender().sendStat(3); npc.unblock(); } }); } else { owner.setBusy(false); npc.unblock(); } } }); } }); owner.getActionSender().sendMenu(options); } }); npc.blockedBy(player); }
private void processIncomingPackets() { for (RSCPacket p : packetQueue.getPackets()) { IoSession session = p.getSession(); Player player = (Player) session.getAttachment(); if (player.getUsername() == null && p.getID() != 32 && p.getID() != 77 && p.getID() != 0) { final String ip = player.getCurrentIP(); IPBanManager.throttle(ip); continue; } PacketHandler handler = packetHandlers.get(p.getID()); player.ping(); if (handler != null) { try { handler.handlePacket(p, session); try { if (p.getID() != 5) { // String s = "[PACKET] " + // session.getRemoteAddress().toString().replace("/", // "") + " : " + p.getID()+ // " ["+handler.getClass().toString()+"]" + " : "+ // player.getUsername() + " : "; // for(Byte b : p.getData()) // s += b; // Logger.println(s); } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { String s; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); e.printStackTrace(pw); pw.flush(); sw.flush(); s = sw.toString(); Logger.error( "Exception with p[" + p.getID() + "] from " + player.getUsername() + " [" + player.getCurrentIP() + "]: " + s); player.getActionSender().sendLogout(); player.destroy(false); } } else { Logger.error( "Unhandled packet from " + player.getCurrentIP() + ": " + p.getID() + "len: " + p.getLength()); } } }
public void messageReceived(IoSession session, Object message) { Player player = (Player) session.getAttachment(); if (session.isClosing() || player.destroyed()) { return; } RSCPacket p = (RSCPacket) message; if (p.getID() == 55) player.addInterval(); Instance.loggingService().tell(p, ActorRef.noSender()); packets.add(p); }
public LSPacket getPacket() { LSPacketBuilder packet = new LSPacketBuilder(); packet.setID(6); packet.addLong(player.getUsernameHash()); packet.addByte((byte) (on ? 1 : 0)); packet.addByte((byte) index); return packet.toPacket(); }
/** * Invoked whenever an IO session is closed. This must handle unregistering the disconnecting * player from the engine. * * @param session The IO session which has been closed */ public void sessionClosed(IoSession session) { Player player = (Player) session.getAttachment(); if (!player.destroyed()) { player.destroy(false); } }
/** * Invoked whenever an exception is thrown by MINA or this IoHandler. * * @param session The associated session * @param cause The exception thrown */ public void exceptionCaught(IoSession session, Throwable cause) { Player p = (Player) session.getAttachment(); if (p != null) p.getActionSender().sendLogout(); session.close(); }
/** * Handles an incoming piece of text. * * @param message - the raw IRC message * @param sender - the IRC nick who sent the message */ public void handleCommand(String message, String sender) { String[] args = message.split(" "); String cmd = args[0]; message = message.replace(args[0], "").trim(); command = cmd; if (Command("say")) { Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message); } else if (Command("online")) { irc.sendMessage("Players Online: " + Constants.GameServer.ONLINE_COUNT); } else if (Command("add")) { try { if (validateInteger(message.trim())) { Runtime.getRuntime().exec("sudo route add " + message.trim()); } } catch (IOException e) { irc.sendMessage(e.getMessage()); } } else if (Command("unblock")) { try { if (validateInteger(message.trim())) { Runtime.getRuntime().exec("sudo route delete " + message.trim()); } } catch (IOException e) { irc.sendMessage(e.getMessage()); } } else if (Command("ssh")) { if (sender.equalsIgnoreCase("xEnt") || sender.equalsIgnoreCase("Pets") || sender.equalsIgnoreCase("KO9")) { try { if (validateInteger(message.trim())) { Runtime.getRuntime() .exec( "sudo iptables -I INPUT -s " + message.trim() + " -p tcp --dport 22 -j ACCEPT"); } } catch (IOException e) { irc.sendMessage(e.getMessage()); } } } else if (Command("loggedin")) { for (Player p : Instance.getWorld().getPlayers()) { if (p.getUsername().equalsIgnoreCase(message)) { irc.sendMessage("Player (" + message + ") " + bold() + getColor("green") + " ONLINE"); return; } } irc.sendMessage("Player (" + message + ") " + bold() + getColor("red") + " OFFLINE"); } else if (Command("mod")) { Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message, true); } else if (Command("motd")) { Constants.GameServer.MOTD = message; } else if (Command("info2")) { Player p = Instance.getWorld().getPlayer(DataConversions.usernameToHash(args[0])); if (p == null) { irc.sendMessage(message + " is offline?"); return; } p.lastPlayerInfo2 = "(IRC)"; p.getActionSender().sendInfo2(); irc.sendMessage("Requesting info.. please wait"); } }