Updated mongodb driver to 3.7.0

This commit is contained in:
simon 2018-05-11 21:06:18 -04:00
parent e98575b23f
commit 854863ede9
57 changed files with 383 additions and 383 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
@ -15,14 +20,14 @@
<orderEntry type="module" module-name="Server" /> <orderEntry type="module" module-name="Server" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" /> <orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" />

View File

@ -1,13 +1,12 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.ServerConfiguration; import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.Memory; import net.simon987.server.assembly.Memory;
import net.simon987.server.game.*; import net.simon987.server.game.*;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User; import net.simon987.server.user.User;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.awt.*; import java.awt.*;
@ -251,8 +250,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("t", ID); dbObject.put("t", ID);
@ -276,7 +275,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
return dbObject; return dbObject;
} }
public static Cubot deserialize(DBObject obj) { public static Cubot deserialize(Document obj) {
Cubot cubot = new Cubot(); Cubot cubot = new Cubot();
cubot.setObjectId((long) obj.get("i")); cubot.setObjectId((long) obj.get("i"));
@ -294,7 +293,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
cubot.maxShield = config.getInt("cubot_max_shield"); cubot.maxShield = config.getInt("cubot_max_shield");
return cubot; return cubot;
} }
/** /**

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotBattery extends CpuHardware { public class CubotBattery extends CpuHardware {
@ -45,9 +44,9 @@ public class CubotBattery extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -56,7 +55,7 @@ public class CubotBattery extends CpuHardware {
} }
public static CubotBattery deserialize(DBObject obj) { public static CubotBattery deserialize(Document obj) {
return new CubotBattery((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotBattery((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }

View File

@ -1,12 +1,11 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.Programmable; import net.simon987.server.game.Programmable;
import org.bson.Document;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -128,9 +127,9 @@ public class CubotComPort extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -138,7 +137,7 @@ public class CubotComPort extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotComPort deserialize(DBObject obj) { public static CubotComPort deserialize(Document obj) {
return new CubotComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotCore extends CpuHardware { public class CubotCore extends CpuHardware {
@ -42,9 +41,9 @@ public class CubotCore extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -53,7 +52,7 @@ public class CubotCore extends CpuHardware {
} }
public static CubotCore deserialize(DBObject obj) { public static CubotCore deserialize(Document obj) {
return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,12 +1,11 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.game.Action; import net.simon987.server.game.Action;
import net.simon987.server.game.TileMap; import net.simon987.server.game.TileMap;
import org.bson.Document;
public class CubotDrill extends CpuHardware { public class CubotDrill extends CpuHardware {
@ -62,9 +61,9 @@ public class CubotDrill extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -72,7 +71,7 @@ public class CubotDrill extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotDrill deserialize(DBObject obj) { public static CubotDrill deserialize(Document obj) {
return new CubotDrill((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotDrill((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotFloppyDrive extends CpuHardware { public class CubotFloppyDrive extends CpuHardware {
@ -79,9 +78,9 @@ public class CubotFloppyDrive extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -93,12 +92,12 @@ public class CubotFloppyDrive extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotFloppyDrive deserialize(DBObject obj) { public static CubotFloppyDrive deserialize(Document obj) {
CubotFloppyDrive drive = new CubotFloppyDrive((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); CubotFloppyDrive drive = new CubotFloppyDrive((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
if (obj.containsField("floppy")) { if (obj.containsKey("floppy")) {
drive.floppyDisk = FloppyDisk.deserialise((DBObject) obj.get("floppy")); drive.floppyDisk = FloppyDisk.deserialise((Document) obj.get("floppy"));
} }
return drive; return drive;

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotHologram extends CpuHardware { public class CubotHologram extends CpuHardware {
@ -83,14 +82,14 @@ public class CubotHologram extends CpuHardware {
return HWID; return HWID;
} }
public static CubotHologram deserialize(DBObject obj) { public static CubotHologram deserialize(Document obj) {
return new CubotHologram((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotHologram((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotInventory extends CpuHardware { public class CubotInventory extends CpuHardware {
@ -52,9 +51,9 @@ public class CubotInventory extends CpuHardware {
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -62,7 +61,7 @@ public class CubotInventory extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotInventory deserialize(DBObject obj) { public static CubotInventory deserialize(Document obj) {
return new CubotInventory((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotInventory((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotKeyboard extends CpuHardware { public class CubotKeyboard extends CpuHardware {
@ -53,9 +52,9 @@ public class CubotKeyboard extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -63,7 +62,7 @@ public class CubotKeyboard extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotKeyboard deserialize(DBObject obj) { public static CubotKeyboard deserialize(Document obj) {
return new CubotKeyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotKeyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,7 +1,5 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
@ -9,6 +7,7 @@ import net.simon987.server.game.Action;
import net.simon987.server.game.Attackable; import net.simon987.server.game.Attackable;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.InventoryHolder; import net.simon987.server.game.InventoryHolder;
import org.bson.Document;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -93,9 +92,9 @@ public class CubotLaser extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -103,7 +102,7 @@ public class CubotLaser extends CpuHardware {
return dbObject; return dbObject;
} }
public static CubotLaser deserialize(DBObject obj) { public static CubotLaser deserialize(Document obj) {
return new CubotLaser((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotLaser((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,13 +1,12 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.game.Action; import net.simon987.server.game.Action;
import net.simon987.server.game.Direction; import net.simon987.server.game.Direction;
import net.simon987.server.io.JSONSerialisable; import net.simon987.server.io.JSONSerialisable;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class CubotLeg extends CpuHardware implements JSONSerialisable { public class CubotLeg extends CpuHardware implements JSONSerialisable {
@ -86,9 +85,9 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -96,7 +95,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
return dbObject; return dbObject;
} }
public static CubotLeg deserialize(DBObject obj) { public static CubotLeg deserialize(Document obj) {
return new CubotLeg((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotLeg((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }

View File

@ -1,7 +1,5 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Memory; import net.simon987.server.assembly.Memory;
@ -10,6 +8,7 @@ import net.simon987.server.game.pathfinding.Node;
import net.simon987.server.game.pathfinding.Pathfinder; import net.simon987.server.game.pathfinding.Pathfinder;
import net.simon987.server.io.JSONSerialisable; import net.simon987.server.io.JSONSerialisable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
@ -150,9 +149,9 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -160,7 +159,7 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
return dbObject; return dbObject;
} }
public static CubotLidar deserialize(DBObject obj) { public static CubotLidar deserialize(Document obj) {
return new CubotLidar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotLidar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,6 +1,5 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.DBObject;
import net.simon987.cubotplugin.event.ChargeShieldCommandListener; import net.simon987.cubotplugin.event.ChargeShieldCommandListener;
import net.simon987.cubotplugin.event.CpuInitialisationListener; import net.simon987.cubotplugin.event.CpuInitialisationListener;
import net.simon987.cubotplugin.event.UserCreationListener; import net.simon987.cubotplugin.event.UserCreationListener;
@ -11,6 +10,7 @@ import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, CpuHardwareDeserializer { public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, CpuHardwareDeserializer {
@ -25,7 +25,7 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
} }
@Override @Override
public GameObject deserializeObject(DBObject object) { public GameObject deserializeObject(Document object) {
int objType = (int) object.get("t"); int objType = (int) object.get("t");
@ -38,7 +38,7 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
} }
@Override @Override
public CpuHardware deserializeHardware(DBObject obj) { public CpuHardware deserializeHardware(Document obj) {
int hwid = (int) obj.get("hwid"); int hwid = (int) obj.get("hwid");
switch (hwid) { switch (hwid) {

View File

@ -1,10 +1,9 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotShield extends CpuHardware { public class CubotShield extends CpuHardware {
@ -28,8 +27,8 @@ public class CubotShield extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -49,8 +48,8 @@ public class CubotShield extends CpuHardware {
getCpu().getRegisterSet().getRegister("B").setValue(shield); getCpu().getRegisterSet().getRegister("B").setValue(shield);
} }
} }
public static CubotShield deserialize(DBObject obj) { public static CubotShield deserialize(Document obj) {
return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,17 +1,16 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.assembly.Memory; import net.simon987.server.assembly.Memory;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import org.bson.Document;
/** /**
* Represents a floppy disk that is inside a floppy drive. * Represents a floppy disk that is inside a floppy drive.
* Floppies contains 80 tracks with 18 sectors per track. * Floppies contains 80 tracks with 18 sectors per track.
* That's 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44Mb) * That's 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44Mb)
*/ */
public class FloppyDisk implements MongoSerialisable { public class FloppyDisk implements MongoSerializable {
/** /**
* Contents of the disk * Contents of the disk
@ -84,8 +83,8 @@ public class FloppyDisk implements MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("rwHeadTrack", rwHeadTrack); dbObject.put("rwHeadTrack", rwHeadTrack);
dbObject.put("memory", memory.mongoSerialise()); dbObject.put("memory", memory.mongoSerialise());
@ -93,12 +92,12 @@ public class FloppyDisk implements MongoSerialisable {
return dbObject; return dbObject;
} }
public static FloppyDisk deserialise(DBObject obj) { public static FloppyDisk deserialise(Document obj) {
FloppyDisk floppyDisk = new FloppyDisk(); FloppyDisk floppyDisk = new FloppyDisk();
floppyDisk.rwHeadTrack = (int) obj.get("rwHeadTrack"); floppyDisk.rwHeadTrack = (int) obj.get("rwHeadTrack");
floppyDisk.memory = Memory.deserialize((DBObject) obj.get("memory")); floppyDisk.memory = Memory.deserialize((Document) obj.get("memory"));
return floppyDisk; return floppyDisk;
} }

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
@ -14,14 +19,14 @@
<orderEntry type="module" module-name="Server" /> <orderEntry type="module" module-name="Server" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" /> <orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" />

View File

@ -1,10 +1,10 @@
package net.simon987.mischwplugin; package net.simon987.mischwplugin;
import com.mongodb.BasicDBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Util; import net.simon987.server.assembly.Util;
import org.bson.Document;
/** /**
* Hardware to get game time * Hardware to get game time
@ -37,9 +37,9 @@ public class Clock extends CpuHardware {
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);

View File

@ -1,12 +1,12 @@
package net.simon987.mischwplugin; package net.simon987.mischwplugin;
import com.mongodb.DBObject;
import net.simon987.mischwplugin.event.CpuInitialisationListener; import net.simon987.mischwplugin.event.CpuInitialisationListener;
import net.simon987.server.ServerConfiguration; import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.io.CpuHardwareDeserializer; import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
/** /**
* Plugin that adds miscellaneous hardware to the game * Plugin that adds miscellaneous hardware to the game
@ -22,7 +22,7 @@ public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserialize
} }
@Override @Override
public CpuHardware deserializeHardware(DBObject hwJson) { public CpuHardware deserializeHardware(Document hwJson) {
int hwid = (int) hwJson.get("hwid"); int hwid = (int) hwJson.get("hwid");
switch (hwid) { switch (hwid) {

View File

@ -1,8 +1,8 @@
package net.simon987.mischwplugin; package net.simon987.mischwplugin;
import com.mongodb.BasicDBObject;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import org.bson.Document;
import java.util.Random; import java.util.Random;
@ -34,9 +34,9 @@ public class RandomNumberGenerator extends CpuHardware {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
@ -17,14 +22,14 @@
<orderEntry type="module" module-name="Server" /> <orderEntry type="module" module-name="Server" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" /> <orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" />

View File

@ -1,7 +1,5 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.Util; import net.simon987.server.assembly.Util;
import net.simon987.server.game.Attackable; import net.simon987.server.game.Attackable;
@ -9,6 +7,7 @@ import net.simon987.server.game.GameObject;
import net.simon987.server.game.Rechargeable; import net.simon987.server.game.Rechargeable;
import net.simon987.server.game.Updatable; import net.simon987.server.game.Updatable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
@ -150,8 +149,8 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -162,7 +161,7 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
return dbObject; return dbObject;
} }
public static ElectricBox deserialize(DBObject obj) { public static ElectricBox deserialize(Document obj) {
ElectricBox electricBox = new ElectricBox(); ElectricBox electricBox = new ElectricBox();
electricBox.setHp((int) obj.get("hp")); electricBox.setHp((int) obj.get("hp"));

View File

@ -1,15 +1,14 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.Updatable; import net.simon987.server.game.Updatable;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Game objects that regularly creates NonPlayerCharacters * Game objects that regularly creates NonPlayerCharacters
@ -133,15 +132,15 @@ public class Factory extends GameObject implements Updatable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
dbObject.put("y", getY()); dbObject.put("y", getY());
dbObject.put("t", ID); dbObject.put("t", ID);
BasicDBList tmpNpcArray = new BasicDBList(); List<Long> tmpNpcArray = new ArrayList<>(npcs.size());
for (NonPlayerCharacter npc : npcs) { for (NonPlayerCharacter npc : npcs) {
tmpNpcArray.add(npc.getObjectId()); tmpNpcArray.add(npc.getObjectId());
@ -152,14 +151,14 @@ public class Factory extends GameObject implements Updatable {
return dbObject; return dbObject;
} }
public static Factory deserialise(DBObject obj) { public static Factory deserialise(Document obj) {
Factory factory = new Factory(); Factory factory = new Factory();
factory.setObjectId((long) obj.get("i")); factory.setObjectId((long) obj.get("i"));
factory.setX((int) obj.get("x")); factory.setX((int) obj.get("x"));
factory.setY((int) obj.get("y")); factory.setY((int) obj.get("y"));
factory.tmpNpcArray = ((BasicDBList) obj.get("tmpNpcArray")).toArray(); factory.tmpNpcArray = ((ArrayList) obj.get("tmpNpcArray")).toArray();
return factory; return factory;
} }

View File

@ -1,10 +1,9 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.event.ObjectDeathEvent; import net.simon987.server.event.ObjectDeathEvent;
import net.simon987.server.game.Direction; import net.simon987.server.game.Direction;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -80,8 +79,8 @@ public class HarvesterNPC extends NonPlayerCharacter {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -94,7 +93,7 @@ public class HarvesterNPC extends NonPlayerCharacter {
return dbObject; return dbObject;
} }
public static HarvesterNPC deserialize(DBObject obj) { public static HarvesterNPC deserialize(Document obj) {
HarvesterNPC npc = new HarvesterNPC(); HarvesterNPC npc = new HarvesterNPC();
npc.setObjectId((long) obj.get("i")); npc.setObjectId((long) obj.get("i"));

View File

@ -1,6 +1,5 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.DBObject;
import net.simon987.npcplugin.event.CpuInitialisationListener; import net.simon987.npcplugin.event.CpuInitialisationListener;
import net.simon987.npcplugin.event.VaultWorldUpdateListener; import net.simon987.npcplugin.event.VaultWorldUpdateListener;
import net.simon987.npcplugin.event.WorldCreationListener; import net.simon987.npcplugin.event.WorldCreationListener;
@ -11,6 +10,7 @@ import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,7 +34,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
} }
@Override @Override
public GameObject deserializeObject(DBObject obj) { public GameObject deserializeObject(Document obj) {
int objType = (int) obj.get("t"); int objType = (int) obj.get("t");
@ -60,7 +60,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
} }
@Override @Override
public CpuHardware deserializeHardware(DBObject obj) { public CpuHardware deserializeHardware(Document obj) {
int hwid = (int) obj.get("hwid"); int hwid = (int) obj.get("hwid");
switch (hwid) { switch (hwid) {

View File

@ -1,9 +1,8 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.game.Attackable; import net.simon987.server.game.Attackable;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
/** /**
@ -89,8 +88,8 @@ public class Obstacle extends GameObject implements Attackable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -116,7 +115,7 @@ public class Obstacle extends GameObject implements Attackable {
return json; return json;
} }
public static Obstacle deserialize(DBObject obj) { public static Obstacle deserialize(Document obj) {
Obstacle obstacle = new Obstacle((int) obj.get("hp")); Obstacle obstacle = new Obstacle((int) obj.get("hp"));
obstacle.setObjectId((long) obj.get("i")); obstacle.setObjectId((long) obj.get("i"));

View File

@ -1,9 +1,8 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.game.*; import net.simon987.server.game.*;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class Portal extends GameObject implements Enterable { public class Portal extends GameObject implements Enterable {
@ -48,8 +47,8 @@ public class Portal extends GameObject implements Enterable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -64,7 +63,7 @@ public class Portal extends GameObject implements Enterable {
return dbObject; return dbObject;
} }
public static Portal deserialize(DBObject obj) { public static Portal deserialize(Document obj) {
Portal portal = new Portal(); Portal portal = new Portal();

View File

@ -1,13 +1,12 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Util; import net.simon987.server.assembly.Util;
import net.simon987.server.game.Action; import net.simon987.server.game.Action;
import net.simon987.server.game.ControllableUnit; import net.simon987.server.game.ControllableUnit;
import org.bson.Document;
import java.util.ArrayList; import java.util.ArrayList;
@ -67,9 +66,9 @@ public class RadioReceiverHardware extends CpuHardware {
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("hwid", (int) HWID); dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId()); dbObject.put("cubot", cubot.getObjectId());
@ -77,7 +76,7 @@ public class RadioReceiverHardware extends CpuHardware {
return dbObject; return dbObject;
} }
public static RadioReceiverHardware deserialize(DBObject obj) { public static RadioReceiverHardware deserialize(Document obj) {
return new RadioReceiverHardware((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); return new RadioReceiverHardware((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
} }
} }

View File

@ -1,10 +1,9 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.Programmable; import net.simon987.server.game.Programmable;
import net.simon987.server.game.Updatable; import net.simon987.server.game.Updatable;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
@ -66,8 +65,8 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -77,7 +76,7 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
return dbObject; return dbObject;
} }
public static RadioTower deserialize(DBObject obj) { public static RadioTower deserialize(Document obj) {
RadioTower tower = new RadioTower(); RadioTower tower = new RadioTower();
tower.setObjectId((long) obj.get("i")); tower.setObjectId((long) obj.get("i"));

View File

@ -1,11 +1,10 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.crypto.RandomStringGenerator; import net.simon987.server.crypto.RandomStringGenerator;
import net.simon987.server.game.*; import net.simon987.server.game.*;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.Arrays; import java.util.Arrays;
@ -124,8 +123,8 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -152,7 +151,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
return json; return json;
} }
public static VaultDoor deserialize(DBObject obj) { public static VaultDoor deserialize(Document obj) {
VaultDoor vaultDoor = new VaultDoor(0); //cypherId ? VaultDoor vaultDoor = new VaultDoor(0); //cypherId ?
vaultDoor.setX((int) obj.get("x")); vaultDoor.setX((int) obj.get("x"));
@ -160,7 +159,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
vaultDoor.setObjectId((long) obj.get("i")); vaultDoor.setObjectId((long) obj.get("i"));
if (obj.containsField("homeX") && obj.containsField("homeY")) { if (obj.containsKey("homeX") && obj.containsKey("homeY")) {
vaultDoor.setHomeX((int) obj.get("homeX")); vaultDoor.setHomeX((int) obj.get("homeX"));
vaultDoor.setHomeY((int) obj.get("homeY")); vaultDoor.setHomeY((int) obj.get("homeY"));
} }

View File

@ -1,11 +1,10 @@
package net.simon987.npcplugin; package net.simon987.npcplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.game.ControllableUnit; import net.simon987.server.game.ControllableUnit;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.Location; import net.simon987.server.game.Location;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
/** /**
* Final exit portal located in the 'last' World of a Vault dimension * Final exit portal located in the 'last' World of a Vault dimension
@ -15,8 +14,8 @@ public class VaultExitPortal extends Portal {
public static final int ID = 9; public static final int ID = 9;
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
dbObject.put("x", getX()); dbObject.put("x", getX());
@ -44,7 +43,7 @@ public class VaultExitPortal extends Portal {
return super.enter(object); return super.enter(object);
} }
public static Portal deserialize(DBObject obj) { public static Portal deserialize(Document obj) {
VaultExitPortal portal = new VaultExitPortal(); VaultExitPortal portal = new VaultExitPortal();

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
@ -17,14 +22,14 @@
<orderEntry type="module" module-name="Server" /> <orderEntry type="module" module-name="Server" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" /> <orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" />

View File

@ -1,9 +1,8 @@
package net.simon987.biomassplugin; package net.simon987.biomassplugin;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.InventoryHolder; import net.simon987.server.game.InventoryHolder;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class BiomassBlob extends GameObject implements InventoryHolder { public class BiomassBlob extends GameObject implements InventoryHolder {
@ -43,9 +42,9 @@ public class BiomassBlob extends GameObject implements InventoryHolder {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("t", ID); dbObject.put("t", ID);
dbObject.put("i", getObjectId()); dbObject.put("i", getObjectId());
@ -65,15 +64,8 @@ public class BiomassBlob extends GameObject implements InventoryHolder {
this.biomassCount = biomassCount; this.biomassCount = biomassCount;
} }
// public int getStyle() {
// return style;
// }
//
// public void setStyle(int style) {
// this.style = style;
// }
public static BiomassBlob deserialize(DBObject obj) { public static BiomassBlob deserialize(Document obj) {
BiomassBlob biomassBlob = new BiomassBlob(); BiomassBlob biomassBlob = new BiomassBlob();

View File

@ -1,6 +1,5 @@
package net.simon987.biomassplugin; package net.simon987.biomassplugin;
import com.mongodb.DBObject;
import net.simon987.biomassplugin.event.ObjectDeathListener; import net.simon987.biomassplugin.event.ObjectDeathListener;
import net.simon987.biomassplugin.event.WorldCreationListener; import net.simon987.biomassplugin.event.WorldCreationListener;
import net.simon987.biomassplugin.event.WorldUpdateListener; import net.simon987.biomassplugin.event.WorldUpdateListener;
@ -9,6 +8,8 @@ import net.simon987.server.game.GameObject;
import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
public class BiomassPlugin extends ServerPlugin implements GameObjectDeserializer { public class BiomassPlugin extends ServerPlugin implements GameObjectDeserializer {
@ -23,7 +24,7 @@ public class BiomassPlugin extends ServerPlugin implements GameObjectDeserialize
} }
@Override @Override
public GameObject deserializeObject(DBObject object) { public GameObject deserializeObject(Document object) {
int objType = (int) object.get("t"); int objType = (int) object.get("t");

View File

@ -1,11 +1,11 @@
package net.simon987.pluginradioactivecloud; package net.simon987.pluginradioactivecloud;
import com.mongodb.DBObject;
import net.simon987.server.ServerConfiguration; import net.simon987.server.ServerConfiguration;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
public class RadioactiveCloudPlugin extends ServerPlugin implements GameObjectDeserializer { public class RadioactiveCloudPlugin extends ServerPlugin implements GameObjectDeserializer {
@ -16,7 +16,7 @@ public class RadioactiveCloudPlugin extends ServerPlugin implements GameObjectDe
} }
@Override @Override
public GameObject deserializeObject(DBObject object) { public GameObject deserializeObject(Document object) {
return null; return null;
} }

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
@ -16,14 +21,14 @@
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" /> <orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.10.1" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.7.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.5.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" /> <orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.7.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" /> <orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.8.v20171121" level="project" />

View File

@ -107,12 +107,12 @@
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId> <artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version> <version>3.7.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId> <artifactId>spring-security-core</artifactId>
<version>5.0.4.RELEASE</version> <version>5.0.5.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sparkjava</groupId> <groupId>com.sparkjava</groupId>

View File

@ -1,7 +1,11 @@
package net.simon987.server; package net.simon987.server;
import com.mongodb.*; import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import net.simon987.server.crypto.CryptoProvider; import net.simon987.server.crypto.CryptoProvider;
import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventDispatcher; import net.simon987.server.event.GameEventDispatcher;
@ -16,9 +20,9 @@ import net.simon987.server.user.User;
import net.simon987.server.user.UserManager; import net.simon987.server.user.UserManager;
import net.simon987.server.user.UserStatsHelper; import net.simon987.server.user.UserStatsHelper;
import net.simon987.server.websocket.SocketServer; import net.simon987.server.websocket.SocketServer;
import org.bson.Document;
import java.io.File; import java.io.File;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
public class GameServer implements Runnable { public class GameServer implements Runnable {
@ -49,17 +53,13 @@ public class GameServer implements Runnable {
this.config = new ServerConfiguration("config.properties"); this.config = new ServerConfiguration("config.properties");
try{ mongo = new MongoClient(config.getString("mongo_address"), config.getInt("mongo_port"));
mongo = new MongoClient(config.getString("mongo_address"), config.getInt("mongo_port")); MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
DB db = mongo.getDB(config.getString("mongo_dbname"));
DBCollection userCollection = db.getCollection("user"); MongoCollection<Document> userCollection = db.getCollection("user");
userManager = new UserManager(userCollection); userManager = new UserManager(userCollection);
userStatsHelper = new UserStatsHelper(userCollection); userStatsHelper = new UserStatsHelper(userCollection);
} catch (UnknownHostException e) {
e.printStackTrace();
}
gameUniverse = new GameUniverse(config); gameUniverse = new GameUniverse(config);
gameUniverse.setMongo(mongo); gameUniverse.setMongo(mongo);
@ -201,14 +201,14 @@ public class GameServer implements Runnable {
LogManager.LOGGER.info("Loading all data from MongoDB"); LogManager.LOGGER.info("Loading all data from MongoDB");
DB db = mongo.getDB(config.getString("mongo_dbname")); MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
DBCollection worlds = db.getCollection("world"); MongoCollection<Document> worlds = db.getCollection("world");
DBCollection server = db.getCollection("server"); MongoCollection<Document> server = db.getCollection("server");
BasicDBObject whereQuery = new BasicDBObject(); Document whereQuery = new Document();
whereQuery.put("shouldUpdate", true); whereQuery.put("shouldUpdate", true);
DBCursor cursor = worlds.find(whereQuery); MongoCursor<Document> cursor = worlds.find(whereQuery).iterator();
GameUniverse universe = GameServer.INSTANCE.getGameUniverse(); GameUniverse universe = GameServer.INSTANCE.getGameUniverse();
while (cursor.hasNext()) { while (cursor.hasNext()) {
World w = World.deserialize(cursor.next()); World w = World.deserialize(cursor.next());
@ -222,9 +222,9 @@ public class GameServer implements Runnable {
} }
//Load misc server info //Load misc server info
cursor = server.find(); cursor = server.find().iterator();
if (cursor.hasNext()) { if (cursor.hasNext()) {
DBObject serverObj = cursor.next(); Document serverObj = cursor.next();
gameUniverse.setTime((long) serverObj.get("time")); gameUniverse.setTime((long) serverObj.get("time"));
gameUniverse.setNextObjectId((long) serverObj.get("nextObjectId")); gameUniverse.setNextObjectId((long) serverObj.get("nextObjectId"));
} }
@ -237,19 +237,21 @@ public class GameServer implements Runnable {
LogManager.LOGGER.info("Saving to MongoDB | W:" + gameUniverse.getWorldCount() + " | U:" + gameUniverse.getUserCount()); LogManager.LOGGER.info("Saving to MongoDB | W:" + gameUniverse.getWorldCount() + " | U:" + gameUniverse.getUserCount());
try{ try{
DB db = mongo.getDB(config.getString("mongo_dbname")); MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname"));
UpdateOptions updateOptions = new UpdateOptions();
updateOptions.upsert(true);
int unloaded_worlds = 0; int unloaded_worlds = 0;
DBCollection worlds = db.getCollection("world"); MongoCollection<Document> worlds = db.getCollection("world");
DBCollection users = db.getCollection("user"); MongoCollection<Document> users = db.getCollection("user");
DBCollection server = db.getCollection("server"); MongoCollection<Document> server = db.getCollection("server");
int insertedWorlds = 0; int insertedWorlds = 0;
GameUniverse universe = GameServer.INSTANCE.getGameUniverse(); GameUniverse universe = GameServer.INSTANCE.getGameUniverse();
for (World w : universe.getWorlds()) { for (World w : universe.getWorlds()) {
insertedWorlds++; insertedWorlds++;
worlds.save(w.mongoSerialise()); worlds.replaceOne(new Document("_id", w.getId()), w.mongoSerialise(), updateOptions);
//If the world should unload, it is removed from the Universe after having been saved. //If the world should unload, it is removed from the Universe after having been saved.
if (w.shouldUnload()){ if (w.shouldUnload()){
@ -258,18 +260,18 @@ public class GameServer implements Runnable {
} }
} }
for (User u : GameServer.INSTANCE.getGameUniverse().getUsers()) {
for (User u : GameServer.INSTANCE.getGameUniverse().getUsers()) {
if (!u.isGuest()) { if (!u.isGuest()) {
users.save(u.mongoSerialise()); users.replaceOne(new Document("_id", u.getUsername()), u.mongoSerialise(), updateOptions);
} }
} }
BasicDBObject serverObj = new BasicDBObject(); Document serverObj = new Document();
serverObj.put("_id", "serverinfo"); //A constant id ensures only one entry is kept and updated, instead of a new entry created every save.
serverObj.put("time", gameUniverse.getTime()); serverObj.put("time", gameUniverse.getTime());
serverObj.put("nextObjectId", gameUniverse.getNextObjectId()); serverObj.put("nextObjectId", gameUniverse.getNextObjectId());
server.save(serverObj); //A constant id ensures only one entry is kept and updated, instead of a new entry created every save.
server.replaceOne(new Document("_id", "serverinfo"), serverObj, updateOptions);
LogManager.LOGGER.info("" + insertedWorlds + " worlds saved, " + unloaded_worlds + " unloaded"); LogManager.LOGGER.info("" + insertedWorlds + " worlds saved, " + unloaded_worlds + " unloaded");
} catch (Exception e) { } catch (Exception e) {

View File

@ -3,7 +3,6 @@ package net.simon987.server;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

View File

@ -1,26 +1,26 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.ServerConfiguration; import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.assembly.exception.CancelledException;
import net.simon987.server.assembly.instruction.*; import net.simon987.server.assembly.instruction.*;
import net.simon987.server.event.CpuInitialisationEvent; import net.simon987.server.event.CpuInitialisationEvent;
import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEvent;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User; import net.simon987.server.user.User;
import org.bson.Document;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* CPU: Central Processing Unit. A CPU is capable of reading bytes from * CPU: Central Processing Unit. A CPU is capable of reading bytes from
* a Memory object and execute them. A CPU object holds registers objects and * a Memory object and execute them. A CPU object holds registers objects and
* a Memory object. * a Memory object.
*/ */
public class CPU implements MongoSerialisable { public class CPU implements MongoSerializable {
/** /**
* *
@ -347,21 +347,21 @@ public class CPU implements MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("memory", memory.mongoSerialise()); dbObject.put("memory", memory.mongoSerialise());
dbObject.put("registerSet", registerSet.mongoSerialise()); dbObject.put("registerSet", registerSet.mongoSerialise());
dbObject.put("codeSegmentOffset", codeSectionOffset); dbObject.put("codeSegmentOffset", codeSectionOffset);
BasicDBList hardwareList = new BasicDBList(); List<Document> hardwareList = new ArrayList<>();
for (Integer address : attachedHardware.keySet()) { for (Integer address : attachedHardware.keySet()) {
CpuHardware hardware = attachedHardware.get(address); CpuHardware hardware = attachedHardware.get(address);
BasicDBObject serialisedHw = hardware.mongoSerialise(); Document serialisedHw = hardware.mongoSerialise();
serialisedHw.put("address", address); serialisedHw.put("address", address);
hardwareList.add(serialisedHw); hardwareList.add(serialisedHw);
} }
@ -372,22 +372,22 @@ public class CPU implements MongoSerialisable {
} }
public static CPU deserialize(DBObject obj, User user) throws CancelledException { public static CPU deserialize(Document obj, User user) throws CancelledException {
CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user); CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user);
cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset"); cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset");
BasicDBList hardwareList = (BasicDBList) obj.get("hardware"); ArrayList hardwareList = (ArrayList) obj.get("hardware");
for (Object serialisedHw : hardwareList) { for (Object serialisedHw : hardwareList) {
CpuHardware hardware = CpuHardware.deserialize((DBObject) serialisedHw); CpuHardware hardware = CpuHardware.deserialize((Document) serialisedHw);
hardware.setCpu(cpu); hardware.setCpu(cpu);
cpu.attachHardware(hardware, (int) ((BasicDBObject) serialisedHw).get("address")); cpu.attachHardware(hardware, (int) ((Document) serialisedHw).get("address"));
} }
cpu.memory = Memory.deserialize((DBObject) obj.get("memory")); cpu.memory = Memory.deserialize((Document) obj.get("memory"));
cpu.registerSet = RegisterSet.deserialize((DBObject) obj.get("registerSet")); cpu.registerSet = RegisterSet.deserialize((Document) obj.get("registerSet"));
return cpu; return cpu;

View File

@ -1,13 +1,13 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.io.CpuHardwareDeserializer; import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
public abstract class CpuHardware implements MongoSerialisable { public abstract class CpuHardware implements MongoSerializable {
CPU cpu; CPU cpu;
@ -26,7 +26,7 @@ public abstract class CpuHardware implements MongoSerialisable {
public abstract char getId(); public abstract char getId();
public static CpuHardware deserialize(DBObject obj) { public static CpuHardware deserialize(Document obj) {
for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) { for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) {

View File

@ -1,11 +1,10 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -22,7 +21,7 @@ import java.util.zip.InflaterOutputStream;
/** /**
* Represents the available memory for a CPU in the game universe * Represents the available memory for a CPU in the game universe
*/ */
public class Memory implements Target, MongoSerialisable { public class Memory implements Target, MongoSerializable {
/** /**
@ -133,9 +132,9 @@ public class Memory implements Target, MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
try { try {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
@ -154,7 +153,7 @@ public class Memory implements Target, MongoSerialisable {
return dbObject; return dbObject;
} }
public static Memory deserialize(DBObject obj) { public static Memory deserialize(Document obj) {
Memory memory = new Memory(0); Memory memory = new Memory(0);

View File

@ -1,21 +1,20 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import com.mongodb.BasicDBList; import net.simon987.server.io.MongoSerializable;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.io.MongoSerialisable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* A set of registers for a CPU * A set of registers for a CPU
*/ */
public class RegisterSet implements Target, MongoSerialisable { public class RegisterSet implements Target, MongoSerializable {
/** /**
* List of registers * List of registers
@ -145,10 +144,10 @@ public class RegisterSet implements Target, MongoSerialisable {
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBList registers = new BasicDBList(); List<Document> registers = new ArrayList<>();
for (Integer index : this.registers.keySet()) { for (Integer index : this.registers.keySet()) {
JSONObject register = new JSONObject(); Document register = new Document();
register.put("index", index); register.put("index", index);
register.put("name", getRegister(index).getName()); register.put("name", getRegister(index).getName());
@ -157,24 +156,24 @@ public class RegisterSet implements Target, MongoSerialisable {
registers.add(register); registers.add(register);
} }
BasicDBObject obj = new BasicDBObject(); Document obj = new Document();
obj.put("registers", registers); obj.put("registers", registers);
return obj; return obj;
} }
public static RegisterSet deserialize(DBObject obj) { public static RegisterSet deserialize(Document obj) {
RegisterSet registerSet = new RegisterSet(); RegisterSet registerSet = new RegisterSet();
BasicDBList registers = (BasicDBList) obj.get("registers"); List registers = (ArrayList) obj.get("registers");
for (Object sRegister : registers) { for (Object sRegister : registers) {
Register register = new Register((String) ((DBObject) sRegister).get("name")); Register register = new Register((String) ((Document) sRegister).get("name"));
register.setValue((int) ((DBObject) sRegister).get("value")); register.setValue((int) ((Document) sRegister).get("value"));
registerSet.registers.put((int) ((DBObject) sRegister).get("index"), register); registerSet.registers.put((int) ((Document) sRegister).get("index"), register);
} }

View File

@ -1,11 +1,11 @@
package net.simon987.server.game; package net.simon987.server.game;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.io.JSONSerialisable; import net.simon987.server.io.JSONSerialisable;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import net.simon987.server.plugin.ServerPlugin; import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.awt.*; import java.awt.*;
@ -15,7 +15,7 @@ import java.util.ArrayList;
* An INSTANCE of an object (e.g. a Tree, a character ...) inside the * An INSTANCE of an object (e.g. a Tree, a character ...) inside the
* game universe * game universe
*/ */
public abstract class GameObject implements JSONSerialisable, MongoSerialisable { public abstract class GameObject implements JSONSerialisable, MongoSerializable {
private boolean dead; private boolean dead;
/** /**
@ -223,8 +223,8 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
return new JSONObject(); return new JSONObject();
} }
public static GameObject deserialize(DBObject obj) { public static GameObject deserialize(Document obj) {
//
for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) { for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) {
if (plugin instanceof GameObjectDeserializer) { if (plugin instanceof GameObjectDeserializer) {

View File

@ -1,6 +1,9 @@
package net.simon987.server.game; package net.simon987.server.game;
import com.mongodb.*; import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.ServerConfiguration; import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.Assembler; import net.simon987.server.assembly.Assembler;
@ -9,6 +12,7 @@ import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.assembly.exception.CancelledException;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User; import net.simon987.server.user.User;
import org.bson.Document;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -56,12 +60,12 @@ public class GameUniverse {
*/ */
private World loadWorld(int x, int y, String dimension) { private World loadWorld(int x, int y, String dimension) {
DB db = mongo.getDB(GameServer.INSTANCE.getConfig().getString("mongo_dbname")); MongoDatabase db = mongo.getDatabase(GameServer.INSTANCE.getConfig().getString("mongo_dbname"));
DBCollection worlds = db.getCollection("world"); MongoCollection<Document> worlds = db.getCollection("world");
BasicDBObject whereQuery = new BasicDBObject(); Document whereQuery = new Document();
whereQuery.put("_id", World.idFromCoordinates(x, y, dimension)); whereQuery.put("_id", World.idFromCoordinates(x, y, dimension));
DBCursor cursor = worlds.find(whereQuery); MongoCursor<Document> cursor = worlds.find(whereQuery).iterator();
if (cursor.hasNext()) { if (cursor.hasNext()) {
return World.deserialize(cursor.next()); return World.deserialize(cursor.next());
} }

View File

@ -1,16 +1,15 @@
package net.simon987.server.game; package net.simon987.server.game;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.io.JSONSerialisable; import net.simon987.server.io.JSONSerialisable;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import org.bson.Document;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import java.awt.*; import java.awt.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Random; import java.util.Random;
import java.util.zip.Deflater; import java.util.zip.Deflater;
@ -19,7 +18,7 @@ import java.util.zip.DeflaterOutputStream;
/** /**
* A 2D map of Tile objects of size width*height * A 2D map of Tile objects of size width*height
*/ */
public class TileMap implements JSONSerialisable, MongoSerialisable { public class TileMap implements JSONSerialisable, MongoSerializable {
public static final int VOID = -1; public static final int VOID = -1;
public static final int PLAIN_TILE = 0; public static final int PLAIN_TILE = 0;
@ -141,25 +140,34 @@ public class TileMap implements JSONSerialisable, MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("tiles", tiles); //Flatten multi-dimensional array
ArrayList<Integer> bsonTiles = new ArrayList<>();
for (int x = 0; x < this.width; x++) {
for (int y = 0; y < this.height; y++) {
bsonTiles.add(tiles[x][y]);
}
}
dbObject.put("tiles", bsonTiles);
return dbObject; return dbObject;
} }
public static TileMap deserialize(DBObject object, int size) { public static TileMap deserialize(Document object, int size) {
BasicDBList terrain = (BasicDBList) object.get("tiles"); ArrayList<Integer> terrain = (ArrayList<Integer>) object.get("tiles");
int[][] tiles = new int[size][size]; int[][] tiles = new int[size][size];
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
tiles[x][y] = (int) ((BasicDBList) terrain.get(x)).get(y); tiles[x][y] = terrain.get(x * size + y);
} }
} }

View File

@ -1,21 +1,20 @@
package net.simon987.server.game; package net.simon987.server.game;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEvent;
import net.simon987.server.event.WorldUpdateEvent; import net.simon987.server.event.WorldUpdateEvent;
import net.simon987.server.game.pathfinding.Pathfinder; import net.simon987.server.game.pathfinding.Pathfinder;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import org.bson.Document;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class World implements MongoSerialisable { public class World implements MongoSerializable {
/** /**
* Size of the side of this world * Size of the side of this world
@ -171,17 +170,15 @@ public class World implements MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
BasicDBList objects = new BasicDBList(); List<Document> objects = new ArrayList<>();
for (GameObject obj : gameObjects.values()) { for (GameObject obj : gameObjects.values()) {
objects.add(obj.mongoSerialise()); objects.add(obj.mongoSerialise());
} }
dbObject.put("_id", getId());
dbObject.put("dimension", getDimension()); dbObject.put("dimension", getDimension());
dbObject.put("objects", objects); dbObject.put("objects", objects);
@ -214,7 +211,7 @@ public class World implements MongoSerialisable {
} }
public static World deserialize(DBObject dbObject) { public static World deserialize(Document dbObject) {
World world = new World((int) dbObject.get("size")); World world = new World((int) dbObject.get("size"));
world.x = (int) dbObject.get("x"); world.x = (int) dbObject.get("x");
@ -222,13 +219,13 @@ public class World implements MongoSerialisable {
world.dimension = (String) dbObject.get("dimension"); world.dimension = (String) dbObject.get("dimension");
world.updatable = (int) dbObject.get("updatable"); world.updatable = (int) dbObject.get("updatable");
world.tileMap = TileMap.deserialize((BasicDBObject) dbObject.get("terrain"), world.getWorldSize()); world.tileMap = TileMap.deserialize((Document) dbObject.get("terrain"), world.getWorldSize());
BasicDBList objects = (BasicDBList) dbObject.get("objects"); ArrayList<Document> objects = (ArrayList<Document>) dbObject.get("objects");
for (Object obj : objects) { for (Object obj : objects) {
GameObject object = GameObject.deserialize((DBObject) obj); GameObject object = GameObject.deserialize((Document) obj);
object.setWorld(world); object.setWorld(world);
world.addObject(object); world.addObject(object);

View File

@ -1,13 +1,12 @@
package net.simon987.server.game.debug; package net.simon987.server.game.debug;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.event.DebugCommandEvent; import net.simon987.server.event.DebugCommandEvent;
import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener; import net.simon987.server.event.GameEventListener;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.game.World; import net.simon987.server.game.World;
import org.bson.Document;
import java.util.Arrays; import java.util.Arrays;
@ -28,7 +27,7 @@ public class SpawnObjCommandListener implements GameEventListener {
World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"), World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"),
false, e.getString("dimension")); false, e.getString("dimension"));
DBObject dbObj = (DBObject) JSON.parse(e.getString("data")); Document dbObj = Document.parse(e.getString("data"));
dbObj.put("i", GameServer.INSTANCE.getGameUniverse().getNextObjectId()); dbObj.put("i", GameServer.INSTANCE.getGameUniverse().getNextObjectId());
GameObject object = GameObject.deserialize(dbObj); GameObject object = GameObject.deserialize(dbObj);

View File

@ -1,10 +1,10 @@
package net.simon987.server.io; package net.simon987.server.io;
import com.mongodb.DBObject;
import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.CpuHardware;
import org.bson.Document;
public interface CpuHardwareDeserializer { public interface CpuHardwareDeserializer {
CpuHardware deserializeHardware(DBObject hwJson); CpuHardware deserializeHardware(Document hwJson);
} }

View File

@ -1,10 +1,10 @@
package net.simon987.server.io; package net.simon987.server.io;
import com.mongodb.DBObject;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import org.bson.Document;
public interface GameObjectDeserializer { public interface GameObjectDeserializer {
GameObject deserializeObject(DBObject object); GameObject deserializeObject(Document object);
} }

View File

@ -1,9 +0,0 @@
package net.simon987.server.io;
import com.mongodb.BasicDBObject;
public interface MongoSerialisable {
BasicDBObject mongoSerialise();
}

View File

@ -0,0 +1,9 @@
package net.simon987.server.io;
import org.bson.Document;
public interface MongoSerializable {
Document mongoSerialise();
}

View File

@ -1,19 +1,18 @@
package net.simon987.server.user; package net.simon987.server.user;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.CPU; import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.assembly.exception.CancelledException;
import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEvent;
import net.simon987.server.event.UserCreationEvent; import net.simon987.server.event.UserCreationEvent;
import net.simon987.server.game.ControllableUnit; import net.simon987.server.game.ControllableUnit;
import net.simon987.server.io.MongoSerialisable; import net.simon987.server.io.MongoSerializable;
import org.bson.Document;
/** /**
* Represents a User (or player) of the game * Represents a User (or player) of the game
*/ */
public class User implements MongoSerialisable { public class User implements MongoSerializable {
private String username; private String username;
@ -45,9 +44,9 @@ public class User implements MongoSerialisable {
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject(); Document dbObject = new Document();
dbObject.put("_id", username); // a constant id ensures only one entry per user is kept and updated, instead of a new entry created every save for every user. dbObject.put("_id", username); // a constant id ensures only one entry per user is kept and updated, instead of a new entry created every save for every user.
dbObject.put("username", username); dbObject.put("username", username);
@ -62,18 +61,18 @@ public class User implements MongoSerialisable {
} }
public static User deserialize(DBObject obj) throws CancelledException { public static User deserialize(Document obj) throws CancelledException {
User user = new User((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("controlledUnit"))); User user = new User((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("controlledUnit")));
user.username = (String) obj.get("username"); user.username = (String) obj.get("username");
user.userCode = (String) obj.get("code"); user.userCode = (String) obj.get("code");
user.password = (String) obj.get("password"); user.password = (String) obj.get("password");
user.moderator = (boolean) obj.get("moderator"); user.moderator = (boolean) obj.get("moderator");
user.stats = new UserStats((BasicDBObject) obj.get("stats")); user.stats = new UserStats((Document) obj.get("stats"));
user.getControlledUnit().setParent(user); user.getControlledUnit().setParent(user);
user.cpu = CPU.deserialize((DBObject) obj.get("cpu"), user); user.cpu = CPU.deserialize((Document) obj.get("cpu"), user);
return user; return user;
} }

View File

@ -1,22 +1,21 @@
package net.simon987.server.user; package net.simon987.server.user;
import com.mongodb.BasicDBObject; import com.mongodb.client.MongoCollection;
import com.mongodb.DBCollection; import com.mongodb.client.MongoCursor;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.assembly.exception.CancelledException;
import net.simon987.server.crypto.RandomStringGenerator; import net.simon987.server.crypto.RandomStringGenerator;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.springframework.security.crypto.bcrypt.BCrypt; import org.springframework.security.crypto.bcrypt.BCrypt;
import java.util.ArrayList; import java.util.ArrayList;
public class UserManager { public class UserManager {
private DBCollection userCollection; private MongoCollection<Document> userCollection;
public UserManager(DBCollection userCollection) { public UserManager(MongoCollection<Document> userCollection) {
this.userCollection = userCollection; this.userCollection = userCollection;
} }
@ -30,7 +29,7 @@ public class UserManager {
ArrayList<User> userList = new ArrayList<>(); ArrayList<User> userList = new ArrayList<>();
DBCursor cursor = userCollection.find(); MongoCursor<Document> cursor = userCollection.find().iterator();
while (cursor.hasNext()) { while (cursor.hasNext()) {
try { try {
userList.add(User.deserialize(cursor.next())); userList.add(User.deserialize(cursor.next()));
@ -58,10 +57,10 @@ public class UserManager {
} }
//Check if exists //Check if exists
DBObject where = new BasicDBObject(); Document where = new Document();
where.put("_id", username); where.put("_id", username);
if (userCollection.findOne(where) != null) { if (userCollection.find(where).first() != null) {
throw new RegistrationException("Username is already in use"); throw new RegistrationException("Username is already in use");
} }
@ -73,9 +72,9 @@ public class UserManager {
String hashedPassword = BCrypt.hashpw(password, salt); String hashedPassword = BCrypt.hashpw(password, salt);
user.setPassword(hashedPassword); user.setPassword(hashedPassword);
DBObject dbUser = user.mongoSerialise(); Document dbUser = user.mongoSerialise();
userCollection.save(dbUser); userCollection.insertOne(dbUser);
} catch (Exception e) { } catch (Exception e) {
throw new RegistrationException("An exception occurred while trying to create user: " + e.getMessage()); throw new RegistrationException("An exception occurred while trying to create user: " + e.getMessage());
} }
@ -89,10 +88,10 @@ public class UserManager {
*/ */
public boolean validateUser(String username, String password) { public boolean validateUser(String username, String password) {
DBObject where = new BasicDBObject(); Document where = new Document();
where.put("_id", username); where.put("_id", username);
DBObject user = userCollection.findOne(where); Document user = userCollection.find(where).first();
return user != null && BCrypt.checkpw(password, (String) user.get("password")); return user != null && BCrypt.checkpw(password, (String) user.get("password"));
} }
@ -114,7 +113,7 @@ public class UserManager {
String hashedPassword = BCrypt.hashpw(newPassword, salt); String hashedPassword = BCrypt.hashpw(newPassword, salt);
user.setPassword(hashedPassword); user.setPassword(hashedPassword);
userCollection.save(user.mongoSerialise()); //Save new password immediately userCollection.replaceOne(new Document("_id", username), user.mongoSerialise()); //Save new password immediately
} }
/** /**

View File

@ -1,28 +1,29 @@
package net.simon987.server.user; package net.simon987.server.user;
import com.mongodb.BasicDBList; import net.simon987.server.io.MongoSerializable;
import com.mongodb.BasicDBObject;
import net.simon987.server.io.MongoSerialisable;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.bson.Document;
public class UserStats implements MongoSerialisable { import java.util.ArrayList;
private BasicDBObject stats; public class UserStats implements MongoSerializable {
private Document stats;
UserStats() { UserStats() {
this.stats = new BasicDBObject(); this.stats = new Document();
} }
UserStats(BasicDBObject stats) { UserStats(Document stats) {
if (stats != null) { if (stats != null) {
this.stats = stats; this.stats = stats;
} else { } else {
this.stats = new BasicDBObject(); this.stats = new Document();
} }
} }
@Override @Override
public BasicDBObject mongoSerialise() { public Document mongoSerialise() {
return stats; return stats;
} }
@ -36,7 +37,7 @@ public class UserStats implements MongoSerialisable {
public void incrementStat(String name, int count) { public void incrementStat(String name, int count) {
stats.putIfAbsent(name, 0); stats.putIfAbsent(name, 0);
stats.put(name, stats.getInt(name) + count); stats.put(name, stats.getInteger(name) + count);
} }
/** /**
@ -57,8 +58,7 @@ public class UserStats implements MongoSerialisable {
* @return The value of the stat. Returns 0 if not found * @return The value of the stat. Returns 0 if not found
*/ */
public int getInt(String name) { public int getInt(String name) {
return stats.getInteger(name, 0);
return stats.getInt(name, 0);
} }
/** /**
@ -69,10 +69,10 @@ public class UserStats implements MongoSerialisable {
*/ */
public void addToStringSet(String name, String value) { public void addToStringSet(String name, String value) {
stats.putIfAbsent(name, new BasicDBList()); stats.putIfAbsent(name, new ArrayList<>());
try { try {
((BasicDBList) stats.get(name)).add(value); ((ArrayList<String>) stats.get(name)).add(value);
} catch (ClassCastException e) { } catch (ClassCastException e) {
LogManager.LOGGER.severe("UserStats: cannot add to list because stat already exists and is not a list"); LogManager.LOGGER.severe("UserStats: cannot add to list because stat already exists and is not a list");
} }
@ -87,16 +87,16 @@ public class UserStats implements MongoSerialisable {
*/ */
public boolean removeFromSet(String name, String value) { public boolean removeFromSet(String name, String value) {
if (stats.putIfAbsent(name, new BasicDBList()) != null) { if (stats.putIfAbsent(name, new ArrayList()) != null) {
return ((BasicDBList) stats.get(name)).remove(value); return ((ArrayList) stats.get(name)).remove(value);
} }
return false; return false;
} }
public BasicDBList getSet(String name) { public ArrayList getSet(String name) {
stats.putIfAbsent(name, new BasicDBList()); stats.putIfAbsent(name, new ArrayList());
return (BasicDBList) stats.get(name); return (ArrayList) stats.get(name);
} }
} }

View File

@ -1,11 +1,11 @@
package net.simon987.server.user; package net.simon987.server.user;
import com.mongodb.*; import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import org.bson.Document;
import java.util.AbstractMap; import java.util.*;
import java.util.ArrayList;
import java.util.Map;
/** /**
* Retrieve user stats in a structured fashion * Retrieve user stats in a structured fashion
@ -15,12 +15,12 @@ public class UserStatsHelper {
/** /**
* Database collection of users * Database collection of users
*/ */
private DBCollection users; private MongoCollection<Document> users;
/** /**
* @param users Database collection of users * @param users Database collection of users
*/ */
public UserStatsHelper(DBCollection users) { public UserStatsHelper(MongoCollection<Document> users) {
this.users = users; this.users = users;
} }
@ -35,11 +35,11 @@ public class UserStatsHelper {
ArrayList<Map.Entry<User, Integer>> rows = new ArrayList<>(); ArrayList<Map.Entry<User, Integer>> rows = new ArrayList<>();
BasicDBObject orderBy = new BasicDBObject("$stats." + statName, -1); Document orderBy = new Document("$stats." + statName, -1);
DBCursor cursor = users.find().sort(orderBy).limit(n); MongoCursor<Document> cursor = users.find().sort(orderBy).limit(n).iterator();
while (cursor.hasNext()) { while (cursor.hasNext()) {
DBObject dbUser = cursor.next(); Document dbUser = cursor.next();
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username")); User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username"));
rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getInt(statName))); rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getInt(statName)));
} }
@ -54,26 +54,27 @@ public class UserStatsHelper {
* @param n Maximum number of players * @param n Maximum number of players
* @return Top n players, in User,set format, in descending order * @return Top n players, in User,set format, in descending order
*/ */
public ArrayList<Map.Entry<User, BasicDBList>> getTopNSetLength(String statName, int n) { public ArrayList<Map.Entry<User, ArrayList>> getTopNSetLength(String statName, int n) {
ArrayList<Map.Entry<User, BasicDBList>> rows = new ArrayList<>(); ArrayList<Map.Entry<User, ArrayList>> rows = new ArrayList<>();
BasicDBList ifNullList = new BasicDBList(); List<Object> ifNullList = new ArrayList<>(2);
ifNullList.add("$stats." + statName); ifNullList.add("$stats." + statName);
ifNullList.add(new BasicDBList()); ifNullList.add(new ArrayList());
BasicDBObject project = new BasicDBObject(); Document project = new Document();
project.put("setLength", new BasicDBObject("$size", new BasicDBObject("$ifNull", ifNullList))); project.put("setLength", new Document("$size", new Document("$ifNull", ifNullList)));
project.put("username", 1); project.put("username", 1);
Iterable<DBObject> results = users.aggregate(
new BasicDBObject("$project", project),
new BasicDBObject("$sort", new BasicDBObject("setLength", -1)),
new BasicDBObject("$limit", n)
).results();
for (DBObject dbUser : results) { Iterator<Document> results = users.aggregate(Arrays.asList(
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username")); new Document("$project", project),
new Document("$sort", new Document("setLength", -1)),
new Document("$limit", n))
).iterator();
while (results.hasNext()) {
User user = GameServer.INSTANCE.getGameUniverse().getUser((String) results.next().get("username"));
rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getSet(statName))); rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getSet(statName)));
} }

View File

@ -14,7 +14,7 @@ server_name=Official MAR server
#Database #Database
mongo_dbname=mar_beta mongo_dbname=mar_beta
#Change to 'mongodb' to use in docker #Change to 'mongodb' to use in docker
mongo_address=mongodb mongo_address=localhost
mongo_port=27017 mongo_port=27017
#Biomass #Biomass
biomass_yield=2 biomass_yield=2