Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Check if server is full [PHP]

Comments in 'Plugin Development' started by deot, Sep 29, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    I wanted to code a plugin to transfer player if server is full :) (GoAwayAnna and Fallback Server don't work currently)
    As all I know, I must need to transfer player on PreLogin, so this what I got:
    PHP:
    public function onPreLogin(PlayerPreLoginEvent $event){
         
            
    // Code to check if server is full? I just use if it's cancelled...
            
    if ($this->isCancelled($event->getPlayer())){
            
    $player $event->getPlayer();
         
              if(
    $this->fastTransfer instanceof FastTransfer)
              {
                 return 
    $this->fastTransfer->transferPlayer($player$this->getIP(), $this->getPort());
              }
              return 
    false;
            }
    }
    I know this code is wrong, I already tried it... :( Does anybody know where do I wrong? Please help... :)
    I don't know how to check if server is full, so I use isCancelled, because I think if PreLogin is cancel means that server is full (This is just my idea.... and it's wrong I think)
    So? Anybody help? :)
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Use PlayerKickEvent and check if it kicked the player due to Server Full.
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Blame FastTransfer, it hasn't been updated to 1.6 yet. :( Anyways @shoghicp will update it pretty soon, once 1.6 is stable enough. ;)
    deot likes this.
  4. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    If I use PlayerKickEvent, it won't work... I can only transfer player when PreLogin... Because in MPCE 0.12.1, if you transfer player when they already logged in (joined) it won't disconnect with previous server... :/
  5. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    There's must be a temporary solution right now... Hmm.... Any idea to check if server full??
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    All the other auto-transfer plugins will not work properly if FastTransfer itself isn't working. FastTransfer's packet protocols aren't updated yet(that's what I think), but it'll be soon. ;)
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    if(count($this->getServer()->getOnlinePlayers()) == $this->getServer()->getMaxPlayers()) {
        
    // code
    }
  8. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    What happens if the server has a VIP slot plugin installed? o_O It should be:
    PHP:
    if(count($server->getOnlinePlayers()) >= $server->getMaxPlayers()){
        
    //execute code here
    }
    BTW your solution wouldn't have worked, you can't use count() on an integer, it would throw you an error. $server->getMaxPlayers() itself already returns an integer. :p
    Last edited: Sep 29, 2015
    CraftYourBukkit and Hotshot_9930 like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, the server player count SHOULD NOT exceed maximum. A VIP slot plugin should reserve slots instead of taking more slots. Therefore, it is safe to assume that count(Server->getOnlinePlayers()) <= Server->getMaxPlayers().

    There are no changes in the transfer protocol. It is a new unintended client-side issue.

    Today I worked out a temporary solution, WHICH HAS A LOT OF DISADVANTAGES BOTH TO THE SERVER AND THE PLAYER, PLEASE READ BELOW.

    First of all, you transfer the player normally using FastTransfer API function.
    Second, add this code, assuming your context is a PluginBase:
    PHP:
            $interfaces $this->getServer()->getNetwork()->getInterfaces();
            foreach(
    $interfaces as $interface){
                if(
    $interface instanceof RakLibInterface){
                    
    $identifier $player->getAddress() . ":" $player->getPort();
                    
    $interface->closeSession($identifier"transferring");
                }
            }
    This is EXTREMELY hacky and may fail to work in any future PocketMine updates, even just a minor internal change in RakLib or PocketMine. But this is yet a minor disadvantage.

    What this script does and does NOT dk:
    • It notifies the RakLib thread in a similar manner to what happens when a player clicks the "Quit to title". Hence, PocketMine and RakLib assumes that the client has already left the server, BUT the client still has a connected socket with the server, and the client WILL still keep sending data to the server until MCPE is closed.
    • The client also joins another server like what FastTransfer is supposed to do, but it does NOT close the connection to the old server. As a result, the client is actually joining two servers. The previous server assumes the client has quitted, but the client doesn't know that.
    • The client may keep sending data to the old server, which the old server MAY consider unsuitable, and hence you may see a message from the RakLib thread saying that the client IP address has been blocked for XXX seconds. So if you transfer the user back to the old server, it may fail to connect.
    • There is constant data sending, so the client and the server BOTH use a large amount of bandwidth for unnecessary reasons. According to @shoghicp, the client may even somehow send chunks to the server, thinking that itself is the server and the server is the client.
    • If you transfer the client to a third server in the second server, the client will be connecting to 3 servers with 3 open sockets, while 2 are unnecessary.
    • If you transfer the client back to the first server, strange bugs may occur.
    • If you transfer the client to the same server recursively, God knows what you are trying to do and you will get issues and complaints flying straight onto your bed.
    Therefore, for the sake of both the client and the server, it is best to tell the client the address to join and tell the client to join that server directly (or next time don't ask server to transfer you again). However, it is still possible, but transferring is no longer as direct as the concept of redirect like that in HTTP.
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    and why shoghi doesn't do anything in pocketmine 1.6 ? there are lots of things to do.
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    He does, he works very hard on pocketmine.
    Everysingle bug cant be fixed all at once, things take time.
    Just be patient.
  12. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    Yah Tru
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Wow… A client thinking itself as a server?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How do you see "nothing"?

    BTW, y no likes :(
    CavinMiana likes this.

Share This Page

Advertisement