1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

PlayerCount

Discussion in 'Development' started by Draglor56, Apr 21, 2020.

  1. Draglor56

    Draglor56 Silverfish

    Messages:
    24
    I need help with my plugin,
    I wanted to find out the count of players from my network because I am using a Proxy and with the function getOnlinePlayers () I can only get the PlayerCount from the current Server.
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Which proxy are you using?
     
  3. Draglor56

    Draglor56 Silverfish

    Messages:
    24
    I am using the Waterdog Proxy, maybe you know it?
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    There are three methods you could use. (Maybe more)
    1) Create socket and send UnconnectedPing to target server. Then handle UnconnectedPong...
    PHP:
    /** @var UnconnectedPong $pong */
    $data explode(";"$pong->serverName);
    $playerCount $data[4];
    $maxPlayerCount $data[5];
    This method works when players are online and too when players are offline.

    2) You can use this awesome plugin by @Alemiz. However it depends another plugin on waterdog server
    3) I'm using waterdog api on my server. It's quite buggy, but it works. It's used in this plugin

    And as usual.. you can use queryapi by xpaw.
     
  5. xxAROX

    xxAROX Creeper

    Messages:
    2
    GitHub:
    xxarox
  6. Draglor56

    Draglor56 Silverfish

    Messages:
    24
    Do you have an Example Code how can I get the PlayerCount
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    function pingServer() {
        
    $targetIp "mc.bedrockplay.eu"// target server address
        
    $targetPort 19132// target server port

        
    $port 1212// random empty port
        
        
    $targetIp gethostbyname($targetIp);

        
    $socket socket_create(AF_INETSOCK_DGRAMSOL_UDP);
        if(!
    socket_bind($socket"0.0.0.0"$port)) {
            echo 
    "Couldn't bind to 0.0.0.0:$port";
            return;
        }

        
    $ping = new \raklib\protocol\UnconnectedPing();
        
    $ping->pingID rand(100000555555); // random long
        
    $ping->encode();

        
    socket_sendto($socket$ping->bufferstrlen($ping->buffer), 0$targetIp$targetPort);

        
    receivingPong:
        
    $pongBuffer socket_recvfrom($socket$buffer655350$ip$port);
        if(
    $targetIp != $ip || $targetPort != $port) {
            goto 
    receivingPong;
        }

        
    $pong = new \raklib\protocol\UnconnectedPong($pongBuffer);
        
    $pong->decode();

        
    $data explode(";"$pong->serverName);
      
        
    $playerCount $data[4];
        
    $maxPlayerCount $data[5];
    }
    I'd recommend to put this in AsyncTask
     
  8. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    it's easy to get the number of players
    just use:
    PHP:
    $PlayerCount sizeof($this->getServer()->getOnlinePlayers());
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.