Added basic classes for automatic auth-key registration.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Thu Oct 06 22:29:49 CEST 2011
|
||||
build.number=43
|
||||
#Sat Oct 08 12:44:09 CEST 2011
|
||||
build.number=47
|
||||
|
||||
@@ -81,6 +81,12 @@ public class Webserver {
|
||||
this.server.createContext("/user_list.xml", new UserList());
|
||||
XmlStats.LogDebug("Created context /user_list.xml.");
|
||||
|
||||
this.server.createContext("/auth_register.xml", new AuthRegister());
|
||||
XmlStats.LogDebug("Created context /auth_register.xml.");
|
||||
|
||||
this.server.createContext("auth_deregister.xml", new AuthDeregister());
|
||||
XmlStats.LogDebug("Created context /auth_deregister.xml.");
|
||||
|
||||
this.server.start();
|
||||
XmlStats.LogDebug("Started webserver.");
|
||||
}
|
||||
|
||||
49
src/de/sockenklaus/XmlStats/XmlWorkers/AuthDeregister.java
Normal file
49
src/de/sockenklaus/XmlStats/XmlWorkers/AuthDeregister.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
*
|
||||
*/
|
||||
public class AuthDeregister extends XmlWorker {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXml(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getXml(Map<String, List<String>> parameters)
|
||||
throws XmlStatsException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getSumXml(List<String> playerList,
|
||||
Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getUserXml(List<String> playerList,
|
||||
Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
104
src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java
Normal file
104
src/de/sockenklaus/XmlStats/XmlWorkers/AuthRegister.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.sockenklaus.XmlStats.XmlWorkers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import de.sockenklaus.XmlStats.XmlStats;
|
||||
import de.sockenklaus.XmlStats.XmlStatsRegistry;
|
||||
import de.sockenklaus.XmlStats.Exceptions.XmlStatsException;
|
||||
|
||||
/**
|
||||
* @author socrates
|
||||
*
|
||||
*/
|
||||
public class AuthRegister extends XmlWorker {
|
||||
|
||||
private String authKeyFilename;
|
||||
private String tempAuthKeyFilname;
|
||||
|
||||
public AuthRegister(){
|
||||
super();
|
||||
this.authKeyFilename = "auth_keys.yaml";
|
||||
this.tempAuthKeyFilname = "auth_keys_tmp.yml";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getXml(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getXml(Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
|
||||
if(parameters.containsKey("key")){
|
||||
for (String key : parameters.get("key")){
|
||||
XmlStats x_temp = (XmlStats)XmlStatsRegistry.get("xmlstats");
|
||||
File authKeyFile = new File(x_temp.getDataFolder(), this.authKeyFilename);
|
||||
|
||||
Configuration authKeyConf = new Configuration(authKeyFile);
|
||||
if(authKeyFile.exists()){
|
||||
authKeyConf.load();
|
||||
/*
|
||||
* Hier kann geschaut werden, ob der Key in der AuthKey steht
|
||||
*
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Datei existiert nicht, Key kann nicht existieren
|
||||
*/
|
||||
File tempAuthKeyFile = new File(x_temp.getDataFolder(), this.tempAuthKeyFilname);
|
||||
|
||||
Configuration tempAuthKeyConf = new Configuration(tempAuthKeyFile);
|
||||
if(tempAuthKeyFile.exists()){
|
||||
tempAuthKeyConf.load();
|
||||
if(tempAuthKeyConf.getList("keys") != null && tempAuthKeyConf.getList("keys").contains(key)){
|
||||
/*
|
||||
* Key existiert schon in auth_keys_tmp... mach was
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
else tempAuthKeyConf.setProperty("keys.key",key);
|
||||
}
|
||||
else {
|
||||
tempAuthKeyConf.setProperty("keys.key", key);
|
||||
/*
|
||||
* Key wurde in auth_keys_tmp eingetragen... jetzt reagieren.
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
tempAuthKeyConf.save();
|
||||
}
|
||||
}
|
||||
XmlStats.LogWarn("auth_register: There should be a key, but acutally there is no...");
|
||||
throw new XmlStatsException("auth_register: There should be a key, but actually there is no...");
|
||||
|
||||
}
|
||||
else throw new XmlStatsException("No key given!");
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getSumXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getSumXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
return this.getXml(parameters);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see de.sockenklaus.XmlStats.XmlWorkers.XmlWorker#getUserXml(java.util.List, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected Element getUserXml(List<String> playerList, Map<String, List<String>> parameters) throws XmlStatsException {
|
||||
return this.getXml(parameters);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user