2222public class Base {
2323 private static LoggerAdapter adapter ;
2424 private static IEaglerXServerAPI api ;
25- private static ConfigManager config ;
25+ private static IPBlacklist ipblacklist ;
2626
2727 public static void setLogger (LoggerAdapter log ) {
2828 adapter = log ;
@@ -32,7 +32,9 @@ public static void setApi(IEaglerXServerAPI api1) {
3232 api = api1 ;
3333 }
3434
35- public static String apiVer = "1.0.2" ;
35+ public static ConfigManager config ;
36+
37+ public static String pluginVer = "1.0.2" ;
3638
3739 public static boolean checkVer (String v1 , String v2 ) {
3840 String [] c = v1 .split ("\\ ." );
@@ -67,11 +69,13 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
6769 String origin = conn .getWebSocketHeader (EnumWebSocketHeader .HEADER_ORIGIN );
6870 String brand = conn .getEaglerBrandString ();
6971 String name = conn .getUsername ();
72+ String notAllowed1 = "not allowed on the server" ;
73+ String notAllowed2 = "not allowed" ;
7074
7175 if (origin != null && !origin .equals ("null" )) {
7276 for (String origin1 : config .blacklist .origins ) {
7377 if (matches (origin , origin1 )) {
74- setKick (e , formatKickMessage ("origin" , "website" , origin , conn .getWebSocketHost ()));
78+ setKick (e , formatKickMessage ("origin" , "website" , notAllowed1 , notAllowed2 , origin , conn .getWebSocketHost ()));
7579 webhook (conn , origin , brand , "origin" );
7680 return ;
7781 }
@@ -81,7 +85,7 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
8185 if (brand != null && !brand .equals ("null" )) {
8286 for (String brand1 : config .blacklist .brands ) {
8387 if (matches (brand , brand1 )) {
84- setKick (e , formatKickMessage ("brand" , "client" , brand , conn .getWebSocketHost ()));
88+ setKick (e , formatKickMessage ("brand" , "client" , notAllowed1 , notAllowed2 , brand , conn .getWebSocketHost ()));
8589 webhook (conn , origin , brand , "brand" );
8690 return ;
8791 }
@@ -91,7 +95,7 @@ public static void handleConnection(IEaglercraftLoginEvent e) {
9195 if (name != null && !name .equals ("null" )) {
9296 for (String name1 : config .blacklist .players ) {
9397 if (matches (name , name1 ) || (name .length () > 16 || name .length () < 3 )) {
94- setKick (e , formatKickMessage ("player" , "username" , name , conn .getWebSocketHost ()));
98+ setKick (e , formatKickMessage ("player" , "username" , notAllowed1 , notAllowed2 , name , conn .getWebSocketHost ()));
9599 webhook (conn , origin , name , "player" );
96100 return ;
97101 }
@@ -117,6 +121,8 @@ public static void handleMOTD(IEaglercraftMOTDEvent e) {
117121 .map (line -> line
118122 .replaceAll ("%blocktype%" , "origin" )
119123 .replaceAll ("%easyblocktype%" , "website" )
124+ .replaceAll ("%notallowed1%" , "blacklisted" )
125+ .replaceAll ("%notallowed2%" , "blacklisted" )
120126 .replaceAll ("%blocked%" , origin )
121127 .replaceAll ("%host%" , conn .getWebSocketHost ()))
122128 .map (line -> LegacyComponentSerializer .legacySection ().serialize (
@@ -130,8 +136,6 @@ public static void handleMOTD(IEaglercraftMOTDEvent e) {
130136 return ;
131137 }
132138 }
133- } else if (origin != null && !origin .equals ("null" )) {
134- setMOTD (conn , m );
135139 }
136140 }
137141 }
@@ -168,14 +172,28 @@ public static void setMOTD(IMOTDConnection conn, List<String> m) {
168172 }
169173 }
170174
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+
171187 public static boolean matches (String text1 , String text2 ) {
172188 return text1 .toLowerCase ().matches (text2 .replace ("." , "\\ ." ).replaceAll ("\\ *" , ".*" ).toLowerCase ());
173189 }
174190
175- public static Component formatKickMessage (String type , String easytype , String value , String host ) {
191+ public static Component formatKickMessage (String type , String easytype , String notAllowed1 , String notAllowed2 , String value , String host ) {
176192 String help = "" ;
177193 if (type != "player" ) {
178194 help = config .messages .help .generic ;
195+ } else if (type == "ip" ) {
196+ help = config .messages .help .ip ;
179197 } else {
180198 help = config .messages .help .player ;
181199 }
@@ -184,6 +202,8 @@ public static Component formatKickMessage(String type, String easytype, String v
184202 .replaceAll ("%help%" , help )
185203 .replaceAll ("%blocktype%" , type )
186204 .replaceAll ("%easyblocktype%" , easytype )
205+ .replaceAll ("%notallowed1%" , notAllowed1 )
206+ .replaceAll ("%notallowed2%" , notAllowed2 )
187207 .replaceAll ("%blocked%" , value )
188208 .replaceAll ("%host%" , host ));
189209 }
@@ -194,7 +214,7 @@ public static void webhook(IEaglerLoginConnection plr, String origin, String bra
194214 return ;
195215
196216 CompletableFuture .runAsync (() -> {
197- String addr = (plr . getPlayerAddress () != null ? plr . getPlayerAddress (). toString (). substring ( 1 ) : "undefined:undefined" ). split ( ":" )[ 0 ] ;
217+ String addr = getAddr (plr ) ;
198218 int protocol = !plr .isEaglerXRewindPlayer () ? plr .getMinecraftProtocol () : plr .getRewindProtocolVersion ();
199219 String host = plr .getWebSocketHost ();
200220 String userAgent = plr .getWebSocketHeader (EnumWebSocketHeader .HEADER_USER_AGENT );
@@ -235,6 +255,10 @@ public static void webhook(IEaglerLoginConnection plr, String origin, String bra
235255 });
236256 }
237257
258+ public static String getAddr (IEaglerLoginConnection plr ) {
259+ return (plr .getPlayerAddress () != null ? plr .getPlayerAddress ().toString ().substring (1 ) : "undefined:undefined" ).split (":" )[0 ];
260+ }
261+
238262 public static void init () {
239263 File motdIcon = new File (config .messages .motd .icon );
240264 if (!motdIcon .exists ()) {
@@ -246,6 +270,7 @@ public static void init() {
246270 getLogger ().warn (e .toString ());
247271 }
248272 }
273+ ipblacklist = new IPBlacklist ();
249274 }
250275
251276 public static void reloadConfig () {
0 commit comments