diff --git a/Plugin Cubot/src/net/simon987/cubotplugin/CubotLaser.java b/Plugin Cubot/src/net/simon987/cubotplugin/CubotLaser.java index c9f4233..13002c4 100644 --- a/Plugin Cubot/src/net/simon987/cubotplugin/CubotLaser.java +++ b/Plugin Cubot/src/net/simon987/cubotplugin/CubotLaser.java @@ -54,14 +54,14 @@ public class CubotLaser extends CpuHardware { } else { //The inventory holder can't provide this item //todo Add emote here - System.out.println("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 //todo Add emote here - System.out.println("FAILED: take (Nothing in front)"); + System.out.println("DEBUG: FAILED: take (Nothing in front)"); } } diff --git a/Plugin Cubot/src/net/simon987/cubotplugin/CubotPlugin.java b/Plugin Cubot/src/net/simon987/cubotplugin/CubotPlugin.java index 2fea52f..d3a2940 100644 --- a/Plugin Cubot/src/net/simon987/cubotplugin/CubotPlugin.java +++ b/Plugin Cubot/src/net/simon987/cubotplugin/CubotPlugin.java @@ -3,9 +3,9 @@ package net.simon987.cubotplugin; import net.simon987.cubotplugin.event.CpuInitialisationListener; import net.simon987.cubotplugin.event.UserCreationListener; import net.simon987.server.assembly.CpuHardware; -import net.simon987.server.game.CpuHardwareDeserializer; import net.simon987.server.game.GameObject; -import net.simon987.server.game.GameObjectDeserializer; +import net.simon987.server.io.CpuHardwareDeserializer; +import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; import org.json.simple.JSONObject; diff --git a/Plugin Cubot/src/net/simon987/cubotplugin/CubotRadar.java b/Plugin Cubot/src/net/simon987/cubotplugin/CubotRadar.java index 37d8525..bbe810e 100644 --- a/Plugin Cubot/src/net/simon987/cubotplugin/CubotRadar.java +++ b/Plugin Cubot/src/net/simon987/cubotplugin/CubotRadar.java @@ -98,7 +98,7 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable { mem[counter] = -1; } - System.out.println("path to" + destX + "," + destY); + System.out.println("DEBUG: path to" + destX + "," + destY); break; case GET_MAP: diff --git a/Plugin Cubot/src/net/simon987/cubotplugin/event/CpuInitialisationListener.java b/Plugin Cubot/src/net/simon987/cubotplugin/event/CpuInitialisationListener.java index 3483ce4..25024e5 100644 --- a/Plugin Cubot/src/net/simon987/cubotplugin/event/CpuInitialisationListener.java +++ b/Plugin Cubot/src/net/simon987/cubotplugin/event/CpuInitialisationListener.java @@ -5,6 +5,7 @@ import net.simon987.server.assembly.CPU; import net.simon987.server.event.CpuInitialisationEvent; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; +import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; public class CpuInitialisationListener implements GameEventListener { @@ -15,7 +16,7 @@ public class CpuInitialisationListener implements GameEventListener { @Override public void handle(GameEvent event) { - System.out.println("CPU Init"); + LogManager.LOGGER.fine("(Plugin) Handled CPU Initialisation event (Cubot Plugin)"); CPU cpu = (CPU)event.getSource(); User user = ((CpuInitialisationEvent)event).getUser(); diff --git a/Plugin Cubot/src/net/simon987/cubotplugin/event/UserCreationListener.java b/Plugin Cubot/src/net/simon987/cubotplugin/event/UserCreationListener.java index 4a5f5a7..d9f94e7 100644 --- a/Plugin Cubot/src/net/simon987/cubotplugin/event/UserCreationListener.java +++ b/Plugin Cubot/src/net/simon987/cubotplugin/event/UserCreationListener.java @@ -5,6 +5,7 @@ import net.simon987.server.GameServer; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; import net.simon987.server.event.UserCreationEvent; +import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; import java.awt.*; @@ -20,6 +21,7 @@ public class UserCreationListener implements GameEventListener { User user = (User)event.getSource(); + LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)"); Cubot cubot = new Cubot(); @@ -28,6 +30,8 @@ public class UserCreationListener implements GameEventListener { cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); + cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item")); + cubot.setParent(user); Point point = cubot.getWorld().getRandomPassableTile(); diff --git a/Plugin Kiln/src/net/simon987/kilnplugin/KilnPlugin.java b/Plugin Kiln/src/net/simon987/kilnplugin/KilnPlugin.java index 1b66834..438295f 100644 --- a/Plugin Kiln/src/net/simon987/kilnplugin/KilnPlugin.java +++ b/Plugin Kiln/src/net/simon987/kilnplugin/KilnPlugin.java @@ -1,7 +1,7 @@ package net.simon987.kilnplugin; import net.simon987.server.game.GameObject; -import net.simon987.server.game.GameObjectDeserializer; +import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.plugin.ServerPlugin; import org.json.simple.JSONObject; diff --git a/Plugin Plant/src/net/simon987/plantplugin/PlantPlugin.java b/Plugin Plant/src/net/simon987/plantplugin/PlantPlugin.java index d57414e..64c924d 100644 --- a/Plugin Plant/src/net/simon987/plantplugin/PlantPlugin.java +++ b/Plugin Plant/src/net/simon987/plantplugin/PlantPlugin.java @@ -2,7 +2,7 @@ package net.simon987.plantplugin; import net.simon987.plantplugin.event.WorldCreationListener; import net.simon987.server.game.GameObject; -import net.simon987.server.game.GameObjectDeserializer; +import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; import org.json.simple.JSONObject; diff --git a/Server/src/net/simon987/server/Main.java b/Server/src/net/simon987/server/Main.java index 46ab9ce..e651772 100644 --- a/Server/src/net/simon987/server/Main.java +++ b/Server/src/net/simon987/server/Main.java @@ -10,9 +10,50 @@ import java.net.InetSocketAddress; public class Main { public static void main(String[] args){ - //TODO: Copper/Iron/Biomass: on hover only //TODO: Docs - //TODO: + /* + * - Intel 8086 p.14 design + * - Memory: Storage organisation: From a storage pov, 8086 memory spaces are + * organised as identical arrays of 16-bit words + */ + //TODO: Object information Window (Hover, click ?) + //TODO: Website front page + //TODO: Account page + //TODO: Chat (Slack?) + //TODO: Inventory indicator + //TODO: Dig animations + //TODO: Withdraw animation / action + //TODO: HWN, HWQ Instruction + //TODO: Prevent Biomass from blocking Worlds + //TODO: Change code documentation (Check for "Database" etc..) + //TODO: Load and save: handle no save / invalid save + // - Make sure the Hardware is saved and can be loaded + //TODO: Add more logs + //TODO: Clean sprites + + //--------------------------------- + + //TODO: Software Interrupts (PIC): Interupt flag? + /* + * - INT/INTO instruction + * - IRET instruction + */ + //TODO: Clock hardware + //TODO: Floppy drive hardware (and item?) + //TODO: LEA instruction + //TODO: XCHG instruction + //TODO: SAL/SAR instruction + //TODO: ROL/ROR/RCL/RCR instruction + //TODO: LOOP/LOOPE/LOOPX/LOOPNE/LOOPNZ ? + //TODO: World goto (form) + //TODO: Save backup (keep X saves, Zip em) + //TODO: Log backup (keep X backups, Zip em) + //TODO: More tests + //TODO: Handle client disconnects + //TODO: Cache objects requests? + //TODO: Ability to toggle debug stuff + //TODO: Data segment, DB, DW, DD, DQ + LogManager.initialize(); ServerConfiguration config = new ServerConfiguration(new File("config.properties")); diff --git a/Server/src/net/simon987/server/assembly/Assembler.java b/Server/src/net/simon987/server/assembly/Assembler.java index 92c702f..cc5ccfa 100755 --- a/Server/src/net/simon987/server/assembly/Assembler.java +++ b/Server/src/net/simon987/server/assembly/Assembler.java @@ -98,7 +98,7 @@ public class Assembler { line = line.substring(0, line.indexOf(':')); String label = line.trim(); - System.out.println("Label " + label + " @ " + (result.origin + currentOffset)); + System.out.println("DEBUG: Label " + label + " @ " + (result.origin + currentOffset)); result.labels.put(label, (char) (result.origin + currentOffset)); } } diff --git a/Server/src/net/simon987/server/assembly/CpuHardware.java b/Server/src/net/simon987/server/assembly/CpuHardware.java index 92ac165..f1e62cf 100644 --- a/Server/src/net/simon987/server/assembly/CpuHardware.java +++ b/Server/src/net/simon987/server/assembly/CpuHardware.java @@ -2,7 +2,7 @@ package net.simon987.server.assembly; import net.simon987.server.GameServer; -import net.simon987.server.game.CpuHardwareDeserializer; +import net.simon987.server.io.CpuHardwareDeserializer; import net.simon987.server.io.JSONSerialisable; import net.simon987.server.plugin.ServerPlugin; import org.json.simple.JSONObject; diff --git a/Server/src/net/simon987/server/assembly/Instruction.java b/Server/src/net/simon987/server/assembly/Instruction.java index 6d68a48..23e14b8 100755 --- a/Server/src/net/simon987/server/assembly/Instruction.java +++ b/Server/src/net/simon987/server/assembly/Instruction.java @@ -1,6 +1,8 @@ package net.simon987.server.assembly; +import net.simon987.server.assembly.exception.IllegalOperandException; + import java.io.ByteArrayOutputStream; /** diff --git a/Server/src/net/simon987/server/assembly/IllegalOperandException.java b/Server/src/net/simon987/server/assembly/exception/IllegalOperandException.java similarity index 60% rename from Server/src/net/simon987/server/assembly/IllegalOperandException.java rename to Server/src/net/simon987/server/assembly/exception/IllegalOperandException.java index a998823..a6c3dd5 100644 --- a/Server/src/net/simon987/server/assembly/IllegalOperandException.java +++ b/Server/src/net/simon987/server/assembly/exception/IllegalOperandException.java @@ -1,6 +1,5 @@ -package net.simon987.server.assembly; +package net.simon987.server.assembly.exception; -import net.simon987.server.assembly.exception.AssemblyException; public class IllegalOperandException extends AssemblyException { public IllegalOperandException(String msg, int line) { diff --git a/Server/src/net/simon987/server/assembly/instruction/CmpInstruction.java b/Server/src/net/simon987/server/assembly/instruction/CmpInstruction.java index 06ef08b..5eeb138 100644 --- a/Server/src/net/simon987/server/assembly/instruction/CmpInstruction.java +++ b/Server/src/net/simon987/server/assembly/instruction/CmpInstruction.java @@ -34,8 +34,6 @@ public class CmpInstruction extends Instruction { status.setOverflowFlag(Util.checkOverFlowAdd16(a, b)); status.setCarryFlag(Util.checkCarry16(result)); - - // System.out.println(a + " ?= " + b); return status; } diff --git a/Server/src/net/simon987/server/game/GameObject.java b/Server/src/net/simon987/server/game/GameObject.java index d95b4bf..74ea6bc 100755 --- a/Server/src/net/simon987/server/game/GameObject.java +++ b/Server/src/net/simon987/server/game/GameObject.java @@ -1,6 +1,7 @@ package net.simon987.server.game; import net.simon987.server.GameServer; +import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.JSONSerialisable; import net.simon987.server.plugin.ServerPlugin; import org.json.simple.JSONObject; diff --git a/Server/src/net/simon987/server/game/GameUniverse.java b/Server/src/net/simon987/server/game/GameUniverse.java index 941b1ae..9249876 100644 --- a/Server/src/net/simon987/server/game/GameUniverse.java +++ b/Server/src/net/simon987/server/game/GameUniverse.java @@ -231,4 +231,9 @@ public class GameUniverse implements JSONSerialisable{ return null; } + + public void removeUser(User user) { + users.remove(user); + + } } diff --git a/Server/src/net/simon987/server/game/TmpObject.java b/Server/src/net/simon987/server/game/TmpObject.java deleted file mode 100644 index 89089d7..0000000 --- a/Server/src/net/simon987/server/game/TmpObject.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.simon987.server.game; - -import net.simon987.server.GameServer; - -public class TmpObject extends GameObject{ - - public TmpObject(){ - - GameServer.INSTANCE.getGameUniverse(); - - setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(0,0)); - setX(6); - setY(6); - - } - - @Override - public char getMapInfo() { - return 0; - } -} diff --git a/Server/src/net/simon987/server/game/pathfinding/Pathfinder.java b/Server/src/net/simon987/server/game/pathfinding/Pathfinder.java index ad25845..d369796 100755 --- a/Server/src/net/simon987/server/game/pathfinding/Pathfinder.java +++ b/Server/src/net/simon987/server/game/pathfinding/Pathfinder.java @@ -116,7 +116,7 @@ public class Pathfinder { } //Incomplete path - LogManager.LOGGER.info("Incomplete path! " + counter); + LogManager.LOGGER.fine("Incomplete path! " + counter); return null; } diff --git a/Server/src/net/simon987/server/game/CpuHardwareDeserializer.java b/Server/src/net/simon987/server/io/CpuHardwareDeserializer.java similarity index 84% rename from Server/src/net/simon987/server/game/CpuHardwareDeserializer.java rename to Server/src/net/simon987/server/io/CpuHardwareDeserializer.java index d65ba97..fce1067 100644 --- a/Server/src/net/simon987/server/game/CpuHardwareDeserializer.java +++ b/Server/src/net/simon987/server/io/CpuHardwareDeserializer.java @@ -1,4 +1,4 @@ -package net.simon987.server.game; +package net.simon987.server.io; import net.simon987.server.assembly.CpuHardware; import org.json.simple.JSONObject; diff --git a/Server/src/net/simon987/server/game/GameObjectDeserializer.java b/Server/src/net/simon987/server/io/GameObjectDeserializer.java similarity index 64% rename from Server/src/net/simon987/server/game/GameObjectDeserializer.java rename to Server/src/net/simon987/server/io/GameObjectDeserializer.java index 6fb0fb5..46a9efc 100644 --- a/Server/src/net/simon987/server/game/GameObjectDeserializer.java +++ b/Server/src/net/simon987/server/io/GameObjectDeserializer.java @@ -1,5 +1,6 @@ -package net.simon987.server.game; +package net.simon987.server.io; +import net.simon987.server.game.GameObject; import org.json.simple.JSONObject; public interface GameObjectDeserializer { diff --git a/Server/src/net/simon987/server/webserver/ObjectsRequestHandler.java b/Server/src/net/simon987/server/webserver/ObjectsRequestHandler.java index e0dd8e5..8895f4c 100644 --- a/Server/src/net/simon987/server/webserver/ObjectsRequestHandler.java +++ b/Server/src/net/simon987/server/webserver/ObjectsRequestHandler.java @@ -12,52 +12,40 @@ import java.util.ArrayList; public class ObjectsRequestHandler implements MessageHandler { - private String cachedResponse; - private long timeCached; @Override public void handle(OnlineUser user, JSONObject json) { if (json.get("t").equals("object")) { LogManager.LOGGER.info("(WS) Objects request from " + user.getUser().getUsername()); - if (timeCached == GameServer.INSTANCE.getGameUniverse().getTime()) { + + if (json.containsKey("x") && json.containsKey("y")) { + int x = Long.valueOf((long) json.get("x")).intValue(); + int y = Long.valueOf((long) json.get("y")).intValue(); + + ArrayList gameObjects = GameServer.INSTANCE.getGameUniverse().getWorld(x, y).getGameObjects(); + + JSONObject response = new JSONObject(); + JSONArray objects = new JSONArray(); + + + for (GameObject object : gameObjects) { + + if (object instanceof JSONSerialisable) { + objects.add(object.serialise()); + } + + } + + response.put("t", "object"); + response.put("objects", objects); + if (user.getWebSocket().isOpen()) { - user.getWebSocket().send(cachedResponse); + user.getWebSocket().send(response.toJSONString()); } - } else { - - if (json.containsKey("x") && json.containsKey("y")) { - int x = Long.valueOf((long) json.get("x")).intValue(); - int y = Long.valueOf((long) json.get("y")).intValue(); - - ArrayList gameObjects = GameServer.INSTANCE.getGameUniverse().getWorld(x, y).getGameObjects(); - - JSONObject response = new JSONObject(); - JSONArray objects = new JSONArray(); - - - for (GameObject object : gameObjects) { - - if (object instanceof JSONSerialisable) { - objects.add(object.serialise()); - } - - } - - response.put("t", "object"); - response.put("objects", objects); - - cachedResponse = response.toJSONString(); - timeCached = GameServer.INSTANCE.getGameUniverse().getTime(); - - if (user.getWebSocket().isOpen()) { - user.getWebSocket().send(cachedResponse); - } - } else { - LogManager.LOGGER.info("(WS) Malformed Objects request from " + user.getUser().getUsername()); - } + LogManager.LOGGER.info("(WS) Malformed Objects request from " + user.getUser().getUsername()); } } } diff --git a/Server/src/net/simon987/server/webserver/OnlineUserManager.java b/Server/src/net/simon987/server/webserver/OnlineUserManager.java index c58f8c6..d04e737 100644 --- a/Server/src/net/simon987/server/webserver/OnlineUserManager.java +++ b/Server/src/net/simon987/server/webserver/OnlineUserManager.java @@ -1,5 +1,6 @@ package net.simon987.server.webserver; +import net.simon987.server.GameServer; import org.java_websocket.WebSocket; import java.util.ArrayList; @@ -41,6 +42,7 @@ public class OnlineUserManager { */ public void remove(OnlineUser user) { onlineUsers.remove(user); + GameServer.INSTANCE.getGameUniverse().removeUser(user.getUser()); } public ArrayList getOnlineUsers() {