mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-09-21 06:13:13 -04:00
See extended.
[fixed] Characters could sometimes walk through buildings due to unsigned object Ids [fixed] Critical networking bugs [fixed] Client crash whenever an object was destroyed [added] Loading of client objects is now multithreaded. [updated] Reworked awareness system(engine). [fixed] lots of other small engine fixes.
This commit is contained in:
Binary file not shown.
@@ -190,7 +190,15 @@ public class NGECore {
|
||||
|
||||
// Planets
|
||||
terrainService.addPlanet(1, "tatooine", "terrain/tatooine.trn", true);
|
||||
|
||||
terrainService.addPlanet(2, "naboo", "terrain/naboo.trn", true);
|
||||
terrainService.addPlanet(3, "corellia", "terrain/corellia.trn", true);
|
||||
terrainService.addPlanet(4, "rori", "terrain/rori.trn", true);
|
||||
terrainService.addPlanet(5, "lok", "terrain/lok.trn", true);
|
||||
terrainService.addPlanet(6, "dantooine", "terrain/dantooine.trn", true);
|
||||
terrainService.addPlanet(7, "talus", "terrain/talus.trn", true);
|
||||
terrainService.addPlanet(8, "yavin4", "terrain/yavin4.trn", true);
|
||||
terrainService.addPlanet(9, "endor", "terrain/endor.trn", true);
|
||||
terrainService.addPlanet(10, "dathomir", "terrain/dathomir.trn", true);
|
||||
terrainService.loadSnapShotObjects();
|
||||
|
||||
// Zone services that need to be loaded after the above
|
||||
|
||||
@@ -43,8 +43,7 @@ public class LoginServerString extends SWGMessage {
|
||||
|
||||
result.putShort((short)2);
|
||||
result.putInt(0x0E20D7E9);
|
||||
result.putShort((short)loginServerString.length());
|
||||
result.put(loginServerString.getBytes());
|
||||
result.put(getAsciiString(loginServerString));
|
||||
result.flip();
|
||||
|
||||
return result;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SceneDestroyObject extends SWGMessage {
|
||||
}
|
||||
|
||||
public IoBuffer serialize() {
|
||||
IoBuffer result = IoBuffer.allocate(14).order(ByteOrder.LITTLE_ENDIAN);
|
||||
IoBuffer result = IoBuffer.allocate(15).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
result.putShort((short)3);
|
||||
result.putInt(0x4D45D504);
|
||||
|
||||
@@ -796,7 +796,7 @@ public class CreatureObject extends TangibleObject implements IPersistent {
|
||||
upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Neutral);
|
||||
upvpm.setStatus(16);
|
||||
}
|
||||
//destination.getSession().write(upvpm.serialize());
|
||||
destination.getSession().write(upvpm.serialize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ public class CharacterService implements INetworkDispatch {
|
||||
|
||||
core.getCreatureODB().put(object, Long.class, CreatureObject.class, object.getTransaction());
|
||||
// might not need to commit transaction but better safe than sorry
|
||||
object.getTransaction().commit();
|
||||
object.getTransaction().commitSync();
|
||||
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("INSERT INTO characters (id, \"firstName\", \"lastName\", \"accountId\", \"galaxyId\", \"statusId\", appearance, gmflag) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
ps.setLong(1, object.getObjectID());
|
||||
|
||||
@@ -38,6 +38,7 @@ import protocol.swg.ClientPermissionsMessage;
|
||||
import protocol.swg.ConnectionServerLagResponse;
|
||||
import protocol.swg.GalaxyLoopTimesResponse;
|
||||
import protocol.swg.GameServerLagResponse;
|
||||
import protocol.swg.HeartBeatMessage;
|
||||
|
||||
import engine.clients.Client;
|
||||
import engine.resources.database.DatabaseConnection;
|
||||
@@ -74,11 +75,13 @@ public class ConnectionService implements INetworkDispatch {
|
||||
clientIdMsg.deserialize(data);
|
||||
|
||||
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
|
||||
if(client == null) System.out.println("NULL Client");
|
||||
if(client == null) {
|
||||
System.out.println("NULL Client");
|
||||
return;
|
||||
}
|
||||
client.setSession(session);
|
||||
ResultSet resultSet;
|
||||
PreparedStatement preparedStatement;
|
||||
System.out.println(clientIdMsg.getSessionKey().length);
|
||||
|
||||
try {
|
||||
|
||||
@@ -90,10 +93,12 @@ public class ConnectionService implements INetworkDispatch {
|
||||
client.setAccountId(resultSet.getInt("accountId"));
|
||||
AccountFeatureBits accountFeatureBits = new AccountFeatureBits();
|
||||
ClientPermissionsMessage clientPermissionsMessage = new ClientPermissionsMessage();
|
||||
session.write(new HeartBeatMessage().serialize());
|
||||
session.write(accountFeatureBits.serialize());
|
||||
session.write(clientPermissionsMessage.serialize());
|
||||
preparedStatement.close();
|
||||
|
||||
} else {
|
||||
System.out.println("Cant get login session");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PlayerService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}, 0, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void postZoneIn(final CreatureObject creature) {
|
||||
|
||||
@@ -269,7 +269,6 @@ public class SimulationService implements INetworkDispatch {
|
||||
|
||||
DataTransformWithParent dataTransform = new DataTransformWithParent();
|
||||
dataTransform.deserialize(data);
|
||||
//System.out.println("Movement Counter: " + dataTransform.getMovementCounter());
|
||||
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
|
||||
|
||||
if(core.objectService.getObject(dataTransform.getCellId()) == null)
|
||||
@@ -438,15 +437,13 @@ public class SimulationService implements INetworkDispatch {
|
||||
|
||||
if(client.getParent() == null)
|
||||
return;
|
||||
|
||||
session.suspendWrite();
|
||||
|
||||
CreatureObject object = (CreatureObject) client.getParent();
|
||||
boolean remove = remove(object, object.getPosition().x, object.getPosition().z);
|
||||
if(remove)
|
||||
System.out.println("Successful quadtree remove");
|
||||
|
||||
if(object.getContainer() == null) {
|
||||
//if(object.getContainer() == null) {
|
||||
HashSet<Client> oldObservers = new HashSet<Client>(object.getObservers());
|
||||
for(Iterator<Client> it = oldObservers.iterator(); it.hasNext();) {
|
||||
Client observerClient = it.next();
|
||||
@@ -454,9 +451,9 @@ public class SimulationService implements INetworkDispatch {
|
||||
observerClient.getParent().makeUnaware(object);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
object.getContainer().remove(object);
|
||||
}
|
||||
//} else {
|
||||
// object.getContainer().remove(object);
|
||||
//}
|
||||
|
||||
|
||||
object.createTransaction(core.getCreatureODB().getEnvironment());
|
||||
|
||||
@@ -23,7 +23,10 @@ package services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import engine.resources.scene.Planet;
|
||||
|
||||
@@ -115,16 +118,34 @@ public class TerrainService {
|
||||
|
||||
public void loadSnapShotObjects() {
|
||||
|
||||
for(Planet planet : planets) {
|
||||
Map<Planet, Thread> threadMap = new HashMap<Planet, Thread>();
|
||||
|
||||
for(final Planet planet : planets) {
|
||||
|
||||
if(planet.getSnapshotVisitor() != null) {
|
||||
|
||||
core.objectService.loadSnapshotObjects(planet);
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
core.objectService.loadSnapshotObjects(planet);
|
||||
}
|
||||
|
||||
});
|
||||
thread.start();
|
||||
threadMap.put(planet, thread);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// wait for threads to finish loading
|
||||
for(Planet planet : planets) {
|
||||
try {
|
||||
threadMap.get(planet).join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ package services.object;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -107,6 +110,19 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
});
|
||||
long highestId;
|
||||
|
||||
|
||||
try {
|
||||
PreparedStatement ps = databaseConnection.preparedStatement("SELECT id FROM highestid WHERE id=(SELECT max(id) FROM highestid)");
|
||||
ResultSet result = ps.executeQuery();
|
||||
result.next();
|
||||
highestId = result.getInt("id");
|
||||
this.highestId.set(highestId);
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public SWGObject createObject(String Template, long objectID, Planet planet, Point3D position, Quaternion orientation) {
|
||||
@@ -286,9 +302,9 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
|
||||
private long generateObjectID() {
|
||||
Random random = new Random();
|
||||
/*Random random = new Random();
|
||||
|
||||
long objectID = random.nextLong();
|
||||
long objectID = random.nextInt();
|
||||
|
||||
if(getObject(objectID) != null)
|
||||
return generateObjectID();
|
||||
@@ -296,23 +312,22 @@ public class ObjectService implements INetworkDispatch {
|
||||
if(core.getCreatureODB().contains(new Long(objectID), Long.class, CreatureObject.class))
|
||||
return generateObjectID();
|
||||
|
||||
return objectID;
|
||||
return objectID;*/
|
||||
|
||||
/*long newId = highestId.incrementAndGet();
|
||||
long newId = highestId.incrementAndGet();
|
||||
PreparedStatement ps2;
|
||||
|
||||
try {
|
||||
ps2 = databaseConnection.preparedStatement("UPDATE highestid SET id=" + newId + " WHERE id=" + highestId.get());
|
||||
ps2 = databaseConnection.preparedStatement("UPDATE highestid SET id=" + newId + " WHERE id=" + (newId-1));
|
||||
ps2.executeUpdate();
|
||||
highestId.set(newId);
|
||||
ps2.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(getObject(highestId.longValue()) == null)
|
||||
return highestId.longValue();
|
||||
if(getObject(newId) == null)
|
||||
return newId;
|
||||
else
|
||||
return generateObjectID();*/
|
||||
return generateObjectID();
|
||||
|
||||
|
||||
}
|
||||
@@ -327,22 +342,25 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
@Override
|
||||
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
|
||||
|
||||
data = data.order(ByteOrder.LITTLE_ENDIAN);
|
||||
data.position(0);
|
||||
SelectCharacter selectCharacter = new SelectCharacter();
|
||||
selectCharacter.deserialize(data);
|
||||
|
||||
|
||||
long objectId = selectCharacter.getCharacterId();
|
||||
Client client = core.getClient((Integer) session.getAttribute("connectionId"));
|
||||
if(client == null)
|
||||
if(client == null) {
|
||||
System.out.println("NULL Client");
|
||||
return;
|
||||
}
|
||||
CreatureObject creature = null;
|
||||
if(getObject(objectId) == null) {
|
||||
|
||||
if(getCreatureFromDB(objectId) == null)
|
||||
return;
|
||||
|
||||
|
||||
creature = getCreatureFromDB(objectId);
|
||||
if(creature == null) {
|
||||
System.out.println("Cant get creature from db");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -388,10 +406,10 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
|
||||
UnkByteFlag unkByteFlag = new UnkByteFlag();
|
||||
//session.write(unkByteFlag.serialize());
|
||||
session.write(unkByteFlag.serialize());
|
||||
|
||||
ParametersMessage parameters = new ParametersMessage();
|
||||
//session.write(parameters.serialize());
|
||||
session.write(parameters.serialize());
|
||||
|
||||
core.buffService.clearBuffs(creature);
|
||||
|
||||
@@ -425,6 +443,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
public void loadSnapshotObjects(Planet planet) {
|
||||
|
||||
System.out.println("Loading client objects for: " + planet.getName());
|
||||
WorldSnapshotVisitor visitor = planet.getSnapshotVisitor();
|
||||
int counter = 0;
|
||||
for(SnapshotChunk chunk : visitor.getChunks()) {
|
||||
@@ -449,6 +468,8 @@ public class ObjectService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Finished loading client objects for: " + planet.getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user