Server mod checking

This commit is contained in:
Anuken
2019-09-29 22:59:23 -04:00
parent 73e9f55e55
commit 7fccd18910
7 changed files with 54 additions and 8 deletions

View File

@@ -964,7 +964,7 @@ tutorial.withdraw = In some situations, taking items directly from blocks is nec
tutorial.deposit = Deposit items into blocks by dragging from your ship to the destination block.\n\n[accent]Deposit your copper back into the core.[] tutorial.deposit = Deposit items into blocks by dragging from your ship to the destination block.\n\n[accent]Deposit your copper back into the core.[]
tutorial.waves = The[lightgray] enemy[] approaches.\n\nDefend the core for 2 waves.[accent] Click[] to shoot.\nBuild more turrets and drills. Mine more copper. tutorial.waves = The[lightgray] enemy[] approaches.\n\nDefend the core for 2 waves.[accent] Click[] to shoot.\nBuild more turrets and drills. Mine more copper.
tutorial.waves.mobile = The[lightgray] enemy[] approaches.\n\nDefend the core for 2 waves. Your ship will automatically fire at enemies.\nBuild more turrets and drills. Mine more copper. tutorial.waves.mobile = The[lightgray] enemy[] approaches.\n\nDefend the core for 2 waves. Your ship will automatically fire at enemies.\nBuild more turrets and drills. Mine more copper.
tutorial.launch = Once you reach a specific wave, you are able to[accent] launch the core[], leaving your defenses behind and[accent] obtaining all the resources in your core.[]\nThese resources can then be used to research new technology.\n\n[accent]Press the launch button. tutorial.launch = Once you reach a specific wave, you are able to[accent] launch the core[], leaving your defenses behind and[accent] obtaining all the resources in your core.[]\nThese obtained resources can then be used to research new technology.\n\n[accent]Press the launch button.
item.copper.description = The most basic structural material. Used extensively in all types of blocks. item.copper.description = The most basic structural material. Used extensively in all types of blocks.
item.lead.description = A basic starter material. Used extensively in electronics and liquid transportation blocks. item.lead.description = A basic starter material. Used extensively in electronics and liquid transportation blocks.

View File

@@ -236,7 +236,7 @@ public class NetClient implements ApplicationListener{
netClient.disconnectQuietly(); netClient.disconnectQuietly();
state.set(State.menu); state.set(State.menu);
logic.reset(); logic.reset();
ui.showText("$disconnect", reason); ui.showText("$disconnect", reason, Align.left);
ui.loadfrag.hide(); ui.loadfrag.hide();
} }

View File

@@ -104,6 +104,23 @@ public class NetServer implements ApplicationListener{
return; return;
} }
Array<String> extraMods = packet.mods.copy();
Array<String> missingMods = mods.getIncompatibility(extraMods);
if(!extraMods.isEmpty() || !missingMods.isEmpty()){
//can't easily be localized since kick reasons can't have formatted text with them
StringBuilder result = new StringBuilder("[accent]Incompatible mods![]\n\n");
if(!missingMods.isEmpty()){
result.append("Missing:[lightgray]\n").append("> ").append(missingMods.toString("\n> "));
result.append("[]\n");
}
if(!extraMods.isEmpty()){
result.append("Unnecessary mods:[lightgray]\n").append("> ").append(extraMods.toString("\n> "));
}
con.kick(result.toString());
}
if(!admins.isWhitelisted(packet.uuid, packet.usid)){ if(!admins.isWhitelisted(packet.uuid, packet.usid)){
info.adminUsid = packet.usid; info.adminUsid = packet.usid;
info.lastName = packet.name; info.lastName = packet.name;

View File

@@ -360,11 +360,15 @@ public class UI implements ApplicationListener, Loadable{
} }
public void showText(String titleText, String text){ public void showText(String titleText, String text){
showText(titleText, text, Align.center);
}
public void showText(String titleText, String text, int align){
new Dialog(titleText){{ new Dialog(titleText){{
cont.row(); cont.row();
cont.addImage().width(400f).pad(2).colspan(2).height(4f).color(Pal.accent); cont.addImage().width(400f).pad(2).colspan(2).height(4f).color(Pal.accent);
cont.row(); cont.row();
cont.add(text).width(400f).wrap().get().setAlignment(Align.center, Align.center); cont.add(text).width(400f).wrap().get().setAlignment(align, align);
cont.row(); cont.row();
buttons.addButton("$ok", this::hide).size(90, 50).pad(4); buttons.addButton("$ok", this::hide).size(90, 50).pad(4);
}}.show(); }}.show();

View File

@@ -9,11 +9,12 @@ import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.Pixmap.*; import io.anuke.arc.graphics.Pixmap.*;
import io.anuke.arc.graphics.Texture.*; import io.anuke.arc.graphics.Texture.*;
import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.graphics.g2d.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.io.*; import io.anuke.arc.util.io.*;
import io.anuke.arc.util.serialization.*; import io.anuke.arc.util.serialization.*;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.plugin.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import java.io.*; import java.io.*;
@@ -221,6 +222,19 @@ public class Mods implements Loadable{
return loaded.select(l -> !l.meta.hidden).map(l -> l.name + ":" + l.meta.version); return loaded.select(l -> !l.meta.hidden).map(l -> l.name + ":" + l.meta.version);
} }
/** @return the mods that the client is missing.
* The inputted array is changed to contain the extra mods that the client has but the server does.*/
public Array<String> getIncompatibility(Array<String> out){
Array<String> mods = getModStrings();
Array<String> result = mods.copy();
for(String mod : mods){
if(out.remove(mod)){
result.remove(mod);
}
}
return result;
}
/** Iterates through each mod with a main class.*/ /** Iterates through each mod with a main class.*/
public void each(Consumer<Mod> cons){ public void each(Consumer<Mod> cons){
loaded.each(p -> p.mod != null, p -> cons.accept(p.mod)); loaded.each(p -> p.mod != null, p -> cons.accept(p.mod));
@@ -242,8 +256,16 @@ public class Mods implements Loadable{
String mainClass = meta.main == null ? camelized.toLowerCase() + "." + camelized + "Mod" : meta.main; String mainClass = meta.main == null ? camelized.toLowerCase() + "." + camelized + "Mod" : meta.main;
Mod mainMod; Mod mainMod;
FileHandle mainFile = zip;
String[] path = (mainClass.replace('.', '/') + ".class").split("/");
for(String str : path){
if(!str.isEmpty()){
mainFile = mainFile.child(str);
}
}
//make sure the main class exists before loading it; if it doesn't just don't put it there //make sure the main class exists before loading it; if it doesn't just don't put it there
if(zip.child(mainClass.replace('.', '/') + ".class").exists()){ if(mainFile.exists()){
//other platforms don't have standard java class loaders //other platforms don't have standard java class loaders
if(mobile){ if(mobile){
throw new IllegalArgumentException("This mod is not compatible with " + (ios ? "iOS" : "Android") + "."); throw new IllegalArgumentException("This mod is not compatible with " + (ios ? "iOS" : "Android") + ".");
@@ -257,6 +279,11 @@ public class Mods implements Loadable{
mainMod = null; mainMod = null;
} }
//all plugins are hidden implicitly
if(mainMod instanceof Plugin){
meta.hidden = true;
}
return new LoadedMod(sourceFile, zip, mainMod, meta); return new LoadedMod(sourceFile, zip, mainMod, meta);
} }

View File

@@ -49,7 +49,7 @@ public abstract class NetConnection{
/** Kick with an arbitrary reason. */ /** Kick with an arbitrary reason. */
public void kick(String reason){ public void kick(String reason){
Log.info("Kicking connection {0}; Reason: {1}", address, reason); Log.info("Kicking connection {0}; Reason: {1}", address, reason.replace("\n", " "));
if(player != null && player.uuid != null){ if(player != null && player.uuid != null){
PlayerInfo info = netServer.admins.getInfo(player.uuid); PlayerInfo info = netServer.admins.getInfo(player.uuid);

View File

@@ -2,8 +2,6 @@ package io.anuke.mindustry.plugin;
import io.anuke.mindustry.mod.*; import io.anuke.mindustry.mod.*;
/** Use Mod instead. */
@Deprecated
public abstract class Plugin extends Mod{ public abstract class Plugin extends Mod{
} }