Only append one number to make unique hostname

Instead of naming servers like "pserv-0", "pserv-0-1", "pserv-0-1-2", only append a single number like "pserv-3"
This commit is contained in:
Jesse Clark 2017-10-07 16:51:49 +11:00 committed by GitHub
parent 98007073b8
commit aa41db9f3c

@ -15,12 +15,13 @@ function Server(ip=createRandomIp(), hostname="", organizationName="",
//Connection information //Connection information
this.ip = ip; this.ip = ip;
var i = 0; var i = 0;
while (GetServerByHostname(hostname) != null) { var suffix = "";
while (GetServerByHostname(hostname+suffix) != null) {
//Server already exists //Server already exists
hostname = hostname + "-" + i; suffix = "-" + i;
++i; ++i;
} }
this.hostname = hostname; this.hostname = hostname + suffix;
this.organizationName = organizationName; this.organizationName = organizationName;
this.isConnectedTo = isConnectedTo; //Whether the player is connected to this server this.isConnectedTo = isConnectedTo; //Whether the player is connected to this server