mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Added HTTPD module: list
This commit is contained in:
parent
d7ed667b89
commit
6d48c90d16
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Tue Dec 17 17:32:25 CET 2013
|
#Wed Dec 18 14:11:43 CET 2013
|
||||||
build.number=686
|
build.number=694
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.HTTPD;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class Module_players extends TFM_HTTPD_Module
|
||||||
|
{
|
||||||
|
public Module_players(NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
final JSONObject response = new JSONObject();
|
||||||
|
|
||||||
|
final JSONArray players = new JSONArray();
|
||||||
|
final JSONArray superadmins = new JSONArray();
|
||||||
|
final JSONArray telnetadmins = new JSONArray();
|
||||||
|
final JSONArray senioradmins = new JSONArray();
|
||||||
|
final JSONArray developers = new JSONArray();
|
||||||
|
|
||||||
|
// All online players
|
||||||
|
for (Player player : TotalFreedomMod.server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
players.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Super admins (non-telnet and non-senior)
|
||||||
|
for (String superadmin : TFM_SuperadminList.getSuperadminNames())
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.getSenioradminNames().contains(superadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TFM_SuperadminList.getTelnetadminNames().contains(superadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
superadmins.add(getName(superadmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Telnet admins (non-senior)
|
||||||
|
for (String telnetadmin : TFM_SuperadminList.getTelnetadminNames())
|
||||||
|
{
|
||||||
|
if (TFM_SuperadminList.getSenioradminNames().contains(telnetadmin))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
telnetadmins.add(getName(telnetadmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Senior admins
|
||||||
|
for (String senioradmin : TFM_SuperadminList.getSenioradminNames())
|
||||||
|
{
|
||||||
|
senioradmins.add(getName(senioradmin));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Developers
|
||||||
|
developers.addAll(TFM_Util.DEVELOPERS);
|
||||||
|
|
||||||
|
response.put("players", players);
|
||||||
|
response.put("superadmins", superadmins);
|
||||||
|
response.put("telnetadmins", telnetadmins);
|
||||||
|
response.put("senioradmins", senioradmins);
|
||||||
|
response.put("developers", developers);
|
||||||
|
|
||||||
|
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, response.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(String caseInsensitiveName)
|
||||||
|
{
|
||||||
|
final OfflinePlayer player = Bukkit.getOfflinePlayer(caseInsensitiveName);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
return caseInsensitiveName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return player.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,12 @@ public abstract class NanoHTTPD
|
|||||||
* Common mime type for dynamic content: html
|
* Common mime type for dynamic content: html
|
||||||
*/
|
*/
|
||||||
public static final String MIME_HTML = "text/html";
|
public static final String MIME_HTML = "text/html";
|
||||||
|
// TFM Start
|
||||||
|
/**
|
||||||
|
* Common mime type for dynamic content: json
|
||||||
|
*/
|
||||||
|
public static final String MIME_JSON = "application/json";
|
||||||
|
// TFM End
|
||||||
/**
|
/**
|
||||||
* Pseudo-Parameter to use to store the actual query string in the parameters map for later re-processing.
|
* Pseudo-Parameter to use to store the actual query string in the parameters map for later re-processing.
|
||||||
*/
|
*/
|
||||||
|
@ -117,6 +117,14 @@ public class TFM_HTTPD_Manager
|
|||||||
{
|
{
|
||||||
return new Module_permbans(session).getResponse();
|
return new Module_permbans(session).getResponse();
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
PLAYERS(new ModuleExecutable(true, "players")
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Response getResponse(HTTPSession session)
|
||||||
|
{
|
||||||
|
return new Module_players(session).getResponse();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
private final ModuleExecutable moduleExecutable;
|
private final ModuleExecutable moduleExecutable;
|
||||||
|
@ -536,7 +536,7 @@ public class TFM_PlayerListener implements Listener
|
|||||||
|
|
||||||
// Finally, set message
|
// Finally, set message
|
||||||
event.setMessage(message);
|
event.setMessage(message);
|
||||||
|
|
||||||
// Broadcast it to console (since 1.7 doesn't do that anymore)
|
// Broadcast it to console (since 1.7 doesn't do that anymore)
|
||||||
TFM_Log.info(String.format(event.getFormat(), player.getDisplayName(), event.getMessage()), true);
|
TFM_Log.info(String.format(event.getFormat(), player.getDisplayName(), event.getMessage()), true);
|
||||||
|
|
||||||
|
@ -21,10 +21,11 @@ import org.bukkit.util.FileUtil;
|
|||||||
|
|
||||||
public class TFM_SuperadminList
|
public class TFM_SuperadminList
|
||||||
{
|
{
|
||||||
private static Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>();
|
private static final Map<String, TFM_Superadmin> superadminList = new HashMap<String, TFM_Superadmin>();
|
||||||
private static List<String> superadminNames = new ArrayList<String>();
|
private static List<String> superadminNames = new ArrayList<String>();
|
||||||
|
private static List<String> senioradminNames = new ArrayList<String>();
|
||||||
|
private static List<String> telnetadminNames = new ArrayList<String>();
|
||||||
private static List<String> superadminIPs = new ArrayList<String>();
|
private static List<String> superadminIPs = new ArrayList<String>();
|
||||||
private static List<String> seniorAdminNames = new ArrayList<String>();
|
|
||||||
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
private static int cleanThreshold = 24 * 7; // 1 Week in hours
|
||||||
|
|
||||||
private TFM_SuperadminList()
|
private TFM_SuperadminList()
|
||||||
@ -42,6 +43,16 @@ public class TFM_SuperadminList
|
|||||||
return superadminNames;
|
return superadminNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getTelnetadminNames()
|
||||||
|
{
|
||||||
|
return telnetadminNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getSenioradminNames()
|
||||||
|
{
|
||||||
|
return senioradminNames;
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadSuperadminList()
|
public static void loadSuperadminList()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -87,19 +98,19 @@ public class TFM_SuperadminList
|
|||||||
{
|
{
|
||||||
superadminNames.clear();
|
superadminNames.clear();
|
||||||
superadminIPs.clear();
|
superadminIPs.clear();
|
||||||
seniorAdminNames.clear();
|
senioradminNames.clear();
|
||||||
|
|
||||||
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Entry<String, TFM_Superadmin> pair = it.next();
|
Entry<String, TFM_Superadmin> pair = it.next();
|
||||||
|
|
||||||
String admin_name = pair.getKey().toLowerCase();
|
String name = pair.getKey().toLowerCase();
|
||||||
TFM_Superadmin superadmin = pair.getValue();
|
TFM_Superadmin superadmin = pair.getValue();
|
||||||
|
|
||||||
if (superadmin.isActivated())
|
if (superadmin.isActivated())
|
||||||
{
|
{
|
||||||
superadminNames.add(admin_name);
|
superadminNames.add(name);
|
||||||
|
|
||||||
for (String ip : superadmin.getIps())
|
for (String ip : superadmin.getIps())
|
||||||
{
|
{
|
||||||
@ -108,19 +119,24 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
if (superadmin.isSeniorAdmin())
|
if (superadmin.isSeniorAdmin())
|
||||||
{
|
{
|
||||||
seniorAdminNames.add(admin_name);
|
senioradminNames.add(name);
|
||||||
|
|
||||||
for (String console_alias : superadmin.getConsoleAliases())
|
for (String console_alias : superadmin.getConsoleAliases())
|
||||||
{
|
{
|
||||||
seniorAdminNames.add(console_alias.toLowerCase());
|
senioradminNames.add(console_alias.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (superadmin.isTelnetAdmin())
|
||||||
|
{
|
||||||
|
telnetadminNames.add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
superadminNames = TFM_Util.removeDuplicates(superadminNames);
|
superadminNames = TFM_Util.removeDuplicates(superadminNames);
|
||||||
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
|
superadminIPs = TFM_Util.removeDuplicates(superadminIPs);
|
||||||
seniorAdminNames = TFM_Util.removeDuplicates(seniorAdminNames);
|
senioradminNames = TFM_Util.removeDuplicates(senioradminNames);
|
||||||
|
|
||||||
TFM_AdminWorld.getInstance().wipeAccessCache();
|
TFM_AdminWorld.getInstance().wipeAccessCache();
|
||||||
}
|
}
|
||||||
@ -264,7 +280,7 @@ public class TFM_SuperadminList
|
|||||||
|
|
||||||
if (!(user instanceof Player))
|
if (!(user instanceof Player))
|
||||||
{
|
{
|
||||||
return seniorAdminNames.contains(username);
|
return senioradminNames.contains(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Superadmin entry = getAdminEntry((Player) user);
|
TFM_Superadmin entry = getAdminEntry((Player) user);
|
||||||
|
Loading…
Reference in New Issue
Block a user