Added exception checking for disconnect operations

This commit is contained in:
Treeku
2014-05-31 19:43:59 +01:00
parent 58385aeb4c
commit 90fc465c56
+57 -18
View File
@@ -793,32 +793,46 @@ public class SimulationService implements INetworkDispatch {
if(object.getAttachment("proposer") != null)
object.setAttachment("proposer", null);
//session.suspendWrite();
final long objectId = object.getObjectID();
if(!ghost.isSet(PlayerFlags.LD))
ghost.toggleFlag(PlayerFlags.LD);
for (CreatureObject opponent : new ArrayList<CreatureObject>(object.getDuelList())) {
if (opponent != null) {
core.combatService.handleEndDuel(object, opponent, true);
try {
for (CreatureObject opponent : new ArrayList<CreatureObject>(object.getDuelList())) {
if (opponent != null) {
core.combatService.handleEndDuel(object, opponent, true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (core.mountService.isMounted(object)) {
core.mountService.dismount(object, (CreatureObject) container);
}
core.mountService.storeAll(object);
List<Integer> joinedChannels = ghost.getJoinedChatChannels();
for (Integer roomId : joinedChannels) {
ChatRoom room = core.chatService.getChatRoom(roomId.intValue());
try {
if (core.mountService.isMounted(object)) {
core.mountService.dismount(object, (CreatureObject) container);
}
if (room != null) { core.chatService.leaveChatRoom(object, roomId.intValue(), false); }
// work-around for any channels that may have been deleted, or only spawn on server startup, that were added to the joined channels
else { ghost.removeChannel(roomId); }
core.mountService.storeAll(object);
} catch (Exception e) {
e.printStackTrace();
}
try {
for (Integer roomId : ghost.getJoinedChatChannels()) {
ChatRoom room = core.chatService.getChatRoom(roomId.intValue());
if (room != null) {
core.chatService.leaveChatRoom(object, roomId.intValue(), false);
} else {
// work-around for any channels that may have been deleted, or only spawn on server startup, that were added to the joined channels
ghost.removeChannel(roomId);
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*
object.createTransaction(core.getCreatureODB().getEnvironment());
core.getCreatureODB().put(object, Long.class, CreatureObject.class, object.getTransaction());
@@ -830,15 +844,40 @@ public class SimulationService implements INetworkDispatch {
SWGObject object = core.objectService.getObject(objectId);
if (object.getAttachment("disconnectTask") != null) {
//core.connectionService.disconnect(client);
try {
core.combatService.endCombat(object);
} catch (Exception e) {
e.printStackTrace();
}
core.simulationService.remove(object, object.getPosition().x, object.getPosition().z, true);
/*
try {
Thread.sleep(900000)
} catch (Exception e) {
e.printStackTrace();
}
// If connectionService fails for some reason, this will call disconnect again after 15 mins.
// This should never actually be needed though:
try {
if (object != null && object.getAttachment("disconnectTask") != null && client != null) {
core.connectionService.disconnect(client);
}
} catch (Exception e) {
System.err.println("ConnectionService:disconnect(): Error disconnecting client.");
e.printStackTrace();
}
*/
}
}
}, 120, TimeUnit.SECONDS);
core.removeClient(session);
object.setAttachment("disconnectTask", disconnectTask);
core.combatService.endCombat(object); // temp fix for ending combat on disconnect
}