Fixed bug with relogging and set it up to support CU as well

This commit is contained in:
Josh Larson
2016-05-13 13:30:09 -05:00
parent 9adbdb8efe
commit a712a8222d
7 changed files with 47 additions and 65 deletions

View File

@@ -36,6 +36,11 @@ public class ClientConnection extends Manager {
return true;
}
public void hardReset() {
sender.hardReset();
receiver.hardReset();
}
public void setLoginPort(int loginPort) {
sender.setLoginPort(loginPort);
}

View File

@@ -65,19 +65,13 @@ public class ClientReceiver extends Service {
this.recvIntentChain = new IntentChain();
this.stateIntentChain = new IntentChain();
this.timeout = timeout;
this.status = ClientConnectionStatus.DISCONNECTED;
}
@Override
public boolean initialize() {
registerForIntent(ClientSonyPacketIntent.TYPE);
rxSequence = -1;
lastPacket.set(0);
fragmentedBuffer.clear();
recvIntentChain.reset();
stateIntentChain.reset();
port = 0;
zone = false;
status = ClientConnectionStatus.DISCONNECTED;
hardReset();
return super.initialize();
}
@@ -137,6 +131,17 @@ public class ClientReceiver extends Service {
rxSequence = -1;
}
public void hardReset() {
setConnectionState(ClientConnectionStatus.DISCONNECTED);
rxSequence = -1;
lastPacket.set(0);
fragmentedBuffer.clear();
recvIntentChain.reset();
stateIntentChain.reset();
port = 0;
zone = false;
}
public double getTimeSinceLastPacket() {
return (System.nanoTime() - lastPacket.get()) / 1E6;
}
@@ -207,8 +212,6 @@ public class ClientReceiver extends Service {
}
private void onSessionRequest(SessionRequest request) {
if (!zone)
setConnectionState(ClientConnectionStatus.DISCONNECTED);
if (zone) {
Log.out(this, "Zone Session Request");
setConnectionState(ClientConnectionStatus.ZONE_CONNECTED);

View File

@@ -54,10 +54,16 @@ public class ClientSender extends Service {
registerForIntent(ClientConnectionChangedIntent.TYPE);
registerForIntent(ServerToClientPacketIntent.TYPE);
registerForIntent(ClientSonyPacketIntent.TYPE);
hardReset();
return super.initialize();
}
public void hardReset() {
connectionId = -1;
port = 0;
zone = false;
return super.initialize();
packager.reset();
resender.reset();
}
public boolean start() {

View File

@@ -16,11 +16,10 @@ import com.projectswg.networking.NetInterceptor.InterceptorProperties;
import com.projectswg.resources.ClientConnectionStatus;
import com.projectswg.resources.ServerConnectionStatus;
import com.projectswg.services.PacketRecordingService;
import com.projectswg.utilities.Log;
public class Connections extends Manager {
public static final String VERSION = "0.9.4";
public static final String VERSION = "0.9.6";
private final ServerConnection server;
private final ClientConnection client;
@@ -130,7 +129,6 @@ public class Connections extends Manager {
}
private void processServerStatusChanged(ServerConnectionChangedIntent scci) {
Log.out(this, "Server Status Changed: %s -> %s", scci.getOldStatus(), scci.getStatus());
if (callback != null)
callback.onServerStatusChanged(scci.getOldStatus(), scci.getStatus());
if (scci.getStatus() != ServerConnectionStatus.CONNECTED && scci.getStatus() != ServerConnectionStatus.CONNECTING) {
@@ -142,27 +140,11 @@ public class Connections extends Manager {
error += "\nInstalled Version: " + VERSION;
client.send(new ErrorMessage("Network", error, false));
}
stop();
terminate();
boolean success = false;
while (!success) {
try { Thread.sleep(5); } catch (InterruptedException e) { break; }
success = initialize();
if (!success) {
terminate();
continue;
}
success = start();
if (!success) {
stop();
terminate();
}
}
client.hardReset();
}
}
private void processClientStatusChanged(ClientConnectionChangedIntent ccci) {
Log.out(this, "Client Status Changed: %s -> %s", ccci.getOldStatus(), ccci.getStatus());
switch (ccci.getStatus()) {
case LOGIN_CONNECTED:
if (ccci.getOldStatus() == ClientConnectionStatus.DISCONNECTED)

View File

@@ -8,7 +8,6 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
@@ -19,12 +18,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import resources.network.NetBufferStream;
import network.PacketType;
import network.packets.swg.SWGPacket;
import network.packets.swg.holo.HoloConnectionStarted;
import network.packets.swg.holo.HoloConnectionStopped;
import network.packets.swg.holo.HoloSetProtocolVersion;
import network.packets.swg.zone.object_controller.ObjectController;
import com.projectswg.control.Intent;
import com.projectswg.control.Manager;
import com.projectswg.intents.ClientConnectionChangedIntent;
@@ -184,30 +179,21 @@ public class ServerConnection extends Manager {
private void processPacketToSwg(byte [] packet) {
ByteBuffer data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN);
int crc = data.getInt(2);
SWGPacket swg;
if (crc == 0x80CE5E46)
swg = ObjectController.decodeController(data);
else {
swg = PacketType.getForCrc(crc);
if (swg != null)
swg.decode(data);
}
if (swg != null)
processPacket(swg, packet);
else
Log.err(this, "Incoming packet is null! Data: " + Arrays.toString(packet));
PacketType type = PacketType.fromCrc(data.getInt(2));
processPacket(type, packet);
}
private void processPacket(SWGPacket packet, byte [] raw) {
recvIntentChain.broadcastAfter(new ServerToClientPacketIntent(packet, raw), getIntentManager());
if (packet instanceof HoloConnectionStarted) {
private void processPacket(PacketType type, byte [] raw) {
recvIntentChain.broadcastAfter(new ServerToClientPacketIntent(type, raw), getIntentManager());
if (type == PacketType.HOLO_CONNECTION_STARTED) {
updateStatus(ServerConnectionStatus.CONNECTED);
while (!outQueue.isEmpty())
send(outQueue.poll());
Log.out(this, "Server connected");
} else if (packet instanceof HoloConnectionStopped) {
switch (((HoloConnectionStopped) packet).getReason()) {
} else if (type == PacketType.HOLO_CONNECTION_STOPPED) {
HoloConnectionStopped packet = new HoloConnectionStopped();
packet.decode(ByteBuffer.wrap(raw));
switch (packet.getReason()) {
case INVALID_PROTOCOL:
disconnect(ServerConnectionStatus.DISCONNECT_INVALID_PROTOCOL);
break;

View File

@@ -2,7 +2,7 @@ package com.projectswg;
import java.net.InetAddress;
import network.packets.swg.SWGPacket;
import network.PacketType;
import com.projectswg.control.IntentManager;
import com.projectswg.intents.ClientConnectionChangedIntent;
@@ -58,12 +58,12 @@ public class ServerConnectionWrapper {
private void onServerData(ServerToClientPacketIntent i) {
if (callback != null)
callback.onServerPacket(i.getPacket(), i.getRawData());
callback.onServerPacket(i.getPacketType(), i.getRawData());
}
public interface ConnectionCallback {
void onServerConnectionChanged(ServerConnectionStatus old, ServerConnectionStatus status);
void onServerPacket(SWGPacket packet, byte [] data);
void onServerPacket(PacketType type, byte [] data);
}
}

View File

@@ -1,6 +1,6 @@
package com.projectswg.intents;
import network.packets.swg.SWGPacket;
import network.PacketType;
import com.projectswg.control.Intent;
@@ -8,25 +8,25 @@ public class ServerToClientPacketIntent extends Intent {
public static final String TYPE = "ServerToClientPacketIntent";
private SWGPacket packet;
private PacketType type;
private byte [] rawData;
public ServerToClientPacketIntent(SWGPacket packet, byte [] rawData) {
public ServerToClientPacketIntent(PacketType type, byte [] rawData) {
super(TYPE);
setPacket(packet);
setPacketType(type);
setRawData(rawData);
}
public SWGPacket getPacket() {
return packet;
public PacketType getPacketType() {
return type;
}
public byte [] getRawData() {
return rawData;
}
public void setPacket(SWGPacket packet) {
this.packet = packet;
public void setPacketType(PacketType type) {
this.type = type;
}
public void setRawData(byte [] rawData) {