Solved Ping a server?

Discussion in 'BungeeCord Plugin Development' started by Inkzzz, May 8, 2015.

  1. Inkzzz

    Resource Staff

    Hello there,
    I'm wondering how to ping a server via bungeecord API?

    Thanks in advance!
     
  2. Sorry to bump but I need this!
     
  3. Inkzzz

    Resource Staff

    I remember using something like this in a plugin I made a while back:
    Code (Text):
    static ServerChecker instance;
      static Map<ServerInfo, Boolean> servers = new HashMap();

      public CheckTask(ServerChecker instance) {
        instance = instance;
      }

      public static void checkServers()
      {
        for (Map.Entry entry : instance.getProxy().getServers().entrySet())
        {
          ServerInfo si = (ServerInfo)entry.getValue();

          if (ServerChecker.typeList.equals("WHITELIST") ?
            ServerChecker.serverList.contains(si.getName()) :
            !ServerChecker.serverList.contains(si.getName()))
          {
            Callback callback = new Callback()
            {
              public void done(ServerPing sp, Throwable ex)
              {
                boolean bl;
                if (ex == null)
                  bl = true;
                else {
                  bl = false;
                }

                if (!CheckTask.servers.containsKey(CheckTask.this)) {
                  CheckTask.servers.put(CheckTask.this, Boolean.valueOf(bl));
                } else if (((Boolean)CheckTask.servers.get(CheckTask.this)).booleanValue() != bl)
                {
                  BaseComponent[] msg;
                  if (bl)
                    msg = TextComponent.fromLegacyText(ServerChecker.online_msg.replaceAll("%server%", CheckTask.this.getName()));
                  else {
                    msg = TextComponent.fromLegacyText(ServerChecker.offline_msg.replaceAll("%server%", CheckTask.this.getName()));
                  }

                  for (ProxiedPlayer p : CheckTask.instance.getProxy().getPlayers()) {
                    if (p.hasPermission("serverchecker.notify")) {
                      p.sendMessage(msg);
                    }
                  }

                  CheckTask.servers.put(CheckTask.this, Boolean.valueOf(bl));
                }
              }
            };
            ((ServerInfo)entry.getValue()).ping(callback);
          }
        }
      }
     
  4. If you want to Ping "or hack a server"
    Launch this command on Terminal.
    and spam it in windows of Terminal, like 20
    ping 65500 (ip)
     
    • Funny Funny x 4
    • Winner Winner x 1
  5. Kid please. Thats easy stuff thats fixed on 99% of the computers. We are talking about bungeecord -_-
     
    • Winner Winner x 2
    • Like Like x 1
    • Agree Agree x 1
  6. Its still the same as you said in your reply, use the ping method on a ServerInfo object, if you want, you can be a bit more specific and i can send you a snippet of code that would do what you need for you :)
     

  7. instance = instance will never work since they're both the same variable. this.instance =/= instance too.
     
    • Agree Agree x 1
  8. Inkzzz

    Resource Staff

    I just got a bit of code from previous work. It was initialized somewhere else.
     
  9. simpleauthority

    Supporter

    Code (Java):
    (InetAddress.getByName(Server.getServerInfo().getAddress().split(":")[0]).isReachable(5000)) ? "reachable" : "not reachable";
    Creates new InetAddress object from the server's IP address, then attempts to reach it with a 5000ms (5s) timeout.
     
    • Like Like x 1
    • Optimistic Optimistic x 1
  10. Ahahahaah! Let's not try to stress a server xD

    I was going to say what @orabrush said. Use the InetAddress
     
  11. simpleauthority

    Supporter

    • Optimistic Optimistic x 2
  12. It pings a server, exactly what OP asked for. If not then it's not my fault that OP didn't explain in more detail.

    OP even posted a code snippet using the code I linked.
     
  13. Inkzzz

    Resource Staff

    Thanks, but this is old. Additionally, this was sorted a while back.
     
  14. simpleauthority

    Supporter

    The API documentation says "Asynchronously gets the current player count on this server."

    But hey, okay.

    (I wasn't trying to be confrontational. I apologize if I came across as such :))