This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
forked from SpigotMC/BungeeCord
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 71 additions & 29 deletions
100
bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,111 @@ | ||
package net.md_5.bungee; | ||
|
||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.security.Security; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Arrays; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.gson.JsonIOException; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
import joptsimple.OptionParser; | ||
import joptsimple.OptionSet; | ||
import net.md_5.bungee.api.ChatColor; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.command.ConsoleCommandSender; | ||
|
||
|
||
public class BungeeCordLauncher | ||
{ | ||
|
||
public static void main(String[] args) throws Exception | ||
{ | ||
Security.setProperty( "networkaddress.cache.ttl", "30" ); | ||
Security.setProperty( "networkaddress.cache.negative.ttl", "10" ); | ||
|
||
OptionParser parser = new OptionParser(); | ||
parser.allowsUnrecognizedOptions(); | ||
parser.acceptsAll( Arrays.asList( "v", "version" ) ); | ||
parser.acceptsAll( Arrays.asList( "v", "version") ); | ||
parser.acceptsAll( Arrays.asList( "noconsole" ) ); | ||
|
||
OptionSet options = parser.parse( args ); | ||
|
||
if ( options.has( "version" ) ) | ||
if ( options.has("version") ) | ||
{ | ||
System.out.println( Bootstrap.class.getPackage().getImplementationVersion() ); | ||
System.out.println(Bootstrap.class.getPackage().getImplementationVersion()); | ||
return; | ||
} | ||
|
||
if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null ) | ||
if ( BungeeCord.class.getPackage().getSpecificationVersion() != null && System.getProperty( "IReallyKnowWhatIAmDoingISwear" ) == null) | ||
{ | ||
Date buildDate = new SimpleDateFormat( "yyyyMMdd" ).parse( BungeeCord.class.getPackage().getSpecificationVersion() ); | ||
|
||
Calendar deadline = Calendar.getInstance(); | ||
deadline.add( Calendar.WEEK_OF_YEAR, -4 ); | ||
if ( buildDate.before( deadline.getTime() ) ) | ||
String version = BungeeCord.class.getPackage().getSpecificationVersion(); | ||
int currentVersion = version.equalsIgnoreCase("unknown") ? 0 : Integer.parseInt( version ); | ||
|
||
try | ||
{ | ||
URL api = new URL( "https://api.github.com/repos/HexagonMC/BungeeCord/releases/latest" ); | ||
URLConnection con = api.openConnection(); | ||
// 15 second timeout at various stages | ||
con.setConnectTimeout( 15000 ); | ||
con.setReadTimeout( 15000 ); | ||
|
||
String tagName = null; | ||
|
||
try | ||
{ | ||
JsonObject json = new JsonParser().parse( new InputStreamReader( con.getInputStream() ) ).getAsJsonObject(); | ||
tagName = json.get( "tag_name" ).getAsString(); | ||
|
||
int latestVersion = Integer.parseInt( tagName.substring( 1, tagName.length() ) ); | ||
|
||
if ( latestVersion > currentVersion ) | ||
{ | ||
System.err.println("*** Warning, this build is outdated ***"); | ||
System.err.println("*** Please download a new build from https://github.com/HexagonMC/BungeeCord/releases ***"); | ||
System.err.println("*** You will get NO support regarding this build ***"); | ||
System.err.println("*** Server will start in 10 seconds ***"); | ||
Thread.sleep(TimeUnit.SECONDS.toMillis(10)); | ||
} | ||
} | ||
catch ( JsonIOException e ) | ||
{ | ||
throw new IOException(e); | ||
} | ||
catch ( JsonSyntaxException e ) | ||
{ | ||
throw new IOException( e ); | ||
} | ||
catch( NumberFormatException e ) | ||
{ | ||
throw new IOException( e ); | ||
} | ||
} | ||
catch ( IOException e ) | ||
{ | ||
System.err.println( "*** Warning, this build is outdated ***" ); | ||
System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" ); | ||
System.err.println( "*** You will get NO support regarding this build ***" ); | ||
System.err.println( "*** Server will start in 10 seconds ***" ); | ||
Thread.sleep( TimeUnit.SECONDS.toMillis( 10 ) ); | ||
System.err.println( "*** Can not test if up to date ***" ); | ||
System.err.println( "*** Using current version without warranty ***" ); | ||
System.err.println( "*** Server will start in 2 seconds ***" ); | ||
Thread.sleep( TimeUnit.SECONDS.toMillis( 2 ) ); | ||
} | ||
} | ||
|
||
BungeeCord bungee = new BungeeCord(); | ||
ProxyServer.setInstance( bungee ); | ||
bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() ); | ||
bungee.start(); | ||
|
||
if ( !options.has( "noconsole" ) ) | ||
{ | ||
String line; | ||
while ( bungee.isRunning && ( line = bungee.getConsoleReader().readLine( ">" ) ) != null ) | ||
{ | ||
if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) ) | ||
{ | ||
if ( !bungee.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), line ) ) | ||
bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" ); | ||
} | ||
} | ||
} | ||
} | ||
} |
299a447
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting this message with a freshly compiled version. Not outdated.
299a447
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Spurlex Did you compile the version by yourself or did you download it from the releases page?
299a447
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiled myself. Must it be downloaded from releases to not have this check?
299a447
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Spurlex I guess this happens as your own versioning is out of sync with the one our build server uses. We will look into it and check if we can make an easy-to-use option to disable the Update check (It's already disabled if you set the Environment-Variable "IReallyKnowWhatIAmDoingISwear" to anything but null.)
299a447
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Spurlex Try v27+, should be not check for update when using a self compiled version.