Fixed ratelimit order to be FIFO

This commit is contained in:
LAX1DUDE 2022-04-02 14:29:09 -07:00
parent 1fd47f074e
commit 05c903b0ed
3 changed files with 19 additions and 15 deletions

Binary file not shown.

View File

@ -340,12 +340,14 @@ public class EaglerMOTD extends Plugin implements Listener {
public void onMOTD(WebsocketMOTDEvent evt) { public void onMOTD(WebsocketMOTDEvent evt) {
MOTDConnection con = new MOTDConnection(evt.getListener(), evt.getMOTD()); MOTDConnection con = new MOTDConnection(evt.getListener(), evt.getMOTD());
if(con.execute()) { if(con.execute()) {
if(max_total_sockets > 0) {
synchronized(motdConnections) { synchronized(motdConnections) {
while(motdConnections.size() >= max_total_sockets) { while(motdConnections.size() >= max_total_sockets) {
MOTDConnection c = motdConnections.remove(0); MOTDConnection c = motdConnections.remove(motdConnections.size() - 1);
c.close(); c.close();
} }
} }
}
InetAddress addr = con.motd.getRemoteAddress(); InetAddress addr = con.motd.getRemoteAddress();
boolean flag = false; boolean flag = false;
for(BanList.IPBan b : BanList.blockedBans) { for(BanList.IPBan b : BanList.blockedBans) {
@ -356,11 +358,12 @@ public class EaglerMOTD extends Plugin implements Listener {
} }
if(flag) { if(flag) {
synchronized(motdConnections) { synchronized(motdConnections) {
motdConnections.add(con); motdConnections.add(0, con);
} }
}else { }else {
if(allow_banned_ips || !BanList.checkIpBanned(addr).isBanned()) { if(allow_banned_ips || !BanList.checkIpBanned(addr).isBanned()) {
synchronized(motdConnections) { synchronized(motdConnections) {
if(max_sockets_per_ip > 0) {
int i = 0; int i = 0;
int c = 0; int c = 0;
while(i < motdConnections.size()) { while(i < motdConnections.size()) {
@ -373,6 +376,7 @@ public class EaglerMOTD extends Plugin implements Listener {
} }
++i; ++i;
} }
}
motdConnections.add(0, con); motdConnections.add(0, con);
} }
}else { }else {

View File

@ -1,4 +1,4 @@
name: EaglerMOTD name: EaglerMOTD
main: net.lax1dude.eaglercraft.eaglermotd.EaglerMOTD main: net.lax1dude.eaglercraft.eaglermotd.EaglerMOTD
version: 1.0 version: 1.0.2
author: LAX1DUDE author: LAX1DUDE