You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 15:36:17 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60e5ba3a6a | |||
| 9fa3fad70c | |||
| 860f61f765 | |||
| c5137bf3dc | |||
| 5150418796 | |||
| 5c71b318fb | |||
| 1cac407c45 |
File diff suppressed because one or more lines are too long
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.eu.habbo</groupId>
|
<groupId>com.eu.habbo</groupId>
|
||||||
<artifactId>Habbo</artifactId>
|
<artifactId>Habbo</artifactId>
|
||||||
<version>4.1.9</version>
|
<version>4.1.11</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
+18
-2
@@ -1,14 +1,30 @@
|
|||||||
package com.eu.habbo.messages.incoming.users;
|
package com.eu.habbo.messages.incoming.users;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
|
import com.eu.habbo.habbohotel.rooms.Room;
|
||||||
|
import com.eu.habbo.habbohotel.users.Habbo;
|
||||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||||
|
|
||||||
public class ActivateEffectEvent extends MessageHandler {
|
public class ActivateEffectEvent extends MessageHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handle() throws Exception {
|
public void handle() throws Exception {
|
||||||
int effectId = this.packet.readInt();
|
int effectId = this.packet.readInt();
|
||||||
|
Habbo habbo = this.client.getHabbo();
|
||||||
|
if (habbo == null) return;
|
||||||
|
|
||||||
if (this.client.getHabbo().getInventory().getEffectsComponent().ownsEffect(effectId)) {
|
if (habbo.getInventory().getEffectsComponent().ownsEffect(effectId)) {
|
||||||
this.client.getHabbo().getInventory().getEffectsComponent().activateEffect(effectId);
|
habbo.getInventory().getEffectsComponent().activateEffect(effectId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rankId = habbo.getHabboInfo().getRank().getId();
|
||||||
|
if (Emulator.getGameEnvironment().getPermissionsManager().isEffectBlocked(effectId, rankId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Room room = habbo.getHabboInfo().getCurrentRoom();
|
||||||
|
if (room == null || habbo.getHabboInfo().getRiding() != null) return;
|
||||||
|
|
||||||
|
room.giveEffect(habbo, effectId, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,7 @@ public class AuthHttpHandler extends ChannelInboundHandlerAdapter {
|
|||||||
private static final String CHECK_EMAIL_PATH = "/api/auth/check-email";
|
private static final String CHECK_EMAIL_PATH = "/api/auth/check-email";
|
||||||
private static final String CHECK_USERNAME_PATH = "/api/auth/check-username";
|
private static final String CHECK_USERNAME_PATH = "/api/auth/check-username";
|
||||||
private static final String ROOM_TEMPLATES_PATH = "/api/auth/room-templates";
|
private static final String ROOM_TEMPLATES_PATH = "/api/auth/room-templates";
|
||||||
|
private static final String NEWS_PATH = "/api/auth/news";
|
||||||
private static final String REMEMBER_PATH = "/api/auth/remember";
|
private static final String REMEMBER_PATH = "/api/auth/remember";
|
||||||
private static final String REFRESH_PATH = "/api/auth/refresh";
|
private static final String REFRESH_PATH = "/api/auth/refresh";
|
||||||
private static final String SERVER_KEY_PATH = "/api/auth/server-key";
|
private static final String SERVER_KEY_PATH = "/api/auth/server-key";
|
||||||
@@ -57,6 +58,7 @@ public class AuthHttpHandler extends ChannelInboundHandlerAdapter {
|
|||||||
&& !path.equals(FORGOT_PATH) && !path.equals(LOGOUT_PATH)
|
&& !path.equals(FORGOT_PATH) && !path.equals(LOGOUT_PATH)
|
||||||
&& !path.equals(CHECK_EMAIL_PATH) && !path.equals(CHECK_USERNAME_PATH)
|
&& !path.equals(CHECK_EMAIL_PATH) && !path.equals(CHECK_USERNAME_PATH)
|
||||||
&& !path.equals(ROOM_TEMPLATES_PATH)
|
&& !path.equals(ROOM_TEMPLATES_PATH)
|
||||||
|
&& !path.equals(NEWS_PATH)
|
||||||
&& !path.equals(REMEMBER_PATH)
|
&& !path.equals(REMEMBER_PATH)
|
||||||
&& !path.equals(REFRESH_PATH)
|
&& !path.equals(REFRESH_PATH)
|
||||||
&& !path.equals(SERVER_KEY_PATH)
|
&& !path.equals(SERVER_KEY_PATH)
|
||||||
@@ -98,6 +100,22 @@ public class AuthHttpHandler extends ChannelInboundHandlerAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path.equals(NEWS_PATH)) {
|
||||||
|
if (req.method() != HttpMethod.GET && req.method() != HttpMethod.HEAD) {
|
||||||
|
sendJson(ctx, req, HttpResponseStatus.METHOD_NOT_ALLOWED, errorPayload("Use GET."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String ip = resolveClientIp(ctx, req);
|
||||||
|
if (!AuthRateLimiter.tryProbe(ip)) {
|
||||||
|
long secs = AuthRateLimiter.secondsUntilProbeReset(ip);
|
||||||
|
sendJson(ctx, req, HttpResponseStatus.TOO_MANY_REQUESTS,
|
||||||
|
errorPayload("Too many requests. Try again in " + secs + "s."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleNews(ctx, req);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (path.equals(SERVER_KEY_PATH)) {
|
if (path.equals(SERVER_KEY_PATH)) {
|
||||||
if (req.method() != HttpMethod.GET && req.method() != HttpMethod.HEAD) {
|
if (req.method() != HttpMethod.GET && req.method() != HttpMethod.HEAD) {
|
||||||
sendJson(ctx, req, HttpResponseStatus.METHOD_NOT_ALLOWED, errorPayload("Use GET."));
|
sendJson(ctx, req, HttpResponseStatus.METHOD_NOT_ALLOWED, errorPayload("Use GET."));
|
||||||
@@ -682,6 +700,76 @@ public class AuthHttpHandler extends ChannelInboundHandlerAdapter {
|
|||||||
sendJson(ctx, req, HttpResponseStatus.OK, res);
|
sendJson(ctx, req, HttpResponseStatus.OK, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long NEWS_CACHE_TTL_MS = 30_000L;
|
||||||
|
private static final int NEWS_IMAGE_MAX_BYTES = 512 * 1024;
|
||||||
|
private static volatile NewsCacheEntry NEWS_CACHE = null;
|
||||||
|
|
||||||
|
private static final class NewsCacheEntry {
|
||||||
|
final byte[] jsonBytes;
|
||||||
|
final long expiresAt;
|
||||||
|
NewsCacheEntry(byte[] j, long e) { jsonBytes = j; expiresAt = e; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNews(ChannelHandlerContext ctx, FullHttpRequest req) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
NewsCacheEntry cached = NEWS_CACHE;
|
||||||
|
|
||||||
|
if (cached == null || cached.expiresAt < now) {
|
||||||
|
JsonArray items = new JsonArray();
|
||||||
|
int limit = Math.max(1, Math.min(20, Emulator.getConfig().getInt("login.news.limit", 5)));
|
||||||
|
try (Connection conn = Emulator.getDatabase().getDataSource().getConnection();
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
|
"SELECT id, title, body, image, link_text, link_url " +
|
||||||
|
"FROM ui_news WHERE enabled = 1 " +
|
||||||
|
"ORDER BY sort_order ASC, id DESC LIMIT ?")) {
|
||||||
|
stmt.setInt(1, limit);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
int id = rs.getInt("id");
|
||||||
|
JsonObject n = new JsonObject();
|
||||||
|
n.addProperty("id", id);
|
||||||
|
n.addProperty("title", rs.getString("title"));
|
||||||
|
n.addProperty("body", rs.getString("body"));
|
||||||
|
|
||||||
|
String image = rs.getString("image");
|
||||||
|
if (image != null && image.length() > NEWS_IMAGE_MAX_BYTES) {
|
||||||
|
LOGGER.warn("ui_news id={} image is {} bytes (>{}KB cap), omitting in response",
|
||||||
|
id, image.length(), NEWS_IMAGE_MAX_BYTES / 1024);
|
||||||
|
image = null;
|
||||||
|
}
|
||||||
|
n.addProperty("image", image); // gson encodes null as JSON null
|
||||||
|
|
||||||
|
n.addProperty("linkText", rs.getString("link_text"));
|
||||||
|
n.addProperty("linkUrl", rs.getString("link_url"));
|
||||||
|
items.add(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("ui_news list failed", e);
|
||||||
|
sendJson(ctx, req, HttpResponseStatus.INTERNAL_SERVER_ERROR, errorPayload("Server error."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject res = new JsonObject();
|
||||||
|
res.add("news", items);
|
||||||
|
byte[] bytes = res.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
cached = new NewsCacheEntry(bytes, now + NEWS_CACHE_TTL_MS);
|
||||||
|
NEWS_CACHE = cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
FullHttpResponse response = new DefaultFullHttpResponse(
|
||||||
|
HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
|
||||||
|
Unpooled.wrappedBuffer(cached.jsonBytes));
|
||||||
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=utf-8");
|
||||||
|
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, cached.jsonBytes.length);
|
||||||
|
response.headers().set(HttpHeaderNames.CACHE_CONTROL, "public, max-age=30");
|
||||||
|
applyCors(req, response);
|
||||||
|
boolean keepAlive = isKeepAlive(req);
|
||||||
|
if (keepAlive) response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
|
||||||
|
var future = ctx.writeAndFlush(response);
|
||||||
|
if (!keepAlive) future.addListener(ChannelFutureListener.CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleServerKey(ChannelHandlerContext ctx, FullHttpRequest req) {
|
private void handleServerKey(ChannelHandlerContext ctx, FullHttpRequest req) {
|
||||||
try {
|
try {
|
||||||
JsonObject ok = new JsonObject();
|
JsonObject ok = new JsonObject();
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user