TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_punishments.java

48 lines
1.7 KiB
Java
Raw Normal View History

2018-03-03 04:29:08 +00:00
package me.totalfreedom.totalfreedommod.httpd.module;
import java.io.File;
2018-03-03 04:29:08 +00:00
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
import me.totalfreedom.totalfreedommod.punishments.PunishmentList;
2018-03-03 04:29:08 +00:00
public class Module_punishments extends HTTPDModule
{
public Module_punishments(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
{
super(plugin, session);
}
@Override
public NanoHTTPD.Response getResponse()
{
File adminFile = new File(plugin.getDataFolder(), PunishmentList.CONFIG_FILENAME);
if (adminFile.exists())
{
final String remoteAddress = socket.getInetAddress().getHostAddress();
if (!isAuthorized(remoteAddress))
{
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
2019-09-10 05:43:02 +00:00
"You may not view the punishment list. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
2018-03-03 04:29:08 +00:00
}
else
{
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), PunishmentList.CONFIG_FILENAME));
}
}
else
{
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
"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();
}
}