Пример #1
0
 public void emptyWorld() {
   for (Player p : world.getPlayers()) {
     p.save();
     p.getActionSender().sendLogout();
   }
   Instance.getServer().getLoginConnector().getActionSender().saveProfiles();
 }
Пример #2
0
  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());
      }
    }
  }
Пример #3
0
  /**
   * 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();
  }
Пример #4
0
  /**
   * 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");
    }
  }