Moved over Streamable inner classes, added test map
This commit is contained in:
@@ -189,6 +189,8 @@ project(":server") {
|
|||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly project(":annotations")
|
||||||
|
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
compile project(":kryonet")
|
compile project(":kryonet")
|
||||||
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
|
||||||
|
|||||||
Binary file not shown.
@@ -135,6 +135,7 @@ public class NetServer extends Module{
|
|||||||
player.dead = true;
|
player.dead = true;
|
||||||
player.setNet(player.x, player.y);
|
player.setNet(player.x, player.y);
|
||||||
player.color.set(packet.color);
|
player.color.set(packet.color);
|
||||||
|
player.color.a = 1f;
|
||||||
connections.put(id, player);
|
connections.put(id, player);
|
||||||
|
|
||||||
trace.playerid = player.id;
|
trace.playerid = player.id;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import static io.anuke.mindustry.Vars.*;
|
|||||||
|
|
||||||
public class Maps implements Disposable{
|
public class Maps implements Disposable{
|
||||||
/**List of all built-in maps.*/
|
/**List of all built-in maps.*/
|
||||||
private static final String[] defaultMapNames = {};
|
private static final String[] defaultMapNames = {"test"};
|
||||||
/**Tile format version.*/
|
/**Tile format version.*/
|
||||||
private static final int version = 0;
|
private static final int version = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
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.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.core.Timers;
|
||||||
import io.anuke.ucore.function.BiConsumer;
|
import io.anuke.ucore.function.BiConsumer;
|
||||||
import io.anuke.ucore.function.Consumer;
|
import io.anuke.ucore.function.Consumer;
|
||||||
|
|||||||
@@ -156,4 +156,46 @@ public class Packets {
|
|||||||
public enum AdminAction{
|
public enum AdminAction{
|
||||||
kick, ban, trace
|
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<? extends Streamable> 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<? extends Streamable>)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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package io.anuke.mindustry.net;
|
|||||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||||
|
|
||||||
public class Registrator {
|
public class Registrator {
|
||||||
private static Class<?>[] classes = {
|
private static Class<?>[] classes = {
|
||||||
|
|||||||
@@ -3,57 +3,15 @@ package io.anuke.mindustry.net;
|
|||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||||
|
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
public class Streamable implements ImportantPacket{
|
public class Streamable implements ImportantPacket{
|
||||||
public transient ByteArrayInputStream stream;
|
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<? extends Streamable> 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<? extends Streamable>)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 static class StreamBuilder{
|
||||||
public final int id;
|
public final int id;
|
||||||
public final Class<? extends Streamable> type;
|
public final Class<? extends Streamable> type;
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ public class WorldGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class OreEntry{
|
static class OreEntry{
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import io.anuke.mindustry.net.NetworkIO;
|
|||||||
import io.anuke.mindustry.net.Packets.Connect;
|
import io.anuke.mindustry.net.Packets.Connect;
|
||||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||||
import io.anuke.mindustry.net.Streamable;
|
import io.anuke.mindustry.net.Streamable;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||||
import io.anuke.ucore.UCore;
|
import io.anuke.ucore.UCore;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package io.anuke.mindustry.server;
|
package io.anuke.mindustry.server;
|
||||||
|
|
||||||
import io.anuke.mindustry.Vars;
|
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.game.Content;
|
||||||
import io.anuke.mindustry.io.BundleLoader;
|
import io.anuke.mindustry.io.BundleLoader;
|
||||||
import io.anuke.ucore.modules.ModuleCore;
|
import io.anuke.ucore.modules.ModuleCore;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.anuke.mindustry.server;
|
package io.anuke.mindustry.server;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationLogger;
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.IntMap;
|
import com.badlogic.gdx.utils.IntMap;
|
||||||
@@ -49,16 +48,6 @@ public class ServerControl extends Module {
|
|||||||
Effects.setEffectProvider((a, b, c, d, e, f) -> {});
|
Effects.setEffectProvider((a, b, c, d, e, f) -> {});
|
||||||
Sounds.setHeadless(true);
|
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 = {};
|
String[] commands = {};
|
||||||
|
|
||||||
if(args.length > 0){
|
if(args.length > 0){
|
||||||
@@ -140,6 +129,11 @@ public class ServerControl extends Module {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(world.maps().all().size == 0){
|
||||||
|
err("No maps found to host with!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Map result = null;
|
Map result = null;
|
||||||
|
|
||||||
if(arg.length > 0) {
|
if(arg.length > 0) {
|
||||||
@@ -230,6 +224,7 @@ public class ServerControl extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
|
//netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
|
||||||
|
|
||||||
info("&lyServer: &lb{0}", arg[0]);
|
info("&lyServer: &lb{0}", arg[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -743,7 +738,23 @@ public class ServerControl extends Module {
|
|||||||
Response response = handler.handleMessage(line);
|
Response response = handler.handleMessage(line);
|
||||||
|
|
||||||
if (response.type == ResponseType.unknownCommand) {
|
if (response.type == ResponseType.unknownCommand) {
|
||||||
|
|
||||||
|
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.");
|
err("Invalid command. Type 'help' for help.");
|
||||||
|
}
|
||||||
}else if (response.type == ResponseType.fewArguments) {
|
}else if (response.type == ResponseType.fewArguments) {
|
||||||
err("Too few command arguments. Usage: " + response.command.text + " " + response.command.paramText);
|
err("Too few command arguments. Usage: " + response.command.text + " " + response.command.paramText);
|
||||||
}else if (response.type == ResponseType.manyArguments) {
|
}else if (response.type == ResponseType.manyArguments) {
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
package io.anuke.mindustry.server;
|
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 com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||||
import io.anuke.kryonet.KryoClient;
|
import io.anuke.kryonet.KryoClient;
|
||||||
import io.anuke.kryonet.KryoServer;
|
import io.anuke.kryonet.KryoServer;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
|
|
||||||
public class ServerLauncher{
|
public class ServerLauncher extends HeadlessApplication{
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
|
|
||||||
Net.setClientProvider(new KryoClient());
|
Net.setClientProvider(new KryoClient());
|
||||||
Net.setServerProvider(new KryoServer());
|
Net.setServerProvider(new KryoServer());
|
||||||
|
|
||||||
new HeadlessApplication(new MindustryServer(args));
|
new ServerLauncher(new MindustryServer(args));
|
||||||
|
|
||||||
//find and handle uncaught exceptions in libGDX thread
|
//find and handle uncaught exceptions in libGDX thread
|
||||||
for(Thread thread : Thread.getAllStackTraces().keySet()){
|
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) { }
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user