@@ -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 }
0 commit comments