Skip to content

Commit d4541c9

Browse files
committed
udpate
1 parent 58e9819 commit d4541c9

File tree

6 files changed

+76
-74
lines changed

6 files changed

+76
-74
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88

99

1010
group = 'dev.colbster937'
11-
version = '1.1.1'
11+
version = '1.1.2'
1212
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
1313
def targetJavaVersion = 17
1414

src/main/java/dev/colbster937/originblacklist/base/Base.java

Lines changed: 74 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
6969
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
7070
String brand = conn.getEaglerBrandString();
7171
String name = conn.getUsername();
72+
String ip = getAddr(conn);
7273
String notAllowed1 = "not allowed on the server";
7374
String notAllowed2 = "not allowed";
7475

@@ -96,11 +97,18 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
9697
for (String name1 : config.blacklist.players) {
9798
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
9899
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
99-
webhook(conn, origin, name, "player");
100+
webhook(conn, origin, brand, "player");
100101
return;
101102
}
102103
}
103104
}
105+
106+
if (ip != null && !ip.equalsIgnoreCase("null")) {
107+
if (ipblacklist.check(ip)) {
108+
setKick(e, formatKickMessage("ip address", "ip", notAllowed1, notAllowed2, ip, conn.getWebSocketHost()));
109+
webhook(conn, origin, brand, "ip");
110+
}
111+
}
104112
}
105113

106114
public static void setKick(IEaglercraftLoginEvent e, Component msg) {
@@ -114,30 +122,61 @@ public static void setKick(IEaglercraftLoginEvent e, Component msg) {
114122
}
115123

116124
public static void handleMOTD(IEaglercraftMOTDEvent e) {
117-
if (config.messages.motd.enabled) {
118-
IMOTDConnection conn = e.getMOTDConnection();
119-
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
120-
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
121-
.map(line -> line
122-
.replaceAll("%blocktype%", "origin")
123-
.replaceAll("%easyblocktype%", "website")
124-
.replaceAll("%notallowed1%", "blacklisted")
125-
.replaceAll("%notallowed2%", "blacklisted")
126-
.replaceAll("%blocked%", origin)
127-
.replaceAll("%host%", conn.getWebSocketHost()))
128-
.map(line -> LegacyComponentSerializer.legacySection().serialize(
129-
MiniMessage.miniMessage().deserialize(line)))
130-
.collect(Collectors.toList());
131-
132-
if (origin != null && !origin.equals("null")) {
133-
for (String origin1 : config.blacklist.origins) {
134-
if (matches(origin, origin1)) {
135-
setMOTD(conn, m);
136-
return;
137-
}
125+
if (!config.messages.motd.enabled) return;
126+
127+
IMOTDConnection conn = e.getMOTDConnection();
128+
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
129+
String host = conn.getWebSocketHost() != null ? conn.getWebSocketHost() : "";
130+
String ip = getAddr(conn);
131+
132+
String blocktype1 = null;
133+
String easyblocktype1 = null;
134+
String blocked1 = null;
135+
136+
if (origin != null && !"null".equals(origin)) {
137+
for (String origin2 : config.blacklist.origins) {
138+
if (matches(origin, origin2)) {
139+
blocktype1 = "origin";
140+
easyblocktype1 = "website";
141+
blocked1 = origin;
142+
break;
138143
}
139144
}
140145
}
146+
147+
if (blocktype1 == null && ip != null && !"null".equalsIgnoreCase(ip)) {
148+
boolean blocked = ipblacklist != null && ipblacklist.check(ip);
149+
if (!blocked) {
150+
for (String ip2 : config.blacklist.ips) {
151+
if (matches(ip, ip2)) { blocked = true; break; }
152+
}
153+
}
154+
if (blocked) {
155+
blocktype1 = "ip address";
156+
easyblocktype1 = "ip";
157+
blocked1 = ip;
158+
}
159+
}
160+
161+
if (blocktype1 == null) return;
162+
163+
final String finalBlocktype = blocktype1;
164+
final String finalEasyblocktype = easyblocktype1;
165+
final String finalBlocked = blocked1;
166+
167+
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
168+
.map(line -> line
169+
.replace("%blocktype%", finalBlocktype)
170+
.replace("%easyblocktype%", finalEasyblocktype)
171+
.replace("%notallowed1%", "blacklisted")
172+
.replace("%notallowed2%", "blacklisted")
173+
.replace("%blocked%", finalBlocked)
174+
.replace("%host%", host))
175+
.map(line -> LegacyComponentSerializer.legacySection()
176+
.serialize(MiniMessage.miniMessage().deserialize(line)))
177+
.collect(Collectors.toList());
178+
179+
setMOTD(conn, m);
141180
}
142181

143182
public static void setMOTD(IMOTDConnection conn, List<String> m) {
@@ -172,30 +211,18 @@ public static void setMOTD(IMOTDConnection conn, List<String> m) {
172211
}
173212
}
174213

175-
public static String handlePre(String ip, String name) {
176-
if (ip != null && !ip.equalsIgnoreCase("null")) {
177-
for (String ip1 : Base.config.blacklist.ips) {
178-
if (ipblacklist.check(ip)) {
179-
Component kick = formatKickMessage("ip address", "ip", "blacklisted", "blacklisted", ip, "");
180-
return LegacyComponentSerializer.legacySection().serialize(kick);
181-
}
182-
}
183-
}
184-
return "false";
185-
}
186-
187214
public static boolean matches(String text1, String text2) {
188215
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
189216
}
190217

191218
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
192219
String help = "";
193-
if (type != "player") {
194-
help = config.messages.help.generic;
195-
} else if (type == "ip") {
220+
if ("player".equals(type)) {
221+
help = config.messages.help.player;
222+
} else if ("ip address".equals(type)) {
196223
help = config.messages.help.ip;
197224
} else {
198-
help = config.messages.help.player;
225+
help = config.messages.help.generic;
199226
}
200227
return MiniMessage.miniMessage().deserialize(
201228
config.messages.kick
@@ -229,7 +256,7 @@ public static void webhook(IEaglerLoginConnection plr, String origin, String bra
229256
"embeds": [
230257
{
231258
"title": "Player Information",
232-
"description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s"
259+
"description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **UA:** %s\\n⏪ **Rewind:** %s"
233260
}
234261
]
235262
}
@@ -255,8 +282,14 @@ public static void webhook(IEaglerLoginConnection plr, String origin, String bra
255282
});
256283
}
257284

258-
public static String getAddr(IEaglerLoginConnection plr) {
259-
var addr1 = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined";
285+
public static String getAddr(IEaglerLoginConnection conn) {
286+
var addr1 = conn.getPlayerAddress() != null ? conn.getPlayerAddress().toString().substring(1) : "0.0.0.0:0";
287+
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
288+
return addr2;
289+
}
290+
291+
public static String getAddr(IMOTDConnection conn) {
292+
var addr1 = conn.getSocketAddress() != null ? conn.getSocketAddress().toString().substring(1) : "0.0.0.0:0";
260293
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
261294
return addr2;
262295
}

src/main/java/dev/colbster937/originblacklist/bukkit/OriginBlacklistBukkit.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,4 @@ public void onLogin(EaglercraftLoginEvent event) {
5151
public void onMOTD(EaglercraftMOTDEvent event) {
5252
Base.handleMOTD(event);
5353
}
54-
55-
@EventHandler
56-
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
57-
String ip = event.getAddress().getHostAddress();
58-
String name = event.getName();
59-
String blacklisted = Base.handlePre(ip, name);
60-
if (!blacklisted.equals("false")) {
61-
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, blacklisted);
62-
}
63-
}
6454
}

src/main/java/dev/colbster937/originblacklist/bungee/OriginBlacklistBungee.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,4 @@ public void onLogin(EaglercraftLoginEvent event) {
5050
public void onMOTD(EaglercraftMOTDEvent event) {
5151
Base.handleMOTD(event);
5252
}
53-
54-
@EventHandler
55-
public void onPreLogin(PreLoginEvent event) {
56-
String ip = event.getConnection().getAddress().getAddress().getHostAddress();
57-
String name = event.getConnection().getName();
58-
String blacklisted = Base.handlePre(ip, name);
59-
if (!blacklisted.equals("false")) {
60-
event.setCancelReason(blacklisted);
61-
event.setCancelled(true);
62-
}
63-
}
6453
}

src/main/java/dev/colbster937/originblacklist/velocity/OriginBlacklistVelocity.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,4 @@ public void onLogin(EaglercraftLoginEvent event) {
5555
public void onMOTD(EaglercraftMOTDEvent event) {
5656
Base.handleMOTD(event);
5757
}
58-
59-
@Subscribe
60-
public void onPreLogin(PreLoginEvent event) {
61-
String ip = event.getConnection().getRemoteAddress().getAddress().toString();
62-
String name = event.getUsername();
63-
String blacklisted = Base.handlePre(ip, name);
64-
if (!blacklisted.equals("false")) {
65-
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(blacklisted)));
66-
}
67-
}
6858
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ messages:
2727
enabled: true
2828
text: |
2929
<red>This %easyblocktype% is %notallowed2%!</red>
30-
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
30+
<dark_gray>»</dark_gray> <gray>%blocked%</gray>
3131
icon: "blacklisted.png"
3232

3333
# Origin + Brand blacklist supports wildcards

0 commit comments

Comments
 (0)