Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZetaMap authored Nov 21, 2021
1 parent bb9e59c commit 35ded26
Show file tree
Hide file tree
Showing 10 changed files with 1,084 additions and 561 deletions.
245 changes: 120 additions & 125 deletions src/main/java/data/BM.java
Original file line number Diff line number Diff line change
@@ -1,146 +1,141 @@
package data;

import java.util.ArrayList;

import arc.Core;
import arc.struct.Seq;
import arc.util.Log;

import util.AntiVpn;
import util.Strings;
import util.filter.FilterType;


public class BM {
private static ArrayList<String> bannedClients = new Seq<String>().addAll("VALVE", "tuttop", "CODEX", "IGGGAMES", "IgruhaOrg", "FreeTP.Org").list(),
defaultBannedNames = new Seq<String>().addAll("[Server]", "[server]", "@e", "@a", "@p", "@t", "~").list(),
bannedIps = new ArrayList<>(),
bannedNames = new ArrayList<>();
private static Seq<String> bannedClients = new Seq<String>().addAll("VALVE", "tuttop", "CODEX", "IGGGAMES", "IgruhaOrg", "FreeTP.Org"),
bannedIps = new Seq<>(),
bannedNames = new Seq<>();

public static void blacklistCommand(String[] arg) {
ArrayList<String> list = new ArrayList<>();
list.addAll(defaultBannedNames);
list.addAll(bannedClients);

if (arg[0].equals("list")) {
StringBuilder builder = new StringBuilder();

if (arg[1].equals("name")) {
int best = Strings.bestLength(bannedNames);
int max = best > 18+String.valueOf(bannedNames.size()).length() ? best+4 : 23+String.valueOf(bannedNames.size()).length();

Log.info("List of banned names:");
Log.info(Strings.lJust("| Custom list: Total: " + bannedNames.size(), max) + " Default list: Total: " + list.size());
for (int i=0; i<Math.max(bannedNames.size(), list.size()); i++) {
try { builder.append(Strings.lJust("| | " + bannedNames.get(i), max+1)); }
catch (IndexOutOfBoundsException e) { builder.append("|" + Strings.createSpaces(max)); }
try { builder.append(" | " + list.get(i)); }
catch (IndexOutOfBoundsException e) {}

Log.info(builder.toString());
builder = new StringBuilder();
}

} else if (arg[1].equals("ip")) {
int best = Strings.bestLength(bannedIps);
int max = best > 18+String.valueOf(bannedIps.size()).length() ? best+4 : 23+String.valueOf(bannedIps.size()).length();

Log.info("List of banned ip:");
Log.info(Strings.lJust("| Custom list: Total: " + bannedIps.size(), max) + " Default list: Total: " + AntiVpn.vpnServersList.size() + " (Anti VPN list)");
for (int i=0; i<Math.max(bannedIps.size(), AntiVpn.vpnServersList.size()); i++) {
try { builder.append(Strings.lJust("| | " + bannedIps.get(i), max+1)); }
catch (IndexOutOfBoundsException e) {
builder.append("|" + Strings.createSpaces(max));
if (i > 20) break;
}
try {
if (i == 20) builder.append(" | ...." + (AntiVpn.vpnServersList.size()-i) + " more");
else if (i < 20) builder.append(" | " + AntiVpn.vpnServersList.get(i));
} catch (IndexOutOfBoundsException e) {}

Log.info(builder.toString());
builder = new StringBuilder();

if (i > 20 && bannedIps.size() < 20) break;
}

} else Log.err("Invalid argument. possible arguments: name, ip");

} else if (arg[0].equals("add")) {
if (arg.length == 3) {
if (arg[1].equals("name")) {
if (arg[2].length() > 40) Log.err("A nickname cannot exceed 40 characters");
else if (bannedNames.contains(arg[2])) Log.err("'@' is already in the blacklist", arg[2]);
else {
bannedNames.add(arg[2]);
saveSettings();
Log.info("'@' was added to the blacklist", arg[2]);
}

} else if (arg[1].equals("ip")) {
if (arg[2].split("\\.").length != 4 || !Strings.canParseByteList(arg[2].split("\\."))) Log.err("Incorrect format for IPv4");
else if (bannedIps.contains(arg[2])) Log.err("'@' is already in the blacklist", arg[2]);
else {
bannedIps.add(arg[2]);
saveSettings();
Log.info("'@' was added to the blacklist", arg[2]);
}

} else Log.err("Invalid argument. possible arguments: name, ip");
} else Log.err("Please enter a value");
Seq<String> list = new Seq<String>().addAll("[server]", "~").addAll(bannedClients);

} else if (arg[0].equals("remove")) {
if (arg.length == 3) {
if (arg[1].equals("name")) {
if (!bannedNames.contains(arg[2])) Log.err("'@' isn't in custom blacklist", arg[2]);
else if (list.contains(arg[2])) Log.err("You can't remove a name from the default list");
else {
bannedNames.remove(arg[2]);
saveSettings();
Log.info("'@' has been removed from the blacklist", arg[2]);
}

} else if (arg[1].equals("ip")) {
if (arg[2].split("\\.").length != 4 || !Strings.canParseByteList(arg[2].split("\\."))) Log.err("Incorrect format for IPv4");
else {
bannedIps.remove(arg[2]);
saveSettings();
Log.info("'@' has been removed from the blacklist", arg[2]);
}

} else Log.err("Invalid argument. possible arguments: name, ip");
} else Log.err("Please enter a value");

} else if (arg[0].equals("clear")) {
if (arg[1].equals("name")) {
bannedNames.clear();
saveSettings();
Log.info("Name blacklist emptied!");

} else if (arg[1].equals("ip")) {
bannedIps.clear();
saveSettings();
Log.info("IP blacklist emptied!");

} else Log.err("Invalid argument. possible arguments: name, ip");

} else Log.err("Invalid argument. possible arguments: list, add, remove");
switch (arg[0]) {
case "list":
StringBuilder builder = new StringBuilder();

if (arg[1].equals("name")) {
int best = Strings.bestLength(bannedNames);
int max = best > 18+String.valueOf(bannedNames.size).length() ? best+4 : 23+String.valueOf(bannedNames.size).length();

Log.info("List of banned names:");
Log.info(Strings.lJust("| Custom list: Total: " + bannedNames.size, max) + " Default list: Total: " + list.size);
for (int i=0; i<Math.max(bannedNames.size, list.size); i++) {
try { builder.append(Strings.lJust("| | " + bannedNames.get(i), max+1)); }
catch (IndexOutOfBoundsException e) { builder.append("|" + Strings.createSpaces(max)); }
try { builder.append(" | " + list.get(i)); }
catch (IndexOutOfBoundsException e) {}

Log.info(builder.toString());
builder = new StringBuilder();
}

} else if (arg[1].equals("ip")) {
int best = Strings.bestLength(bannedIps);
int max = best > 18+String.valueOf(bannedIps.size).length() ? best+4 : 23+String.valueOf(bannedIps.size).length();

Log.info("List of banned ip:");
Log.info(Strings.lJust("| Custom list: Total: " + bannedIps.size, max) + " Default list: Total: " + AntiVpn.vpnServersList.size() + " (Anti VPN list)");
for (int i=0; i<Math.max(bannedIps.size, AntiVpn.vpnServersList.size()); i++) {
try { builder.append(Strings.lJust("| | " + bannedIps.get(i), max+1)); }
catch (IndexOutOfBoundsException e) {
builder.append("|" + Strings.createSpaces(max));
if (i > 20) break;
}
try {
if (i == 20) builder.append(" | ...." + (AntiVpn.vpnServersList.size()-i) + " more");
else if (i < 20) builder.append(" | " + AntiVpn.vpnServersList.get(i));
} catch (IndexOutOfBoundsException e) {}

Log.info(builder.toString());
builder = new StringBuilder();

if (i > 20 && bannedIps.size < 20) break;
}

} else Log.err("Invalid argument. possible arguments: name, ip");
break;

case "add":
if (arg.length == 3) {
if (arg[1].equals("name")) {
if (arg[2].length() > 40) Log.err("A nickname cannot exceed 40 characters");
else if (bannedNames.contains(arg[2])) Log.err("'@' is already in the blacklist", arg[2]);
else {
bannedNames.add(arg[2]);
saveSettings();
Log.info("'@' was added to the blacklist", arg[2]);
}

} else if (arg[1].equals("ip")) {
if (arg[2].split("\\.").length != 4 || !Strings.canParseByteList(arg[2].split("\\."))) Log.err("Incorrect format for IPv4");
else if (bannedIps.contains(arg[2])) Log.err("'@' is already in the blacklist", arg[2]);
else {
bannedIps.add(arg[2]);
saveSettings();
Log.info("'@' was added to the blacklist", arg[2]);
}

} else Log.err("Invalid argument. possible arguments: name, ip");
} else Log.err("Please enter a value");
break;

case "remove":
if (arg.length == 3) {
if (arg[1].equals("name")) {
if (!bannedNames.contains(arg[2])) Log.err("'@' isn't in custom blacklist", arg[2]);
else if (list.contains(arg[2])) Log.err("You can't remove a name from the default list");
else {
bannedNames.remove(arg[2]);
saveSettings();
Log.info("'@' has been removed from the blacklist", arg[2]);
}

} else if (arg[1].equals("ip")) {
if (arg[2].split("\\.").length != 4 || !Strings.canParseByteList(arg[2].split("\\."))) Log.err("Incorrect format for IPv4");
else {
bannedIps.remove(arg[2]);
saveSettings();
Log.info("'@' has been removed from the blacklist", arg[2]);
}

} else Log.err("Invalid argument. possible arguments: name, ip");
} else Log.err("Please enter a value");
break;

case "clear":
if (arg[1].equals("name")) {
bannedNames.clear();
saveSettings();
Log.info("Name blacklist emptied!");

} else if (arg[1].equals("ip")) {
bannedIps.clear();
saveSettings();
Log.info("IP blacklist emptied!");

} else Log.err("Invalid argument. possible arguments: name, ip");
break;

default: Log.err("Invalid argument. possible arguments: list, add, remove");
}
}


public static void nameCheck(mindustry.gen.Player player) {
String name = TempData.get(player).stripedName;

if (bannedNames.contains(name) || defaultBannedNames.contains(name))
player.kick("[scarlet]Invalid nickname: []Please don't use [accent]'" + bannedNames.get(bannedNames.indexOf(name)) + "'[white] in your nickname.");

else if (bannedClients.contains(name))
player.con.kick("Ingenuine copy of Mindustry.\n\n"
+ "Mindustry is free on: [royal]https://anuke.itch.io/mindustry[]\n"
+ "Mindustry est gratuit ici : [royal]https://anuke.itch.io/mindustry[]\n");

else if (bannedIps.contains(player.con.address))
player.kick("[scarlet]The IP you are using is blacklisted. [lightgray](your ip: " + player.ip() +")");

if (name.startsWith(FilterType.prefix)) player.kick("[scarlet]Your nickname must not start with [orange]'" + FilterType.prefix + "'");
else if (bannedNames.contains(name) || name.toLowerCase().equals("[server]") || name.equals("~")) player.kick("[scarlet]This nickname is banned!");
else if (bannedClients.contains(name)) player.con.kick("Ingenuine copy of Mindustry.\n\nMindustry is free on: [royal]https://anuke.itch.io/mindustry[]\n");
else if (bannedIps.contains(player.con.address)) player.kick("[scarlet]Your IP is blacklisted. [lightgray](ip: " + player.ip() +")");
else if (AntiVpn.isEnabled && AntiVpn.checkIP(player.ip()))
player.kick("[scarlet]Anti VPN is activated on this server! []Please deactivate your VPN to be able to connect to the server.");
}
Expand All @@ -149,11 +144,11 @@ else if (AntiVpn.isEnabled && AntiVpn.checkIP(player.ip()))
public static void init() {
try {
if (Core.settings.has("bannedNamesList")) {
bannedNames = Core.settings.getJson("bannedNamesList", Seq.class, Seq::new).list();
bannedNames = Core.settings.getJson("bannedNamesList", Seq.class, Seq::new);
} else saveSettings();

if (Core.settings.has("bannedIpsList")) {
bannedIps = Core.settings.getJson("bannedIpsList", Seq.class, Seq::new).list();
bannedIps = Core.settings.getJson("bannedIpsList", Seq.class, Seq::new);
} else saveSettings();

} catch (Exception e) { saveSettings(); }
Expand Down
57 changes: 46 additions & 11 deletions src/main/java/data/TempData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package data;

import arc.func.Boolf;
import arc.struct.ObjectMap;
import arc.struct.Seq;

Expand All @@ -11,9 +12,9 @@ public class TempData {
private static ObjectMap<Player, TempData> data = new ObjectMap<>();
public static final String creatorID = "k6uyrb9D3dEAAAAArLs28w==";
public final Player player;
public MSG msgData = new MSG();
public mindustry.game.Team spectate = null;
public final String realName, noColorName, stripedName;
public float savedBuildSpeed = 0;
public int hue = 0;
public boolean votedVNW = false,
votedRTV = false,
Expand All @@ -30,20 +31,21 @@ public TempData(Player p){
this.stripedName = String.valueOf(Strings.stripGlyphs(this.noColorName));
this.isCreator = p.uuid().equals(creatorID);
}

public boolean spectate() {
return this.spectate != null;
}

public String toString() {
return "TempData{"
+ "spectate: " + this.spectate + ", realName: " + this.realName
+ ", noColorName: " + this.noColorName + ", stripedName: " + this.stripedName
+ ", savedBuildSpeed: " + this.savedBuildSpeed + ", hue: " + this.hue
return "TempData{"
+ "player: " + this.player + ", spectate: " + this.spectate
+ ", realName: " + this.realName + ", noColorName: " + this.noColorName
+ ", stripedName: " + this.stripedName + ", hue: " + this.hue
+ ", votedVNW: " + this.votedVNW + ", votedRTV: " + this.votedRTV
+ ", rainbowed: " + this.rainbowed + ", hasEffect: " + this.hasEffect
+ ", isMuted: " + this.isMuted + ", inGodmode: " + this.inGodmode
+ ", isCreator: " + this.isCreator + "}";
+ ", isCreator: " + this.isCreator
+ "}";
}


Expand All @@ -54,9 +56,9 @@ public static Seq<TempData> copy() {
public static TempData getByName(String name) {
return get(data.keys().toSeq().find(p -> p.name.equals(name)));
}
public static TempData getByID(String uuid) {
return get(data.keys().toSeq().find(p -> p.uuid().equals(uuid)));

public static TempData getByID(String id) {
return get(data.keys().toSeq().find(p -> p.uuid().equals(id)));
}

public static TempData get(Player p) {
Expand All @@ -65,6 +67,7 @@ public static TempData get(Player p) {
}

public static TempData put(TempData data) {
data.msgData.player = data.player;
TempData.data.put(data.player, data);
return data;
}
Expand All @@ -74,6 +77,7 @@ public static TempData putDefault(Player p) {
}

public static void remove(Player p) {
get(p).msgData.removeTarget();
data.remove(p);
}

Expand All @@ -85,7 +89,38 @@ public static void setAll(arc.func.Cons<TempData> item) {
data.forEach(d -> item.get(d.value));
}

public static Seq<TempData> filter(arc.func.Boolf<TempData> pred) {
public static Seq<TempData> filter(Boolf<TempData> pred) {
return data.values().toSeq().filter(pred);
}

public static TempData find(Boolf<TempData> pred) {
return data.values().toSeq().find(pred);
}


public class MSG {
public Player player = null, target = null;
public boolean targetOnline = false;

private MSG() {
}

public void setTarget(Player target) {
TempData t = TempData.get(target);

if (t != null) {
this.target = target;
this.targetOnline = true;
t.msgData.target = this.player;
}
}

public void removeTarget() {
if (this.target != null) {
MSG t = TempData.get(this.target).msgData;
t.target = null;
t.targetOnline = false;
}
}
}
}
Loading

0 comments on commit 35ded26

Please sign in to comment.