mirror of
https://github.com/Quackster/Havana.git
synced 2025-07-03 13:17:46 +00:00
Add Watchdog.IS_IMAGER_ONLINE
This commit is contained in:
parent
0e4d3ace8f
commit
4e350d416f
2 changed files with 46 additions and 24 deletions
|
@ -6,6 +6,7 @@ import org.alexdev.duckhttpd.response.ResponseBuilder;
|
||||||
import org.alexdev.duckhttpd.server.connection.WebConnection;
|
import org.alexdev.duckhttpd.server.connection.WebConnection;
|
||||||
import org.alexdev.duckhttpd.util.MimeType;
|
import org.alexdev.duckhttpd.util.MimeType;
|
||||||
import org.alexdev.havana.util.config.GameConfiguration;
|
import org.alexdev.havana.util.config.GameConfiguration;
|
||||||
|
import org.alexdev.http.server.Watchdog;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
@ -27,6 +28,7 @@ public class ImagerController {
|
||||||
public static void imager_redirect(WebConnection webConnection) {
|
public static void imager_redirect(WebConnection webConnection) {
|
||||||
boolean sentFurniResponse = false;
|
boolean sentFurniResponse = false;
|
||||||
|
|
||||||
|
if (Watchdog.IS_IMAGER_ONLINE) {
|
||||||
var reqConfig = RequestConfig.custom()
|
var reqConfig = RequestConfig.custom()
|
||||||
.setConnectTimeout(GameConfiguration.getInstance().getInteger("site.imaging.timeout"))
|
.setConnectTimeout(GameConfiguration.getInstance().getInteger("site.imaging.timeout"))
|
||||||
.build();
|
.build();
|
||||||
|
@ -54,7 +56,10 @@ public class ImagerController {
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
ignored.printStackTrace();
|
ignored.printStackTrace();
|
||||||
} finally {
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!sentFurniResponse) {
|
if (!sentFurniResponse) {
|
||||||
FullHttpResponse response = ResponseBuilder.create(
|
FullHttpResponse response = ResponseBuilder.create(
|
||||||
HttpResponseStatus.NO_CONTENT, MimeType.getContentType("png"), new byte[0]
|
HttpResponseStatus.NO_CONTENT, MimeType.getContentType("png"), new byte[0]
|
||||||
|
@ -62,5 +67,4 @@ public class ImagerController {
|
||||||
webConnection.send(response);
|
webConnection.send(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,9 @@ import org.alexdev.http.game.news.NewsDateKey;
|
||||||
import org.alexdev.http.util.config.WebSettingsConfigWriter;
|
import org.alexdev.http.util.config.WebSettingsConfigWriter;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -35,6 +37,7 @@ public class Watchdog implements Runnable {
|
||||||
public static List<NewsArticle> NEWS_STAFF = new ArrayList<>();
|
public static List<NewsArticle> NEWS_STAFF = new ArrayList<>();
|
||||||
|
|
||||||
public static int USERS_ONLNE;
|
public static int USERS_ONLNE;
|
||||||
|
public static boolean IS_IMAGER_ONLINE;
|
||||||
public static boolean IS_SERVER_ONLINE;
|
public static boolean IS_SERVER_ONLINE;
|
||||||
public static int LAST_VISITS;
|
public static int LAST_VISITS;
|
||||||
|
|
||||||
|
@ -73,6 +76,21 @@ public class Watchdog implements Runnable {
|
||||||
if (this.counter.get() % 30 == 0) {
|
if (this.counter.get() % 30 == 0) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
String imagerPath = ServerConfiguration.getString("site.imager.path");
|
||||||
|
|
||||||
|
if (!imagerPath.isBlank()) {
|
||||||
|
try {
|
||||||
|
URL url = new URL(imagerPath);
|
||||||
|
String hostname = url.getHost();
|
||||||
|
int port = url.getPort();
|
||||||
|
|
||||||
|
IS_IMAGER_ONLINE = isServerOnline(hostname, port);
|
||||||
|
} catch (MalformedURLException e) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IS_SERVER_ONLINE = isServerOnline(ServerConfiguration.getString("rcon.ip"), ServerConfiguration.getInteger("rcon.port"));
|
||||||
|
|
||||||
IS_SERVER_ONLINE = isServerOnline(ServerConfiguration.getString("rcon.ip"), ServerConfiguration.getInteger("rcon.port"));
|
IS_SERVER_ONLINE = isServerOnline(ServerConfiguration.getString("rcon.ip"), ServerConfiguration.getInteger("rcon.port"));
|
||||||
USERS_ONLNE = Integer.parseInt(SettingsDao.getSetting("players.online"));
|
USERS_ONLNE = Integer.parseInt(SettingsDao.getSetting("players.online"));
|
||||||
LAST_VISITS = SiteDao.getLastVisits();
|
LAST_VISITS = SiteDao.getLastVisits();
|
||||||
|
|
Loading…
Add table
Reference in a new issue