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

Routing Servers by domain?

Discussion in 'Help' started by herohamp, Jan 31, 2018.

  1. herohamp

    herohamp Silverfish

    Messages:
    19
    GitHub:
    herohamp
    Say I want to run multiple mcpe servers on 1 physical server with 1 public ip on the same port, how would I do that? With websites I would use something like nginx to route them based on domain name, is there a way to route mcpe servers by domain name using special software or would nginx work, because nginx handles websockets.
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You could have one "relay" server that uses the loginpacket to check what domain the player entered and then transfer the player to the server he/she wants, that runs on another port.
     
  3. herohamp

    herohamp Silverfish

    Messages:
    19
    GitHub:
    herohamp
    I am new to making plugins could you provide some example code @HimbeersaftLP
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Something along those lines should work
    PHP:
    protected $players = [];
    protected 
    $servers = [
        
    "mycool.server.com" => ["mynormal.server.com"19132],
        
    "mycooler.server.com" => ["mynormal.server.com"19133],
        
    "mycoolest.server.com" => ["mynormal.server.com"19134]
    ];
    public function 
    onLoginPacket(DataPacketReceiveEvent $event){
        
    $packet $event->getPacket();
        if(
    $packet instanceof LoginPacket){
            
    $this->players[TextFormat::clean($packet->username)] = $packet->serverAddress;
        }
    }
    public function 
    onPreLogin(PlayerPreLoginEvent $event) {
        
    $name $event->getPlayer()->getName();
        if (isset(
    $this->players[$name]) && isset($this->servers[$this->players[$name]])) {
            
    $server $this->servers[$this->players[$name]];
            
    $event->getPlayer()->transfer($server[0], $server[1]);
        } else {
            
    $event->getPlayer()->kick();
        }
    }
    Though, I'm not sure if transfering players on PreLoginEvent will work.
     
  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.