mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-07-14 00:02:07 -04:00
Fixed some server crashes with some engine changes; also added a creature ODB
This commit is contained in:
+11
-3
@@ -233,13 +233,15 @@ public class NGECore {
|
||||
private ObjectDatabase auctionODB;
|
||||
private ObjectDatabase resourceHistoryODB;
|
||||
private ObjectDatabase swgObjectODB;
|
||||
private ObjectDatabase creatureODB;
|
||||
private ObjectDatabase bountiesODB;
|
||||
private ObjectDatabase cityODB;
|
||||
|
||||
public static boolean PACKET_DEBUG = false;
|
||||
|
||||
public NGECore() {
|
||||
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -302,6 +304,7 @@ public class NGECore {
|
||||
}
|
||||
|
||||
setGalaxyStatus(GalaxyStatus.Loading);
|
||||
creatureODB = new ObjectDatabase("players", true, true, true, CreatureObject.class);
|
||||
swgObjectODB = new ObjectDatabase("swgobjects", true, true, true, SWGObject.class);
|
||||
mailODB = new ObjectDatabase("mails", true, true, true, Mail.class);
|
||||
guildODB = new ObjectDatabase("guild", true, true, true, GuildObject.class);
|
||||
@@ -509,7 +512,7 @@ public class NGECore {
|
||||
|
||||
terrainService.loadSnapShotObjects();
|
||||
objectService.loadServerTemplates();
|
||||
objectService.loadBuildings();
|
||||
objectService.loadObjects();
|
||||
harvesterService.loadHarvesters();
|
||||
|
||||
simulationService.insertSnapShotObjects();
|
||||
@@ -669,6 +672,10 @@ public class NGECore {
|
||||
return databaseConnection2;
|
||||
}
|
||||
|
||||
public ObjectDatabase getCreatureODB() {
|
||||
return creatureODB;
|
||||
}
|
||||
|
||||
public ObjectDatabase getSWGObjectODB() {
|
||||
return swgObjectODB;
|
||||
}
|
||||
@@ -804,8 +811,9 @@ public class NGECore {
|
||||
public long getGalacticTime() {
|
||||
return System.currentTimeMillis() - galacticTime;
|
||||
}
|
||||
|
||||
|
||||
public void closeODBs() {
|
||||
creatureODB.close();
|
||||
swgObjectODB.close();
|
||||
mailODB.close();
|
||||
guildODB.close();
|
||||
|
||||
@@ -67,87 +67,63 @@ public class WaypointObject extends IntangibleObject implements Serializable, ID
|
||||
super.init();
|
||||
}
|
||||
|
||||
public int getCellId() {
|
||||
synchronized(objectMutex) {
|
||||
return cellId;
|
||||
}
|
||||
public synchronized int getCellId() {
|
||||
return cellId;
|
||||
}
|
||||
|
||||
|
||||
public void setCellId(int cellId) {
|
||||
synchronized(objectMutex) {
|
||||
this.cellId = cellId;
|
||||
}
|
||||
public synchronized void setCellId(int cellId) {
|
||||
this.cellId = cellId;
|
||||
}
|
||||
|
||||
|
||||
public long getLocationNetworkId() {
|
||||
synchronized(objectMutex) {
|
||||
return locationNetworkId;
|
||||
}
|
||||
public synchronized long getLocationNetworkId() {
|
||||
return locationNetworkId;
|
||||
}
|
||||
|
||||
|
||||
public void setLocationNetworkId(long locationNetworkId) {
|
||||
synchronized(objectMutex) {
|
||||
this.locationNetworkId = locationNetworkId;
|
||||
}
|
||||
public synchronized void setLocationNetworkId(long locationNetworkId) {
|
||||
this.locationNetworkId = locationNetworkId;
|
||||
}
|
||||
|
||||
|
||||
public int getPlanetCRC() {
|
||||
synchronized(objectMutex) {
|
||||
return planetCRC;
|
||||
}
|
||||
public synchronized int getPlanetCRC() {
|
||||
return planetCRC;
|
||||
}
|
||||
|
||||
|
||||
public void setPlanetCRC(int planetCRC) {
|
||||
synchronized(objectMutex) {
|
||||
this.planetCRC = planetCRC;
|
||||
}
|
||||
public synchronized void setPlanetCRC(int planetCRC) {
|
||||
this.planetCRC = planetCRC;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
synchronized(objectMutex) {
|
||||
return name;
|
||||
}
|
||||
public synchronized String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
synchronized(objectMutex) {
|
||||
this.name = name;
|
||||
}
|
||||
public synchronized void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public byte getColor() {
|
||||
synchronized(objectMutex) {
|
||||
return color;
|
||||
}
|
||||
public synchronized byte getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
public void setColor(byte color) {
|
||||
synchronized(objectMutex) {
|
||||
this.color = color;
|
||||
}
|
||||
public synchronized void setColor(byte color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
public boolean isActive() {
|
||||
synchronized(objectMutex) {
|
||||
return isActive;
|
||||
}
|
||||
public synchronized boolean isActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
|
||||
public void setActive(boolean isActive) {
|
||||
synchronized(objectMutex) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -354,7 +354,8 @@ public class CharacterService implements INetworkDispatch {
|
||||
createStarterClothing(object, sharedRaceTemplate, clientCreateCharacter.getStarterProfession());
|
||||
//core.scriptService.callScript("scripts/", "demo", "CreateStartingCharacter", core, object);
|
||||
|
||||
core.getSWGObjectODB().put(object.getObjectID(), object);
|
||||
System.out.println("Saving character with name: " + object.getCustomName());
|
||||
core.getCreatureODB().put(object.getObjectID(), object);
|
||||
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("INSERT INTO characters (id, \"firstName\", \"lastName\", \"accountId\", \"galaxyId\", \"statusId\", appearance, gmflag) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
ps.setLong(1, object.getObjectID());
|
||||
|
||||
@@ -170,17 +170,10 @@ public class ObjectService implements INetworkDispatch {
|
||||
core.harvesterService.saveHarvesters();
|
||||
core.playerCityService.saveAllCities();
|
||||
core.closeODBs();
|
||||
System.out.println("Databases closed.");
|
||||
}
|
||||
});
|
||||
|
||||
ODBCursor cursor = core.getSWGObjectODB().getCursor();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
SWGObject object = (SWGObject) cursor.next();
|
||||
if (object != null && !(object instanceof BuildingObject))
|
||||
objectList.put(object.getObjectID(), object);
|
||||
}
|
||||
|
||||
long highestId;
|
||||
|
||||
try {
|
||||
@@ -195,7 +188,63 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadBuildings() {
|
||||
public void loadObjects() {
|
||||
System.out.println("Loading objects...");
|
||||
ODBCursor cursor = core.getSWGObjectODB().getCursor();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
SWGObject object = (SWGObject) cursor.next();
|
||||
if (object != null && !(object instanceof BuildingObject))
|
||||
objectList.put(object.getObjectID(), object);
|
||||
}
|
||||
|
||||
cursor = core.getCreatureODB().getCursor();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
CreatureObject object = (CreatureObject) cursor.next();
|
||||
if (object != null) {
|
||||
System.out.println("Loaded character with name: " + object.getCustomName());
|
||||
objectList.put(object.getObjectID(), object);
|
||||
|
||||
loadServerTemplate(object);
|
||||
object.viewChildren(object, true, true, (child) -> loadServerTemplate(child));
|
||||
} else {
|
||||
System.err.println("Character was null!");
|
||||
}
|
||||
}
|
||||
|
||||
// Loading characters by using a lookup
|
||||
try {
|
||||
PreparedStatement ps = core.getDatabase1().preparedStatement("SELECT * FROM characters");
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
long objectId = resultSet.getLong("id");
|
||||
CreatureObject object = (CreatureObject) core.getCreatureODB().get(objectId);
|
||||
if (object != null) {
|
||||
if (object.getCustomName() == null || object.getCustomName().isEmpty()) {
|
||||
String first = resultSet.getString("firstName");
|
||||
String last = resultSet.getString("lastName");
|
||||
if (last.isEmpty())
|
||||
object.setCustomName(first);
|
||||
else
|
||||
object.setCustomName(first + " " + last);
|
||||
}
|
||||
System.out.println("Loaded character manually with name: " + object.getCustomName());
|
||||
objectList.put(objectId, object);
|
||||
} else {
|
||||
System.err.println("Attempt failed to recover character.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
loadBuildings();
|
||||
System.out.println("Finished loading objects.");
|
||||
}
|
||||
|
||||
private void loadBuildings() {
|
||||
ODBCursor cursor = core.getSWGObjectODB().getCursor();
|
||||
|
||||
while(cursor.hasNext()) {
|
||||
@@ -680,10 +729,8 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
|
||||
public CreatureObject getCreatureFromDB(long objectId) {
|
||||
SWGObject object = (SWGObject) core.getSWGObjectODB().get(objectId);
|
||||
if(!(object instanceof CreatureObject))
|
||||
return null;
|
||||
if (object != null && getObject(object.getObjectID()) == null) {
|
||||
CreatureObject object = (CreatureObject) core.getCreatureODB().get(objectId);
|
||||
if (object != null) {
|
||||
loadServerTemplate(object);
|
||||
object.viewChildren(object, true, true, (child) -> loadServerTemplate(child));
|
||||
}
|
||||
@@ -1010,20 +1057,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
creature = (CreatureObject) getObject(objectId);
|
||||
if (creature.getCustomName() == null || creature.getCustomName().isEmpty()) {
|
||||
PreparedStatement ps = core.getDatabase1().preparedStatement("SELECT * FROM characters WHERE \"id\" = ?");
|
||||
ps.setLong(1, creature.getObjectID());
|
||||
ResultSet resultSet = ps.executeQuery();
|
||||
|
||||
String name = "";
|
||||
while (resultSet.next()) {
|
||||
String first = resultSet.getString("firstName").trim();
|
||||
String last = resultSet.getString("lastName").trim();
|
||||
if (last.isEmpty())
|
||||
name = first;
|
||||
else
|
||||
name = first + " " + last;
|
||||
}
|
||||
creature.setCustomName(name);
|
||||
System.err.println("Creature's custom name was null/empty! Name: " + creature.getCustomName());
|
||||
}
|
||||
if(creature.getAttachment("disconnectTask") != null && creature.getClient() != null && !creature.getClient().getSession().isClosing())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user