Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Added update check
Browse files Browse the repository at this point in the history
  • Loading branch information
Zartec committed Mar 3, 2016
1 parent ff92b11 commit 299a447
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<manifestEntries>
<Main-Class>net.md_5.bungee.Bootstrap</Main-Class>
<Implementation-Version>${describe}</Implementation-Version>
<Specification-Version>${maven.build.timestamp}</Specification-Version>
<Specification-Version>${build.number}</Specification-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
100 changes: 71 additions & 29 deletions bootstrap/src/main/java/net/md_5/bungee/BungeeCordLauncher.java
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" );
}
}
}
}
}

5 comments on commit 299a447

@Mxchael
Copy link

@Mxchael Mxchael commented on 299a447 Mar 4, 2016

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.

@sleiss
Copy link

@sleiss sleiss commented on 299a447 Mar 4, 2016

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?

@Mxchael
Copy link

@Mxchael Mxchael commented on 299a447 Mar 4, 2016

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?

@sleiss
Copy link

@sleiss sleiss commented on 299a447 Mar 4, 2016

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.)

@sleiss
Copy link

@sleiss sleiss commented on 299a447 Mar 4, 2016

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.

Please sign in to comment.