mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
HTTPD updates
This commit is contained in:
parent
eccf940b81
commit
81002cbe97
@ -61,7 +61,6 @@ public class HTTPDaemon extends FreedomService
|
||||
module("activitylog", Module_activitylog.class, true);
|
||||
module("admins", Module_admins.class, true);
|
||||
module("bans", Module_bans.class, true);
|
||||
module("file", Module_file.class, true);
|
||||
module("help", Module_help.class, false);
|
||||
module("list", Module_list.class, false);
|
||||
module("logfile", Module_logfile.class, true);
|
||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
|
||||
@ -17,6 +18,13 @@ public class Module_activitylog extends HTTPDModule
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||
|
||||
if (!isAuthorized(remoteAddress))
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"You may not view the activity log. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
}
|
||||
File activityLogFile = new File(plugin.getDataFolder(), ActivityLog.FILENAME);
|
||||
if (activityLogFile.exists())
|
||||
{
|
||||
@ -28,4 +36,10 @@ public class Module_activitylog extends HTTPDModule
|
||||
"Error 404: Not Found - The requested resource was not found on this server.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthorized(String remoteAddress)
|
||||
{
|
||||
Admin entry = plugin.al.getEntryByIp(remoteAddress);
|
||||
return entry != null && entry.isActive();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class Module_admins extends HTTPDModule
|
||||
if (!isAuthorized(remoteAddress))
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"You may not view the admin list, Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
"You may not view the admin list. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ public class Module_bans extends HTTPDModule
|
||||
if (!isAuthorized(remoteAddress))
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"You may not view the ban list, Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
"You may not view the ban list, Your IP. " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2,9 +2,15 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import java.util.Collection;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class Module_list extends HTTPDModule
|
||||
{
|
||||
@ -15,30 +21,127 @@ public class Module_list extends HTTPDModule
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody()
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
final StringBuilder body = new StringBuilder();
|
||||
|
||||
final Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
|
||||
body.append("<p>There are ").append(onlinePlayers.size()).append("/").append(Bukkit.getMaxPlayers()).append(" players online:</p>\r\n");
|
||||
|
||||
body.append("<ul>\r\n");
|
||||
|
||||
for (Player player : onlinePlayers)
|
||||
if (params.get("json") != null && params.get("json").equals("true"))
|
||||
{
|
||||
String tag = plugin.rm.getDisplay(player).getTag();
|
||||
body.append("<li>").append(tag).append(player.getName()).append("</li>\r\n");
|
||||
final JSONObject responseObject = new JSONObject();
|
||||
|
||||
final JSONArray operators = new JSONArray();
|
||||
final JSONArray imposters = new JSONArray();
|
||||
final JSONArray masterbuilders = new JSONArray();
|
||||
final JSONArray superadmins = new JSONArray();
|
||||
final JSONArray telnetadmins = new JSONArray();
|
||||
final JSONArray senioradmins = new JSONArray();
|
||||
final JSONArray developers = new JSONArray();
|
||||
final JSONArray executives = new JSONArray();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
|
||||
if (isImposter(player))
|
||||
{
|
||||
imposters.add(player.getName());
|
||||
}
|
||||
|
||||
if (plugin.mbl.isMasterBuilder(player))
|
||||
{
|
||||
masterbuilders.add(player.getName());
|
||||
}
|
||||
|
||||
if (FUtil.DEVELOPERS.contains(player.getName()))
|
||||
{
|
||||
developers.add(player.getName());
|
||||
}
|
||||
|
||||
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !FUtil.DEVELOPERS.contains(player.getName()))
|
||||
{
|
||||
executives.add(player.getName());
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdmin(player) && !hasSpecialTitle(player))
|
||||
{
|
||||
FLog.info(player.getName() + " is an op");
|
||||
operators.add(player.getName());
|
||||
}
|
||||
|
||||
if (!hasSpecialTitle(player) && plugin.al.isAdmin(player))
|
||||
{
|
||||
Admin admin = plugin.al.getAdmin(player);
|
||||
switch (admin.getRank())
|
||||
{
|
||||
case SUPER_ADMIN:
|
||||
superadmins.add(player.getName());
|
||||
break;
|
||||
case TELNET_ADMIN:
|
||||
telnetadmins.add(player.getName());
|
||||
break;
|
||||
case SENIOR_ADMIN:
|
||||
senioradmins.add(player.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
responseObject.put("operators", operators);
|
||||
responseObject.put("imposters", imposters);
|
||||
responseObject.put("masterbuilders", masterbuilders);
|
||||
responseObject.put("superadmins", superadmins);
|
||||
responseObject.put("telnetadmins", telnetadmins);
|
||||
responseObject.put("senioradmins", senioradmins);
|
||||
responseObject.put("developers", developers);
|
||||
responseObject.put("executives", executives);
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
return response;
|
||||
}
|
||||
else
|
||||
{
|
||||
final StringBuilder body = new StringBuilder();
|
||||
|
||||
body.append("</ul>\r\n");
|
||||
final Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
|
||||
return body.toString();
|
||||
body.append("<p>There are ").append(onlinePlayers.size()).append("/").append(Bukkit.getMaxPlayers()).append(" players online:</p>\r\n");
|
||||
|
||||
body.append("<ul>\r\n");
|
||||
|
||||
for (Player player : onlinePlayers)
|
||||
{
|
||||
String tag = plugin.rm.getDisplay(player).getTag();
|
||||
body.append("<li>").append(tag).append(player.getName()).append("</li>\r\n");
|
||||
}
|
||||
|
||||
body.append("</ul>\r\n");
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_HTML, body.toString());
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isImposter(Player player)
|
||||
{
|
||||
if (plugin.al.isAdminImpostor(player) || plugin.pv.isPlayerImpostor(player) || plugin.mbl.isMasterBuilderImpostor(player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasSpecialTitle(Player player)
|
||||
{
|
||||
if (FUtil.DEVELOPERS.contains(player.getName()) || ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) || ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
return "Total Freedom - Online Users";
|
||||
return "Total Freedom - Online Players";
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
@ -31,6 +32,7 @@ public class Module_players extends HTTPDModule
|
||||
final JSONArray telnetadmins = new JSONArray();
|
||||
final JSONArray senioradmins = new JSONArray();
|
||||
final JSONArray developers = new JSONArray();
|
||||
final JSONArray executives = new JSONArray();
|
||||
|
||||
// All online players
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
@ -70,12 +72,16 @@ public class Module_players extends HTTPDModule
|
||||
// Developers
|
||||
developers.addAll(FUtil.DEVELOPERS);
|
||||
|
||||
// Executives
|
||||
executives.addAll(ConfigEntry.SERVER_EXECUTIVES.getList());
|
||||
|
||||
responseObject.put("players", players);
|
||||
responseObject.put("masterbuilders", masterbuilders);
|
||||
responseObject.put("superadmins", superadmins);
|
||||
responseObject.put("telnetadmins", telnetadmins);
|
||||
responseObject.put("senioradmins", senioradmins);
|
||||
responseObject.put("developers", developers);
|
||||
responseObject.put("executives", developers);
|
||||
|
||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
|
Loading…
Reference in New Issue
Block a user