Server mod checking
This commit is contained in:
@@ -236,7 +236,7 @@ public class NetClient implements ApplicationListener{
|
||||
netClient.disconnectQuietly();
|
||||
state.set(State.menu);
|
||||
logic.reset();
|
||||
ui.showText("$disconnect", reason);
|
||||
ui.showText("$disconnect", reason, Align.left);
|
||||
ui.loadfrag.hide();
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,23 @@ public class NetServer implements ApplicationListener{
|
||||
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)){
|
||||
info.adminUsid = packet.usid;
|
||||
info.lastName = packet.name;
|
||||
|
||||
@@ -360,11 +360,15 @@ public class UI implements ApplicationListener, Loadable{
|
||||
}
|
||||
|
||||
public void showText(String titleText, String text){
|
||||
showText(titleText, text, Align.center);
|
||||
}
|
||||
|
||||
public void showText(String titleText, String text, int align){
|
||||
new Dialog(titleText){{
|
||||
cont.row();
|
||||
cont.addImage().width(400f).pad(2).colspan(2).height(4f).color(Pal.accent);
|
||||
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();
|
||||
buttons.addButton("$ok", this::hide).size(90, 50).pad(4);
|
||||
}}.show();
|
||||
|
||||
@@ -9,11 +9,12 @@ import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.Pixmap.*;
|
||||
import io.anuke.arc.graphics.Texture.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.ArcAnnotate.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.io.*;
|
||||
import io.anuke.arc.util.serialization.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.plugin.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
|
||||
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 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.*/
|
||||
public void each(Consumer<Mod> cons){
|
||||
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;
|
||||
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
|
||||
if(zip.child(mainClass.replace('.', '/') + ".class").exists()){
|
||||
if(mainFile.exists()){
|
||||
//other platforms don't have standard java class loaders
|
||||
if(mobile){
|
||||
throw new IllegalArgumentException("This mod is not compatible with " + (ios ? "iOS" : "Android") + ".");
|
||||
@@ -257,6 +279,11 @@ public class Mods implements Loadable{
|
||||
mainMod = null;
|
||||
}
|
||||
|
||||
//all plugins are hidden implicitly
|
||||
if(mainMod instanceof Plugin){
|
||||
meta.hidden = true;
|
||||
}
|
||||
|
||||
return new LoadedMod(sourceFile, zip, mainMod, meta);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class NetConnection{
|
||||
|
||||
/** Kick with an arbitrary 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){
|
||||
PlayerInfo info = netServer.admins.getInfo(player.uuid);
|
||||
|
||||
@@ -2,8 +2,6 @@ package io.anuke.mindustry.plugin;
|
||||
|
||||
import io.anuke.mindustry.mod.*;
|
||||
|
||||
/** Use Mod instead. */
|
||||
@Deprecated
|
||||
public abstract class Plugin extends Mod{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user