Moved over Streamable inner classes, added test map

This commit is contained in:
Anuken 2018-06-14 17:11:38 -04:00
parent 1436e78305
commit fab3704dbd
13 changed files with 99 additions and 66 deletions

View file

@ -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"

Binary file not shown.

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<? 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);
}
}
}

View file

@ -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 = {

View file

@ -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<? 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 final int id;
public final Class<? extends Streamable> type;

View file

@ -114,7 +114,6 @@ public class WorldGenerator {
}
}
}
}
static class OreEntry{

View file

@ -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;

View file

@ -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;

View file

@ -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) {

View file

@ -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) { }
});
}
}