mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-04 06:22:58 +00:00
Fixed typos & cleaned comments. Added autologin debug option. Added construction site base
This commit is contained in:
parent
ae41bd9cb9
commit
71e88afdc9
@ -569,7 +569,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
public int hardwareQuery(int address) {
|
||||
HardwareModule hardware = hardwareAddresses.get(address);
|
||||
|
||||
|
||||
if (hardware != null) {
|
||||
return hardware.getId();
|
||||
} else {
|
||||
|
@ -21,4 +21,6 @@ public class TileVaultWall extends Tile {
|
||||
public boolean isBlocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -286,14 +286,14 @@ public class Assembler {
|
||||
|
||||
if (tokens[0].toUpperCase().equals(".TEXT")) {
|
||||
|
||||
result.defineSecton(Section.TEXT, currentLine, currentOffset);
|
||||
result.defineSection(Section.TEXT, currentLine, currentOffset);
|
||||
throw new PseudoInstructionException(currentLine);
|
||||
|
||||
} else if (tokens[0].toUpperCase().equals(".DATA")) {
|
||||
|
||||
LogManager.LOGGER.fine("DEBUG: .data @" + currentLine);
|
||||
|
||||
result.defineSecton(Section.DATA, currentLine, currentOffset);
|
||||
result.defineSection(Section.DATA, currentLine, currentOffset);
|
||||
throw new PseudoInstructionException(currentLine);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class AssemblyResult {
|
||||
* @param currentLine Line number of the section declaration
|
||||
* @throws DuplicateSectionException when a section is defined twice
|
||||
*/
|
||||
void defineSecton(Section section, int currentLine, int currentOffset) throws DuplicateSectionException {
|
||||
void defineSection(Section section, int currentLine, int currentOffset) throws DuplicateSectionException {
|
||||
|
||||
if (section == Section.TEXT) {
|
||||
//Code section
|
||||
|
@ -55,9 +55,6 @@ public class CPU implements MongoSerializable {
|
||||
*/
|
||||
private HardwareHost hardwareHost;
|
||||
|
||||
|
||||
private ServerConfiguration config;
|
||||
|
||||
private int registerSetSize;
|
||||
|
||||
private static final char EXECUTION_COST_ADDR = 0x0050;
|
||||
@ -67,7 +64,6 @@ public class CPU implements MongoSerializable {
|
||||
* Creates a new CPU
|
||||
*/
|
||||
public CPU(ServerConfiguration config, ControllableUnit unit) throws CancelledException {
|
||||
this.config = config;
|
||||
instructionSet = new DefaultInstructionSet();
|
||||
registerSet = new DefaultRegisterSet();
|
||||
codeSectionOffset = config.getInt("org_offset");
|
||||
|
@ -2,13 +2,13 @@ package net.simon987.server.assembly;
|
||||
|
||||
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.io.JSONSerialisable;
|
||||
import net.simon987.server.io.JSONSerializable;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
|
||||
public abstract class HardwareModule implements MongoSerializable, JSONSerialisable {
|
||||
public abstract class HardwareModule implements MongoSerializable, JSONSerializable {
|
||||
|
||||
private CPU cpu;
|
||||
|
||||
|
@ -203,8 +203,6 @@ public abstract class Instruction {
|
||||
|
||||
//Destination bits are left blank
|
||||
|
||||
//System.out.println("o1: " + o1.getType());
|
||||
|
||||
for (byte b : code.bytes()) {
|
||||
out.write(b);
|
||||
}
|
||||
|
@ -84,11 +84,9 @@ class MachineCode {
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
out.write(value >> 8);
|
||||
out.write(value);
|
||||
|
||||
|
||||
for (Character s : additionalWords) {
|
||||
out.write(s >> 8);
|
||||
out.write(s);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.simon987.server.assembly.exception;
|
||||
|
||||
/**
|
||||
* Class of exceptions that should stop assembly immediatly
|
||||
* Class of exceptions that should stop assembly immediately
|
||||
*/
|
||||
public class FatalAssemblyException extends AssemblyException {
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class OffsetOverflowException extends FatalAssemblyException {
|
||||
/**
|
||||
* Create a new Offset Overflow Exception
|
||||
*/
|
||||
public OffsetOverflowException(int offset, int memsiz, int line) {
|
||||
super(message + offset + " > " + memsiz, line);
|
||||
public OffsetOverflowException(int offset, int memSize, int line) {
|
||||
super(message + offset + " > " + memSize, line);
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,6 @@ import net.simon987.server.assembly.Util;
|
||||
*/
|
||||
public class AddInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 2;
|
||||
|
||||
public AddInstruction() {
|
||||
|
@ -13,9 +13,6 @@ import net.simon987.server.assembly.Target;
|
||||
*/
|
||||
public class CallInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 21;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -8,7 +8,6 @@ import net.simon987.server.assembly.Target;
|
||||
/**
|
||||
* Send hardware interrupt
|
||||
* <br>Used to interact with the World using hardware
|
||||
*
|
||||
*/
|
||||
public class HwiInstruction extends Instruction {
|
||||
|
||||
|
@ -1,32 +1,32 @@
|
||||
package net.simon987.server.assembly.instruction;
|
||||
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.*;
|
||||
|
||||
public class HwqInstruction extends Instruction {
|
||||
|
||||
private static final int OPCODE = 28;
|
||||
|
||||
private CPU cpu;
|
||||
private Register b;
|
||||
|
||||
public HwqInstruction(CPU cpu) {
|
||||
super("hwq", OPCODE);
|
||||
this.cpu = cpu;
|
||||
this.b = cpu.getRegisterSet().getRegister("B");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status execute(Target src, int srcIndex, Status status) {
|
||||
cpu.getHardwareHost().hardwareQuery(src.get(srcIndex));
|
||||
b.setValue(cpu.getHardwareHost().hardwareQuery(src.get(srcIndex)));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status execute(int src, Status status) {
|
||||
cpu.getHardwareHost().hardwareQuery(src);
|
||||
b.setValue(cpu.getHardwareHost().hardwareQuery(src));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JgInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 15;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -10,9 +10,6 @@ import net.simon987.server.assembly.Target;
|
||||
*/
|
||||
public class JgeInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 16;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JlInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 17;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JleInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 18;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JmpInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 10;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -7,9 +7,6 @@ import net.simon987.server.assembly.Target;
|
||||
|
||||
public class JnsInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 27;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JnzInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 13;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -7,9 +7,6 @@ import net.simon987.server.assembly.Target;
|
||||
|
||||
public class JsInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 26;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -5,9 +5,6 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/11/2017.
|
||||
*/
|
||||
public class JzInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
|
@ -20,9 +20,6 @@ import net.simon987.server.assembly.Target;
|
||||
*/
|
||||
public class MovInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 1;
|
||||
|
||||
public MovInstruction() {
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
public class OrInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 5;
|
||||
|
||||
public OrInstruction() {
|
||||
|
@ -10,9 +10,6 @@ import net.simon987.server.assembly.Target;
|
||||
*/
|
||||
public class PopInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 20;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -10,9 +10,6 @@ import net.simon987.server.assembly.Status;
|
||||
*/
|
||||
public class PopfInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 44;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -2,14 +2,8 @@ package net.simon987.server.assembly.instruction;
|
||||
|
||||
import net.simon987.server.assembly.*;
|
||||
|
||||
/**
|
||||
* Created by simon on 02/06/17.
|
||||
*/
|
||||
public class PushInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 19;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -10,9 +10,6 @@ import net.simon987.server.assembly.Status;
|
||||
*/
|
||||
public class PushfInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 45;
|
||||
|
||||
private CPU cpu;
|
||||
|
@ -4,9 +4,6 @@ import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
|
||||
/**
|
||||
* Created by simon on 02/06/17.
|
||||
*/
|
||||
public class RetInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
|
@ -4,9 +4,6 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SarInstruction extends Instruction {
|
||||
|
||||
private static final int OPCODE = 41;
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
public class ShlInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 6;
|
||||
|
||||
public ShlInstruction() {
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
public class ShrInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 7;
|
||||
|
||||
public ShrInstruction() {
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
public class SubInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 3;
|
||||
|
||||
public SubInstruction() {
|
||||
|
@ -5,14 +5,8 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
public class TestInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 11;
|
||||
|
||||
public TestInstruction() {
|
||||
|
@ -2,12 +2,12 @@ package net.simon987.server.crypto;
|
||||
|
||||
interface Cypher {
|
||||
|
||||
public char[] encrypt(char[] plainText, char[] key) throws CryptoException;
|
||||
char[] encrypt(char[] plainText, char[] key) throws CryptoException;
|
||||
|
||||
public char[] decrypt(char[] cypherText, char[] key) throws CryptoException;
|
||||
char[] decrypt(char[] cypherText, char[] key) throws CryptoException;
|
||||
|
||||
public String textCharset();
|
||||
|
||||
public String keyCharset();
|
||||
String textCharset();
|
||||
|
||||
String keyCharset();
|
||||
|
||||
}
|
@ -36,7 +36,7 @@ public class NoCypher implements Cypher {
|
||||
char c = cypherText[i];
|
||||
int c_ind = charset.indexOf(c);
|
||||
if (c_ind == -1){
|
||||
throw new InvalidCharsetException("Cyphertext contains invalid character: " + c);
|
||||
throw new InvalidCharsetException("CypherText contains invalid character: " + c);
|
||||
}
|
||||
plaintext[i] = c;
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* Based on the RandomString class by erickson:
|
||||
* https://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string
|
||||
*
|
||||
*/
|
||||
|
||||
package net.simon987.server.crypto;
|
||||
|
||||
@ -12,6 +6,10 @@ import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Based on the RandomString class by erickson:
|
||||
* https://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string
|
||||
*/
|
||||
public class RandomStringGenerator {
|
||||
|
||||
/**
|
||||
@ -23,9 +21,9 @@ public class RandomStringGenerator {
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
static final String UPPER_ALPHA_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
static final String LOWER_ALPHA_CHARSET = UPPER_ALPHA_CHARSET.toLowerCase(Locale.ROOT);
|
||||
static final String NUMERIC_CHARSET = "0123456789";
|
||||
private static final String UPPER_ALPHA_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String LOWER_ALPHA_CHARSET = UPPER_ALPHA_CHARSET.toLowerCase(Locale.ROOT);
|
||||
private static final String NUMERIC_CHARSET = "0123456789";
|
||||
static final String ALPHANUMERIC_CHARSET = UPPER_ALPHA_CHARSET + LOWER_ALPHA_CHARSET + NUMERIC_CHARSET;
|
||||
|
||||
private final Random random;
|
||||
|
@ -82,6 +82,7 @@ public class GameUniverse {
|
||||
*
|
||||
* @return World, null if not found and not created.
|
||||
*/
|
||||
@SuppressWarnings("SuspiciousNameCombination")
|
||||
public World getWorld(int x, int y, boolean createNew, String dimension) {
|
||||
|
||||
// Wrapping coordinates around cyclically
|
||||
@ -252,12 +253,12 @@ public class GameUniverse {
|
||||
int i = 1;
|
||||
|
||||
while (i < 50000) {
|
||||
if (getUser("guest" + String.valueOf(i)) != null) {
|
||||
if (getUser("guest" + i) != null) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return "guest" + String.valueOf(i);
|
||||
return "guest" + i;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.simon987.server.game.item;
|
||||
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.io.JSONSerialisable;
|
||||
import net.simon987.server.io.JSONSerializable;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public abstract class Item implements JSONSerialisable, MongoSerializable {
|
||||
public abstract class Item implements JSONSerializable, MongoSerializable {
|
||||
|
||||
|
||||
public Item(Document document) {
|
||||
|
@ -79,9 +79,9 @@ public enum Direction {
|
||||
return Direction.EAST;
|
||||
} else if (dx < 0 && dx <= dy) {
|
||||
return Direction.WEST;
|
||||
} else if (dy > 0 && dy >= dx) {
|
||||
} else if (dy > 0) {
|
||||
return Direction.NORTH;
|
||||
} else if (dy < 0 && dy <= dx) {
|
||||
} else if (dy < 0) {
|
||||
return Direction.SOUTH;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -2,7 +2,7 @@ package net.simon987.server.game.objects;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.io.JSONSerialisable;
|
||||
import net.simon987.server.io.JSONSerializable;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
@ -15,7 +15,7 @@ import java.util.ArrayList;
|
||||
* An instance of an object (e.g. a Cubot, a NPC...) inside the
|
||||
* game universe
|
||||
*/
|
||||
public abstract class GameObject implements JSONSerialisable, MongoSerializable {
|
||||
public abstract class GameObject implements JSONSerializable, MongoSerializable {
|
||||
|
||||
private boolean dead;
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ public abstract class Structure extends GameObject {
|
||||
private int width;
|
||||
|
||||
/**
|
||||
* Lenght of the structure in tiles for the y axis
|
||||
* Length of the structure in tiles for the y axis
|
||||
*/
|
||||
private int height;
|
||||
|
||||
|
@ -54,13 +54,7 @@ public class Node implements Comparable {
|
||||
public int compareTo(Object o) {
|
||||
Node other = (Node) o;
|
||||
|
||||
if (fScore < other.fScore) {
|
||||
return -1;
|
||||
} else if (fScore > other.fScore) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Integer.compare(fScore, other.fScore);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,10 +12,6 @@ import java.util.Collections;
|
||||
*/
|
||||
public class Pathfinder {
|
||||
|
||||
|
||||
/**
|
||||
* Create a pathfinder
|
||||
*/
|
||||
public Pathfinder() {
|
||||
|
||||
}
|
||||
@ -113,9 +109,7 @@ public class Pathfinder {
|
||||
}
|
||||
|
||||
//Incomplete path
|
||||
// LogManager.LOGGER.fine("Incomplete path! " + counter);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,5 +146,4 @@ public class Pathfinder {
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package net.simon987.server.game.world;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.io.JSONSerialisable;
|
||||
import net.simon987.server.io.JSONSerializable;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONArray;
|
||||
@ -16,7 +16,7 @@ import java.util.Random;
|
||||
/**
|
||||
* A 2D map of Tile objects of size width*height
|
||||
*/
|
||||
public class TileMap implements JSONSerialisable, MongoSerializable {
|
||||
public class TileMap implements JSONSerializable, MongoSerializable {
|
||||
|
||||
/**
|
||||
* The map of tile
|
||||
|
@ -2,7 +2,7 @@ package net.simon987.server.io;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public interface JSONSerialisable {
|
||||
public interface JSONSerializable {
|
||||
|
||||
JSONObject jsonSerialise();
|
||||
|
@ -38,12 +38,7 @@ public class LogManager {
|
||||
flush();
|
||||
}
|
||||
};
|
||||
handler.setFilter(new Filter() {
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
return record.getLevel().intValue() <= Level.INFO.intValue();
|
||||
}
|
||||
});
|
||||
handler.setFilter(record -> record.getLevel().intValue() <= Level.INFO.intValue());
|
||||
handler.setLevel(Level.ALL);
|
||||
|
||||
try {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.simon987.server.user;
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.exception.CancelledException;
|
||||
import net.simon987.server.crypto.RandomStringGenerator;
|
||||
@ -29,10 +28,9 @@ public class UserManager {
|
||||
|
||||
ArrayList<User> userList = new ArrayList<>();
|
||||
|
||||
MongoCursor<Document> cursor = userCollection.find().iterator();
|
||||
while (cursor.hasNext()) {
|
||||
for (Document document : userCollection.find()) {
|
||||
try {
|
||||
userList.add(User.deserialize(cursor.next()));
|
||||
userList.add(User.deserialize(document));
|
||||
} catch (CancelledException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -143,7 +141,7 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Validate an access token sent by the client
|
||||
* @param token 128-char accesss token
|
||||
* @param token 128-char access token
|
||||
* @return username of the corresponding user, null if not found
|
||||
*/
|
||||
public User validateAuthToken(String token) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.simon987.server.user;
|
||||
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import net.simon987.server.GameServer;
|
||||
import org.bson.Document;
|
||||
|
||||
@ -36,10 +35,8 @@ public class UserStatsHelper {
|
||||
ArrayList<Map.Entry<User, Integer>> rows = new ArrayList<>();
|
||||
|
||||
Document orderBy = new Document("$stats." + statName, -1);
|
||||
MongoCursor<Document> cursor = users.find().sort(orderBy).limit(n).iterator();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
Document dbUser = cursor.next();
|
||||
for (Document dbUser : users.find().sort(orderBy).limit(n)) {
|
||||
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username"));
|
||||
rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getInt(statName)));
|
||||
}
|
||||
@ -66,15 +63,12 @@ public class UserStatsHelper {
|
||||
project.put("setLength", new Document("$size", new Document("$ifNull", ifNullList)));
|
||||
project.put("username", 1);
|
||||
|
||||
|
||||
Iterator<Document> results = users.aggregate(Arrays.asList(
|
||||
for (Document document : users.aggregate(Arrays.asList(
|
||||
new Document("$project", project),
|
||||
new Document("$sort", new Document("setLength", -1)),
|
||||
new Document("$limit", n))
|
||||
).iterator();
|
||||
|
||||
while (results.hasNext()) {
|
||||
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) results.next().get("username"));
|
||||
)) {
|
||||
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) document.get("username"));
|
||||
rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getSet(statName)));
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,14 @@ public class PlayPage implements TemplateViewRoute {
|
||||
|
||||
@Override
|
||||
public ModelAndView handle(Request request, Response response) {
|
||||
|
||||
String autoLogin = GameServer.INSTANCE.getConfig().getString("autologin");
|
||||
if (!autoLogin.equals("")) {
|
||||
AlertMessage[] messages = {new AlertMessage("Logged in as " + autoLogin, AlertType.SUCCESS)};
|
||||
request.session().attribute("messages", messages);
|
||||
request.session().attribute("username", autoLogin);
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<>(1);
|
||||
model.put("session", request.session());
|
||||
model.put("gamePageTitle", GameServer.INSTANCE.getConfig().getString("server_name"));
|
||||
|
@ -17,10 +17,7 @@ public class CodeUploadHandler implements MessageHandler {
|
||||
|
||||
LogManager.LOGGER.fine("(WS) Code upload from " + user.getUser().getUsername());
|
||||
|
||||
if (user.getUser().isGuest()) {
|
||||
//Ignore
|
||||
|
||||
} else {
|
||||
if (!user.getUser().isGuest()) {
|
||||
//TODO Should we wait at the end of the tick to modify the CPU ?
|
||||
user.getUser().setUserCode((String) json.get("code"));
|
||||
|
||||
|
@ -88,3 +88,5 @@ radioactive_obstacle_corruption_block_size=10
|
||||
|
||||
#SecretKey
|
||||
secret_key=<your_secret_key>
|
||||
# Construction
|
||||
construction_site_ttl=512
|
||||
|
@ -49,18 +49,6 @@
|
||||
|
||||
<hr>
|
||||
|
||||
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
|
||||
<div class="card-body">
|
||||
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
|
||||
3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt
|
||||
laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin
|
||||
coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes
|
||||
anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings
|
||||
occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard
|
||||
of them accusamus labore sustainable VHS.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<a class="btn btn-primary" role=button data-toggle="collapse" data-target="#debugInfo"
|
||||
aria-expanded="false" aria-controls="debugInfo">Debug information</a>
|
||||
|
@ -0,0 +1,49 @@
|
||||
package net.simon987.constructionplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.InventoryHolder;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
|
||||
public class ConstructionSite extends GameObject implements Updatable, InventoryHolder {
|
||||
|
||||
public static final int MAP_INFO = 0xFFFF; //TODO: determine
|
||||
public static final int LIFETIME = GameServer.INSTANCE.getConfig().getInt("construction_site_ttl");
|
||||
|
||||
private int age;
|
||||
|
||||
@Override
|
||||
public char getMapInfo() {
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
age += 1;
|
||||
|
||||
if (age > LIFETIME) {
|
||||
setDead(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeItem(Item item) {
|
||||
|
||||
//todo: add mats here
|
||||
//todo: inv digitize
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeItem(int itemId) {
|
||||
//NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeItem(int itemId) {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user