Creating servers through BungeeCord

Discussion in 'BungeeCord Plugin Development' started by Mike70387, May 6, 2017.

Thread Status:
Not open for further replies.
  1. Hello there SpigotMC Development Community, I'm facing a bit of a problem for a bit of time now with creating servers on the fly via a bungeecord plugin. The problem lays with connection to those created servers, not creation or startup.

    Here's my method of starting/adding the server to the proxy;

    Code (Text):
        public static void startServer(String name, ServerType type, int port) {
            try {
                ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "java -Xmx1024M -jar " + "/path/to/servers/" + type.name().toLowerCase() + "/" + name + "/" + type.name().toLowerCase() +  ".jar --port " + port);
                try {
                    Process serverProcess = builder.start();
                    if (serverProcess.exitValue() == 0) {
                        BufferedReader read = new BufferedReader(new InputStreamReader(serverProcess.getInputStream()));
                        getServerProcessMap().put(name, read.readLine().trim());
                    } else {
                        throw new Exception("[Server Manager] Failed to retrieve service pid, cancelling...");
                    }
                } catch (Exception e) {
                    Bungee.log("[Server Manager] Fatal: " + e.getMessage() + " (" + e.getClass().getName() + ")");
                }
            } catch (Exception e) {
                Bungee.log("[Server Manager] Fatal: " + e.getMessage() + " (" + e.getClass().getName() + ")");
            }
        }

     
    When trying to connect via my proxy that the server was added to (same machine), it refuses with an AnnotatedConnectionException (not online).

    While starting the server works fine, connection to said server is impossible. (I have opened an independent terminal window and ran the same command, and the server started on the requested port, so not issues there - while the proxy with the server entry was online and connection was still refused). I really have no idea what the problem would be at this time (NOTE: I am copying directories with the server files from a base folder which would ensure the EULA would not interfere with startup, and have made sure the base directory's spigot.yml has bungeecord: true set).

    Another note: I have yet to verify that the dedicated machine's firewall is the issue, though it should not be due to the fact that all of my other server's ports are blocked, which would make the firewall being the issue doubtful in my eyes, and yes, in my creation method I did verify that the server was added to the bungee server list so that is not the problem.

    Proposed solutions would be greatly appreciated.
    Thanks, Mike M
     
  2. Hey,
    Do you construct somewhere a server info ?
     
  3. Yes, I'm currently out and can't grab what I did, but I will do so tomorrow.

    Thanks, @Voone, for the reply.
     
    • Friendly Friendly x 1
  4. Okay I will be present to help you :p
     
  5. @Voone alrighty, I'm home now and this is what I did to construct the server info to insert into the proxy:

    Code (Text):
        public static void addServer(String name, InetSocketAddress port, String motd, boolean restricted) {
            try {
                BungeeCord cord = BungeeCord.getInstance();
                ServerInfo info = new BungeeServerInfo(name, port, motd, restricted);
                cord.getServers().put(name, info);
            } catch (Exception e) {
                Bungee.log("[Server Manager] Failed to add server: " + e.getMessage() + " (" + e.getClass().getName() + ")");
            }
        }
    This has always worked for me in the past, so I've continually used this.
     
  6. Okay, it seems good
    Now, where do you create the folder of the new server ?
     
  7. The server folder is located at, /(root dir of servers)/data/<lobby/game/test>/<name>.
     
  8. Where do you define it in the code ?
     
  9. Sorry for the <very late> response! Can you clarify what you want seen?
     
  10. Figured out the issue, closed.
     
Thread Status:
Not open for further replies.