├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── Plugin Cubot ├── Plugin Cubot.iml ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── net │ │ │ └── simon987 │ │ │ └── cubotplugin │ │ │ ├── Cubot.java │ │ │ ├── CubotBattery.java │ │ │ ├── CubotComPort.java │ │ │ ├── CubotCore.java │ │ │ ├── CubotDrill.java │ │ │ ├── CubotFloppyDrive.java │ │ │ ├── CubotHardwareModule.java │ │ │ ├── CubotHologram.java │ │ │ ├── CubotInventory.java │ │ │ ├── CubotKeyboard.java │ │ │ ├── CubotLaser.java │ │ │ ├── CubotLeg.java │ │ │ ├── CubotLidar.java │ │ │ ├── CubotPlugin.java │ │ │ ├── CubotShield.java │ │ │ ├── CubotStatus.java │ │ │ ├── FloppyDisk.java │ │ │ └── event │ │ │ ├── ChargeShieldCommandListener.java │ │ │ ├── CpuInitialisationListener.java │ │ │ ├── CubotWalkEvent.java │ │ │ ├── DeathEvent.java │ │ │ ├── DeathListener.java │ │ │ ├── PopItemCommandListener.java │ │ │ ├── PutItemCommandListener.java │ │ │ ├── SetInventoryPosition.java │ │ │ ├── UserCreationListener.java │ │ │ └── WalkListener.java │ │ └── resources │ │ └── plugin.properties └── test │ └── net │ └── simon987 │ └── cubotplugin │ └── CubotTest.java ├── Plugin Misc HW ├── Plugin Misc HW.iml ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── simon987 │ │ └── mischwplugin │ │ ├── Clock.java │ │ ├── MiscHWPlugin.java │ │ ├── RandomNumberGenerator.java │ │ └── event │ │ └── CpuInitialisationListener.java │ └── resources │ └── plugin.properties ├── Plugin NPC ├── Plugin NPC.iml ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── simon987 │ │ └── npcplugin │ │ ├── ElectricBox.java │ │ ├── ExecuteCpuTask.java │ │ ├── Factory.java │ │ ├── HackedNPC.java │ │ ├── HarvestTask.java │ │ ├── HarvesterNPC.java │ │ ├── NPCTask.java │ │ ├── NonPlayerCharacter.java │ │ ├── NpcBattery.java │ │ ├── NpcInventory.java │ │ ├── NpcPlugin.java │ │ ├── Obstacle.java │ │ ├── Portal.java │ │ ├── RadioReceiverHardware.java │ │ ├── RadioTower.java │ │ ├── Settlement.java │ │ ├── VaultDimension.java │ │ ├── VaultDoor.java │ │ ├── VaultExitPortal.java │ │ ├── VaultWorldGenerator.java │ │ ├── VaultWorldUtils.java │ │ ├── event │ │ ├── CpuInitialisationListener.java │ │ ├── VaultCompleteEvent.java │ │ ├── VaultCompleteListener.java │ │ ├── VaultWorldUpdateListener.java │ │ └── WorldCreationListener.java │ │ └── world │ │ ├── TileVaultFloor.java │ │ └── TileVaultWall.java │ └── resources │ ├── defaultHackedCubotHardware.json │ └── plugin.properties ├── Plugin Plant ├── Plugin Plant.iml ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── simon987 │ │ └── biomassplugin │ │ ├── BiomassBlob.java │ │ ├── BiomassPlugin.java │ │ ├── ItemBiomass.java │ │ ├── WorldUtils.java │ │ └── event │ │ ├── ObjectDeathListener.java │ │ ├── WorldCreationListener.java │ │ └── WorldUpdateListener.java │ └── resources │ └── plugin.properties ├── Plugin Radioactive Cloud ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── simon987 │ │ └── pluginradioactivecloud │ │ ├── RadioactiveCloud.java │ │ ├── RadioactiveCloudPlugin.java │ │ └── RadioactiveObstacle.java │ └── resources │ └── plugin.properties ├── README.md ├── Server ├── pom.xml └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── simon987 │ │ │ └── server │ │ │ ├── GameServer.java │ │ │ ├── IServerConfiguration.java │ │ │ ├── Main.java │ │ │ ├── ServerConfiguration.java │ │ │ ├── assembly │ │ │ ├── Assembler.java │ │ │ ├── AssemblyResult.java │ │ │ ├── CPU.java │ │ │ ├── DefaultInstructionSet.java │ │ │ ├── DefaultRegisterSet.java │ │ │ ├── HardwareModule.java │ │ │ ├── Instruction.java │ │ │ ├── InstructionSet.java │ │ │ ├── MachineCode.java │ │ │ ├── Memory.java │ │ │ ├── Operand.java │ │ │ ├── OperandType.java │ │ │ ├── Register.java │ │ │ ├── RegisterSet.java │ │ │ ├── Section.java │ │ │ ├── Status.java │ │ │ ├── Target.java │ │ │ ├── Util.java │ │ │ ├── exception │ │ │ │ ├── AssemblyException.java │ │ │ │ ├── CancelledException.java │ │ │ │ ├── DuplicateSectionException.java │ │ │ │ ├── EmptyLineException.java │ │ │ │ ├── FatalAssemblyException.java │ │ │ │ ├── IllegalOperandException.java │ │ │ │ ├── InvalidMnemonicException.java │ │ │ │ ├── InvalidOperandException.java │ │ │ │ ├── OffsetOverflowException.java │ │ │ │ └── PseudoInstructionException.java │ │ │ └── instruction │ │ │ │ ├── AddInstruction.java │ │ │ │ ├── AndInstruction.java │ │ │ │ ├── BrkInstruction.java │ │ │ │ ├── CallInstruction.java │ │ │ │ ├── CmpInstruction.java │ │ │ │ ├── DecInstruction.java │ │ │ │ ├── DivInstruction.java │ │ │ │ ├── HwiInstruction.java │ │ │ │ ├── HwqInstruction.java │ │ │ │ ├── IncInstruction.java │ │ │ │ ├── JaInstruction.java │ │ │ │ ├── JcInstruction.java │ │ │ │ ├── JgInstruction.java │ │ │ │ ├── JgeInstruction.java │ │ │ │ ├── JlInstruction.java │ │ │ │ ├── JleInstruction.java │ │ │ │ ├── JmpInstruction.java │ │ │ │ ├── JnaInstruction.java │ │ │ │ ├── JncInstruction.java │ │ │ │ ├── JnoInstruction.java │ │ │ │ ├── JnsInstruction.java │ │ │ │ ├── JnzInstruction.java │ │ │ │ ├── JoInstruction.java │ │ │ │ ├── JsInstruction.java │ │ │ │ ├── JzInstruction.java │ │ │ │ ├── LeaInstruction.java │ │ │ │ ├── MovInstruction.java │ │ │ │ ├── MulInstruction.java │ │ │ │ ├── NegInstruction.java │ │ │ │ ├── NopInstruction.java │ │ │ │ ├── NotInstruction.java │ │ │ │ ├── OrInstruction.java │ │ │ │ ├── PopInstruction.java │ │ │ │ ├── PopfInstruction.java │ │ │ │ ├── PushInstruction.java │ │ │ │ ├── PushfInstruction.java │ │ │ │ ├── RclInstruction.java │ │ │ │ ├── RcrInstruction.java │ │ │ │ ├── RetInstruction.java │ │ │ │ ├── RolInstruction.java │ │ │ │ ├── RorInstruction.java │ │ │ │ ├── SalInstruction.java │ │ │ │ ├── SarInstruction.java │ │ │ │ ├── SetaInstruction.java │ │ │ │ ├── SetaeInstruction.java │ │ │ │ ├── SetbInstruction.java │ │ │ │ ├── SetbeInstruction.java │ │ │ │ ├── SetcInstruction.java │ │ │ │ ├── SetccInstruction.java │ │ │ │ ├── SeteInstruction.java │ │ │ │ ├── SetgInstruction.java │ │ │ │ ├── SetgeInstruction.java │ │ │ │ ├── SetlInstruction.java │ │ │ │ ├── SetleInstruction.java │ │ │ │ ├── SetnaInstruction.java │ │ │ │ ├── SetnaeInstruction.java │ │ │ │ ├── SetnbInstruction.java │ │ │ │ ├── SetnbeInstruction.java │ │ │ │ ├── SetncInstruction.java │ │ │ │ ├── SetneInstruction.java │ │ │ │ ├── SetngInstruction.java │ │ │ │ ├── SetngeInstruction.java │ │ │ │ ├── SetnlInstruction.java │ │ │ │ ├── SetnleInstruction.java │ │ │ │ ├── SetnoInstruction.java │ │ │ │ ├── SetnsInstruction.java │ │ │ │ ├── SetnzInstruction.java │ │ │ │ ├── SetoInstruction.java │ │ │ │ ├── SetsInstruction.java │ │ │ │ ├── SetzInstruction.java │ │ │ │ ├── ShlInstruction.java │ │ │ │ ├── ShrInstruction.java │ │ │ │ ├── SubInstruction.java │ │ │ │ ├── TestInstruction.java │ │ │ │ ├── XchgInstruction.java │ │ │ │ └── XorInstruction.java │ │ │ ├── crypto │ │ │ ├── AutokeyCypher.java │ │ │ ├── CaesarCypher.java │ │ │ ├── CryptoException.java │ │ │ ├── CryptoProvider.java │ │ │ ├── Cypher.java │ │ │ ├── InvalidCharsetException.java │ │ │ ├── InvalidKeyException.java │ │ │ ├── NoCypher.java │ │ │ ├── RandomStringGenerator.java │ │ │ ├── SecretKeyGenerator.java │ │ │ ├── ShiftSubstitutionCypher.java │ │ │ └── VigenereCypher.java │ │ │ ├── event │ │ │ ├── CpuInitialisationEvent.java │ │ │ ├── DebugCommandEvent.java │ │ │ ├── GameEvent.java │ │ │ ├── GameEventDispatcher.java │ │ │ ├── GameEventListener.java │ │ │ ├── ObjectDeathEvent.java │ │ │ ├── TickEvent.java │ │ │ ├── UserCreationEvent.java │ │ │ ├── WorldGenerationEvent.java │ │ │ └── WorldUpdateEvent.java │ │ │ ├── game │ │ │ ├── GameUniverse.java │ │ │ ├── debug │ │ │ │ ├── ComPortMsgCommandListener.java │ │ │ │ ├── CreateWorldCommandListener.java │ │ │ │ ├── DamageObjCommandListener.java │ │ │ │ ├── HealObjCommandListener.java │ │ │ │ ├── KillAllCommandListener.java │ │ │ │ ├── MoveObjCommandListener.java │ │ │ │ ├── ObjInfoCommandListener.java │ │ │ │ ├── SaveGameCommandListener.java │ │ │ │ ├── SetEnergyCommandListener.java │ │ │ │ ├── SetTileAtCommandListener.java │ │ │ │ ├── SpawnObjCommandListener.java │ │ │ │ ├── TpObjectCommandListener.java │ │ │ │ └── UserInfoCommandListener.java │ │ │ ├── item │ │ │ │ ├── Item.java │ │ │ │ ├── ItemCopper.java │ │ │ │ ├── ItemIron.java │ │ │ │ └── ItemVoid.java │ │ │ ├── objects │ │ │ │ ├── Action.java │ │ │ │ ├── Attackable.java │ │ │ │ ├── ControllableUnit.java │ │ │ │ ├── Direction.java │ │ │ │ ├── Enterable.java │ │ │ │ ├── GameObject.java │ │ │ │ ├── GameRegistry.java │ │ │ │ ├── HardwareHost.java │ │ │ │ ├── InventoryHolder.java │ │ │ │ ├── ItemsContainer.java │ │ │ │ ├── MessageReceiver.java │ │ │ │ ├── Radioactive.java │ │ │ │ ├── Rechargeable.java │ │ │ │ ├── Structure.java │ │ │ │ └── Updatable.java │ │ │ ├── pathfinding │ │ │ │ ├── Node.java │ │ │ │ ├── Pathfinder.java │ │ │ │ └── SortedArrayList.java │ │ │ └── world │ │ │ │ ├── DayNightCycle.java │ │ │ │ ├── Location.java │ │ │ │ ├── Tile.java │ │ │ │ ├── TileCopper.java │ │ │ │ ├── TileFluid.java │ │ │ │ ├── TileIron.java │ │ │ │ ├── TileMap.java │ │ │ │ ├── TilePlain.java │ │ │ │ ├── TileVoid.java │ │ │ │ ├── TileWall.java │ │ │ │ ├── World.java │ │ │ │ ├── WorldGenerationException.java │ │ │ │ └── WorldGenerator.java │ │ │ ├── io │ │ │ ├── JSONSerializable.java │ │ │ └── MongoSerializable.java │ │ │ ├── logging │ │ │ ├── GenericFormatter.java │ │ │ └── LogManager.java │ │ │ ├── plugin │ │ │ ├── PluginManager.java │ │ │ └── ServerPlugin.java │ │ │ ├── user │ │ │ ├── RegistrationException.java │ │ │ ├── User.java │ │ │ ├── UserManager.java │ │ │ ├── UserStats.java │ │ │ └── UserStatsHelper.java │ │ │ ├── web │ │ │ ├── AccountPage.java │ │ │ ├── AlertMessage.java │ │ │ ├── AlertType.java │ │ │ ├── ChangePasswordRoute.java │ │ │ ├── FloppyDownloadRoute.java │ │ │ ├── FloppyUploadRoute.java │ │ │ ├── GuestPolicy.java │ │ │ ├── HomePage.java │ │ │ ├── LeaderBoardPage.java │ │ │ ├── LoginRoute.java │ │ │ ├── LogoutRoute.java │ │ │ ├── PlayPage.java │ │ │ ├── RegisterRoute.java │ │ │ ├── ServerInfoRoute.java │ │ │ └── WebServer.java │ │ │ └── websocket │ │ │ ├── CodeRequestHandler.java │ │ │ ├── CodeUploadHandler.java │ │ │ ├── DebugCommandHandler.java │ │ │ ├── KeypressHandler.java │ │ │ ├── MessageDispatcher.java │ │ │ ├── MessageHandler.java │ │ │ ├── ObjectsRequestHandler.java │ │ │ ├── OnlineUser.java │ │ │ ├── OnlineUserManager.java │ │ │ ├── SocketServer.java │ │ │ ├── TerrainRequestHandler.java │ │ │ └── UserInfoRequestHandler.java │ ├── resources │ │ ├── config.properties │ │ ├── static │ │ │ ├── css │ │ │ │ ├── bootstrap-grid.min.css │ │ │ │ ├── bootstrap-reboot.min.css │ │ │ │ ├── bootstrap4-neon-glow.min.css │ │ │ │ └── mar.css │ │ │ ├── favicon.ico │ │ │ ├── images │ │ │ │ ├── GitHub-Mark-32px.png │ │ │ │ ├── code.png │ │ │ │ ├── cubot.png │ │ │ │ ├── github-logo.png │ │ │ │ ├── hsizegrip.png │ │ │ │ ├── icon.png │ │ │ │ ├── ng-background-dot.png │ │ │ │ ├── sprites.json │ │ │ │ ├── sprites.png │ │ │ │ └── world.png │ │ │ ├── js │ │ │ │ ├── ace │ │ │ │ │ ├── ace.js │ │ │ │ │ ├── ext-searchbox.js │ │ │ │ │ ├── mode-mar.js │ │ │ │ │ ├── theme-ambiance.js │ │ │ │ │ ├── theme-chaos.js │ │ │ │ │ ├── theme-chrome.js │ │ │ │ │ ├── theme-clouds.js │ │ │ │ │ ├── theme-clouds_midnight.js │ │ │ │ │ ├── theme-cobalt.js │ │ │ │ │ ├── theme-crimson_editor.js │ │ │ │ │ ├── theme-dawn.js │ │ │ │ │ ├── theme-dracula.js │ │ │ │ │ ├── theme-dreamweaver.js │ │ │ │ │ ├── theme-eclipse.js │ │ │ │ │ ├── theme-github.js │ │ │ │ │ ├── theme-gob.js │ │ │ │ │ ├── theme-gruvbox.js │ │ │ │ │ ├── theme-idle_fingers.js │ │ │ │ │ ├── theme-iplastic.js │ │ │ │ │ ├── theme-katzenmilch.js │ │ │ │ │ ├── theme-kr_theme.js │ │ │ │ │ ├── theme-kuroir.js │ │ │ │ │ ├── theme-merbivore.js │ │ │ │ │ ├── theme-merbivore_soft.js │ │ │ │ │ ├── theme-mono_industrial.js │ │ │ │ │ ├── theme-monokai.js │ │ │ │ │ ├── theme-pastel_on_dark.js │ │ │ │ │ ├── theme-solarized_dark.js │ │ │ │ │ ├── theme-solarized_light.js │ │ │ │ │ ├── theme-sqlserver.js │ │ │ │ │ ├── theme-terminal.js │ │ │ │ │ ├── theme-textmate.js │ │ │ │ │ ├── theme-tomorrow.js │ │ │ │ │ ├── theme-tomorrow_night.js │ │ │ │ │ ├── theme-tomorrow_night_blue.js │ │ │ │ │ ├── theme-tomorrow_night_bright.js │ │ │ │ │ ├── theme-tomorrow_night_eighties.js │ │ │ │ │ ├── theme-twilight.js │ │ │ │ │ ├── theme-vibrant_ink.js │ │ │ │ │ └── theme-xcode.js │ │ │ │ ├── bootstrap.min.js │ │ │ │ ├── editor.js │ │ │ │ ├── jquery-resizable.min.js │ │ │ │ ├── jquery.min.js │ │ │ │ ├── mar.js │ │ │ │ ├── phaser-plugin-isometric.js │ │ │ │ ├── phaser.js │ │ │ │ └── popper.min.js │ │ │ └── webfonts │ │ │ │ ├── FSEX301-L2.ttf │ │ │ │ ├── MaterialIcons-Regular.ttf │ │ │ │ ├── MaterialIcons-Regular.woff │ │ │ │ └── MaterialIcons-Regular.woff2 │ │ └── templates │ │ │ ├── account.vm │ │ │ ├── footer.vm │ │ │ ├── head.vm │ │ │ ├── header.vm │ │ │ ├── home.vm │ │ │ ├── leaderboard.vm │ │ │ └── play.vm │ └── typescript │ │ ├── Console.ts │ │ ├── GameClient.ts │ │ ├── GameObject.ts │ │ ├── MarGame.ts │ │ ├── World.ts │ │ ├── mar.ts │ │ ├── p2.d.ts │ │ ├── phaser.d.ts │ │ ├── phaser.plugin.isometric.d.ts │ │ ├── pixi.d.ts │ │ └── tsconfig.json │ └── test │ └── java │ └── net │ └── simon987 │ └── server │ ├── ConfigHelper.java │ ├── FakeConfiguration.java │ ├── assembly │ ├── CPUTest.java │ ├── DWTest.java │ ├── LabelTest.java │ ├── MemoryTest.java │ ├── OperandTest.java │ ├── RegisterSetTest.java │ ├── TestComment.java │ ├── TestHelper.java │ └── instruction │ │ ├── AddInstructionTest.java │ │ ├── AndInstructionTest.java │ │ ├── BrkInstructionTest.java │ │ ├── CallInstructionTest.java │ │ ├── SetaInstructionTest.java │ │ ├── SetaeInstructionTest.java │ │ ├── SetbInstructionTest.java │ │ ├── SetbeInstructionTest.java │ │ ├── SetcInstructionTest.java │ │ ├── SetccInstructionTest.java │ │ ├── SeteInstructionTest.java │ │ ├── SetgInstructionTest.java │ │ ├── SetgeInstructionTest.java │ │ ├── SetlInstructionTest.java │ │ ├── SetleInstructionTest.java │ │ ├── SetnaInstructionTest.java │ │ ├── SetnaeInstructionTest.java │ │ ├── SetnbInstructionTest.java │ │ ├── SetnbeInstructionTest.java │ │ ├── SetncInstructionTest.java │ │ ├── SetneInstructionTest.java │ │ ├── SetngInstructionTest.java │ │ ├── SetngeInstructionTest.java │ │ ├── SetnlInstructionTest.java │ │ ├── SetnleInstructionTest.java │ │ ├── SetnoInstructionTest.java │ │ ├── SetnsInstructionTest.java │ │ ├── SetnzInstructionTest.java │ │ ├── SetoInstructionTest.java │ │ ├── SetsInstructionTest.java │ │ └── SetzInstructionTest.java │ └── game │ └── objects │ └── ItemsContainerTest.java ├── Vagrantfile ├── bootstrap.sh ├── docker-compose.yml ├── plugin-contruction ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── simon987 │ │ └── constructionplugin │ │ ├── BluePrint.java │ │ ├── BluePrintRegistry.java │ │ ├── BluePrintUtil.java │ │ ├── ConstructionPlugin.java │ │ ├── ConstructionSite.java │ │ ├── ItemBluePrint.java │ │ ├── Obstacle.java │ │ └── ObstacleBlueprint.java │ └── resources │ └── plugin.properties └── pom.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | Server/src/main/resources/static/css/bootstrap4-neon-glow.min linguist-vendored 2 | Server/src/main/resources/static/css/bootstrap-grid.min linguist-vendored 3 | Server/src/main/resources/static/css/bootstrap-reboot.min linguist-vendored 4 | Server/src/main/resources/static/js/* linguist-vendored 5 | Server/src/main/resources/static/js/ace/* linguist-vendored -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | plugins/Plugin NPC.jar 3 | plugins/Plugin Misc HW.jar 4 | plugins/Plant.jar 5 | plugins/Cubot.jar 6 | .idea/* 7 | mar.log 8 | mar.log.lck 9 | *.iml 10 | *.class 11 | */target/* 12 | plugins/*.jar 13 | save.json 14 | Server/Server.iml 15 | target/* 16 | Server/Server.iml 17 | Server/src/main/java/META-INF/MANIFEST.MF 18 | .settings 19 | .project 20 | .classpath 21 | # VSCode Workspace 22 | .vscode/ -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## General guide 2 | 3 | [Collaboration guide](https://github.com/simon987/Much-Assembly-Required/wiki/Collaboration-Guide) 4 | 5 | ## Before creating a pull request 6 | 7 | Here small unordered list of guidelines to read before creating a pull request 8 | - Use java <= 1.8 features 9 | - Please follow [Google's Java style guide](https://google.github.io/styleguide/javaguide.html) 10 | - Constants (e.g. the energy cost of an in-game action) should be loaded from config.properties 11 | - The project is separated into multiple modules, the `Server` module and its plugins. Plugins should 12 | not depend on another plugin to compile or to run. 13 | (e.g. NPC plugin shouldn't import `net.simon987.biomassplugin` ) 14 | - Use `Logmanager.LOGGER` to log messages to the console. Use `.fine()` for debugging messages and `.info()` for 15 | info for more important messages 16 | that are not too frequently used. 17 | - Do not submit a pull request for a new feature that has not been approved 18 | by [simon987](https://github.com/simon987) in an Issue beforehand 19 | - Please state what tests have been performed in the pull request 20 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.5-jdk-8 2 | COPY /. /app/ 3 | WORKDIR /app 4 | RUN mvn package 5 | WORKDIR /app/target 6 | CMD ["java", "-jar", "/app/target/server-1.4a.jar"] -------------------------------------------------------------------------------- /Plugin Cubot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.plugincubot 14 | plugin-cubot 15 | 1.4a 16 | 17 | 18 | 19 | 20 | net.simon987.server 21 | server 22 | 1.4a 23 | 24 | 25 | 26 | 27 | com.googlecode.json-simple 28 | json-simple 29 | 1.1.1 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | import net.simon987.server.assembly.HardwareModule; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import org.bson.Document; 7 | 8 | public class CubotCore extends HardwareModule { 9 | 10 | public static final int DEFAULT_ADDRESS = 0x000E; 11 | 12 | /** 13 | * Hardware ID (Should be unique) 14 | */ 15 | public static final char HWID = 0x000E; 16 | 17 | private static final int CORE_STATUS_POLL = 1; 18 | private static final int CORE_HULL_POLL = 2; 19 | 20 | public CubotCore(ControllableUnit unit) { 21 | super(null, unit); 22 | } 23 | 24 | public CubotCore(Document document, ControllableUnit unit) { 25 | super(document, unit); 26 | } 27 | 28 | @Override 29 | public void handleInterrupt(Status status) { 30 | 31 | int a = getCpu().getRegisterSet().getRegister("A").getValue(); 32 | 33 | if (a == CORE_STATUS_POLL) { 34 | if (unit instanceof Cubot) { 35 | getCpu().getRegisterSet().getRegister("B").setValue(((Cubot) unit).getStatus()); 36 | } 37 | } else if (a == CORE_HULL_POLL) { 38 | getCpu().getRegisterSet().getRegister("B").setValue(unit.getHp()); 39 | } 40 | } 41 | 42 | @Override 43 | public char getId() { 44 | return HWID; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHardwareModule.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | import net.simon987.server.assembly.HardwareModule; 4 | import net.simon987.server.game.objects.ControllableUnit; 5 | import org.bson.Document; 6 | 7 | public abstract class CubotHardwareModule extends HardwareModule { 8 | 9 | protected Cubot cubot; 10 | 11 | public CubotHardwareModule(Document document, ControllableUnit cubot) { 12 | this.cubot = (Cubot) cubot; 13 | } 14 | 15 | public CubotHardwareModule(Cubot cubot) { 16 | this.cubot = cubot; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotKeyboard.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | import net.simon987.server.assembly.Status; 4 | import net.simon987.server.game.objects.ControllableUnit; 5 | import org.bson.Document; 6 | 7 | public class CubotKeyboard extends CubotHardwareModule { 8 | 9 | public static final int DEFAULT_ADDRESS = 4; 10 | 11 | private static final int KEYBOARD_CLEAR_BUFFER = 0; 12 | private static final int KEYBOARD_FETCH_KEY = 1; 13 | 14 | /** 15 | * Hardware ID (Should be unique) 16 | */ 17 | public static final char HWID = 0x0004; 18 | 19 | public CubotKeyboard(Cubot cubot) { 20 | super(cubot); 21 | } 22 | 23 | public CubotKeyboard(Document document, ControllableUnit cubot) { 24 | super(document, cubot); 25 | } 26 | 27 | @Override 28 | public char getId() { 29 | return HWID; 30 | } 31 | 32 | @Override 33 | public void handleInterrupt(Status status) { 34 | 35 | int a = getCpu().getRegisterSet().getRegister("A").getValue(); 36 | 37 | if (a == KEYBOARD_CLEAR_BUFFER) { 38 | 39 | cubot.clearKeyboardBuffer(); 40 | 41 | } else if (a == KEYBOARD_FETCH_KEY) { 42 | //pop 43 | int key = 0; 44 | if (cubot.getKeyboardBuffer().size() > 0) { 45 | key = cubot.getKeyboardBuffer().get(0); 46 | cubot.getKeyboardBuffer().remove(0); 47 | } 48 | 49 | getCpu().getRegisterSet().getRegister("B").setValue(key); 50 | 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import org.bson.Document; 7 | 8 | public class CubotShield extends CubotHardwareModule { 9 | 10 | public static final char DEFAULT_ADDRESS = 0x000F; 11 | 12 | static final char HWID = 0x000F; 13 | 14 | private static final int SHIELD_CHARGE = 1; 15 | private static final int SHIELD_POLL = 2; 16 | 17 | public static final int COST = GameServer.INSTANCE.getConfig().getInt("shield_energy_cost"); 18 | 19 | public CubotShield(Cubot cubot) { 20 | super(cubot); 21 | } 22 | 23 | public CubotShield(Document document, ControllableUnit cubot) { 24 | super(document, cubot); 25 | } 26 | 27 | @Override 28 | public char getId() { 29 | return HWID; 30 | } 31 | 32 | @Override 33 | public void handleInterrupt(Status status) { 34 | int a = getCpu().getRegisterSet().getRegister("A").getValue(); 35 | // b = amount to charge 36 | if(a == SHIELD_CHARGE) { 37 | int b = getCpu().getRegisterSet().getRegister("B").getValue(); 38 | cubot.chargeShield(b); 39 | } else if (a == SHIELD_POLL) { 40 | int shield = cubot.getShield(); 41 | getCpu().getRegisterSet().getRegister("B").setValue(shield); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotStatus.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | /** 4 | * Status of a Cubot (Special buff or debuff) 5 | */ 6 | public enum CubotStatus { 7 | 8 | DEFAULT(0), 9 | RADIATED(1), 10 | DAMAGED(2), 11 | FACTORY_NEW(3); 12 | 13 | public char val; 14 | 15 | CubotStatus(int val) { 16 | this.val = (char) val; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CubotWalkEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin.event; 2 | 3 | import net.simon987.cubotplugin.Cubot; 4 | import net.simon987.server.event.GameEvent; 5 | 6 | public class CubotWalkEvent extends GameEvent { 7 | 8 | public CubotWalkEvent(Cubot cubot) { 9 | setSource(cubot); 10 | } 11 | 12 | @Override 13 | public Cubot getSource() { 14 | return (Cubot) super.getSource(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin.event; 2 | 3 | import net.simon987.server.event.GameEvent; 4 | import net.simon987.server.game.objects.GameObject; 5 | 6 | public class DeathEvent extends GameEvent { 7 | 8 | public DeathEvent(GameObject object) { 9 | setSource(object); 10 | } 11 | 12 | @Override 13 | public GameObject getSource() { 14 | return (GameObject) super.getSource(); 15 | } 16 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/DeathListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin.event; 2 | 3 | import net.simon987.server.event.GameEvent; 4 | import net.simon987.server.event.GameEventListener; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import net.simon987.server.game.objects.GameObject; 7 | 8 | public class DeathListener implements GameEventListener { 9 | 10 | @Override 11 | public Class getListenedEventType() { 12 | return DeathEvent.class; 13 | } 14 | 15 | @Override 16 | public void handle(GameEvent event) { 17 | DeathEvent DeathEvent = (DeathEvent) event; 18 | GameObject object = DeathEvent.getSource(); 19 | if (object instanceof ControllableUnit) { 20 | ((ControllableUnit) object).getParent().getStats().incrementStat("death", 1); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/PopItemCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin.event; 2 | 3 | import net.simon987.cubotplugin.Cubot; 4 | import net.simon987.cubotplugin.CubotInventory; 5 | import net.simon987.server.GameServer; 6 | import net.simon987.server.event.DebugCommandEvent; 7 | import net.simon987.server.event.GameEvent; 8 | import net.simon987.server.event.GameEventListener; 9 | import net.simon987.server.game.objects.GameObject; 10 | 11 | public class PopItemCommandListener implements GameEventListener { 12 | 13 | @Override 14 | public Class getListenedEventType() { 15 | return DebugCommandEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | DebugCommandEvent e = (DebugCommandEvent) event; 22 | 23 | if (e.getName().equals("clearItem")) { 24 | 25 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId")); 26 | 27 | if (object != null) { 28 | 29 | if (object instanceof Cubot) { 30 | 31 | CubotInventory inventory = (CubotInventory) ((Cubot) object).getHardware(CubotInventory.class); 32 | 33 | e.reply("Removed item from inventory: " + inventory.clearItem()); 34 | } else { 35 | e.reply("Object is not a Cubot"); 36 | } 37 | 38 | } else { 39 | e.reply("Object not found: " + e.getLong("objectId")); 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/WalkListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin.event; 2 | 3 | import net.simon987.server.event.GameEvent; 4 | import net.simon987.server.event.GameEventListener; 5 | 6 | public class WalkListener implements GameEventListener { 7 | 8 | @Override 9 | public Class getListenedEventType() { 10 | return CubotWalkEvent.class; 11 | } 12 | 13 | @Override 14 | public void handle(GameEvent event) { 15 | CubotWalkEvent walkEvent = (CubotWalkEvent) event; 16 | walkEvent.getSource().getParent().getStats().incrementStat("walkDistance", 1); 17 | } 18 | } -------------------------------------------------------------------------------- /Plugin Cubot/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.cubotplugin.CubotPlugin 2 | name=Cubot Plugin 3 | version=1.0 -------------------------------------------------------------------------------- /Plugin Cubot/test/net/simon987/cubotplugin/CubotTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.cubotplugin; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | public class CubotTest { 7 | 8 | @Test 9 | public void test(){ 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Plugin Misc HW/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.pluginmischw 14 | plugin-misc-hw 15 | 1.4a 16 | 17 | 18 | 19 | net.simon987.server 20 | server 21 | 1.4a 22 | 23 | 24 | 25 | com.googlecode.json-simple 26 | json-simple 27 | 1.1.1 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Plugin Misc HW/src/main/java/net/simon987/mischwplugin/Clock.java: -------------------------------------------------------------------------------- 1 | package net.simon987.mischwplugin; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.assembly.HardwareModule; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Util; 7 | import net.simon987.server.game.objects.ControllableUnit; 8 | import org.bson.Document; 9 | 10 | /** 11 | * Hardware to get game time 12 | */ 13 | public class Clock extends HardwareModule { 14 | 15 | private static final char HWID = 0x0008; 16 | 17 | public static final char DEFAULT_ADDRESS = 0x0008; 18 | 19 | public Clock() { 20 | 21 | } 22 | 23 | public Clock(Document document, ControllableUnit unit) { 24 | super(document, unit); 25 | } 26 | 27 | @Override 28 | public void handleInterrupt(Status status) { 29 | 30 | int time = (int) GameServer.INSTANCE.getGameUniverse().getTime(); 31 | 32 | //Will need to be changed to quadword in about 136 years 33 | getCpu().getRegisterSet().getRegister("B").setValue(Util.getHigherWord(time)); 34 | getCpu().getRegisterSet().getRegister("C").setValue(Util.getLowerWord(time)); 35 | 36 | } 37 | 38 | @Override 39 | public char getId() { 40 | return HWID; 41 | } 42 | 43 | 44 | @Override 45 | public Document mongoSerialise() { 46 | 47 | Document dbObject = new Document(); 48 | dbObject.put("type", getClass().getCanonicalName()); 49 | 50 | return dbObject; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Plugin Misc HW/src/main/java/net/simon987/mischwplugin/MiscHWPlugin.java: -------------------------------------------------------------------------------- 1 | package net.simon987.mischwplugin; 2 | 3 | import net.simon987.mischwplugin.event.CpuInitialisationListener; 4 | import net.simon987.server.GameServer; 5 | import net.simon987.server.game.objects.GameRegistry; 6 | import net.simon987.server.logging.LogManager; 7 | import net.simon987.server.plugin.ServerPlugin; 8 | 9 | /** 10 | * Plugin that adds miscellaneous hardware to the game 11 | */ 12 | public class MiscHWPlugin extends ServerPlugin { 13 | 14 | 15 | @Override 16 | public void init(GameServer gameServer) { 17 | listeners.add(new CpuInitialisationListener()); 18 | 19 | GameRegistry registry = gameServer.getRegistry(); 20 | 21 | registry.registerHardware(RandomNumberGenerator.class); 22 | registry.registerHardware(Clock.class); 23 | 24 | LogManager.LOGGER.info("(Mist HW Plugin) Initialised Misc Hardware Plugin"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Plugin Misc HW/src/main/java/net/simon987/mischwplugin/RandomNumberGenerator.java: -------------------------------------------------------------------------------- 1 | package net.simon987.mischwplugin; 2 | 3 | import net.simon987.server.assembly.HardwareModule; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import org.bson.Document; 7 | 8 | import java.util.Random; 9 | 10 | /** 11 | * Hardware to generate random numbers 12 | */ 13 | public class RandomNumberGenerator extends HardwareModule { 14 | 15 | private static final char HWID = 0x0007; 16 | 17 | public static final char DEFAULT_ADDRESS = 0x0007; 18 | 19 | private Random random; 20 | 21 | public RandomNumberGenerator() { 22 | random = new Random(); 23 | } 24 | 25 | public RandomNumberGenerator(Document document, ControllableUnit unit) { 26 | super(document, unit); 27 | random = new Random(); 28 | } 29 | 30 | @Override 31 | public void handleInterrupt(Status status) { 32 | 33 | getCpu().getRegisterSet().getRegister("B").setValue(random.nextInt(0xFFFF)); 34 | 35 | } 36 | 37 | @Override 38 | public char getId() { 39 | return HWID; 40 | } 41 | 42 | @Override 43 | public Document mongoSerialise() { 44 | 45 | Document dbObject = new Document(); 46 | dbObject.put("type", getClass().getCanonicalName()); 47 | 48 | return dbObject; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Plugin Misc HW/src/main/java/net/simon987/mischwplugin/event/CpuInitialisationListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.mischwplugin.event; 2 | 3 | import net.simon987.mischwplugin.Clock; 4 | import net.simon987.mischwplugin.RandomNumberGenerator; 5 | import net.simon987.server.assembly.CPU; 6 | import net.simon987.server.event.CpuInitialisationEvent; 7 | import net.simon987.server.event.GameEvent; 8 | import net.simon987.server.event.GameEventListener; 9 | import net.simon987.server.game.objects.HardwareHost; 10 | 11 | public class CpuInitialisationListener implements GameEventListener { 12 | 13 | @Override 14 | public Class getListenedEventType() { 15 | return CpuInitialisationEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | CPU cpu = (CPU) event.getSource(); 22 | HardwareHost cubot = (HardwareHost) ((CpuInitialisationEvent) event).getUnit(); 23 | cpu.setHardwareHost(cubot); 24 | 25 | RandomNumberGenerator rngHW = new RandomNumberGenerator(); 26 | rngHW.setCpu(cpu); 27 | Clock clock = new Clock(); 28 | clock.setCpu(cpu); 29 | 30 | cpu.getHardwareHost().attachHardware(rngHW, RandomNumberGenerator.DEFAULT_ADDRESS); 31 | cpu.getHardwareHost().attachHardware(clock, Clock.DEFAULT_ADDRESS); 32 | } 33 | } -------------------------------------------------------------------------------- /Plugin Misc HW/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.mischwplugin.MiscHWPlugin 2 | name=Misc HW Plugin 3 | version=1.0 -------------------------------------------------------------------------------- /Plugin NPC/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.pluginnpc 14 | plugin-npc 15 | 1.4a 16 | 17 | 18 | 19 | 20 | com.googlecode.json-simple 21 | json-simple 22 | 1.1.1 23 | 24 | 25 | 26 | net.simon987.server 27 | server 28 | 1.4a 29 | 30 | 31 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/ExecuteCpuTask.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.game.objects.Action; 5 | 6 | public class ExecuteCpuTask extends NPCTask { 7 | 8 | private static final int MAX_EXEC_TIME = GameServer.INSTANCE.getConfig().getInt("npc_exec_time"); 9 | 10 | @Override 11 | public boolean checkCompleted() { 12 | return false; 13 | } 14 | 15 | @Override 16 | public void tick(NonPlayerCharacter npc) { 17 | 18 | HackedNPC hNpc = (HackedNPC) npc; 19 | 20 | //Execute code 21 | int timeout = Math.min(hNpc.getEnergy(), MAX_EXEC_TIME); 22 | hNpc.getCpu().reset(); 23 | int cost = hNpc.getCpu().execute(timeout); 24 | hNpc.spendEnergy(cost); 25 | 26 | if (hNpc.getCurrentAction() == Action.WALKING) { 27 | if (hNpc.spendEnergy(100)) { 28 | if (hNpc.incrementLocation()) { 29 | //Couldn't walk 30 | hNpc.setCurrentAction(Action.IDLE); 31 | } 32 | } else { 33 | hNpc.setCurrentAction(Action.IDLE); 34 | } 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/NPCTask.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin; 2 | 3 | 4 | public abstract class NPCTask { 5 | 6 | public abstract boolean checkCompleted(); 7 | 8 | public abstract void tick(NonPlayerCharacter npc); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/VaultExitPortal.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin; 2 | 3 | import net.simon987.server.game.objects.GameObject; 4 | import net.simon987.server.game.world.Location; 5 | import org.bson.Document; 6 | 7 | /** 8 | * Final exit portal located in the 'last' World of a Vault dimension 9 | */ 10 | public class VaultExitPortal extends Portal { 11 | 12 | public VaultExitPortal() { 13 | 14 | } 15 | 16 | public VaultExitPortal(Document document) { 17 | super(document); 18 | 19 | setDestination(new Location( 20 | document.getInteger("dstWorldX"), 21 | document.getInteger("dstWorldY"), 22 | document.getString("dstDimension"), 23 | document.getInteger("dstX"), 24 | document.getInteger("dstY"))); 25 | setX(document.getInteger("x")); 26 | setY(document.getInteger("y")); 27 | } 28 | 29 | @Override 30 | public boolean enter(GameObject object) { 31 | 32 | //TODO: Trigger vault complete event instead 33 | return super.enter(object); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/event/CpuInitialisationListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin.event; 2 | 3 | import net.simon987.npcplugin.RadioReceiverHardware; 4 | import net.simon987.server.assembly.CPU; 5 | import net.simon987.server.event.CpuInitialisationEvent; 6 | import net.simon987.server.event.GameEvent; 7 | import net.simon987.server.event.GameEventListener; 8 | import net.simon987.server.game.objects.ControllableUnit; 9 | import net.simon987.server.game.objects.HardwareHost; 10 | 11 | public class CpuInitialisationListener implements GameEventListener { 12 | @Override 13 | public Class getListenedEventType() { 14 | return CpuInitialisationEvent.class; 15 | } 16 | 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | CPU cpu = (CPU) event.getSource(); 21 | ControllableUnit controllableUnit = ((CpuInitialisationEvent) event).getUnit(); 22 | cpu.setHardwareHost((HardwareHost) controllableUnit); 23 | 24 | RadioReceiverHardware radioHw = new RadioReceiverHardware(controllableUnit); 25 | radioHw.setCpu(cpu); 26 | 27 | cpu.getHardwareHost().attachHardware(radioHw, RadioReceiverHardware.DEFAULT_ADDRESS); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultCompleteEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin.event; 2 | 3 | import net.simon987.npcplugin.VaultExitPortal; 4 | import net.simon987.server.event.GameEvent; 5 | import net.simon987.server.game.objects.GameObject; 6 | 7 | public class VaultCompleteEvent extends GameEvent { 8 | 9 | private VaultExitPortal portal; 10 | 11 | public VaultCompleteEvent(GameObject object, VaultExitPortal portal) { 12 | 13 | //TODO: Add completion time? 14 | setSource(object); 15 | this.portal = portal; 16 | } 17 | 18 | @Override 19 | public GameObject getSource() { 20 | return (GameObject) super.getSource(); 21 | } 22 | 23 | public VaultExitPortal getPortal() { 24 | return portal; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultCompleteListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin.event; 2 | 3 | import net.simon987.server.event.GameEvent; 4 | import net.simon987.server.event.GameEventListener; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import net.simon987.server.game.objects.GameObject; 7 | import net.simon987.server.logging.LogManager; 8 | 9 | public class VaultCompleteListener implements GameEventListener { 10 | @Override 11 | public Class getListenedEventType() { 12 | return VaultCompleteEvent.class; 13 | } 14 | 15 | @Override 16 | public void handle(GameEvent event) { 17 | VaultCompleteEvent vaultCompleteEvent = (VaultCompleteEvent) event; 18 | GameObject object = vaultCompleteEvent.getSource(); 19 | if (object instanceof ControllableUnit) { 20 | LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Completed vault " + 21 | object.getWorld().getDimension()); 22 | 23 | ((ControllableUnit) object).getParent().getStats().addToStringSet("completedVaults", 24 | vaultCompleteEvent.getPortal().getWorld().getDimension()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/world/TileVaultFloor.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin.world; 2 | 3 | import net.simon987.server.game.world.Tile; 4 | 5 | public class TileVaultFloor extends Tile { 6 | 7 | public static final int ID = 4; 8 | 9 | @Override 10 | public int getId() { 11 | return ID; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/java/net/simon987/npcplugin/world/TileVaultWall.java: -------------------------------------------------------------------------------- 1 | package net.simon987.npcplugin.world; 2 | 3 | import net.simon987.server.game.objects.GameObject; 4 | import net.simon987.server.game.world.Tile; 5 | 6 | public class TileVaultWall extends Tile { 7 | 8 | public static final int ID = 5; 9 | 10 | @Override 11 | public int getId() { 12 | return ID; 13 | } 14 | 15 | @Override 16 | public boolean walk(GameObject object) { 17 | return false; //always blocked 18 | } 19 | 20 | @Override 21 | public boolean isBlocked() { 22 | return true; 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Plugin NPC/src/main/resources/defaultHackedCubotHardware.json: -------------------------------------------------------------------------------- 1 | { 2 | "hardware": [ 3 | { 4 | "type": "net.simon987.cubotplugin.CubotLeg", 5 | "address": 1 6 | }, 7 | { 8 | "type": "net.simon987.cubotplugin.CubotLaser", 9 | "address": 2 10 | }, 11 | { 12 | "type": "net.simon987.cubotplugin.CubotLidar", 13 | "address": 3 14 | }, 15 | { 16 | "type": "net.simon987.cubotplugin.CubotDrill", 17 | "address": 5 18 | }, 19 | { 20 | "type": "net.simon987.npcplugin.NpcInventory", 21 | "item": null, 22 | "address": 6 23 | }, 24 | { 25 | "type": "net.simon987.mischwplugin.RandomNumberGenerator", 26 | "address": 7 27 | }, 28 | { 29 | "type": "net.simon987.mischwplugin.Clock", 30 | "address": 8 31 | }, 32 | { 33 | "type": "net.simon987.cubotplugin.CubotHologram", 34 | "color": 0, 35 | "value": 0, 36 | "string": "", 37 | "mode": 0, 38 | "address": 9 39 | }, 40 | { 41 | "type": "net.simon987.npcplugin.NpcBattery", 42 | "energy": 60000, 43 | "max_energy": 60000, 44 | "address": 262 45 | }, 46 | { 47 | "type": "net.simon987.npcplugin.RadioReceiverHardware", 48 | "cubot": { 49 | "$oid": "5c1d43e40d3d2530aba636df" 50 | }, 51 | "address": 12 52 | }, 53 | { 54 | "type": "net.simon987.cubotplugin.CubotComPort", 55 | "address": 13 56 | }, 57 | { 58 | "type": "net.simon987.cubotplugin.CubotCore", 59 | "address": 14 60 | } 61 | ] 62 | } -------------------------------------------------------------------------------- /Plugin NPC/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.npcplugin.NpcPlugin 2 | name=NPC Plugin 3 | version=1.1 4 | depend=Cubot Plugin -------------------------------------------------------------------------------- /Plugin Plant/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.pluginplant 14 | plugin-biomassBlob 15 | 1.4a 16 | 17 | 18 | 19 | com.googlecode.json-simple 20 | json-simple 21 | 1.1.1 22 | 23 | 24 | 25 | net.simon987.server 26 | server 27 | 1.4a 28 | 29 | 30 | -------------------------------------------------------------------------------- /Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java: -------------------------------------------------------------------------------- 1 | package net.simon987.biomassplugin; 2 | 3 | import net.simon987.biomassplugin.event.ObjectDeathListener; 4 | import net.simon987.biomassplugin.event.WorldCreationListener; 5 | import net.simon987.biomassplugin.event.WorldUpdateListener; 6 | import net.simon987.server.GameServer; 7 | import net.simon987.server.IServerConfiguration; 8 | import net.simon987.server.game.objects.GameRegistry; 9 | import net.simon987.server.logging.LogManager; 10 | import net.simon987.server.plugin.ServerPlugin; 11 | 12 | 13 | public class BiomassPlugin extends ServerPlugin { 14 | 15 | 16 | @Override 17 | public void init(GameServer gameServer) { 18 | 19 | IServerConfiguration config = gameServer.getConfig(); 20 | GameRegistry registry = gameServer.getRegistry(); 21 | 22 | listeners.add(new WorldCreationListener()); 23 | listeners.add(new WorldUpdateListener(config)); 24 | listeners.add(new ObjectDeathListener(config)); 25 | 26 | registry.registerGameObject(BiomassBlob.class); 27 | registry.registerItem(ItemBiomass.ID, ItemBiomass.class); 28 | 29 | LogManager.LOGGER.info("(BiomassPlugin) Initialised Biomass plugin"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Plugin Plant/src/main/java/net/simon987/biomassplugin/ItemBiomass.java: -------------------------------------------------------------------------------- 1 | package net.simon987.biomassplugin; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.game.item.Item; 5 | import net.simon987.server.game.objects.ControllableUnit; 6 | import net.simon987.server.game.objects.Rechargeable; 7 | import org.bson.Document; 8 | 9 | public class ItemBiomass extends Item { 10 | 11 | public static final int ID = 0x0001; 12 | 13 | private static final int energy = GameServer.INSTANCE.getConfig().getInt("biomassEnergyValue"); 14 | 15 | @Override 16 | public int getId() { 17 | return ID; 18 | } 19 | 20 | public ItemBiomass() { 21 | super(null); 22 | } 23 | 24 | public ItemBiomass(Document document) { 25 | super(document); 26 | } 27 | 28 | @Override 29 | public void clear(ControllableUnit unit) { 30 | if (unit instanceof Rechargeable) { 31 | ((Rechargeable) unit).storeEnergy(energy); 32 | } 33 | } 34 | 35 | @Override 36 | public char poll() { 37 | return ID; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Plugin Plant/src/main/java/net/simon987/biomassplugin/event/WorldCreationListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.biomassplugin.event; 2 | 3 | import net.simon987.biomassplugin.BiomassBlob; 4 | import net.simon987.biomassplugin.WorldUtils; 5 | import net.simon987.server.GameServer; 6 | import net.simon987.server.event.GameEvent; 7 | import net.simon987.server.event.GameEventListener; 8 | import net.simon987.server.event.WorldGenerationEvent; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class WorldCreationListener implements GameEventListener { 13 | @Override 14 | public Class getListenedEventType() { 15 | return WorldGenerationEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | int minCount = GameServer.INSTANCE.getConfig().getInt("minBiomassCount"); 22 | int maxCount = GameServer.INSTANCE.getConfig().getInt("maxBiomassCount"); 23 | int yield = GameServer.INSTANCE.getConfig().getInt("biomass_yield"); 24 | 25 | ArrayList biomassBlobs = WorldUtils.generateBlobs(((WorldGenerationEvent) event).getWorld(), 26 | minCount, maxCount, yield); 27 | 28 | for (BiomassBlob blob : biomassBlobs) { 29 | ((WorldGenerationEvent) event).getWorld().addObject(blob); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Plugin Plant/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.biomassplugin.BiomassPlugin 2 | name=Biomass Plugin 3 | version=1.0 4 | depend=NPC Plugin -------------------------------------------------------------------------------- /Plugin Radioactive Cloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.pluginradioactivecloud 14 | plugin-radioactiveCloud 15 | 1.4a 16 | 17 | 18 | 19 | 20 | com.googlecode.json-simple 21 | json-simple 22 | 1.1.1 23 | 24 | 25 | 26 | net.simon987.server 27 | server 28 | 1.4a 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloud.java: -------------------------------------------------------------------------------- 1 | package net.simon987.pluginradioactivecloud; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.game.objects.ControllableUnit; 5 | import net.simon987.server.game.objects.Enterable; 6 | import net.simon987.server.game.objects.GameObject; 7 | import net.simon987.server.game.objects.Radioactive; 8 | 9 | public class RadioactiveCloud extends GameObject implements Radioactive, Enterable { 10 | private final static int CORRUPTION_BLOCK_SIZE = 11 | GameServer.INSTANCE.getConfig().getInt("radioactive_cloud_corruption_block_size"); 12 | 13 | /** 14 | * Called when an object attempts to walk directly into a Enterable object 15 | * 16 | * @param object The game object that attempted to enter 17 | * @return true if successful, false to block the object 18 | */ 19 | @Override 20 | public boolean enter(GameObject object) { 21 | if (object instanceof ControllableUnit) { 22 | ((ControllableUnit) object).getCpu().getMemory().corrupt(CORRUPTION_BLOCK_SIZE); 23 | } 24 | 25 | return true; 26 | } 27 | 28 | @Override 29 | public char getMapInfo() { 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloudPlugin.java: -------------------------------------------------------------------------------- 1 | package net.simon987.pluginradioactivecloud; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.logging.LogManager; 5 | import net.simon987.server.plugin.ServerPlugin; 6 | 7 | public class RadioactiveCloudPlugin extends ServerPlugin { 8 | 9 | @Override 10 | public void init(GameServer gameServer) { 11 | 12 | LogManager.LOGGER.info("(Radioactive cloud Plugin) Initialised Radioactive cloud plugin."); 13 | } 14 | } -------------------------------------------------------------------------------- /Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveObstacle.java: -------------------------------------------------------------------------------- 1 | package net.simon987.pluginradioactivecloud; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.game.objects.ControllableUnit; 5 | import net.simon987.server.game.objects.Enterable; 6 | import net.simon987.server.game.objects.GameObject; 7 | import net.simon987.server.game.objects.Radioactive; 8 | 9 | public class RadioactiveObstacle extends GameObject implements Radioactive, Enterable { 10 | 11 | private final static int corruptionBlockSize = GameServer.INSTANCE.getConfig().getInt("radioactive_obstacle_corruption_block_size"); 12 | private final static int MAP_INFO = 0x0A01; //10 13 | 14 | @Override 15 | public char getMapInfo() { 16 | return MAP_INFO; 17 | } 18 | 19 | @Override 20 | public boolean enter(GameObject object) { 21 | if (object instanceof ControllableUnit) { 22 | ((ControllableUnit) object).getCpu().getMemory().corrupt(corruptionBlockSize); 23 | } 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /Plugin Radioactive Cloud/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.pluginradioactivecloud.RadioactiveCloudPlugin 2 | name=Radioactive cloud Plugin 3 | version=1.4 -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/IServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server; 2 | 3 | public interface IServerConfiguration { 4 | 5 | int getInt(String key); 6 | 7 | String getString(String key); 8 | 9 | void setInt(String key, int value); 10 | 11 | void setString(String key, String value); 12 | } 13 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/Main.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server; 2 | 3 | import net.simon987.server.logging.LogManager; 4 | import net.simon987.server.web.WebServer; 5 | import spark.Spark; 6 | 7 | 8 | public class Main { 9 | public static void main(String[] args) { 10 | 11 | 12 | ServerConfiguration config = new ServerConfiguration("config.properties"); 13 | LogManager.initialize(config); 14 | 15 | GameServer.INSTANCE.load(); 16 | 17 | //Web server 18 | WebServer webServer = new WebServer(GameServer.INSTANCE.getConfig()); 19 | 20 | Spark.awaitInitialization(); 21 | GameServer.INSTANCE.setSocketServer(webServer.getSocketServer()); 22 | 23 | (new Thread(GameServer.INSTANCE)).start(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/DefaultRegisterSet.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * RegisterSet with default values 5 | */ 6 | class DefaultRegisterSet extends RegisterSet { 7 | 8 | 9 | DefaultRegisterSet() { 10 | super(); 11 | 12 | addRegister(1, new Register("A")); 13 | addRegister(2, new Register("B")); 14 | addRegister(3, new Register("C")); 15 | addRegister(4, new Register("D")); 16 | addRegister(5, new Register("X")); 17 | addRegister(6, new Register("Y")); 18 | addRegister(7, new Register("SP")); 19 | addRegister(8, new Register("BP")); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/InstructionSet.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * A set of instructions for a CPU. 5 | *

6 | * Defines what a CPU can do 7 | */ 8 | public interface InstructionSet { 9 | 10 | /** 11 | * Get an instruction by its opcode 12 | * 13 | * @param opcode opcode of the instruction 14 | * @return the instruction, null is not found 15 | */ 16 | Instruction get(int opcode); 17 | 18 | /** 19 | * Get an instruction by its mnemonic 20 | * 21 | * @param mnemonic mnemonic of the instruction, not case sensitive 22 | * @return the instruction, if not found, the default instruction is returned 23 | */ 24 | Instruction get(String mnemonic); 25 | 26 | /** 27 | * Add an instruction to the set 28 | * 29 | * @param instruction instruction to add 30 | */ 31 | void add(Instruction instruction); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/OperandType.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * Types of an operand 5 | */ 6 | public enum OperandType { 7 | 8 | REGISTER16("16-bit Register"), 9 | MEMORY_IMM16("16-bit Memory referred by immediate"), 10 | MEMORY_REG16("16-bit Memory referred by register"), 11 | MEMORY_REG_DISP16("16-bit Memory referred by register with displacement"), 12 | IMMEDIATE16("16-bit Immediate"); 13 | 14 | /** 15 | * Description of the Operand type 16 | */ 17 | private String description; 18 | 19 | public String getDescription() { 20 | return description; 21 | } 22 | 23 | OperandType(String desc) { 24 | this.description = desc; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/Register.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * Represents a register in a cpu 5 | */ 6 | public class Register { 7 | 8 | /** 9 | * Name of the register 10 | */ 11 | private String name; 12 | 13 | /** 14 | * 16-bit value of the register 15 | */ 16 | private char value = 0; 17 | 18 | /** 19 | * Create a new Register 20 | * 21 | * @param name Name of the register, always set in Upper case 22 | */ 23 | public Register(String name) { 24 | this.name = name.toUpperCase(); 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public char getValue() { 32 | return value; 33 | } 34 | 35 | /** 36 | * Set value of the register. 37 | * 38 | * @param value value to set. It is casted to char 39 | */ 40 | public void setValue(int value) { 41 | this.value = (char) value; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | 47 | return name + "=" + value; 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/Section.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * Section of a user-created program. 5 | * The execution will start at the beginning of the code 6 | * segment. 7 | */ 8 | public enum Section { 9 | 10 | /** 11 | * Code section of the program. Contains executable code 12 | */ 13 | TEXT, 14 | 15 | /** 16 | * Data section of the program. Contains initialised data 17 | */ 18 | DATA 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/Target.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | /** 4 | * A Target is a location that can be read and written to during 5 | * the execution of an instruction. 6 | *

7 | * For example: MOV dstTARGET, srcTARGET 8 | *

9 | * A target is usually Memory or Register 10 | */ 11 | public interface Target { 12 | 13 | /** 14 | * Get a value from a Target at an address. 15 | * 16 | * @param address Address of the value. Can refer to a memory address or the index 17 | * of a register 18 | * @return value at specified address 19 | */ 20 | int get(int address); 21 | 22 | /** 23 | * Set a value at an address 24 | * 25 | * @param address address of the value to change 26 | * @param value value to set 27 | */ 28 | void set(int address, int value); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/AssemblyException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when a problem is encountered while parsing a line 5 | * of a user's code, making it impossible to translate it to 6 | * binary code. 7 | */ 8 | public class AssemblyException extends Exception { 9 | 10 | /** 11 | * Line offset in the user's code. 12 | */ 13 | private int line; 14 | 15 | /** 16 | * Create a new Assembly Exception 17 | * 18 | * @param msg Message of the exception 19 | * @param line Line offset in the user's code. 20 | */ 21 | public AssemblyException(String msg, int line) { 22 | super(msg); 23 | this.line = line; 24 | } 25 | 26 | public int getLine() { 27 | return line; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/CancelledException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | public class CancelledException extends Exception { 4 | public CancelledException() { 5 | super("CPU Initialisation was cancelled"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/DuplicateSectionException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when a user attempts to define the same section twice 5 | */ 6 | public class DuplicateSectionException extends AssemblyException { 7 | 8 | /** 9 | * Message of the exception 10 | */ 11 | private static final String message = "Sections can only be defined once"; 12 | 13 | /** 14 | * Create a new Duplicate Section Exception 15 | */ 16 | public DuplicateSectionException(int line) { 17 | super(message, line); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/EmptyLineException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when the parser encounters an empty line 5 | */ 6 | public class EmptyLineException extends AssemblyException { 7 | public EmptyLineException(int line) { 8 | super("Encountered empty line", line); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/FatalAssemblyException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Class of exceptions that should stop assembly immediately 5 | */ 6 | public class FatalAssemblyException extends AssemblyException { 7 | 8 | /** 9 | * Message of the exception 10 | */ 11 | private static final String message = "A fatal assembly error has occurred"; 12 | 13 | /** 14 | * Create a new Duplicate Section Exception 15 | */ 16 | public FatalAssemblyException(String msg, int line) { 17 | super(msg, line); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/IllegalOperandException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | 4 | public class IllegalOperandException extends AssemblyException { 5 | public IllegalOperandException(String msg, int line) { 6 | super(msg, line); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/InvalidMnemonicException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when the parse encounters an invalid mnemonic 5 | */ 6 | public class InvalidMnemonicException extends AssemblyException { 7 | public InvalidMnemonicException(String mnemonic, int line) { 8 | super("Unknown mnemonic \"" + mnemonic + "\"", line); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/InvalidOperandException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when the Assembler attempts to parse a malformed or invalid operand 5 | */ 6 | public class InvalidOperandException extends AssemblyException { 7 | 8 | /** 9 | * Creates a new Invalid operand Exception 10 | * 11 | * @param msg Message 12 | * @param line Line offset in the user's code.Used to display an error icon 13 | * in the editor. 14 | */ 15 | public InvalidOperandException(String msg, int line) { 16 | super(msg, line); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/OffsetOverflowException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when offset for stored instruction/data overflows the size of memory 5 | */ 6 | public class OffsetOverflowException extends FatalAssemblyException { 7 | 8 | /** 9 | * Message of the exception 10 | */ 11 | private static final String message = "Program data exceeds memory size "; 12 | 13 | /** 14 | * Create a new Offset Overflow Exception 15 | */ 16 | public OffsetOverflowException(int offset, int memSize, int line) { 17 | super(message + offset + " > " + memSize, line); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/exception/PseudoInstructionException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.exception; 2 | 3 | /** 4 | * Threw when the parser encounters a pseudo instruction 5 | * (Instruction that doesn't produce any binary output 6 | */ 7 | public class PseudoInstructionException extends AssemblyException { 8 | public PseudoInstructionException(int line) { 9 | super("Pseudo instruction encountered", line); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/BrkInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | 6 | /** 7 | * BRK (Break) Instruction. Will set the break flag and stop the CPU 8 | * execution 9 | */ 10 | public class BrkInstruction extends Instruction { 11 | 12 | public static final int OPCODE = 0; 13 | 14 | public BrkInstruction() { 15 | super("brk", OPCODE); 16 | } 17 | 18 | @Override 19 | public Status execute(Status status) { 20 | 21 | status.setBreakFlag(true); 22 | 23 | return status; 24 | } 25 | 26 | public boolean noOperandsValid() { 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/CallInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Move the execution (Jump) to an address, and save the current IP value, the execution will return to this value 10 | * after the RET instruction is executed 11 | *
12 | * FLAGS are not altered 13 | */ 14 | public class CallInstruction extends Instruction { 15 | 16 | public static final int OPCODE = 21; 17 | 18 | private CPU cpu; 19 | 20 | public CallInstruction(CPU cpu) { 21 | super("call", OPCODE); 22 | 23 | this.cpu = cpu; 24 | } 25 | 26 | @Override 27 | public Status execute(Target src, int srcIndex, Status status) { 28 | //Push ip 29 | cpu.getRegisterSet().set(7, cpu.getRegisterSet().get(7) - 1); //Decrement SP (stack grows towards smaller addresses) 30 | cpu.getMemory().set(cpu.getRegisterSet().get(7), cpu.getIp()); 31 | 32 | //Jmp 33 | cpu.setIp((char) src.get(srcIndex)); 34 | 35 | return status; 36 | } 37 | 38 | @Override 39 | public Status execute(int src, Status status) { 40 | //Push ip 41 | cpu.getRegisterSet().set(7, cpu.getRegisterSet().get(7) - 1); //Decrement SP (stack grows towards smaller addresses) 42 | cpu.getMemory().set(cpu.getRegisterSet().get(7), cpu.getIp()); 43 | 44 | //Jmp 45 | cpu.setIp((char) src); 46 | 47 | return status; 48 | } 49 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/DecInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | public class DecInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 43; 11 | 12 | public DecInstruction() { 13 | super("dec", OPCODE); 14 | } 15 | 16 | @Override 17 | public Status execute(Target dst, int dstIndex, Status status) { 18 | char a = (char) dst.get(dstIndex); 19 | int result = a - 1; 20 | 21 | // Like x86 Carry flag is preserved during INC/DEC 22 | // (Use ADD x, 1 to have carry flag change) 23 | // Other flags set according to result 24 | status.setSignFlag(Util.checkSign16(result)); 25 | status.setZeroFlag((char) result == 0); 26 | status.setOverflowFlag(Util.checkOverFlowSub16(a, 1)); 27 | 28 | dst.set(dstIndex, result); 29 | return status; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/HwiInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Send hardware interrupt 10 | *
Used to interact with the World using hardware 11 | */ 12 | public class HwiInstruction extends Instruction { 13 | 14 | public static final int OPCODE = 9; 15 | 16 | private CPU cpu; 17 | 18 | public HwiInstruction(CPU cpu) { 19 | super("hwi", OPCODE); 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target src, int srcIndex, Status status) { 25 | status.setErrorFlag(cpu.getHardwareHost().hardwareInterrupt(src.get(srcIndex), cpu.getStatus())); 26 | 27 | return status; 28 | } 29 | 30 | @Override 31 | public Status execute(int src, Status status) { 32 | 33 | status.setErrorFlag(cpu.getHardwareHost().hardwareInterrupt(src, cpu.getStatus())); 34 | 35 | return status; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/HwqInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.*; 4 | 5 | public class HwqInstruction extends Instruction { 6 | 7 | private static final int OPCODE = 28; 8 | 9 | private CPU cpu; 10 | private Register b; 11 | 12 | public HwqInstruction(CPU cpu) { 13 | super("hwq", OPCODE); 14 | this.cpu = cpu; 15 | this.b = cpu.getRegisterSet().getRegister("B"); 16 | } 17 | 18 | @Override 19 | public Status execute(Target src, int srcIndex, Status status) { 20 | b.setValue(cpu.getHardwareHost().hardwareQuery(src.get(srcIndex))); 21 | 22 | return status; 23 | } 24 | 25 | @Override 26 | public Status execute(int src, Status status) { 27 | b.setValue(cpu.getHardwareHost().hardwareQuery(src)); 28 | 29 | return status; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/IncInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | public class IncInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 42; 11 | 12 | public IncInstruction() { 13 | super("inc", OPCODE); 14 | } 15 | 16 | @Override 17 | public Status execute(Target dst, int dstIndex, Status status) { 18 | char a = (char) dst.get(dstIndex); 19 | int result = a + 1; 20 | 21 | // Like x86 Carry flag is preserved during INC/DEC 22 | // (Use ADD x, 1 to have carry flag change) 23 | // Other flags set according to result 24 | status.setSignFlag(Util.checkSign16(result)); 25 | status.setZeroFlag((char) result == 0); 26 | status.setOverflowFlag(Util.checkOverFlowAdd16(a, 1)); 27 | 28 | dst.set(dstIndex, result); 29 | return status; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JaInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Jump if above 10 | */ 11 | public class JaInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 46; 14 | 15 | private CPU cpu; 16 | 17 | public JaInstruction(CPU cpu) { 18 | super("ja", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target src, int srcIndex, Status status) { 25 | if (!status.isCarryFlag() && !status.isZeroFlag()) { 26 | cpu.setIp((char) src.get(srcIndex)); 27 | } 28 | return status; 29 | } 30 | 31 | @Override 32 | public Status execute(int src, Status status) { 33 | if (!status.isCarryFlag() && !status.isZeroFlag()) { 34 | cpu.setIp((char) src); 35 | } 36 | return status; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JcInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JcInstruction extends Instruction { 9 | 10 | private static final int OPCODE = 33; 11 | 12 | private CPU cpu; 13 | 14 | public JcInstruction(CPU cpu) { 15 | super("jc", OPCODE); 16 | this.cpu = cpu; 17 | } 18 | 19 | @Override 20 | public Status execute(Target src, int srcIndex, Status status) { 21 | if (status.isCarryFlag()) { 22 | cpu.setIp((char) src.get(srcIndex)); 23 | } 24 | return status; 25 | } 26 | 27 | @Override 28 | public Status execute(int src, Status status) { 29 | if (status.isCarryFlag()) { 30 | cpu.setIp((char) src); 31 | } 32 | return status; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JgInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JgInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 15; 11 | 12 | private CPU cpu; 13 | 14 | public JgInstruction(CPU cpu) { 15 | super("jg", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (status.isSignFlag() == status.isOverflowFlag() && !status.isZeroFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (status.isSignFlag() == status.isOverflowFlag() && !status.isZeroFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JgeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Conditional jump: jump if greater or equal 10 | */ 11 | public class JgeInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 16; 14 | 15 | private CPU cpu; 16 | 17 | public JgeInstruction(CPU cpu) { 18 | super("jge", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target src, int srcIndex, Status status) { 25 | if (status.isSignFlag() == status.isOverflowFlag()) { 26 | cpu.setIp((char) src.get(srcIndex)); 27 | } 28 | return status; 29 | } 30 | 31 | @Override 32 | public Status execute(int src, Status status) { 33 | if (status.isSignFlag() == status.isOverflowFlag()) { 34 | cpu.setIp((char) src); 35 | } 36 | return status; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JlInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JlInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 17; 11 | 12 | private CPU cpu; 13 | 14 | public JlInstruction(CPU cpu) { 15 | super("jl", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (status.isSignFlag() != status.isOverflowFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (status.isSignFlag() != status.isOverflowFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JleInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JleInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 18; 11 | 12 | private CPU cpu; 13 | 14 | public JleInstruction(CPU cpu) { 15 | super("jle", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (status.isSignFlag() != status.isOverflowFlag() || status.isZeroFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (status.isSignFlag() != status.isOverflowFlag() || status.isZeroFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JmpInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JmpInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 10; 11 | 12 | private CPU cpu; 13 | 14 | public JmpInstruction(CPU cpu) { 15 | super("jmp", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | 23 | cpu.setIp((char) src.get(srcIndex)); 24 | return status; 25 | } 26 | 27 | @Override 28 | public Status execute(int src, Status status) { 29 | 30 | cpu.setIp((char) src); 31 | return status; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JnaInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Jump if not above 10 | */ 11 | public class JnaInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 47; 14 | 15 | private CPU cpu; 16 | 17 | public JnaInstruction(CPU cpu) { 18 | super("jna", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target src, int srcIndex, Status status) { 25 | if (status.isCarryFlag() || status.isZeroFlag()) { 26 | cpu.setIp((char) src.get(srcIndex)); 27 | } 28 | return status; 29 | } 30 | 31 | @Override 32 | public Status execute(int src, Status status) { 33 | if (status.isCarryFlag() || status.isZeroFlag()) { 34 | cpu.setIp((char) src); 35 | } 36 | return status; 37 | } 38 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JncInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JncInstruction extends Instruction { 9 | 10 | private static final int OPCODE = 34; 11 | 12 | private CPU cpu; 13 | 14 | public JncInstruction(CPU cpu) { 15 | super("jnc", OPCODE); 16 | this.cpu = cpu; 17 | } 18 | 19 | @Override 20 | public Status execute(Target src, int srcIndex, Status status) { 21 | if (!status.isCarryFlag()) { 22 | cpu.setIp((char) src.get(srcIndex)); 23 | } 24 | return status; 25 | } 26 | 27 | @Override 28 | public Status execute(int src, Status status) { 29 | if (!status.isCarryFlag()) { 30 | cpu.setIp((char) src); 31 | } 32 | return status; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JnoInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | 9 | public class JnoInstruction extends Instruction { 10 | 11 | private static final int OPCODE = 37; 12 | 13 | private CPU cpu; 14 | 15 | public JnoInstruction(CPU cpu) { 16 | super("jno", OPCODE); 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (!status.isOverflowFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (!status.isOverflowFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JnsInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JnsInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 27; 11 | 12 | private CPU cpu; 13 | 14 | public JnsInstruction(CPU cpu) { 15 | super("jns", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (!status.isSignFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (!status.isSignFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JnzInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JnzInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 13; 11 | 12 | private CPU cpu; 13 | 14 | public JnzInstruction(CPU cpu) { 15 | super("jnz", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (!status.isZeroFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (!status.isZeroFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JoInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JoInstruction extends Instruction { 9 | 10 | private static final int OPCODE = 36; 11 | 12 | private CPU cpu; 13 | 14 | public JoInstruction(CPU cpu) { 15 | super("jo", OPCODE); 16 | this.cpu = cpu; 17 | } 18 | 19 | @Override 20 | public Status execute(Target src, int srcIndex, Status status) { 21 | if (status.isOverflowFlag()) { 22 | cpu.setIp((char) src.get(srcIndex)); 23 | } 24 | return status; 25 | } 26 | 27 | @Override 28 | public Status execute(int src, Status status) { 29 | if (status.isOverflowFlag()) { 30 | cpu.setIp((char) src); 31 | } 32 | return status; 33 | } 34 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JsInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JsInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 26; 11 | 12 | private CPU cpu; 13 | 14 | public JsInstruction(CPU cpu) { 15 | super("js", OPCODE); 16 | 17 | this.cpu = cpu; 18 | } 19 | 20 | @Override 21 | public Status execute(Target src, int srcIndex, Status status) { 22 | if (status.isSignFlag()) { 23 | cpu.setIp((char) src.get(srcIndex)); 24 | } 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | if (status.isSignFlag()) { 31 | cpu.setIp((char) src); 32 | } 33 | return status; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/JzInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | public class JzInstruction extends Instruction { 9 | 10 | /** 11 | * Opcode of the instruction 12 | */ 13 | public static final int OPCODE = 14; 14 | 15 | private CPU cpu; 16 | 17 | public JzInstruction(CPU cpu) { 18 | super("jz", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target src, int srcIndex, Status status) { 25 | if (status.isZeroFlag()) { 26 | cpu.setIp((char) src.get(srcIndex)); 27 | } 28 | return status; 29 | } 30 | 31 | @Override 32 | public Status execute(int src, Status status) { 33 | if (status.isZeroFlag()) { 34 | cpu.setIp((char) src); 35 | } 36 | return status; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/LeaInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | 5 | public class LeaInstruction extends Instruction { 6 | 7 | public static final int OPCODE = 30; 8 | 9 | public LeaInstruction() { 10 | super("lea", OPCODE); 11 | } 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/MovInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | 7 | /** 8 | * The MOV instruction copies data from a source to a destination. 9 | * it overwrites the value in the destination. The destination can be 10 | * memory or register, while the source can be an immediate value, memory 11 | * or register. 12 | *

13 | * The instruction might have unexpected behavior if the an 14 | * operand of type [register + displacement] is used and its sum 15 | * is greater than 0xFFFF (It will overflow) 16 | *

17 | *

18 | * The MOV instruction doesn't change any flags 19 | *

20 | */ 21 | public class MovInstruction extends Instruction { 22 | 23 | public static final int OPCODE = 1; 24 | 25 | public MovInstruction() { 26 | super("mov", OPCODE); 27 | } 28 | 29 | @Override 30 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 31 | 32 | dst.set(dstIndex, src.get(srcIndex)); 33 | 34 | return status; 35 | } 36 | 37 | @Override 38 | public Status execute(Target dst, int dstIndex, int src, Status status) { 39 | 40 | dst.set(dstIndex, src); 41 | 42 | 43 | return status; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/NegInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | 7 | public class NegInstruction extends Instruction { 8 | 9 | public static final int OPCODE = 25; 10 | 11 | public NegInstruction() { 12 | super("neg", OPCODE); 13 | } 14 | 15 | @Override 16 | public Status execute(Target dst, int dstIndex, Status status) { 17 | //If the operand is zero, the carry flag is cleared; in all other cases, the carry flag is set. 18 | 19 | char destination = (char) dst.get(dstIndex); 20 | 21 | if (destination == 0) { 22 | status.setCarryFlag(false); 23 | status.setZeroFlag(true); 24 | } else { 25 | status.setCarryFlag(true); 26 | } 27 | 28 | //Attempting to negate a word containing -32,768 causes no change to the operand and sets the Overflow Flag. 29 | if (destination == 0x8000) { 30 | status.setOverflowFlag(true); 31 | } else { 32 | dst.set(dstIndex, -destination); 33 | } 34 | 35 | return status; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/NopInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | 5 | /** 6 | * NOP (No operation instruction). 7 | * Does nothing 8 | */ 9 | public class NopInstruction extends Instruction { 10 | 11 | public static final int OPCODE = 63; 12 | 13 | public NopInstruction() { 14 | super("nop", OPCODE); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/NotInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | 7 | public class NotInstruction extends Instruction { 8 | 9 | public static final int OPCODE = 29; 10 | 11 | public NotInstruction() { 12 | super("not", OPCODE); 13 | } 14 | 15 | @Override 16 | public Status execute(Target dst, int dstIndex, Status status) { 17 | dst.set(dstIndex, ~dst.get(dstIndex)); 18 | 19 | return status; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/OrInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | public class OrInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 5; 11 | 12 | public OrInstruction() { 13 | super("or", OPCODE); 14 | } 15 | 16 | @Override 17 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 18 | 19 | int a = (char) dst.get(dstIndex); 20 | int b = (char) src.get(srcIndex); 21 | 22 | 23 | int result = (a | b); 24 | 25 | status.setSignFlag(Util.checkSign16(result)); 26 | status.setZeroFlag((char) result == 0); 27 | status.setOverflowFlag(false); 28 | status.setCarryFlag(false); 29 | 30 | dst.set(dstIndex, result); 31 | 32 | return status; 33 | } 34 | 35 | @Override 36 | public Status execute(Target dst, int dstIndex, int src, Status status) { 37 | int a = (char) dst.get(dstIndex); 38 | int b = (char) src; 39 | 40 | 41 | int result = (a | b); 42 | 43 | status.setSignFlag(Util.checkSign16(result)); 44 | status.setZeroFlag((char) result == 0); 45 | status.setOverflowFlag(false); 46 | status.setCarryFlag(false); 47 | 48 | dst.set(dstIndex, result); 49 | 50 | return status; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/PopInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | /** 9 | * Created by simon on 02/06/17. 10 | */ 11 | public class PopInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 20; 14 | 15 | private CPU cpu; 16 | 17 | public PopInstruction(CPU cpu) { 18 | super("pop", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Target dst, int dstIndex, Status status) { 25 | 26 | dst.set(dstIndex, cpu.getMemory().get(cpu.getRegisterSet().getRegister("SP").getValue())); 27 | cpu.getRegisterSet().getRegister("SP").setValue(cpu.getRegisterSet().getRegister("SP").getValue() + 1); //Increment SP (stack grows towards smaller) 28 | 29 | return status; 30 | } 31 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/PopfInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Register; 6 | import net.simon987.server.assembly.Status; 7 | 8 | /** 9 | * Pops a single word off the top of the stack and sets the CPU flags to it. 10 | */ 11 | public class PopfInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 44; 14 | 15 | private CPU cpu; 16 | 17 | public PopfInstruction(CPU cpu) { 18 | super("popf", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Status status) { 25 | 26 | Register sp = cpu.getRegisterSet().getRegister("SP"); 27 | 28 | // Get the word on the top of the stack 29 | char flags = (char) cpu.getMemory().get(sp.getValue()); 30 | 31 | // Overwrite the CPU flags 32 | status.fromByte(flags); 33 | 34 | // Increment SP 35 | sp.setValue(sp.getValue() + 1); 36 | 37 | return status; 38 | } 39 | 40 | public boolean noOperandsValid() { 41 | return true; 42 | } 43 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/PushInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.*; 4 | 5 | public class PushInstruction extends Instruction { 6 | 7 | public static final int OPCODE = 19; 8 | 9 | private CPU cpu; 10 | 11 | public PushInstruction(CPU cpu) { 12 | super("push", OPCODE); 13 | 14 | this.cpu = cpu; 15 | } 16 | 17 | @Override 18 | public Status execute(Target src, int srcIndex, Status status) { 19 | 20 | Register sp = cpu.getRegisterSet().getRegister("SP"); 21 | 22 | sp.setValue(sp.getValue() - 1); //Decrement SP (stack grows towards smaller) 23 | cpu.getMemory().set(sp.getValue(), src.get(srcIndex)); 24 | 25 | return status; 26 | } 27 | 28 | @Override 29 | public Status execute(int src, Status status) { 30 | Register sp = cpu.getRegisterSet().getRegister("SP"); 31 | 32 | sp.setValue(sp.getValue() - 1); //Decrement SP (stack grows towards smaller) 33 | cpu.getMemory().set(sp.getValue(), src); 34 | 35 | return status; 36 | } 37 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/PushfInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Register; 6 | import net.simon987.server.assembly.Status; 7 | 8 | /** 9 | * Pushes the current CPU flags onto the stack. 10 | */ 11 | public class PushfInstruction extends Instruction { 12 | 13 | public static final int OPCODE = 45; 14 | 15 | private CPU cpu; 16 | 17 | public PushfInstruction(CPU cpu) { 18 | super("pushf", OPCODE); 19 | 20 | this.cpu = cpu; 21 | } 22 | 23 | @Override 24 | public Status execute(Status status) { 25 | 26 | // Decrement SP 27 | Register sp = cpu.getRegisterSet().getRegister("SP"); 28 | sp.setValue(sp.getValue() - 1); 29 | 30 | // Push the current flags 31 | cpu.getMemory().set(sp.getValue(), status.toByte()); 32 | 33 | return status; 34 | } 35 | 36 | public boolean noOperandsValid() { 37 | return true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/RetInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | 7 | public class RetInstruction extends Instruction { 8 | 9 | /** 10 | * Opcode of the instruction 11 | */ 12 | public static final int OPCODE = 22; 13 | 14 | private CPU cpu; 15 | 16 | public RetInstruction(CPU cpu) { 17 | super("ret", OPCODE); 18 | 19 | this.cpu = cpu; 20 | } 21 | 22 | @Override 23 | public Status execute(Status status) { 24 | cpu.setIp((char) cpu.getMemory().get(cpu.getRegisterSet().get(7))); //Jmp 25 | cpu.getRegisterSet().set(7, cpu.getRegisterSet().get(7) + 1); //Inc SP 26 | 27 | return status; 28 | } 29 | 30 | @Override 31 | public Status execute(int src, Status status) { 32 | cpu.setIp((char) cpu.getMemory().get(cpu.getRegisterSet().get(7))); //Jmp 33 | cpu.getRegisterSet().set(7, cpu.getRegisterSet().get(7) + src + 1); //Inc SP 34 | 35 | return status; 36 | } 37 | 38 | @Override 39 | public boolean noOperandsValid() { 40 | return true; 41 | } 42 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SalInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * Alias of SHL instruction 5 | */ 6 | public class SalInstruction extends ShlInstruction { 7 | 8 | public SalInstruction() { 9 | super("sal"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetaInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetaInstruction extends SetccInstruction { 7 | 8 | public SetaInstruction() { 9 | super("seta"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetaeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetaeInstruction extends SetccInstruction { 7 | 8 | public SetaeInstruction() { 9 | super("setae"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetbInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetbInstruction extends SetccInstruction { 7 | 8 | public SetbInstruction() { 9 | super("setb"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetbeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetbeInstruction extends SetccInstruction { 7 | 8 | public SetbeInstruction() { 9 | super("setbe"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetcInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetcInstruction extends SetccInstruction { 7 | 8 | public SetcInstruction() { 9 | super("setc"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SeteInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SeteInstruction extends SetccInstruction { 7 | 8 | public SeteInstruction() { 9 | super("sete"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetgInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetgInstruction extends SetccInstruction { 7 | 8 | public SetgInstruction() { 9 | super("setg"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetgeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetgeInstruction extends SetccInstruction { 7 | 8 | public SetgeInstruction() { 9 | super("setge"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetlInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetlInstruction extends SetccInstruction { 7 | 8 | public SetlInstruction() { 9 | super("setl"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetleInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetleInstruction extends SetccInstruction { 7 | 8 | public SetleInstruction() { 9 | super("setle"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnaInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnaInstruction extends SetccInstruction { 7 | 8 | public SetnaInstruction() { 9 | super("setna"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnaeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnaeInstruction extends SetccInstruction { 7 | 8 | public SetnaeInstruction() { 9 | super("setnae"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnbInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnbInstruction extends SetccInstruction { 7 | 8 | public SetnbInstruction() { 9 | super("setnb"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnbeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnbeInstruction extends SetccInstruction { 7 | 8 | public SetnbeInstruction() { 9 | super("setnbe"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetncInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetncInstruction extends SetccInstruction { 7 | 8 | public SetncInstruction() { 9 | super("setnc"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetneInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetneInstruction extends SetccInstruction { 7 | 8 | public SetneInstruction() { 9 | super("setne"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetngInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetngInstruction extends SetccInstruction { 7 | 8 | public SetngInstruction() { 9 | super("setng"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetngeInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetngeInstruction extends SetccInstruction { 7 | 8 | public SetngeInstruction() { 9 | super("setnge"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnlInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnlInstruction extends SetccInstruction { 7 | 8 | public SetnlInstruction() { 9 | super("setnl"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnleInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnleInstruction extends SetccInstruction { 7 | 8 | public SetnleInstruction() { 9 | super("setnle"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnoInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnoInstruction extends SetccInstruction { 7 | 8 | public SetnoInstruction() { 9 | super("setno"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnsInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnsInstruction extends SetccInstruction { 7 | 8 | public SetnsInstruction() { 9 | super("setns"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetnzInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetnzInstruction extends SetccInstruction { 7 | 8 | public SetnzInstruction() { 9 | super("setnz"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetoInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetoInstruction extends SetccInstruction { 7 | 8 | public SetoInstruction() { 9 | super("seto"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetsInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetsInstruction extends SetccInstruction { 7 | 8 | public SetsInstruction() { 9 | super("sets"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SetzInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | /** 4 | * alias of SetccInstruction 5 | */ 6 | public class SetzInstruction extends SetccInstruction { 7 | 8 | public SetzInstruction() { 9 | super("setz"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/SubInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | public class SubInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 3; 11 | 12 | public SubInstruction() { 13 | super("sub", OPCODE); 14 | } 15 | 16 | @Override 17 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 18 | 19 | int a = (char) dst.get(dstIndex); 20 | int b = (char) src.get(srcIndex); 21 | 22 | int result = a - b; 23 | 24 | status.setSignFlag(Util.checkSign16(result)); 25 | status.setZeroFlag((char) result == 0); 26 | status.setOverflowFlag(Util.checkOverFlowSub16(a, b)); 27 | status.setCarryFlag(Util.checkCarry16(result)); 28 | 29 | dst.set(dstIndex, result); 30 | 31 | return status; 32 | } 33 | 34 | @Override 35 | public Status execute(Target dst, int dstIndex, int src, Status status) { 36 | 37 | int a = (char) dst.get(dstIndex); 38 | int b = (char) src; 39 | 40 | int result = a - b; 41 | 42 | status.setSignFlag(Util.checkSign16(result)); 43 | status.setZeroFlag((char) result == 0); 44 | status.setOverflowFlag(Util.checkOverFlowSub16(a, b)); 45 | status.setCarryFlag(Util.checkCarry16(result)); 46 | 47 | dst.set(dstIndex, result); 48 | 49 | return status; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/TestInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | public class TestInstruction extends Instruction { 9 | 10 | public static final int OPCODE = 11; 11 | 12 | public TestInstruction() { 13 | super("test", OPCODE); 14 | } 15 | 16 | @Override 17 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 18 | 19 | int a = (char) dst.get(dstIndex); 20 | int b = (char) src.get(srcIndex); 21 | 22 | int result = (a & b); 23 | 24 | status.setSignFlag(Util.checkSign16(result)); 25 | status.setZeroFlag((char) result == 0); 26 | status.setOverflowFlag(false); 27 | status.setCarryFlag(false); 28 | 29 | return status; 30 | } 31 | 32 | @Override 33 | public Status execute(Target dst, int dstIndex, int src, Status status) { 34 | int a = (char) dst.get(dstIndex); 35 | int b = (char) src; 36 | 37 | 38 | int result = (a & b); 39 | 40 | status.setSignFlag(Util.checkSign16(result)); 41 | status.setZeroFlag((char) result == 0); 42 | status.setOverflowFlag(false); 43 | status.setCarryFlag(false); 44 | 45 | return status; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/XchgInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Instruction; 5 | import net.simon987.server.assembly.Status; 6 | import net.simon987.server.assembly.Target; 7 | 8 | 9 | /** 10 | * Swap operands. Does not alter the flags 11 | */ 12 | public class XchgInstruction extends Instruction { 13 | 14 | public static final int OPCODE = 31; 15 | 16 | private CPU cpu; 17 | 18 | public XchgInstruction(CPU cpu) { 19 | super("xchg", OPCODE); 20 | 21 | this.cpu = cpu; 22 | } 23 | 24 | @Override 25 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 26 | 27 | int tmp = dst.get(dstIndex); 28 | dst.set(dstIndex, src.get(srcIndex)); 29 | src.set(srcIndex, tmp); 30 | 31 | return status; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/assembly/instruction/XorInstruction.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Instruction; 4 | import net.simon987.server.assembly.Status; 5 | import net.simon987.server.assembly.Target; 6 | import net.simon987.server.assembly.Util; 7 | 8 | 9 | public class XorInstruction extends Instruction { 10 | 11 | /** 12 | * Opcode of the instruction 13 | */ 14 | public static final int OPCODE = 38; 15 | 16 | public XorInstruction() { 17 | super("xor", OPCODE); 18 | } 19 | 20 | @Override 21 | public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { 22 | 23 | int a = (char) dst.get(dstIndex); 24 | int b = (char) src.get(srcIndex); 25 | 26 | 27 | int result = (a ^ b); 28 | 29 | status.setSignFlag(Util.checkSign16(result)); 30 | status.setZeroFlag((char) result == 0); 31 | status.setOverflowFlag(false); 32 | status.setCarryFlag(false); 33 | 34 | dst.set(dstIndex, result); 35 | 36 | return status; 37 | } 38 | 39 | @Override 40 | public Status execute(Target dst, int dstIndex, int src, Status status) { 41 | int a = (char) dst.get(dstIndex); 42 | int b = (char) src; 43 | 44 | 45 | int result = (a ^ b); 46 | 47 | status.setSignFlag(Util.checkSign16(result)); 48 | status.setZeroFlag((char) result == 0); 49 | status.setOverflowFlag(false); 50 | status.setCarryFlag(false); 51 | 52 | dst.set(dstIndex, result); 53 | 54 | return status; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/AutokeyCypher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public class AutokeyCypher extends ShiftSubstitutionCypher { 4 | 5 | public AutokeyCypher(String charset){ 6 | super(charset); 7 | } 8 | 9 | public AutokeyCypher(){ 10 | super(); 11 | } 12 | 13 | @Override 14 | protected char encryptionShiftAt(int position, char[] plaintext, char[] key, char[] partialCypherText) { 15 | // if (i < key.length){ 16 | // return key[i]; 17 | // } else { 18 | // return plaintext[i - key.length]; 19 | // } 20 | return 0; 21 | } 22 | 23 | @Override 24 | protected char decryptionShiftAt(int position, char[] cypherText, char[] key, char[] partialPlainText) { 25 | // if (i < key.length){ 26 | // return key[i]; 27 | // } else { 28 | // return partialPlainText[i - key.length]; 29 | // } 30 | return 0; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/CaesarCypher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public class CaesarCypher extends ShiftSubstitutionCypher { 4 | 5 | public CaesarCypher(String charset){ 6 | super(charset); 7 | } 8 | 9 | public CaesarCypher(){ 10 | super(); 11 | } 12 | 13 | /** 14 | * Uses the first character of the key as the shift, and ignores the rest. 15 | */ 16 | @Override 17 | protected char encryptionShiftAt(int position, char[] plaintext, char[] key, char[] partialCypherText) { 18 | return key[0]; 19 | } 20 | 21 | /** 22 | * Uses the first character of the key as the shift, and ignores the rest. 23 | */ 24 | @Override 25 | protected char decryptionShiftAt(int position, char[] cypherText, char[] key, char[] partialPlainText) { 26 | return key[0]; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/CryptoException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | 4 | public class CryptoException extends Exception { 5 | 6 | public CryptoException () { 7 | 8 | } 9 | 10 | public CryptoException (String message) { 11 | super (message); 12 | } 13 | 14 | public CryptoException (Throwable cause) { 15 | super (cause); 16 | } 17 | 18 | public CryptoException (String message, Throwable cause) { 19 | super (message, cause); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/CryptoProvider.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public class CryptoProvider{ 4 | 5 | public static final int NO_CYPHER = 0x0000; 6 | public static final int CAESAR_CYPHER = 0x0001; 7 | public static final int VIGENERE_CYPHER = 0x0002; 8 | public static final int AUTOKEY_CYPHER = 0x0003; 9 | 10 | public static final int PASSWORD_LENGTH = 8; //Same as CubotComPort.MESSAGE_LENGTH 11 | 12 | private String charset; 13 | private RandomStringGenerator passwordGenerator; 14 | 15 | public CryptoProvider(String charset){ 16 | this.charset = charset; 17 | this.passwordGenerator = new RandomStringGenerator(PASSWORD_LENGTH, charset); 18 | } 19 | 20 | public CryptoProvider(){ 21 | this(RandomStringGenerator.ALPHANUMERIC_CHARSET); 22 | } 23 | 24 | public Cypher getCypher(int cypherId){ 25 | switch (cypherId){ 26 | case NO_CYPHER: 27 | return new NoCypher(charset); 28 | case CAESAR_CYPHER: 29 | return new CaesarCypher(charset); 30 | case VIGENERE_CYPHER: 31 | return new VigenereCypher(charset); 32 | case AUTOKEY_CYPHER: 33 | return new AutokeyCypher(charset); 34 | default: 35 | return null; 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/Cypher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public interface Cypher { 4 | 5 | char[] encrypt(char[] plainText, char[] key) throws CryptoException; 6 | 7 | char[] decrypt(char[] cypherText, char[] key) throws CryptoException; 8 | 9 | String textCharset(); 10 | 11 | String keyCharset(); 12 | 13 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/InvalidCharsetException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | 4 | public class InvalidCharsetException extends CryptoException { 5 | 6 | public InvalidCharsetException () { 7 | 8 | } 9 | 10 | public InvalidCharsetException (String message) { 11 | super (message); 12 | } 13 | 14 | public InvalidCharsetException (Throwable cause) { 15 | super (cause); 16 | } 17 | 18 | public InvalidCharsetException (String message, Throwable cause) { 19 | super (message, cause); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/InvalidKeyException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | 4 | public class InvalidKeyException extends CryptoException { 5 | 6 | public InvalidKeyException () { 7 | 8 | } 9 | 10 | public InvalidKeyException (String message) { 11 | super (message); 12 | } 13 | 14 | public InvalidKeyException (Throwable cause) { 15 | super (cause); 16 | } 17 | 18 | public InvalidKeyException (String message, Throwable cause) { 19 | super (message, cause); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/NoCypher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public class NoCypher implements Cypher { 4 | 5 | private String charset; 6 | 7 | public NoCypher(String charset){ 8 | this.charset = charset; 9 | } 10 | 11 | public NoCypher() { 12 | this(RandomStringGenerator.ALPHANUMERIC_CHARSET); 13 | } 14 | 15 | public char[] encrypt(char[] plainText, char[] key) throws InvalidCharsetException { 16 | 17 | char[] cypherText = new char[plainText.length]; 18 | for (int i = 0; i < plainText.length; i++) { 19 | char p = plainText[i]; 20 | int p_ind = charset.indexOf(p); 21 | if (p_ind == -1) { 22 | throw new InvalidCharsetException("Plaintext contains invalid character: " + p); 23 | } 24 | cypherText[i] = p; 25 | } 26 | return cypherText; 27 | } 28 | 29 | 30 | public char[] decrypt(char[] cypherText, char[] key) throws InvalidCharsetException { 31 | 32 | char[] plaintext = new char[cypherText.length]; 33 | 34 | for (int i = 0; i < cypherText.length; i++) { 35 | 36 | char c = cypherText[i]; 37 | int c_ind = charset.indexOf(c); 38 | if (c_ind == -1){ 39 | throw new InvalidCharsetException("CypherText contains invalid character: " + c); 40 | } 41 | plaintext[i] = c; 42 | } 43 | return plaintext; 44 | } 45 | 46 | public String textCharset(){ 47 | return charset; 48 | } 49 | 50 | public String keyCharset(){ 51 | return charset; 52 | } 53 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/SecretKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | import javax.crypto.KeyGenerator; 4 | import javax.crypto.SecretKey; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.security.SecureRandom; 7 | import java.util.Base64; 8 | 9 | public class SecretKeyGenerator { 10 | 11 | private static final String KEY_GENERATION_ALGORITHM = "HmacSHA1"; 12 | private KeyGenerator keyGen; 13 | 14 | public SecretKeyGenerator() { 15 | try { 16 | keyGen = KeyGenerator.getInstance(KEY_GENERATION_ALGORITHM); 17 | } catch (NoSuchAlgorithmException e) { 18 | throw new RuntimeException("Error creating Key generator", e); 19 | } 20 | keyGen.init(new SecureRandom(SecureRandom.getSeed(32))); 21 | } 22 | 23 | public String generate() { 24 | SecretKey secretKey = keyGen.generateKey(); 25 | return Base64.getEncoder().encodeToString(secretKey.getEncoded()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/crypto/VigenereCypher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.crypto; 2 | 3 | public class VigenereCypher extends ShiftSubstitutionCypher { 4 | 5 | public VigenereCypher(String charset){ 6 | super(charset); 7 | } 8 | 9 | public VigenereCypher(){ 10 | super(); 11 | } 12 | 13 | @Override 14 | protected char encryptionShiftAt(int position, char[] plaintext, char[] key, char[] partialCypherText) { 15 | // int j = i % key.length; 16 | // return key[j]; 17 | 18 | return 0; 19 | } 20 | 21 | @Override 22 | protected char decryptionShiftAt(int position, char[] cypherText, char[] key, char[] partialPlainText) { 23 | // int j = i % key.length; 24 | // return key[j]; 25 | 26 | return 0; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/CpuInitialisationEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.game.objects.ControllableUnit; 5 | 6 | public class CpuInitialisationEvent extends GameEvent { 7 | 8 | private ControllableUnit unit; 9 | 10 | public CpuInitialisationEvent(CPU cpu, ControllableUnit unit) { 11 | setSource(cpu); 12 | this.unit = unit; 13 | } 14 | 15 | public ControllableUnit getUnit() { 16 | return unit; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/DebugCommandEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.websocket.OnlineUser; 4 | import org.bson.types.ObjectId; 5 | import org.json.simple.JSONObject; 6 | 7 | import java.io.IOException; 8 | 9 | public class DebugCommandEvent extends GameEvent { 10 | 11 | private JSONObject command; 12 | 13 | public DebugCommandEvent(JSONObject json, OnlineUser user) { 14 | this.command = json; 15 | this.setSource(user); 16 | } 17 | 18 | public String getName() { 19 | return (String) command.get("command"); 20 | } 21 | 22 | public String getString(String key) { 23 | return (String) command.get(key); 24 | } 25 | 26 | public int getInt(String key) { 27 | return (int) (long) command.get(key); 28 | } 29 | 30 | public long getLong(String key) { 31 | return (long) command.get(key); 32 | } 33 | 34 | public ObjectId getObjectId(String key) { 35 | return new ObjectId((String) command.get(key)); 36 | } 37 | 38 | /** 39 | * Send back a response to the command issuer 40 | */ 41 | public void reply(String message) { 42 | 43 | JSONObject response = new JSONObject(); 44 | response.put("t", "debug"); 45 | response.put("message", message); 46 | 47 | try { 48 | ((OnlineUser) getSource()).getWebSocket().getRemote().sendString(response.toJSONString()); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/GameEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | 4 | public class GameEvent { 5 | 6 | /** 7 | * If the event is cancelled the action won't be performed 8 | */ 9 | private boolean cancelled = false; 10 | 11 | /** 12 | * The game object that triggered the event 13 | */ 14 | private Object source; 15 | 16 | 17 | //---------------------------- 18 | public boolean isCancelled() { 19 | return cancelled; 20 | } 21 | 22 | public void setCancelled(boolean cancelled) { 23 | this.cancelled = cancelled; 24 | } 25 | 26 | public Object getSource() { 27 | return source; 28 | } 29 | 30 | public void setSource(Object source) { 31 | this.source = source; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/GameEventDispatcher.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.plugin.PluginManager; 4 | import net.simon987.server.plugin.ServerPlugin; 5 | 6 | import java.util.ArrayList; 7 | 8 | 9 | public class GameEventDispatcher { 10 | 11 | private PluginManager pluginManager; 12 | 13 | private ArrayList listeners; 14 | 15 | public GameEventDispatcher(PluginManager pluginManager) { 16 | this.pluginManager = pluginManager; 17 | listeners = new ArrayList<>(5); 18 | } 19 | 20 | public void dispatch(GameEvent event) { 21 | 22 | //Dispatch to 'local' listeners 23 | for (GameEventListener listener : listeners) { 24 | if (event.getClass().equals(listener.getListenedEventType())) { 25 | listener.handle(event); 26 | } 27 | } 28 | 29 | //Dispatch to plugins 30 | for (ServerPlugin plugin : pluginManager.getPlugins()) { 31 | for (GameEventListener listener : plugin.getListeners()) { 32 | if (event.getClass().equals(listener.getListenedEventType())) { 33 | listener.handle(event); 34 | } 35 | } 36 | } 37 | 38 | } 39 | 40 | public ArrayList getListeners() { 41 | return listeners; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/GameEventListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | /** 4 | * Listens for and handles a single type of event 5 | */ 6 | public interface GameEventListener { 7 | 8 | Class getListenedEventType(); 9 | 10 | void handle(GameEvent event); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/ObjectDeathEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | /** 4 | * Event dispatched by a GameObject who has needed callbacks on death 5 | */ 6 | public class ObjectDeathEvent extends GameEvent { 7 | 8 | public ObjectDeathEvent(Object source) { 9 | setSource(source); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/TickEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | public class TickEvent extends GameEvent { 4 | 5 | long time; 6 | 7 | public TickEvent(long time) { 8 | this.time = time; 9 | } 10 | 11 | public long getTime() { 12 | return time; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/UserCreationEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.user.User; 4 | 5 | public class UserCreationEvent extends GameEvent { 6 | 7 | public UserCreationEvent(User user) { 8 | setSource(user); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/WorldGenerationEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.game.world.World; 4 | 5 | public class WorldGenerationEvent extends GameEvent { 6 | 7 | public WorldGenerationEvent(World world) { 8 | setSource(world); 9 | } 10 | 11 | public World getWorld() { 12 | return (World) getSource(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/event/WorldUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.event; 2 | 3 | import net.simon987.server.game.world.World; 4 | 5 | public class WorldUpdateEvent extends GameEvent { 6 | 7 | private World world; 8 | 9 | public WorldUpdateEvent(World world) { 10 | this.world = world; 11 | } 12 | 13 | public World getWorld() { 14 | return world; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/ComPortMsgCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.GameObject; 8 | import net.simon987.server.game.objects.MessageReceiver; 9 | import org.bson.types.ObjectId; 10 | 11 | public class ComPortMsgCommandListener implements GameEventListener { 12 | 13 | @Override 14 | public Class getListenedEventType() { 15 | return DebugCommandEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | DebugCommandEvent e = (DebugCommandEvent) event; 22 | 23 | if (e.getName().equals("comPortMsg")) { 24 | 25 | ObjectId objectId = e.getObjectId("objectId"); 26 | 27 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(objectId); 28 | 29 | if (object != null) { 30 | 31 | if (object instanceof MessageReceiver) { 32 | 33 | e.reply("Result: " + ((MessageReceiver) object).sendMessage(e.getString("message").toCharArray())); 34 | 35 | } else { 36 | e.reply("Object " + objectId + " not MessageReceiver"); 37 | } 38 | 39 | } else { 40 | e.reply("Object " + objectId + " not found"); 41 | } 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/CreateWorldCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.world.World; 8 | 9 | public class CreateWorldCommandListener implements GameEventListener { 10 | 11 | @Override 12 | public Class getListenedEventType() { 13 | return DebugCommandEvent.class; 14 | } 15 | 16 | @Override 17 | public void handle(GameEvent event) { 18 | 19 | DebugCommandEvent e = (DebugCommandEvent) event; 20 | 21 | if (e.getName().equals("createWorld")) { 22 | 23 | World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"), 24 | true, e.getString("dimension")); 25 | 26 | if (world != null) { 27 | 28 | e.reply("Success"); 29 | 30 | } else { 31 | e.reply("Couldn't create world"); 32 | } 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/DamageObjCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.Attackable; 8 | import net.simon987.server.game.objects.GameObject; 9 | 10 | 11 | public class DamageObjCommandListener implements GameEventListener { 12 | 13 | @Override 14 | public Class getListenedEventType() { 15 | return DebugCommandEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | DebugCommandEvent e = (DebugCommandEvent) event; 22 | 23 | if (e.getName().equals("damageObj")) { 24 | 25 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId")); 26 | 27 | if (object != null) { 28 | 29 | if (object instanceof Attackable) { 30 | 31 | int oldHp = ((Attackable) object).getHp(); 32 | int maxHp = ((Attackable) object).getMaxHp(); 33 | ((Attackable) object).damage(e.getInt("amount")); 34 | 35 | e.reply("Success: " + oldHp + "/" + maxHp + " -> " + ((Attackable) object).getHp() + "/" + maxHp); 36 | } else { 37 | e.reply("Object is not Attackable"); 38 | } 39 | 40 | } else { 41 | e.reply("Object not found: " + e.getLong("objectId")); 42 | } 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/HealObjCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.Attackable; 8 | import net.simon987.server.game.objects.GameObject; 9 | 10 | 11 | public class HealObjCommandListener implements GameEventListener { 12 | 13 | @Override 14 | public Class getListenedEventType() { 15 | return DebugCommandEvent.class; 16 | } 17 | 18 | @Override 19 | public void handle(GameEvent event) { 20 | 21 | DebugCommandEvent e = (DebugCommandEvent) event; 22 | 23 | if (e.getName().equals("healObj")) { 24 | 25 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId")); 26 | 27 | if (object != null) { 28 | 29 | if (object instanceof Attackable) { 30 | 31 | int oldHp = ((Attackable) object).getHp(); 32 | int maxHp = ((Attackable) object).getMaxHp(); 33 | ((Attackable) object).heal(e.getInt("amount")); 34 | 35 | e.reply("Success: " + oldHp + "/" + maxHp + " -> " + ((Attackable) object).getHp() + "/" + maxHp); 36 | } else { 37 | e.reply("Object is not Attackable"); 38 | } 39 | 40 | } else { 41 | e.reply("Object not found: " + e.getLong("objectId")); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/KillAllCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.GameObject; 8 | import net.simon987.server.game.world.World; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | 13 | public class KillAllCommandListener implements GameEventListener { 14 | 15 | @Override 16 | public Class getListenedEventType() { 17 | return DebugCommandEvent.class; 18 | } 19 | 20 | @Override 21 | public void handle(GameEvent event) { 22 | 23 | DebugCommandEvent e = (DebugCommandEvent) event; 24 | 25 | if (e.getName().equals("killAll")) { 26 | 27 | World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"), 28 | false, e.getString("dimension")); 29 | 30 | try { 31 | 32 | ArrayList objs = world.getGameObjectsAt(e.getInt("x"), e.getInt("y")); 33 | 34 | for (GameObject o : objs) { 35 | o.setDead(true); 36 | } 37 | 38 | } catch (Exception ex) { 39 | String message = ex.getMessage(); 40 | message += "\n " + Arrays.toString(ex.getStackTrace()).replaceAll(", ", "\n"); 41 | e.reply(message); 42 | } 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/MoveObjCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.GameObject; 8 | 9 | public class MoveObjCommandListener implements GameEventListener { 10 | 11 | @Override 12 | public Class getListenedEventType() { 13 | return DebugCommandEvent.class; 14 | } 15 | 16 | @Override 17 | public void handle(GameEvent event) { 18 | 19 | DebugCommandEvent e = (DebugCommandEvent) event; 20 | 21 | if (e.getName().equals("moveObj")) { 22 | 23 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId")); 24 | 25 | if (object != null) { 26 | 27 | object.setX(e.getInt("x")); 28 | object.setY(e.getInt("y")); 29 | 30 | e.reply("Success"); 31 | } else { 32 | e.reply("Object not found: " + e.getLong("objectId")); 33 | } 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/SaveGameCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | 8 | public class SaveGameCommandListener implements GameEventListener { 9 | 10 | @Override 11 | public Class getListenedEventType() { 12 | return DebugCommandEvent.class; 13 | } 14 | 15 | @Override 16 | public void handle(GameEvent event) { 17 | 18 | DebugCommandEvent e = (DebugCommandEvent) event; 19 | 20 | if (e.getName().equals("saveGame")) { 21 | 22 | GameServer.INSTANCE.save(); 23 | e.reply("Saved the game"); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/SetEnergyCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.GameObject; 8 | import net.simon987.server.game.objects.Rechargeable; 9 | 10 | public class SetEnergyCommandListener implements GameEventListener { 11 | 12 | @Override 13 | public Class getListenedEventType() { 14 | return DebugCommandEvent.class; 15 | } 16 | 17 | @Override 18 | public void handle(GameEvent event) { 19 | 20 | DebugCommandEvent e = (DebugCommandEvent) event; 21 | 22 | if (e.getName().equals("setEnergy")) { 23 | 24 | GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId")); 25 | 26 | if (object != null) { 27 | 28 | if (object instanceof Rechargeable) { 29 | 30 | int oldEnergy = ((Rechargeable) object).getEnergy(); 31 | ((Rechargeable) object).setEnergy(e.getInt("amount")); 32 | 33 | e.reply("Success: " + oldEnergy + " -> " + e.getInt("amount")); 34 | } else { 35 | e.reply("Object is not Rechargeable"); 36 | } 37 | 38 | } else { 39 | e.reply("Object not found: " + e.getLong("objectId")); 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/SetTileAtCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.world.World; 8 | 9 | public class SetTileAtCommandListener implements GameEventListener { 10 | 11 | @Override 12 | public Class getListenedEventType() { 13 | return DebugCommandEvent.class; 14 | } 15 | 16 | @Override 17 | public void handle(GameEvent event) { 18 | 19 | DebugCommandEvent e = (DebugCommandEvent) event; 20 | 21 | if (e.getName().equals("setTileAt")) { 22 | 23 | World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"), 24 | false, e.getString("dimension")); 25 | 26 | if (world != null) { 27 | 28 | world.getTileMap().setTileAt(e.getInt("newTile"), e.getInt("x"), e.getInt("y")); 29 | e.reply("Success"); 30 | 31 | } else { 32 | e.reply("Error: World is uncharted"); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/debug/UserInfoCommandListener.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.debug; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import net.simon987.server.event.GameEvent; 6 | import net.simon987.server.event.GameEventListener; 7 | import net.simon987.server.game.objects.ControllableUnit; 8 | import net.simon987.server.user.User; 9 | 10 | public class UserInfoCommandListener implements GameEventListener { 11 | 12 | @Override 13 | public Class getListenedEventType() { 14 | return DebugCommandEvent.class; 15 | } 16 | 17 | @Override 18 | public void handle(GameEvent event) { 19 | 20 | DebugCommandEvent e = (DebugCommandEvent) event; 21 | 22 | if (e.getName().equals("userInfo")) { 23 | 24 | User user = GameServer.INSTANCE.getGameUniverse().getUser(e.getString("username")); 25 | 26 | if (user != null) { 27 | 28 | String message = "Showing information for user " + e.getString("username") + "\n"; 29 | 30 | message += "isGuest: " + user.isGuest() + "\n"; 31 | 32 | ControllableUnit unit = user.getControlledUnit(); 33 | message += "ControlledUnit: " + unit.getObjectId() + " at (" + unit.getX() + ", " + unit.getY() + ")\n"; 34 | 35 | message += "CPU:" + user.getControlledUnit().getCpu() + "\n"; 36 | message += "Code: " + user.getUserCode(); 37 | 38 | e.reply(message); 39 | 40 | 41 | } else { 42 | e.reply("User not found"); 43 | } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/item/ItemCopper.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.item; 2 | 3 | 4 | import org.bson.Document; 5 | 6 | public class ItemCopper extends Item { 7 | 8 | public static final int ID = 0x0004; 9 | 10 | @Override 11 | public int getId() { 12 | return ID; 13 | } 14 | 15 | public ItemCopper() { 16 | super(null); 17 | } 18 | 19 | public ItemCopper(Document document) { 20 | super(document); 21 | } 22 | 23 | @Override 24 | public char poll() { 25 | return ID; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/item/ItemIron.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.item; 2 | 3 | import org.bson.Document; 4 | 5 | public class ItemIron extends Item { 6 | 7 | public static final int ID = 0x0003; 8 | 9 | @Override 10 | public int getId() { 11 | return ID; 12 | } 13 | 14 | public ItemIron() { 15 | super(null); 16 | } 17 | 18 | public ItemIron(Document document) { 19 | super(document); 20 | } 21 | 22 | @Override 23 | public char poll() { 24 | return ID; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/item/ItemVoid.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.item; 2 | 3 | /** 4 | * Invalid/empty item 5 | */ 6 | public class ItemVoid extends Item { 7 | 8 | public ItemVoid() { 9 | super(null); 10 | } 11 | 12 | @Override 13 | public char poll() { 14 | return 0; 15 | } 16 | 17 | @Override 18 | public int getId() { 19 | return 0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Action.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | public enum Action { 4 | IDLE, 5 | DIGGING, 6 | WALKING, 7 | WITHDRAWING, 8 | DEPOSITING, 9 | LISTENING, 10 | _PLACEHOLDER_, 11 | ATTACKING, 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Attackable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | /** 4 | * Objects that can be attacked or healed 5 | */ 6 | public interface Attackable { 7 | 8 | void setHealRate(int hp); 9 | 10 | int getHp(); 11 | 12 | void setHp(int hp); 13 | 14 | int getMaxHp(); 15 | 16 | void setMaxHp(int hp); 17 | 18 | void heal(int amount); 19 | 20 | void damage(int amount); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/ControllableUnit.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | import net.simon987.server.assembly.CPU; 4 | import net.simon987.server.assembly.Memory; 5 | import net.simon987.server.game.item.Item; 6 | import net.simon987.server.game.world.World; 7 | import net.simon987.server.user.User; 8 | import org.bson.types.ObjectId; 9 | 10 | import java.awt.*; 11 | import java.util.ArrayList; 12 | 13 | public interface ControllableUnit extends MessageReceiver, Rechargeable, Attackable, HardwareHost { 14 | 15 | ObjectId getObjectId(); 16 | 17 | void setKeyboardBuffer(ArrayList kbBuffer); 18 | 19 | void setParent(User user); 20 | 21 | User getParent(); 22 | 23 | ArrayList getKeyboardBuffer(); 24 | 25 | Memory getFloppyData(); 26 | 27 | boolean spendEnergy(int energy); 28 | 29 | int getEnergy(); 30 | 31 | int getX(); 32 | 33 | int getY(); 34 | 35 | void setAction(Action action); 36 | 37 | void setCurrentAction(Action action); 38 | 39 | Action getCurrentAction(); 40 | 41 | World getWorld(); 42 | 43 | ArrayList getConsoleMessagesBuffer(); 44 | 45 | int getConsoleMode(); 46 | 47 | CPU getCpu(); 48 | 49 | void giveItem(Item item); 50 | 51 | Point getFrontTile(); 52 | 53 | void setDirection(Direction direction); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Enterable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | public interface Enterable { 4 | 5 | /** 6 | * Called when an object attempts to walk directly into a Enterable object 7 | * 8 | * @param object The game object that attempted to enter 9 | * @return true if successful, false to block the object 10 | */ 11 | boolean enter(GameObject object); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/HardwareHost.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | import net.simon987.server.assembly.HardwareModule; 4 | import net.simon987.server.assembly.Status; 5 | 6 | public interface HardwareHost { 7 | 8 | void attachHardware(HardwareModule hardware, int address); 9 | 10 | void detachHardware(int address); 11 | 12 | boolean hardwareInterrupt(int address, Status status); 13 | 14 | int hardwareQuery(int address); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/InventoryHolder.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | 4 | import net.simon987.server.game.item.Item; 5 | 6 | public interface InventoryHolder { 7 | 8 | /** 9 | * Place an item into the inventory 10 | */ 11 | boolean placeItem(Item item); 12 | 13 | /** 14 | * Take an item from the inventory 15 | */ 16 | void takeItem(int itemId); 17 | 18 | /** 19 | * @param itemId id of the item 20 | * @return true if the InventoryHolder can provide this item 21 | */ 22 | boolean canTakeItem(int itemId); 23 | } 24 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/MessageReceiver.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | public interface MessageReceiver { 4 | 5 | boolean sendMessage(char[] message); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Radioactive.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | //Alpha: ±5cm 4 | //Beta: 10-20 feet 5 | //Gamma: 100+ feet 6 | 7 | public interface Radioactive { 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Rechargeable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | public interface Rechargeable { 4 | 5 | int getEnergy(); 6 | 7 | void setEnergy(int energy); 8 | 9 | boolean spendEnergy(int spent); 10 | 11 | void storeEnergy(int amount); 12 | 13 | void setMaxEnergy(int maxEnergy); 14 | 15 | int getMaxEnergy(); 16 | } 17 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/objects/Updatable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.objects; 2 | 3 | /** 4 | * Updatable objects needs to be updated each tick 5 | */ 6 | public interface Updatable { 7 | 8 | /** 9 | * Called every tick 10 | */ 11 | void update(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/pathfinding/Node.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.pathfinding; 2 | 3 | /** 4 | * A single node in the search graph 5 | *

6 | * Inspired by http://www.cokeandcode.com/main/tutorials/path-finding/ 7 | */ 8 | public class Node implements Comparable { 9 | 10 | /** 11 | * x coordinate of the node 12 | */ 13 | public int x; 14 | 15 | /** 16 | * y coordinate of the node 17 | */ 18 | public int y; 19 | 20 | /** 21 | * Cost of getting from the start node to this node 22 | */ 23 | public int gScore; 24 | 25 | /** 26 | * Total cost of getting from the start node to the goal 27 | */ 28 | public int fScore; 29 | 30 | /** 31 | * Parent of the node 32 | */ 33 | public Node parent; 34 | 35 | 36 | /** 37 | * Create a new Node 38 | * 39 | * @param x X coordinate of the node 40 | * @param y Y coordinate of the node 41 | */ 42 | public Node(int x, int y) { 43 | this.x = x; 44 | this.y = y; 45 | 46 | gScore = Integer.MAX_VALUE; 47 | fScore = Integer.MAX_VALUE; 48 | } 49 | 50 | /** 51 | * Compare two Nodes using their fScore 52 | */ 53 | @Override 54 | public int compareTo(Object o) { 55 | Node other = (Node) o; 56 | 57 | return Integer.compare(fScore, other.fScore); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "(" + this.x + ", " + this.y + ")"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/pathfinding/SortedArrayList.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.pathfinding; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | /** 7 | * Wrapper of ArrayList to make it sorted 8 | *

9 | * inspired by http://www.cokeandcode.com/main/tutorials/path-finding/ 10 | */ 11 | public class SortedArrayList extends ArrayList { 12 | 13 | /** 14 | * Get the first element from the list 15 | * 16 | * @return element at index 0 17 | */ 18 | Node first() { 19 | return get(0); 20 | } 21 | 22 | 23 | /** 24 | * Add an node to the list and sort it 25 | * 26 | * @param node node to add 27 | * @return always return true 28 | */ 29 | @Override 30 | public boolean add(Node node) { 31 | super.add(node); 32 | Collections.sort(this); 33 | 34 | return true; //Return value ignored 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/DayNightCycle.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.event.GameEvent; 4 | import net.simon987.server.event.GameEventListener; 5 | import net.simon987.server.event.TickEvent; 6 | 7 | public class DayNightCycle implements GameEventListener { 8 | 9 | /** 10 | * Length of an hour in ticks 11 | */ 12 | private static final int HOUR_LENGTH = 16; 13 | 14 | //Current time of the day (0-23) 15 | private int currentDayTime; 16 | 17 | //Current light intensity (0-10) 18 | private int sunIntensity; 19 | 20 | @Override 21 | public Class getListenedEventType() { 22 | return TickEvent.class; 23 | } 24 | 25 | @Override 26 | public void handle(GameEvent event) { 27 | 28 | currentDayTime = (int) ((TickEvent) event).getTime() / HOUR_LENGTH % 24; 29 | 30 | // -0.25x² + 6x - 27 with a minimum of 1 31 | sunIntensity = Math.max((int) Math.round((-(0.25 * currentDayTime * currentDayTime) + (6 * currentDayTime) - 27)), 0) + 1; 32 | } 33 | 34 | public int getCurrentDayTime() { 35 | return currentDayTime; 36 | } 37 | 38 | public int getSunIntensity() { 39 | return sunIntensity; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/Location.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | /** 4 | * Represents a location in the game universe 5 | */ 6 | public class Location { 7 | 8 | public int worldX; 9 | public int worldY; 10 | 11 | public String dimension; 12 | 13 | public int x; 14 | public int y; 15 | 16 | public Location(int worldX, int worldY, String dimension, int x, int y) { 17 | this.worldX = worldX; 18 | this.worldY = worldY; 19 | this.dimension = dimension; 20 | this.x = x; 21 | this.y = y; 22 | } 23 | 24 | public String getWorldId() { 25 | return World.idFromCoordinates(worldX, worldY, dimension); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/Tile.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.item.Item; 4 | import net.simon987.server.game.objects.GameObject; 5 | 6 | public abstract class Tile { 7 | 8 | /** 9 | * @return Unique id of the tile 10 | */ 11 | public abstract int getId(); 12 | 13 | /** 14 | * Called when an object attempts to drill this tile 15 | * 16 | * @return The item obtained by drilling, return null for no item 17 | */ 18 | public Item drill() { 19 | return null; 20 | } 21 | 22 | /** 23 | * Called when a player attempts to walk on this tile 24 | * 25 | * @return true if the object can walk on this tile, false if blocked 26 | */ 27 | public boolean walk(GameObject object) { 28 | return true; 29 | } 30 | 31 | /** 32 | * Check if a tile should be considered 'blocked' (by the LiDAR, for example) 33 | */ 34 | public boolean isBlocked() { 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TileCopper.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.item.Item; 4 | import net.simon987.server.game.item.ItemCopper; 5 | 6 | public class TileCopper extends Tile { 7 | 8 | public static final int ID = 3; 9 | 10 | @Override 11 | public int getId() { 12 | return ID; 13 | } 14 | 15 | @Override 16 | public Item drill() { 17 | return new ItemCopper(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TileFluid.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.item.Item; 4 | import net.simon987.server.game.objects.GameObject; 5 | 6 | public class TileFluid extends Tile { 7 | 8 | public static final int ID = 6; 9 | 10 | @Override 11 | public int getId() { 12 | return 6; 13 | } 14 | 15 | @Override 16 | public Item drill() { 17 | return null; 18 | } 19 | 20 | @Override 21 | public boolean walk(GameObject object) { 22 | object.setDead(true); 23 | return false; 24 | } 25 | 26 | @Override 27 | public boolean isBlocked() { 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TileIron.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.item.Item; 4 | import net.simon987.server.game.item.ItemIron; 5 | 6 | public class TileIron extends Tile { 7 | 8 | public static final int ID = 2; 9 | 10 | @Override 11 | public int getId() { 12 | return ID; 13 | } 14 | 15 | @Override 16 | public Item drill() { 17 | return new ItemIron(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TilePlain.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | public class TilePlain extends Tile { 4 | 5 | public static final int ID = 0; 6 | 7 | @Override 8 | public int getId() { 9 | return ID; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TileVoid.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.objects.GameObject; 4 | 5 | public class TileVoid extends Tile { 6 | 7 | public static final int ID = -1; 8 | 9 | @Override 10 | public int getId() { 11 | return ID; 12 | } 13 | 14 | @Override 15 | public boolean walk(GameObject object) { 16 | return false; //Shouldn't happen! 17 | } 18 | 19 | @Override 20 | public boolean isBlocked() { 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/TileWall.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | import net.simon987.server.game.objects.GameObject; 4 | 5 | public class TileWall extends Tile { 6 | 7 | public static final int ID = 1; 8 | 9 | @Override 10 | public int getId() { 11 | return ID; 12 | } 13 | 14 | @Override 15 | public boolean walk(GameObject object) { 16 | return false; //always blocked 17 | } 18 | 19 | @Override 20 | public boolean isBlocked() { 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/game/world/WorldGenerationException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.game.world; 2 | 3 | public class WorldGenerationException extends Exception { 4 | public WorldGenerationException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/io/JSONSerializable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.io; 2 | 3 | import org.json.simple.JSONObject; 4 | 5 | public interface JSONSerializable { 6 | 7 | JSONObject jsonSerialise(); 8 | 9 | JSONObject debugJsonSerialise(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/io/MongoSerializable.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.io; 2 | 3 | import org.bson.Document; 4 | 5 | public interface MongoSerializable { 6 | 7 | Document mongoSerialise(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/logging/GenericFormatter.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.logging; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.logging.Formatter; 6 | import java.util.logging.LogRecord; 7 | 8 | /** 9 | * Generic formatter for the game logging 10 | */ 11 | public class GenericFormatter extends Formatter { 12 | 13 | @Override 14 | public String format(LogRecord record) { 15 | 16 | StringBuilder sb = new StringBuilder(); 17 | 18 | //Regular record 19 | Date date = new Date(); 20 | SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss:SSS"); //ex. 11/25 22:03:59:010 21 | 22 | sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage())); 23 | sb.append('\n'); 24 | 25 | 26 | return sb.toString(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/user/RegistrationException.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.user; 2 | 3 | public class RegistrationException extends Exception { 4 | 5 | public RegistrationException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/AccountPage.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import spark.ModelAndView; 5 | import spark.Request; 6 | import spark.Response; 7 | import spark.TemplateViewRoute; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class AccountPage implements TemplateViewRoute { 13 | @Override 14 | public ModelAndView handle(Request request, Response response) { 15 | Map model = new HashMap<>(); 16 | model.put("session", request.session()); 17 | 18 | 19 | if (request.session().attribute("username") != null) { 20 | model.put("user", GameServer.INSTANCE.getGameUniverse().getUser(request.session().attribute("username"))); 21 | } 22 | 23 | return new ModelAndView(model, "account.vm"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/AlertMessage.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | public class AlertMessage { 4 | 5 | private String message; 6 | private AlertType type; 7 | 8 | public AlertMessage(String message, AlertType type) { 9 | this.message = message; 10 | this.type = type; 11 | } 12 | 13 | public String getMessage() { 14 | return message; 15 | } 16 | 17 | public AlertType getType() { 18 | return type; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/AlertType.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | public enum AlertType { 4 | 5 | SUCCESS("alert-success"), 6 | INFO("alert-info"), 7 | WARNING("alert-info"), 8 | DANGER("alert-danger"), 9 | PRIMARY("alert-primary"), 10 | SECONDARY("alert-secondary"), 11 | DARK("alert-dark"); 12 | 13 | public String name; 14 | 15 | AlertType(String name) { 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return name; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/FloppyDownloadRoute.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.logging.LogManager; 5 | import spark.Request; 6 | import spark.Response; 7 | import spark.Route; 8 | 9 | public class FloppyDownloadRoute implements Route { 10 | 11 | @Override 12 | public Object handle(Request request, Response response) { 13 | 14 | String username = request.session().attribute("username"); 15 | 16 | if (username != null) { 17 | 18 | response.header("Content-Type", "application/octet-stream"); 19 | response.header("Content-Disposition", "filename=\"floppy.bin\""); 20 | 21 | try { 22 | return GameServer.INSTANCE.getGameUniverse().getUser(username).getControlledUnit().getFloppyData().getBytes(); 23 | } catch (Exception e) { 24 | String message = "Encountered exception while reading floppy data: " + e.getMessage(); 25 | 26 | LogManager.LOGGER.severe(message); 27 | return message; 28 | } 29 | 30 | } else { 31 | response.status(403); 32 | return "Not logged in"; 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/GuestPolicy.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | public enum GuestPolicy { 4 | /** 5 | * Allow guests, must login to have Cubot 6 | */ 7 | ALLOW, 8 | /** 9 | * Block guests completely 10 | */ 11 | BLOCK, 12 | } 13 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/HomePage.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import spark.ModelAndView; 4 | import spark.Request; 5 | import spark.Response; 6 | import spark.TemplateViewRoute; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public class HomePage implements TemplateViewRoute { 12 | 13 | @Override 14 | public ModelAndView handle(Request request, Response response) throws Exception { 15 | 16 | Map model = new HashMap<>(1); 17 | model.put("session", request.session()); 18 | 19 | return new ModelAndView(model, "home.vm"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/LeaderBoardPage.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import spark.ModelAndView; 5 | import spark.Request; 6 | import spark.Response; 7 | import spark.TemplateViewRoute; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | 13 | public class LeaderBoardPage implements TemplateViewRoute { 14 | 15 | @Override 16 | public ModelAndView handle(Request request, Response response) { 17 | Map model = new HashMap<>(2); 18 | model.put("session", request.session()); 19 | model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getLeaderboardStats(25)); 20 | return new ModelAndView(model, "leaderboard.vm"); 21 | } 22 | } -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/LoginRoute.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.logging.LogManager; 5 | import spark.ModelAndView; 6 | import spark.Request; 7 | import spark.Response; 8 | import spark.Route; 9 | 10 | public class LoginRoute implements Route { 11 | @Override 12 | public ModelAndView handle(Request request, Response response) { 13 | String username = request.queryParams("username"); 14 | String password = request.queryParams("password"); 15 | 16 | if (username != null && password != null) { 17 | if (GameServer.INSTANCE.getUserManager().validateUser(username, password)) { 18 | AlertMessage[] messages = {new AlertMessage("Logged in as " + username, AlertType.SUCCESS)}; 19 | request.session().attribute("messages", messages); 20 | request.session().attribute("username", username); 21 | 22 | LogManager.LOGGER.fine("(Web) " + username + " logged in"); 23 | } else { 24 | AlertMessage[] messages = {new AlertMessage("Invalid username or password", AlertType.DANGER)}; 25 | request.session().attribute("messages", messages); 26 | } 27 | } 28 | 29 | response.redirect("/account"); 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/LogoutRoute.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import spark.ModelAndView; 4 | import spark.Request; 5 | import spark.Response; 6 | import spark.Route; 7 | 8 | public class LogoutRoute implements Route { 9 | @Override 10 | public ModelAndView handle(Request request, Response response) { 11 | AlertMessage[] messages = {new AlertMessage("Logged out", AlertType.INFO)}; 12 | request.session().attribute("messages", messages); 13 | request.session().removeAttribute("username"); 14 | 15 | response.redirect("/account"); 16 | return null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/PlayPage.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import spark.ModelAndView; 5 | import spark.Request; 6 | import spark.Response; 7 | import spark.TemplateViewRoute; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | public class PlayPage implements TemplateViewRoute { 13 | 14 | @Override 15 | public ModelAndView handle(Request request, Response response) { 16 | 17 | String autoLogin = GameServer.INSTANCE.getConfig().getString("autologin"); 18 | if (autoLogin != null && !autoLogin.equals("")) { 19 | AlertMessage[] messages = {new AlertMessage("Logged in as " + autoLogin, AlertType.SUCCESS)}; 20 | request.session().attribute("messages", messages); 21 | request.session().attribute("username", autoLogin); 22 | } 23 | 24 | Map model = new HashMap<>(1); 25 | model.put("session", request.session()); 26 | model.put("gamePageTitle", GameServer.INSTANCE.getConfig().getString("server_name")); 27 | 28 | return new ModelAndView(model, "play.vm"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/web/RegisterRoute.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.web; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.logging.LogManager; 5 | import net.simon987.server.user.RegistrationException; 6 | import spark.ModelAndView; 7 | import spark.Request; 8 | import spark.Response; 9 | import spark.Route; 10 | 11 | public class RegisterRoute implements Route { 12 | 13 | @Override 14 | public ModelAndView handle(Request request, Response response) { 15 | String username = request.queryParams("username"); 16 | String password = request.queryParams("password"); 17 | 18 | if (username != null && password != null) { 19 | try { 20 | GameServer.INSTANCE.getUserManager().registerUser(username, password); 21 | 22 | AlertMessage[] messages = {new AlertMessage("Successfully registered", AlertType.SUCCESS)}; 23 | request.session().attribute("messages", messages); 24 | request.session().attribute("username", username); 25 | 26 | LogManager.LOGGER.fine("(Web) " + username + " registered " + request.ip()); 27 | } catch (RegistrationException e) { 28 | AlertMessage[] messages = {new AlertMessage(e.getMessage(), AlertType.DANGER)}; 29 | request.session().attribute("messages", messages); 30 | } 31 | } 32 | 33 | response.redirect("/account"); 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/CodeRequestHandler.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.logging.LogManager; 5 | import org.json.simple.JSONObject; 6 | 7 | import java.io.IOException; 8 | 9 | public class CodeRequestHandler implements MessageHandler { 10 | @Override 11 | public void handle(OnlineUser user, JSONObject json) throws IOException { 12 | 13 | if (json.get("t").equals("codeRequest")) { 14 | 15 | LogManager.LOGGER.fine("(WS) Code request from " + user.getUser().getUsername()); 16 | 17 | if (user.getUser().isGuest()) { 18 | 19 | JSONObject response = new JSONObject(); 20 | 21 | response.put("t", "code"); 22 | response.put("code", GameServer.INSTANCE.getConfig().getString("guest_user_code")); 23 | 24 | user.getWebSocket().getRemote().sendString(response.toJSONString()); 25 | 26 | } else { 27 | 28 | JSONObject response = new JSONObject(); 29 | 30 | response.put("t", "code"); 31 | response.put("code", user.getUser().getUserCode()); 32 | 33 | user.getWebSocket().getRemote().sendString(response.toJSONString()); 34 | } 35 | 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/DebugCommandHandler.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.event.DebugCommandEvent; 5 | import org.json.simple.JSONObject; 6 | 7 | public class DebugCommandHandler implements MessageHandler { 8 | 9 | @Override 10 | public void handle(OnlineUser user, JSONObject json) { 11 | 12 | 13 | if (json.get("t").equals("debug") && user.getUser().isModerator()) { 14 | 15 | DebugCommandEvent e = new DebugCommandEvent(json, user); 16 | GameServer.INSTANCE.getEventDispatcher().dispatch(e); //Ignore cancellation 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/KeypressHandler.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import org.json.simple.JSONObject; 4 | 5 | import java.util.ArrayList; 6 | 7 | 8 | public class KeypressHandler implements MessageHandler { 9 | 10 | @Override 11 | public void handle(OnlineUser user, JSONObject json) { 12 | 13 | if (!user.getUser().isGuest()) { 14 | if (json.get("t").equals("k")) { 15 | 16 | //LogManager.LOGGER.fine("(WS) Received keypress"); 17 | 18 | int key = (int) (long) json.get("k"); 19 | 20 | ArrayList buffer = user.getUser().getControlledUnit().getKeyboardBuffer(); 21 | 22 | if (buffer.size() < 16) { 23 | buffer.add(key); 24 | } 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import org.json.simple.JSONObject; 4 | 5 | import java.io.IOException; 6 | 7 | public interface MessageHandler { 8 | 9 | void handle(OnlineUser user, JSONObject json) throws IOException; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/OnlineUser.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import net.simon987.server.user.User; 4 | import org.eclipse.jetty.websocket.api.Session; 5 | 6 | public class OnlineUser { 7 | 8 | 9 | private boolean authenticated = false; 10 | 11 | private Session webSocket; 12 | 13 | /** 14 | * Associated game user (if authenticated) 15 | */ 16 | private User user; 17 | 18 | public OnlineUser(Session webSocket) { 19 | this.webSocket = webSocket; 20 | 21 | } 22 | 23 | public Session getWebSocket() { 24 | return webSocket; 25 | } 26 | 27 | public User getUser() { 28 | return user; 29 | } 30 | 31 | public void setUser(User user) { 32 | this.user = user; 33 | } 34 | 35 | public boolean isAuthenticated() { 36 | return authenticated; 37 | } 38 | 39 | public void setAuthenticated(boolean authenticated) { 40 | this.authenticated = authenticated; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Server/src/main/java/net/simon987/server/websocket/OnlineUserManager.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.websocket; 2 | 3 | import org.eclipse.jetty.websocket.api.Session; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class OnlineUserManager { 8 | 9 | /** 10 | * List of online users. 11 | */ 12 | private ArrayList onlineUsers = new ArrayList<>(10); 13 | 14 | 15 | public OnlineUser getUser(Session socket) { 16 | 17 | ArrayList _onlineUsers = new ArrayList<>(onlineUsers); 18 | 19 | for (OnlineUser user : _onlineUsers) { 20 | if (user.getWebSocket().equals(socket)) { 21 | return user; 22 | } 23 | } 24 | 25 | return null; 26 | } 27 | 28 | /** 29 | * Add an user to the list 30 | * 31 | * @param user user to add 32 | */ 33 | public void add(OnlineUser user) { 34 | onlineUsers.add(user); 35 | } 36 | 37 | /** 38 | * Remove an user to the list 39 | * 40 | * @param user user to remove 41 | */ 42 | public void remove(OnlineUser user) { 43 | onlineUsers.remove(user); 44 | } 45 | 46 | public ArrayList getOnlineUsers() { 47 | return onlineUsers; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Server/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/GitHub-Mark-32px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/GitHub-Mark-32px.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/code.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/cubot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/cubot.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/github-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/github-logo.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/hsizegrip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/hsizegrip.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/icon.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/ng-background-dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/ng-background-dot.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/sprites.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/images/world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/images/world.png -------------------------------------------------------------------------------- /Server/src/main/resources/static/webfonts/FSEX301-L2.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/webfonts/FSEX301-L2.ttf -------------------------------------------------------------------------------- /Server/src/main/resources/static/webfonts/MaterialIcons-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/webfonts/MaterialIcons-Regular.ttf -------------------------------------------------------------------------------- /Server/src/main/resources/static/webfonts/MaterialIcons-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/webfonts/MaterialIcons-Regular.woff -------------------------------------------------------------------------------- /Server/src/main/resources/static/webfonts/MaterialIcons-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/main/resources/static/webfonts/MaterialIcons-Regular.woff2 -------------------------------------------------------------------------------- /Server/src/main/resources/templates/footer.vm: -------------------------------------------------------------------------------- 1 |

2 | ©2020 simon987 3 |
4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Server/src/main/resources/templates/head.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $title 9 | -------------------------------------------------------------------------------- /Server/src/main/resources/templates/leaderboard.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | #set ($title = "Leaderboard - M.A.R") 4 | #set ($cur_page = "leaderboard") 5 | #parse("head.vm") 6 | 7 | 8 | #parse("header.vm") 9 | 10 |
11 |
12 |
Leaderboard
13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | #foreach($row in $stats) 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | #end 34 | 35 |
PlayerCompleted vaultsDeath countTotal execution time (ms)Walk distance
$row.getKey().getUsername()$row.getValue().get("completedVaults")$row.getValue().get("death")$row.getValue().get("executionTime")$row.getValue().get("walkDistance")
36 |
37 |
38 |
39 | 40 | #parse("footer.vm") 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Server/src/main/typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "outFile": "../resources/static/js/mar.js", 5 | "removeComments": true 6 | }, 7 | "exclude": [ 8 | "node_modules" 9 | ], 10 | "files": [ 11 | "phaser.d.ts", 12 | "phaser.plugin.isometric.d.ts", 13 | "MarGame.ts", 14 | "mar.ts", 15 | "GameClient.ts", 16 | "GameObject.ts", 17 | "World.ts", 18 | "Console.ts" 19 | ] 20 | } -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/ConfigHelper.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server; 2 | 3 | import java.io.File; 4 | 5 | public class ConfigHelper { 6 | public static ServerConfiguration getConfig() { 7 | File workingDir = new File(""); 8 | File file = new File(workingDir.getAbsolutePath(), "config.properties"); 9 | 10 | if (!file.exists()) { 11 | File fallback = new File("Server/src/main/resources/", file.getName()); 12 | if (fallback.exists()) { 13 | file = fallback; 14 | } else { 15 | throw new AssertionError("'config.properties' and " + 16 | "'Server/src/main/resources/config.properties' cannot be found with working directory: " + 17 | workingDir.getAbsolutePath()); 18 | } 19 | } 20 | 21 | return new ServerConfiguration(file.getAbsolutePath()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/FakeConfiguration.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server; 2 | 3 | import java.util.Properties; 4 | 5 | public class FakeConfiguration implements IServerConfiguration { 6 | 7 | private Properties properties; 8 | 9 | 10 | public FakeConfiguration() { 11 | this.properties = new Properties(); 12 | } 13 | 14 | @Override 15 | public int getInt(String key) { 16 | return Integer.parseInt(properties.getProperty(key)); 17 | } 18 | 19 | @Override 20 | public String getString(String key) { 21 | return properties.getProperty(key); 22 | } 23 | 24 | @Override 25 | public void setInt(String key, int value) { 26 | properties.setProperty(key, String.valueOf(value)); 27 | } 28 | 29 | @Override 30 | public void setString(String key, String value) { 31 | properties.setProperty(key, value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/CPUTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | public class CPUTest { 4 | 5 | 6 | } -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/DWTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | import net.simon987.server.FakeConfiguration; 4 | import net.simon987.server.IServerConfiguration; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class DWTest { 10 | 11 | @Test 12 | public void TestSemiColonInString() { 13 | 14 | IServerConfiguration configuration = new FakeConfiguration(); 15 | 16 | configuration.setInt("memory_size", 1000); 17 | configuration.setInt("org_offset", 400); 18 | 19 | Assembler assembler = new Assembler(new DefaultInstructionSet(), new DefaultRegisterSet(), configuration); 20 | 21 | AssemblyResult ar = assembler.parse("DW \";\""); 22 | assertEquals(0, ar.exceptions.size()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/LabelTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertNotNull; 7 | 8 | public class LabelTest { 9 | 10 | @Test 11 | public void TestNumericLabel() { 12 | 13 | Assembler asm = TestHelper.getTestAsm(); 14 | 15 | AssemblyResult ar = asm.parse("999:"); 16 | 17 | assertEquals(ar.labels.size(), 0); 18 | } 19 | 20 | @Test 21 | public void TestValidLabel() { 22 | 23 | Assembler asm = TestHelper.getTestAsm(); 24 | 25 | AssemblyResult ar = asm.parse("\ttest_label: dw 1 ; comment"); 26 | 27 | assertNotNull(ar.labels.get("test_label")); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/MemoryTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | import net.simon987.server.ConfigHelper; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | public class MemoryTest { 9 | 10 | @Test 11 | public void getSet() { 12 | int memorySize = ConfigHelper.getConfig().getInt("memory_size"); 13 | Memory memory = new Memory(memorySize); 14 | 15 | memory.set(1, 1); 16 | assertEquals(1, memory.get(1)); 17 | 18 | memory.set(memorySize / 2 - 1, 1); 19 | assertEquals(1, memory.get(memorySize / 2 - 1)); 20 | 21 | memory.get(memorySize / 2); 22 | memory.get(-1); 23 | 24 | memory.set(memorySize / 2, 1); 25 | memory.set(-1, 1); 26 | } 27 | 28 | @Test 29 | public void write() { 30 | int memorySize = ConfigHelper.getConfig().getInt("memory_size"); 31 | Memory memory = new Memory(memorySize); 32 | 33 | assertTrue(memory.write(0, new char[memorySize], 0, memorySize)); 34 | assertFalse(memory.write(0, new char[memorySize], 0, memorySize + 1)); 35 | assertFalse(memory.write(0, new char[memorySize], 0, -1)); 36 | assertFalse(memory.write(-1, new char[memorySize], 0, 10)); 37 | 38 | assertFalse(memory.write(memorySize, new char[15], 0, 1)); 39 | assertFalse(memory.write((memorySize) - 5, new char[11], 0, 6)); 40 | assertTrue(memory.write((memorySize) - 5, new char[11], 0, 5)); 41 | 42 | } 43 | 44 | 45 | } -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/TestComment.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class TestComment { 8 | 9 | @Test 10 | public void TestCommentInQuotes() { 11 | 12 | Assembler asm = TestHelper.getTestAsm(); 13 | 14 | AssemblyResult r1 = asm.parse("dw \";\", 12"); 15 | assertEquals(r1.bytes.length, 4); 16 | } 17 | 18 | @Test 19 | public void TestRegularComment() { 20 | 21 | Assembler asm = TestHelper.getTestAsm(); 22 | 23 | AssemblyResult r1 = asm.parse("register_SP: DW \"SP=\",0 ; register_A + 28"); 24 | assertEquals(8, r1.bytes.length); 25 | assertEquals(0, r1.exceptions.size()); 26 | } 27 | 28 | @Test 29 | public void TestStandaloneComment() { 30 | 31 | Assembler asm = TestHelper.getTestAsm(); 32 | 33 | AssemblyResult r1 = asm.parse("; Set display_mode to DECIMAL_MODE"); 34 | assertEquals(0, r1.bytes.length); 35 | assertEquals(0, r1.exceptions.size()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/TestHelper.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly; 2 | 3 | import net.simon987.server.FakeConfiguration; 4 | import net.simon987.server.IServerConfiguration; 5 | 6 | class TestHelper { 7 | 8 | static Assembler getTestAsm() { 9 | 10 | IServerConfiguration configuration = new FakeConfiguration(); 11 | 12 | configuration.setInt("memory_size", 1000); 13 | configuration.setInt("org_offset", 400); 14 | 15 | return new Assembler(new DefaultInstructionSet(), new DefaultRegisterSet(), configuration); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/BrkInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Status; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class BrkInstructionTest { 9 | @Test 10 | public void execute() throws Exception { 11 | 12 | //Status 13 | Status status = new Status(); 14 | status.clear(); 15 | 16 | BrkInstruction brkInstruction = new BrkInstruction(); 17 | 18 | brkInstruction.execute(status); 19 | 20 | assertTrue(status.isBreakFlag()); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/CallInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | public class CallInstructionTest { 4 | 5 | 6 | 7 | } -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetaeInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetaeInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETAE; 17 | 18 | public SetaeInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetaeInstruction(); 27 | } 28 | 29 | /** 30 | * SETAE,SETNB,SETNC Above or Equal, Not Below, No Carry CF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(false); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(true); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetbInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetbInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETB; 17 | 18 | public SetbInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetbInstruction(); 27 | } 28 | 29 | /** 30 | * SETB, SETC,SETNAE Below, Carry, Not Above or Equal CF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetcInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetcInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETB; 17 | 18 | public SetcInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetcInstruction(); 27 | } 28 | 29 | /** 30 | * SETB, SETC,SETNAE Below, Carry, Not Above or Equal CF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SeteInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SeteInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETE; 17 | 18 | public SeteInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SeteInstruction(); 27 | } 28 | 29 | /** 30 | * SETE, SETZ Equal, Zero ZF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setZeroFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setZeroFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetnaeInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetnaeInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETB; 17 | 18 | public SetnaeInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetnaeInstruction(); 27 | } 28 | 29 | /** 30 | * SETB, SETC,SETNAE Below, Carry, Not Above or Equal CF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetnbInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetnbInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETAE; 17 | 18 | public SetnbInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetnbInstruction(); 27 | } 28 | 29 | /** 30 | * SETAE,SETNB,SETNC Above or Equal, Not Below, No Carry CF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(false); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(true); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetncInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetncInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETAE; 17 | 18 | public SetncInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetncInstruction(); 27 | } 28 | 29 | /** 30 | * SETAE,SETNB,SETNC Above or Equal, Not Below, No Carry CF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setCarryFlag(false); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setCarryFlag(true); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetneInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetneInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETNE; 17 | 18 | public SetneInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetneInstruction(); 27 | } 28 | 29 | /** 30 | * SETNE, SETNZ Not Equal, Not Zero ZF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setZeroFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 0); 37 | 38 | status.setZeroFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 1); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetnoInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetnoInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETNO; 17 | 18 | public SetnoInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetnoInstruction(); 27 | } 28 | 29 | /** 30 | * SETNO No Overflow OF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setOverflowFlag(false); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setOverflowFlag(true); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetnsInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetnsInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETNS; 17 | 18 | public SetnsInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetnsInstruction(); 27 | } 28 | 29 | /** 30 | * SETS No Sign SF=0 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setSignFlag(false); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setSignFlag(true); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetnzInstructionTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon987/Much-Assembly-Required/ac374f5b525615da3ecb36b08cc5fc53ab73dc96/Server/src/test/java/net/simon987/server/assembly/instruction/SetnzInstructionTest.java -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetoInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetoInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETO; 17 | 18 | public SetoInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetoInstruction(); 27 | } 28 | 29 | /** 30 | * SETO Overflow OF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setOverflowFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setOverflowFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetsInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetsInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETS; 17 | 18 | public SetsInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetsInstruction(); 27 | } 28 | 29 | /** 30 | * SETS Sign SF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setSignFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setSignFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Server/src/test/java/net/simon987/server/assembly/instruction/SetzInstructionTest.java: -------------------------------------------------------------------------------- 1 | package net.simon987.server.assembly.instruction; 2 | 3 | import net.simon987.server.assembly.Register; 4 | import net.simon987.server.assembly.RegisterSet; 5 | import net.simon987.server.assembly.Status; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | 12 | public class SetzInstructionTest { 13 | private RegisterSet registers; 14 | private Status status; 15 | private SetccInstruction instruction; 16 | private int SETCCOPCODE = SetccInstruction.SETE; 17 | 18 | public SetzInstructionTest() { 19 | registers = new RegisterSet(); 20 | registers.put(1, new Register("R")); 21 | registers.clear(); 22 | 23 | status = new Status(); 24 | status.clear(); 25 | 26 | instruction = new SetzInstruction(); 27 | } 28 | 29 | /** 30 | * SETE, SETZ Equal, Zero ZF=1 31 | */ 32 | @Test 33 | public void execution() { 34 | status.setZeroFlag(true); 35 | instruction.execute(registers, 1, SETCCOPCODE, status); 36 | assertEquals(registers.get(1), 1); 37 | 38 | status.setZeroFlag(false); 39 | instruction.execute(registers, 1, SETCCOPCODE, status); 40 | assertEquals(registers.get(1), 0); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.vm.box = "ubuntu/trusty64" 3 | config.vm.provision :shell, path: "bootstrap.sh" 4 | config.vm.network "forwarded_port", guest: 4567, host: 4567 5 | end -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This file is ran during vagrant provision 3 | add-apt-repository ppa:webupd8team/java 4 | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 5 | echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list 6 | apt-get update 7 | echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections 8 | apt-get install -y git maven oracle-java8-installer mongodb-org-server 9 | cd /vagrant/ 10 | mvn clean 11 | mvn install 12 | cd target 13 | java -jar server-1.4a.jar -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2.1" 2 | services: 3 | server: 4 | build: 5 | context: . 6 | command: sh -c "/usr/bin/java -jar /app/target/server-1.4a.jar" 7 | depends_on: 8 | mongodb: 9 | condition: service_healthy 10 | ports: 11 | - 4567:4567 12 | mongodb: 13 | image: mongo:latest 14 | container_name: "mongodb" 15 | environment: 16 | - MONGO_DATA_DIR=/data/db 17 | - MONGO_LOG_DIR=/dev/null 18 | volumes: 19 | - ./data/db:/data/db 20 | ports: 21 | - 27017:27017 22 | command: mongod --logpath=/dev/null --port 27017 23 | healthcheck: 24 | test: echo 'db.stats().ok' | mongo localhost:27017/mar --quiet 25 | interval: 2s 26 | timeout: 2s 27 | retries: 2 28 | -------------------------------------------------------------------------------- /plugin-contruction/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | net.simon987.server 9 | server_root 10 | 1.4a 11 | 12 | 13 | net.simon987.plugincontruction 14 | plugin-construction 15 | 1.4a 16 | 17 | 18 | 19 | 20 | com.googlecode.json-simple 21 | json-simple 22 | 1.1.1 23 | 24 | 25 | 26 | net.simon987.server 27 | server 28 | 1.4a 29 | 30 | 31 | -------------------------------------------------------------------------------- /plugin-contruction/src/main/java/net/simon987/constructionplugin/ConstructionPlugin.java: -------------------------------------------------------------------------------- 1 | package net.simon987.constructionplugin; 2 | 3 | import net.simon987.server.GameServer; 4 | import net.simon987.server.game.objects.GameRegistry; 5 | import net.simon987.server.logging.LogManager; 6 | import net.simon987.server.plugin.ServerPlugin; 7 | 8 | public class ConstructionPlugin extends ServerPlugin { 9 | 10 | @Override 11 | public void init(GameServer gameServer) { 12 | 13 | BluePrintUtil.setSecretKey(gameServer.getSecretKey()); 14 | GameRegistry gameRegistry = gameServer.getRegistry(); 15 | 16 | gameRegistry.registerItem(ItemBluePrint.ID, ItemBluePrint.class); 17 | gameRegistry.registerGameObject(Obstacle.class); 18 | gameRegistry.registerGameObject(ConstructionSite.class); 19 | 20 | BluePrintRegistry.INSTANCE.registerBluePrint(ObstacleBlueprint.class); 21 | 22 | LogManager.LOGGER.info("(Construction Plugin) Initialized construction plugin"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /plugin-contruction/src/main/java/net/simon987/constructionplugin/ObstacleBlueprint.java: -------------------------------------------------------------------------------- 1 | package net.simon987.constructionplugin; 2 | 3 | import net.simon987.server.game.item.ItemIron; 4 | import org.bson.Document; 5 | 6 | public class ObstacleBlueprint extends BluePrint { 7 | 8 | public ObstacleBlueprint() { 9 | super(); 10 | 11 | this.requiredItems.put(ItemIron.ID, 2); //TODO: load from config? 12 | this.targetObject = Obstacle.class; 13 | } 14 | 15 | public ObstacleBlueprint(Document document) { 16 | this.requiredItems.put(ItemIron.ID, 2); //TODO: load from config? 17 | this.targetObject = Obstacle.class; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /plugin-contruction/src/main/resources/plugin.properties: -------------------------------------------------------------------------------- 1 | classpath=net.simon987.constructionplugin.ConstructionPlugin 2 | name=Construction Plugin 3 | version=1.0 4 | --------------------------------------------------------------------------------