From 2a7a4e55999224a5856b75e9fd457793ffb7b962 Mon Sep 17 00:00:00 2001 From: UeberallGebannt Date: Sat, 14 Nov 2020 09:31:58 +0100 Subject: [PATCH] Disable old metrics --- .../main/java/net/md_5/bungee/BungeeCord.java | 10 +- .../main/java/net/md_5/bungee/Metrics.java | 134 ------------------ 2 files changed, 6 insertions(+), 138 deletions(-) delete mode 100644 proxy/src/main/java/net/md_5/bungee/Metrics.java diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 69b3d0f86d..cffd627921 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -121,7 +121,8 @@ public class BungeeCord extends ProxyServer * locations.yml save thread. */ private final Timer saveThread = new Timer( "Reconnect Saver" ); - private final Timer metricsThread = new Timer( "Metrics Thread" ); + // KettleCord (disable metrics) + // private final Timer metricsThread = new Timer( "Metrics Thread" ); /** * Server socket listener. */ @@ -233,7 +234,7 @@ public BungeeCord() throws IOException getPluginManager().registerCommand( null, new CommandIP() ); getPluginManager().registerCommand( null, new CommandBungee() ); getPluginManager().registerCommand( null, new CommandPerms() ); - + if ( !Boolean.getBoolean( "net.md_5.bungee.native.disable" ) ) { if ( EncryptionUtil.nativeFactory.load() ) @@ -286,7 +287,7 @@ public void start() throws Exception registerChannel( ForgeConstants.FML_HANDSHAKE_TAG ); registerChannel( ForgeConstants.FORGE_REGISTER ); - // KettleCord + // KettleCord (disable forge warning) // getLogger().warning( "MinecraftForge support is currently unmaintained and may have unresolved issues. Please use at your own risk." ); } @@ -311,7 +312,8 @@ public void run() } } }, 0, TimeUnit.MINUTES.toMillis( 5 ) ); - metricsThread.scheduleAtFixedRate( new Metrics(), 0, TimeUnit.MINUTES.toMillis( Metrics.PING_INTERVAL ) ); + // KettleCord (disable metrics) + // metricsThread.scheduleAtFixedRate( new Metrics(), 0, TimeUnit.MINUTES.toMillis( Metrics.PING_INTERVAL ) ); Runtime.getRuntime().addShutdownHook( new Thread() { diff --git a/proxy/src/main/java/net/md_5/bungee/Metrics.java b/proxy/src/main/java/net/md_5/bungee/Metrics.java deleted file mode 100644 index eabf757367..0000000000 --- a/proxy/src/main/java/net/md_5/bungee/Metrics.java +++ /dev/null @@ -1,134 +0,0 @@ -package net.md_5.bungee; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.TimerTask; -import net.md_5.bungee.api.ProxyServer; - -public class Metrics extends TimerTask -{ - - /** - * The current revision number - */ - private static final int REVISION = 5; - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "https://mcstats.spigotmc.org"; - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/report/%s"; - /** - * Interval of time to ping (in minutes) - */ - static final int PING_INTERVAL = 10; - boolean firstPost = true; - - @Override - public void run() - { - try - { - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin( !firstPost ); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch ( IOException ex ) - { - // ProxyServer.getInstance().getLogger().info( "[Metrics] " + ex.getMessage() ); - } - } - - /** - * Generic method that posts a plugin to the metrics website. - * - * @param isPing first post or not - * @throws IOException any errors encountered - */ - private void postPlugin(boolean isPing) throws IOException - { - // Construct the post data - final StringBuilder data = new StringBuilder(); - data.append( encode( "guid" ) ).append( '=' ).append( encode( BungeeCord.getInstance().config.getUuid() ) ); - encodeDataPair( data, "version", ProxyServer.getInstance().getVersion() ); - encodeDataPair( data, "server", "0" ); - encodeDataPair( data, "players", Integer.toString( ProxyServer.getInstance().getOnlineCount() ) ); - encodeDataPair( data, "revision", String.valueOf( REVISION ) ); - - // If we're pinging, append it - if ( isPing ) - { - encodeDataPair( data, "ping", "true" ); - } - - // Create the url - URL url = new URL( BASE_URL + String.format( REPORT_URL, encode( "BungeeCord" ) ) ); - - // Connect to the website - URLConnection connection; - - connection = url.openConnection(); - - connection.setDoOutput( true ); - final BufferedReader reader; - final String response; - try ( OutputStreamWriter writer = new OutputStreamWriter( connection.getOutputStream() ) ) - { - writer.write( data.toString() ); - writer.flush(); - reader = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); - response = reader.readLine(); - } - reader.close(); - - if ( response == null || response.startsWith( "ERR" ) ) - { - throw new IOException( response ); //Throw the exception - } - } - - /** - *

- * Encode a key/value data pair to be used in a HTTP post request. This - * INCLUDES a & so the first key/value pair MUST be included manually, - * e.g:

- * - * StringBuffer data = new StringBuffer(); - * data.append(encode("guid")).append('=').append(encode(guid)); - * encodeDataPair(data, "version", description.getVersion()); - * - * - * @param buffer the StringBuilder to append the data pair onto - * @param key the key value - * @param value the value - * @throws UnsupportedEncodingException if UTF-8 encoding not supported - */ - private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException - { - buffer.append( '&' ).append( encode( key ) ).append( '=' ).append( encode( value ) ); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - * @throws UnsupportedEncodingException if UTF-8 encoding not supported - */ - private static String encode(final String text) throws UnsupportedEncodingException - { - return URLEncoder.encode( text, "UTF-8" ); - } -}