diff --git a/build.gradle b/build.gradle index 7fe10efa58..661851a9a4 100644 --- a/build.gradle +++ b/build.gradle @@ -189,6 +189,8 @@ project(":server") { apply plugin: "java" dependencies { + compileOnly project(":annotations") + compile project(":core") compile project(":kryonet") compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion" diff --git a/core/assets/maps/test.mmap b/core/assets/maps/test.mmap index a87649b16a..ab8f0627af 100644 Binary files a/core/assets/maps/test.mmap and b/core/assets/maps/test.mmap differ diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index e3fb7bd309..ffb8f7cfc8 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -135,6 +135,7 @@ public class NetServer extends Module{ player.dead = true; player.setNet(player.x, player.y); player.color.set(packet.color); + player.color.a = 1f; connections.put(id, player); trace.playerid = player.id; diff --git a/core/src/io/anuke/mindustry/io/Maps.java b/core/src/io/anuke/mindustry/io/Maps.java index e8aa937786..ccb229b473 100644 --- a/core/src/io/anuke/mindustry/io/Maps.java +++ b/core/src/io/anuke/mindustry/io/Maps.java @@ -18,7 +18,7 @@ import static io.anuke.mindustry.Vars.*; public class Maps implements Disposable{ /**List of all built-in maps.*/ - private static final String[] defaultMapNames = {}; + private static final String[] defaultMapNames = {"test"}; /**Tile format version.*/ private static final int version = 0; diff --git a/core/src/io/anuke/mindustry/net/Net.java b/core/src/io/anuke/mindustry/net/Net.java index 00eb5e7f3d..ab2261ae95 100644 --- a/core/src/io/anuke/mindustry/net/Net.java +++ b/core/src/io/anuke/mindustry/net/Net.java @@ -13,9 +13,9 @@ import com.badlogic.gdx.utils.reflect.ClassReflection; import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.net.Packet.ImportantPacket; import io.anuke.mindustry.net.Packet.UnimportantPacket; -import io.anuke.mindustry.net.Streamable.StreamBegin; +import io.anuke.mindustry.net.Packets.StreamBegin; import io.anuke.mindustry.net.Streamable.StreamBuilder; -import io.anuke.mindustry.net.Streamable.StreamChunk; +import io.anuke.mindustry.net.Packets.StreamChunk; import io.anuke.ucore.core.Timers; import io.anuke.ucore.function.BiConsumer; import io.anuke.ucore.function.Consumer; diff --git a/core/src/io/anuke/mindustry/net/Packets.java b/core/src/io/anuke/mindustry/net/Packets.java index 5df6011dc3..2ee5883f1d 100644 --- a/core/src/io/anuke/mindustry/net/Packets.java +++ b/core/src/io/anuke/mindustry/net/Packets.java @@ -156,4 +156,46 @@ public class Packets { public enum AdminAction{ kick, ban, trace } + + /**Marks the beginning of a stream.*/ + public static class StreamBegin implements Packet{ + private static int lastid; + + public int id = lastid ++; + public int total; + public Class type; + + @Override + public void write(ByteBuffer buffer) { + buffer.putInt(id); + buffer.putInt(total); + buffer.put(Registrator.getID(type)); + } + + @Override + public void read(ByteBuffer buffer) { + id = buffer.getInt(); + total = buffer.getInt(); + type = (Class)Registrator.getByID(buffer.get()); + } + } + + public static class StreamChunk implements Packet{ + public int id; + public byte[] data; + + @Override + public void write(ByteBuffer buffer) { + buffer.putInt(id); + buffer.putShort((short)data.length); + buffer.put(data); + } + + @Override + public void read(ByteBuffer buffer) { + id = buffer.getInt(); + data = new byte[buffer.getShort()]; + buffer.get(data); + } + } } diff --git a/core/src/io/anuke/mindustry/net/Registrator.java b/core/src/io/anuke/mindustry/net/Registrator.java index 4128f02ed3..e8596b8a92 100644 --- a/core/src/io/anuke/mindustry/net/Registrator.java +++ b/core/src/io/anuke/mindustry/net/Registrator.java @@ -3,8 +3,8 @@ package io.anuke.mindustry.net; import com.badlogic.gdx.utils.ObjectIntMap; import com.badlogic.gdx.utils.reflect.ClassReflection; import io.anuke.mindustry.net.Packets.*; -import io.anuke.mindustry.net.Streamable.StreamBegin; -import io.anuke.mindustry.net.Streamable.StreamChunk; +import io.anuke.mindustry.net.Packets.StreamBegin; +import io.anuke.mindustry.net.Packets.StreamChunk; public class Registrator { private static Class[] classes = { diff --git a/core/src/io/anuke/mindustry/net/Streamable.java b/core/src/io/anuke/mindustry/net/Streamable.java index 1d700b2087..7a697f254e 100644 --- a/core/src/io/anuke/mindustry/net/Streamable.java +++ b/core/src/io/anuke/mindustry/net/Streamable.java @@ -3,57 +3,15 @@ package io.anuke.mindustry.net; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ReflectionException; import io.anuke.mindustry.net.Packet.ImportantPacket; +import io.anuke.mindustry.net.Packets.StreamBegin; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.ByteBuffer; public class Streamable implements ImportantPacket{ public transient ByteArrayInputStream stream; - /**Marks the beginning of a stream.*/ - public static class StreamBegin implements Packet{ - private static int lastid; - - public int id = lastid ++; - public int total; - public Class type; - - @Override - public void write(ByteBuffer buffer) { - buffer.putInt(id); - buffer.putInt(total); - buffer.put(Registrator.getID(type)); - } - - @Override - public void read(ByteBuffer buffer) { - id = buffer.getInt(); - total = buffer.getInt(); - type = (Class)Registrator.getByID(buffer.get()); - } - } - - public static class StreamChunk implements Packet{ - public int id; - public byte[] data; - - @Override - public void write(ByteBuffer buffer) { - buffer.putInt(id); - buffer.putShort((short)data.length); - buffer.put(data); - } - - @Override - public void read(ByteBuffer buffer) { - id = buffer.getInt(); - data = new byte[buffer.getShort()]; - buffer.get(data); - } - } - public static class StreamBuilder{ public final int id; public final Class type; diff --git a/core/src/io/anuke/mindustry/world/WorldGenerator.java b/core/src/io/anuke/mindustry/world/WorldGenerator.java index 7e3f81b46b..8deed0be0b 100644 --- a/core/src/io/anuke/mindustry/world/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/world/WorldGenerator.java @@ -114,7 +114,6 @@ public class WorldGenerator { } } } - } static class OreEntry{ diff --git a/kryonet/src/io/anuke/kryonet/KryoServer.java b/kryonet/src/io/anuke/kryonet/KryoServer.java index 53a4428472..efcb788baa 100644 --- a/kryonet/src/io/anuke/kryonet/KryoServer.java +++ b/kryonet/src/io/anuke/kryonet/KryoServer.java @@ -18,8 +18,8 @@ import io.anuke.mindustry.net.NetworkIO; import io.anuke.mindustry.net.Packets.Connect; import io.anuke.mindustry.net.Packets.Disconnect; import io.anuke.mindustry.net.Streamable; -import io.anuke.mindustry.net.Streamable.StreamBegin; -import io.anuke.mindustry.net.Streamable.StreamChunk; +import io.anuke.mindustry.net.Packets.StreamBegin; +import io.anuke.mindustry.net.Packets.StreamChunk; import io.anuke.ucore.UCore; import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Log; diff --git a/server/src/io/anuke/mindustry/server/MindustryServer.java b/server/src/io/anuke/mindustry/server/MindustryServer.java index 6f48c3f46a..c82c4a5695 100644 --- a/server/src/io/anuke/mindustry/server/MindustryServer.java +++ b/server/src/io/anuke/mindustry/server/MindustryServer.java @@ -1,7 +1,10 @@ package io.anuke.mindustry.server; import io.anuke.mindustry.Vars; -import io.anuke.mindustry.core.*; +import io.anuke.mindustry.core.ContentLoader; +import io.anuke.mindustry.core.Logic; +import io.anuke.mindustry.core.NetServer; +import io.anuke.mindustry.core.World; import io.anuke.mindustry.game.Content; import io.anuke.mindustry.io.BundleLoader; import io.anuke.ucore.modules.ModuleCore; diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index accc8eaf6c..8b0933e3bb 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -1,6 +1,5 @@ package io.anuke.mindustry.server; -import com.badlogic.gdx.ApplicationLogger; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntMap; @@ -49,16 +48,6 @@ public class ServerControl extends Module { Effects.setEffectProvider((a, b, c, d, e, f) -> {}); Sounds.setHeadless(true); - //don't do anything at all for GDX logging: don't want controller info and such - Gdx.app.setApplicationLogger(new ApplicationLogger() { - @Override public void log(String tag, String message) { } - @Override public void log(String tag, String message, Throwable exception) { } - @Override public void error(String tag, String message) { } - @Override public void error(String tag, String message, Throwable exception) { } - @Override public void debug(String tag, String message) { } - @Override public void debug(String tag, String message, Throwable exception) { } - }); - String[] commands = {}; if(args.length > 0){ @@ -140,6 +129,11 @@ public class ServerControl extends Module { return; } + if(world.maps().all().size == 0){ + err("No maps found to host with!"); + return; + } + Map result = null; if(arg.length > 0) { @@ -230,6 +224,7 @@ public class ServerControl extends Module { } //netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]); + info("&lyServer: &lb{0}", arg[0]); }); @@ -743,7 +738,23 @@ public class ServerControl extends Module { Response response = handler.handleMessage(line); if (response.type == ResponseType.unknownCommand) { - err("Invalid command. Type 'help' for help."); + + int minDst = 0; + Command closest = null; + + for(Command command : handler.getCommandList()){ + int dst = Strings.levenshtein(command.text, response.runCommand); + if(dst < 3 && (closest == null || dst < minDst)){ + minDst = dst; + closest = command; + } + } + + if(closest != null){ + err("Command not found. Did you mean \"" + closest.text + "\"?"); + }else { + err("Invalid command. Type 'help' for help."); + } }else if (response.type == ResponseType.fewArguments) { err("Too few command arguments. Usage: " + response.command.text + " " + response.command.paramText); }else if (response.type == ResponseType.manyArguments) { diff --git a/server/src/io/anuke/mindustry/server/ServerLauncher.java b/server/src/io/anuke/mindustry/server/ServerLauncher.java index 1abd040a47..bf3a59ac57 100644 --- a/server/src/io/anuke/mindustry/server/ServerLauncher.java +++ b/server/src/io/anuke/mindustry/server/ServerLauncher.java @@ -1,18 +1,21 @@ package io.anuke.mindustry.server; +import com.badlogic.gdx.ApplicationListener; +import com.badlogic.gdx.ApplicationLogger; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.headless.HeadlessApplication; import io.anuke.kryonet.KryoClient; import io.anuke.kryonet.KryoServer; import io.anuke.mindustry.net.Net; -public class ServerLauncher{ +public class ServerLauncher extends HeadlessApplication{ public static void main(String[] args){ Net.setClientProvider(new KryoClient()); Net.setServerProvider(new KryoServer()); - new HeadlessApplication(new MindustryServer(args)); + new ServerLauncher(new MindustryServer(args)); //find and handle uncaught exceptions in libGDX thread for(Thread thread : Thread.getAllStackTraces().keySet()){ @@ -25,4 +28,18 @@ public class ServerLauncher{ } } } + + public ServerLauncher(ApplicationListener listener) { + super(listener); + + //don't do anything at all for GDX logging: don't want controller info and such + Gdx.app.setApplicationLogger(new ApplicationLogger() { + @Override public void log(String tag, String message) { } + @Override public void log(String tag, String message, Throwable exception) { } + @Override public void error(String tag, String message) { } + @Override public void error(String tag, String message, Throwable exception) { } + @Override public void debug(String tag, String message) { } + @Override public void debug(String tag, String message, Throwable exception) { } + }); + } } \ No newline at end of file