mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Added secure WebSocket, Bug fixes, code cleanup
This commit is contained in:
@@ -15,7 +15,9 @@ public class CubotDrill extends CpuHardware {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 5;
|
||||
|
||||
private static final int GATHER = 1;
|
||||
private static final int POLL = 1;
|
||||
private static final int GATHER_SLOW = 2;
|
||||
private static final int GATHER_FAST = 3;
|
||||
|
||||
private Cubot cubot;
|
||||
|
||||
@@ -32,7 +34,11 @@ public class CubotDrill extends CpuHardware {
|
||||
public void handleInterrupt(Status status) {
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
|
||||
if (a == GATHER) {
|
||||
if (a == POLL) {
|
||||
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(0);
|
||||
|
||||
} else if (a == GATHER_SLOW || a == GATHER_FAST) {
|
||||
|
||||
if (cubot.getAction() != CubotAction.IDLE) {
|
||||
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
|
||||
@@ -46,19 +52,18 @@ public class CubotDrill extends CpuHardware {
|
||||
cubot.setCurrentAction(CubotAction.DIGGING);
|
||||
|
||||
} else {
|
||||
System.out.println("FAILED: dig");
|
||||
//System.out.println("FAILED: dig");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class CubotInventory extends CpuHardware {
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
*/
|
||||
static final int HWID = 0x0006;
|
||||
static final char HWID = 0x0006;
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 6;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CubotInventory extends CpuHardware {
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CubotLaser extends CpuHardware {
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
*/
|
||||
static final int HWID = 0x0002;
|
||||
static final char HWID = 0x0002;
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 2;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CubotLaser extends CpuHardware {
|
||||
|
||||
if(a == WITHDRAW) {
|
||||
|
||||
System.out.println("withdraw");
|
||||
//System.out.println("withdraw");
|
||||
|
||||
Point frontTile = cubot.getFrontTile();
|
||||
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
||||
@@ -55,19 +55,19 @@ public class CubotLaser extends CpuHardware {
|
||||
if (((InventoryHolder) objects.get(0)).takeItem(b)) {
|
||||
|
||||
cubot.setHeldItem(b);
|
||||
System.out.println("took " + b);
|
||||
//System.out.println("took " + b);
|
||||
cubot.setCurrentAction(CubotAction.WITHDRAWING);
|
||||
|
||||
} else {
|
||||
//The inventory holder can't provide this item
|
||||
//todo Add emote here
|
||||
System.out.println("DEBUG: FAILED: take (The inventory holder can't provide this item)");
|
||||
// System.out.println("DEBUG: FAILED: take (The inventory holder can't provide this item)");
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
//Nothing in front
|
||||
System.out.println("DEBUG: FAILED: take (Nothing in front or Cubot is busy)");
|
||||
// System.out.println("DEBUG: FAILED: take (Nothing in front or Cubot is busy)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CubotLaser extends CpuHardware {
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
*/
|
||||
static final int HWID = 0x0001;
|
||||
static final char HWID = 0x0001;
|
||||
|
||||
private Cubot cubot;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
|
||||
@@ -7,11 +7,12 @@ import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.pathfinding.Node;
|
||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.server.io.JSONSerialisable;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CubotRadar extends CpuHardware implements JSONSerialisable {
|
||||
public class CubotLidar extends CpuHardware implements JSONSerialisable {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -26,7 +27,10 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
|
||||
private static final int GET_PATH = 2;
|
||||
private static final int GET_MAP = 3;
|
||||
|
||||
public CubotRadar(Cubot cubot) {
|
||||
private static final int MEMORY_MAP_START = 0x0100;
|
||||
private static final int MEMORY_PATH_START = 0x0000;
|
||||
|
||||
public CubotLidar(Cubot cubot) {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
@@ -104,13 +108,13 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
|
||||
mem[counter] = -1;
|
||||
}
|
||||
|
||||
System.out.println("DEBUG: path to" + destX + "," + destY);
|
||||
LogManager.LOGGER.fine("DEBUG: path to" + destX + "," + destY);
|
||||
break;
|
||||
|
||||
case GET_MAP:
|
||||
char[][] mapInfo = cubot.getWorld().getMapInfo();
|
||||
|
||||
int i = 0;
|
||||
int i = MEMORY_MAP_START;
|
||||
for (int y = 0; y < World.WORLD_SIZE; y++) {
|
||||
for (int x = 0; x < World.WORLD_SIZE; x++) {
|
||||
getCpu().getMemory().set(i++, mapInfo[x][y]);
|
||||
@@ -125,13 +129,13 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static CubotRadar deserialize(JSONObject hwJSON){
|
||||
return new CubotRadar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int)(long)hwJSON.get("cubot")));
|
||||
public static CubotLidar deserialize(JSONObject hwJSON) {
|
||||
return new CubotLidar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
|
||||
}
|
||||
}
|
||||
@@ -43,12 +43,14 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
|
||||
return CubotLeg.deserialize(hwJson);
|
||||
case CubotLaser.HWID:
|
||||
return CubotLaser.deserialize(hwJson);
|
||||
case CubotRadar.HWID:
|
||||
return CubotRadar.deserialize(hwJson);
|
||||
case CubotLidar.HWID:
|
||||
return CubotLidar.deserialize(hwJson);
|
||||
case CubotDrill.HWID:
|
||||
return CubotDrill.deserialize(hwJson);
|
||||
case CubotInventory.HWID:
|
||||
return CubotInventory.deserialize(hwJson);
|
||||
case Keyboard.HWID:
|
||||
return Keyboard.deserialize(hwJson);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Keyboard extends CpuHardware {
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", HWID);
|
||||
json.put("hwid", (int) HWID);
|
||||
json.put("cubot", cubot.getObjectId());
|
||||
|
||||
return json;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
legHw.setCpu(cpu);
|
||||
CubotLaser laserHw = new CubotLaser((Cubot) user.getControlledUnit());
|
||||
laserHw.setCpu(cpu);
|
||||
CubotRadar radarHw = new CubotRadar((Cubot) user.getControlledUnit());
|
||||
CubotLidar radarHw = new CubotLidar((Cubot) user.getControlledUnit());
|
||||
radarHw.setCpu(cpu);
|
||||
Keyboard keyboard = new Keyboard((Cubot) user.getControlledUnit());
|
||||
keyboard.setCpu(cpu);
|
||||
@@ -36,7 +36,7 @@ public class CpuInitialisationListener implements GameEventListener {
|
||||
|
||||
cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(radarHw, CubotRadar.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(radarHw, CubotLidar.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(keyboard, Keyboard.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(drillHw, CubotDrill.DEFAULT_ADDRESS);
|
||||
cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS);
|
||||
|
||||
@@ -25,7 +25,9 @@ public class UserCreationListener implements GameEventListener {
|
||||
|
||||
Cubot cubot = new Cubot();
|
||||
|
||||
cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(0,0));
|
||||
cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(
|
||||
GameServer.INSTANCE.getConfig().getInt("new_user_worldX"),
|
||||
GameServer.INSTANCE.getConfig().getInt("new_user_worldY")));
|
||||
cubot.getWorld().getGameObjects().add(cubot);
|
||||
|
||||
cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
||||
|
||||
Reference in New Issue
Block a user