Deprecated Serverlist

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1025 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
Zenexer 2011-03-30 13:16:54 +00:00
parent d4f15e62d2
commit d60bef2138
9 changed files with 0 additions and 1730 deletions

View File

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project [ <!ENTITY buildinc SYSTEM "../build.inc.xml"> ]>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="EssentialsServerlist" default="default" basedir=".">
<description>Builds, tests, and runs the project EssentialsServerlist.</description>
<import file="nbproject/build-impl.xml"/>
&buildinc;
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="EssentialsServerlist-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
build.xml.data.CRC32=b3f32d5a
build.xml.script.CRC32=d07c143a
build.xml.stylesheet.CRC32=28e38971@1.38.2.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=28f52c06
nbproject/build-impl.xml.script.CRC32=bdef3982
nbproject/build-impl.xml.stylesheet.CRC32=19debb58@1.42.1.45

View File

@ -1,76 +0,0 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=EssentialsServerlist
application.vendor=Paul
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/EssentialsServerlist.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar-1=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
includes=**
jar.compress=false
javac.classpath=\
${reference.Essentials.jar}:\
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar-1}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}:\
${libs.junit_4.classpath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
project.Essentials=../Essentials
reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>EssentialsServerlist</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
<definitions>../lib\nblibraries.properties</definitions>
</libraries>
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
<reference>
<foreign-project>Essentials</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
</references>
</configuration>
</project>

View File

@ -1,149 +0,0 @@
package net.mcserverlist.bukkit;
import com.earth2me.essentials.Essentials;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
public class Mcsl extends JavaPlugin
{
private static final Logger logger = Logger.getLogger("Minecraft");
private McslPlayerListener playerListener;
public final String author;
public Mcsl() throws IOException
{
PluginDescriptionFile desc = this.getDescription();
// Compile author list
List<String> authors = new ArrayList<String>();
authors.add("Vimae Development");
int alen = authors.size();
if (alen == 1)
{
author = " by " + authors.get(0);
}
else if (alen > 1)
{
int i = 0;
StringBuilder bldr = new StringBuilder();
for (String a : desc.getAuthors())
{
if (i + 1 == alen)
{
if (alen > 2) bldr.append(",");
bldr.append(" and ");
}
else if (i++ > 0)
{
bldr.append(", ");
}
bldr.append(a);
}
bldr.insert(0, " by ");
author = bldr.toString();
}
else
{
author = "";
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
McslCommands mcslCmd;
try
{
switch (McslCommands.valueOf(cmd.getName().toUpperCase()))
{
case WHITELIST:
whitelist(sender, WhitelistCommands.valueOf(args[0].toUpperCase()), args);
return true;
default:
return false;
}
}
catch (IllegalArgumentException ex)
{
return false;
}
catch (Exception ex)
{
logger.log(Level.WARNING, "MCSL encountered an unknown error.", ex);
sender.sendMessage("MCSL encountered an unknown error.");
return true;
}
}
@SuppressWarnings("LoggerStringConcat")
public void onEnable()
{
Plugin p = this.getServer().getPluginManager().getPlugin("Essentials");
if (p != null) {
if (!this.getServer().getPluginManager().isPluginEnabled(p)) {
this.getServer().getPluginManager().enablePlugin(p);
}
}
playerListener = new McslPlayerListener(this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Lowest, this);
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version.");
}
logger.info(getDescription().getName() + " version " + getDescription().getVersion() + author + " enabled.");
}
@SuppressWarnings("LoggerStringConcat")
public void onDisable()
{
logger.info(getDescription().getName() + " version " + getDescription().getVersion() + " disabled.");
}
private void whitelist(CommandSender sender, WhitelistCommands cmd, String[] args)
{
if (!playerListener.isWhitelistEnabled())
{
sender.sendMessage("§cThe whitelist is disabled.");
return;
}
if (!sender.isOp())
{
sender.sendMessage("§cYou must be an operator to manage the whitelist.");
return;
}
switch (cmd)
{
case RELOAD:
playerListener.whitelistReload();
sender.sendMessage("A whitelist updated has been queued.");
break;
}
}
private enum McslCommands
{
WHITELIST
}
private enum WhitelistCommands
{
RELOAD
}
}

View File

@ -1,209 +0,0 @@
package net.mcserverlist.bukkit;
import com.earth2me.essentials.Essentials;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.player.*;
public class McslPlayerListener extends PlayerListener
{
private final static Logger logger = Logger.getLogger("Minecraft");
private boolean running = true;
private final Server server;
private Thread thread;
private Whitelist whitelist = null;
private volatile boolean updateNeeded = true;
@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
public McslPlayerListener(Mcsl parent)
{
this.server = parent.getServer();
// Get the data from the server.properties file as the server sees it, rather than reading it manually
try
{
this.whitelist = new Whitelist(server);
}
catch (Throwable ex)
{
// Disable the plugin
logger.log(Level.WARNING, "Error encountered while initializing MCServerlist plugin.", ex);
parent.getPluginLoader().disablePlugin(parent);
return;
}
// Run Update on a set interval of 1 minute with an initial delay of 10 seconds
thread = new Thread(new UpdateRunnable());
thread.setDaemon(true);
thread.start();
}
@Override
@SuppressWarnings("FinalizeDeclaration")
protected void finalize() throws Throwable
{
// Stop the timer
if (thread != null && thread.isAlive())
{
running = false;
thread.join();
}
super.finalize();
}
@Override
public void onPlayerLogin(PlayerLoginEvent event)
{
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED)
return;
Player player = event.getPlayer();
// Check the whitelist
if (!Essentials.getSettings().getWhitelistEnabled() || player.isOp() || whitelist == null || whitelist.isAllowed(player.getName()))
{
// Player is an op, there is no whitelist, or the player is whitelisted.
return;
}
// Player is not whitelisted.
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "This server employs a whitelist.");
}
@Override
public void onPlayerJoin(PlayerEvent event)
{
update();
}
@Override
public void onPlayerQuit(PlayerEvent event)
{
update();
}
public boolean isWhitelistEnabled()
{
return whitelist != null;
}
public void whitelistReload()
{
whitelist.update();
}
public void update()
{
updateNeeded = true;
}
private class UpdateRunnable implements Runnable
{
@SuppressWarnings("SleepWhileInLoop")
public void run()
{
do
{
if (updateNeeded)
{
updateNeeded = false;
update();
}
try
{
Thread.sleep(60000);
}
catch (InterruptedException ex)
{
logger.info("Forcing MCServerlist update.");
}
}
while (running);
}
@SuppressWarnings("CallToThreadDumpStack")
public void update()
{
// Check that we aren't receiving an event inappropriately
if (Essentials.getSettings().getMcslKey() == null || Essentials.getSettings().getMcslKey().equals("")) return;
// Compile a comma-space-delimted list of players
Player[] players = server.getOnlinePlayers();
StringBuilder list = new StringBuilder();
if (players.length > 0)
{
for (int i = 0; i < players.length; i++)
{
if (i > 0) list.append(", ");
list.append(players[i].getName());
}
}
try
{
// Compile POST data
StringBuilder data = new StringBuilder();
data.append("key=");
data.append(URLEncoder.encode(Essentials.getSettings().getMcslKey(), "UTF-8"));
data.append("&player_count=");
data.append(Integer.toString(players.length));
data.append("&max_players=");
data.append(Integer.toString(server.getMaxPlayers()));
data.append("&player_list=");
data.append(URLEncoder.encode(list.toString(), "UTF-8"));
OutputStreamWriter tx = null;
BufferedReader rx = null;
try
{
// Send POST request
URL url = new URL("http://mcserverlist.net/api/update");
// Swap line for testing purposes
//URL url = new URL("http://localhost/mcsl/update.php");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setUseCaches(false);
http.setConnectTimeout(1000);
http.setAllowUserInteraction(false);
http.setInstanceFollowRedirects(true);
http.setRequestProperty("User-Agent", "Java;Mcsl");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
http.setRequestProperty("X-Mcsl-Key", Essentials.getSettings().getMcslKey());
http.setRequestProperty("X-Minecraft-Name", URLEncoder.encode(server.getName(), "UTF-8"));
http.setRequestProperty("X-Minecraft-Version", server.getVersion());
http.setDoInput(true);
http.setDoOutput(true);
tx = new OutputStreamWriter(http.getOutputStream());
tx.write(data.toString());
tx.flush();
// Get the HTTP response
rx = new BufferedReader(new InputStreamReader(http.getInputStream()));
for (String l = ""; rx.ready(); l = rx.readLine())
{
if ("".equals(l)) continue;
else if (l.startsWith("i:")) logger.info(l.substring(2));
else if (l.startsWith("w:")) logger.warning(l.substring(2));
else System.out.println(l);
}
}
finally
{
if (tx != null) tx.close();
if (rx != null) rx.close();
}
}
catch (Exception ex)
{
logger.log(Level.WARNING, "Error communication with MCServerlist.", ex);
ex.printStackTrace();
}
}
}
}

View File

@ -1,107 +0,0 @@
package net.mcserverlist.bukkit;
import com.earth2me.essentials.Essentials;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
public class Whitelist
{
private static final Logger logger = Logger.getLogger("Minecraft");
private List<String> allowed = new ArrayList<String>();
private final Object allowedLock = new Object();
private Server server;
public Whitelist(Server server)
{
this.server = server;
}
public void update()
{
Thread thread = new Thread(new UpdateRunnable());
thread.setDaemon(true);
thread.start();
}
public boolean isAllowed(String player)
{
String p = player.toLowerCase();
synchronized (allowedLock)
{
return allowed.contains(p);
}
}
private class UpdateRunnable implements Runnable
{
@SuppressWarnings("CallToThreadDumpStack")
public void run()
{
// Check that we aren't receiving an event inappropriately
if (Essentials.getSettings().getMcslKey() == null || Essentials.getSettings().getMcslKey().equals("")) return;
try
{
OutputStreamWriter tx = null;
BufferedReader rx = null;
try
{
// Send GET request
URL url = new URL("http://mcserverlist.net/api/whitelist");
// Swap line for testing purposes
//URL url = new URL("http://localhost/mcsl/whitelist.php");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setUseCaches(false);
http.setConnectTimeout(1000);
http.setAllowUserInteraction(false);
http.setInstanceFollowRedirects(true);
http.setRequestProperty("User-Agent", "Java;Mcsl");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
http.setRequestProperty("X-Mcsl-Key", Essentials.getSettings().getMcslKey());
http.setRequestProperty("X-Minecraft-Name", URLEncoder.encode(server.getName(), "UTF-8"));
http.setRequestProperty("X-Minecraft-Version", server.getVersion());
http.setDoInput(true);
http.setDoOutput(false);
// Get the HTTP response
rx = new BufferedReader(new InputStreamReader(http.getInputStream()));
List<String> allowed = new ArrayList<String>();
for (String l = ""; rx.ready(); l = rx.readLine())
{
if ("".equals(l)) continue;
else if (l.startsWith("i:")) logger.info(l.substring(2));
else if (l.startsWith("w:")) logger.warning(l.substring(2));
else allowed.add(l.toLowerCase()); // Add to whitelist
}
synchronized (Whitelist.this.allowedLock)
{
Whitelist.this.allowed = allowed;
allowed = null; // Remove our reference so that we don't accidentally use it
}
}
finally
{
if (tx != null) tx.close();
if (rx != null) rx.close();
}
}
catch (Exception ex)
{
logger.log(Level.WARNING, "Error communication with MCServerlist.", ex);
ex.printStackTrace();
}
}
}
}

View File

@ -1,5 +0,0 @@
name: EssentialsServerlist
main: net.mcserverlist.bukkit.Mcsl
version: TeamCity
website: http://mcserverlist.net/
description: Official MCServerlist API implementation