Reconnection issues

This commit is contained in:
Manevolent
2018-08-29 11:44:14 -04:00
parent 2207e65392
commit b7282cc337
5 changed files with 84 additions and 163 deletions
@@ -1,9 +1,11 @@
package com.github.manevolent.ts3j.protocol.packet.handler.client; package com.github.manevolent.ts3j.protocol.packet.handler.client;
import com.github.manevolent.ts3j.command.Command;
import com.github.manevolent.ts3j.command.SingleCommand; import com.github.manevolent.ts3j.command.SingleCommand;
import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter; import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter;
import com.github.manevolent.ts3j.protocol.Packet; import com.github.manevolent.ts3j.protocol.Packet;
import com.github.manevolent.ts3j.protocol.ProtocolRole; import com.github.manevolent.ts3j.protocol.ProtocolRole;
import com.github.manevolent.ts3j.protocol.TS3DNS;
import com.github.manevolent.ts3j.protocol.client.ClientConnectionState; import com.github.manevolent.ts3j.protocol.client.ClientConnectionState;
import com.github.manevolent.ts3j.protocol.packet.PacketBody2Command; import com.github.manevolent.ts3j.protocol.packet.PacketBody2Command;
import com.github.manevolent.ts3j.protocol.packet.PacketBody8Init1; import com.github.manevolent.ts3j.protocol.packet.PacketBody8Init1;
@@ -188,49 +190,48 @@ public class LocalClientHandlerConnecting extends LocalClientHandler {
alphaBytes = null; alphaBytes = null;
getClient().writePacket(new PacketBody2Command( Command clientinit = new SingleCommand(
"clientinit",
ProtocolRole.CLIENT, ProtocolRole.CLIENT,
new SingleCommand( new CommandSingleParameter("client_nickname", getClient().getNickname()),
"clientinit", new CommandSingleParameter("client_version", "3.?.? [Build: 5680278000]"),
ProtocolRole.CLIENT, new CommandSingleParameter("client_platform", "Windows"),
new CommandSingleParameter("client_nickname", getClient().getNickname()), new CommandSingleParameter(
new CommandSingleParameter("client_version", "3.?.? [Build: 5680278000]"), "client_version_sign",
new CommandSingleParameter("client_platform", "Windows"), "DX5NIYLvfJEUjuIbCidnoeozxIDRRkpq3I9vVMBmE9L2qnekOoBzSenkzsg2lC9CMv8K5hkEzhr2TYUYSwUXCg=="
new CommandSingleParameter( ),
"client_version_sign", new CommandSingleParameter("client_input_hardware", "1"),
"DX5NIYLvfJEUjuIbCidnoeozxIDRRkpq3I9vVMBmE9L2qnekOoBzSenkzsg2lC9CMv8K5hkEzhr2TYUYSwUXCg==" new CommandSingleParameter("client_output_hardware", "1"),
), new CommandSingleParameter("client_default_channel",
new CommandSingleParameter("client_input_hardware", "1"), getClient().getOption("client.default_channel", String.class)
new CommandSingleParameter("client_output_hardware", "1"), ),
new CommandSingleParameter("client_default_channel", new CommandSingleParameter("client_default_channel_password",
getClient().getOption("client.default_channel", String.class) getClient().getOption("client.default_channel_password", String.class)
), ),
new CommandSingleParameter("client_default_channel_password", new CommandSingleParameter("client_server_password",
getClient().getOption("client.default_channel_password", String.class) getClient().getOption("client.server_password", String.class)
), ),
new CommandSingleParameter( new CommandSingleParameter("client_nickname_phonetic",
"client_server_password", getClient().getOption("client.nickname_phonetic", String.class)
getClient().getOption("client.server_password", String.class) ),
), new CommandSingleParameter("client_meta_data", ""),
new CommandSingleParameter("client_nickname_phonetic", new CommandSingleParameter("client_default_token",
getClient().getOption("client.nickname_phonetic", String.class) getClient().getOption("client.default_token", String.class)
), ),
new CommandSingleParameter("client_meta_data", ""), new CommandSingleParameter("client_key_offset",
new CommandSingleParameter("client_default_token", Long.toString(getClient().getIdentity().getKeyOffset())
getClient().getOption("client.default_token", String.class) ),
), new CommandSingleParameter(
new CommandSingleParameter( "hwid",
"client_key_offset", getClient().getOption("client.hwid", String.class) != null ?
Long.toString(getClient().getIdentity().getKeyOffset()) getClient().getOption("client.hwid", String.class) :
), "+LyYqbDqOvEEpN5pdAbF8/v5kZ0="
new CommandSingleParameter(
"hwid",
getClient().getOption("client.hwid", String.class) != null ?
getClient().getOption("client.hwid", String.class) :
"+LyYqbDqOvEEpN5pdAbF8/v5kZ0="
)
) )
)); );
Ts3Debugging.debug(clientinit.build());
getClient().writePacket(new PacketBody2Command(ProtocolRole.CLIENT, clientinit));
getClient().setCommandProcessor(getClient()); getClient().setCommandProcessor(getClient());
getClient().setState(ClientConnectionState.RETRIEVING_DATA); getClient().setState(ClientConnectionState.RETRIEVING_DATA);
@@ -1,9 +1,31 @@
package com.github.manevolent.ts3j.protocol.packet.handler.client; package com.github.manevolent.ts3j.protocol.packet.handler.client;
import com.github.manevolent.ts3j.command.CommandProcessException;
import com.github.manevolent.ts3j.command.CommandProcessor;
import com.github.manevolent.ts3j.command.MultiCommand;
import com.github.manevolent.ts3j.protocol.client.ClientConnectionState;
import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket; import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket;
public class LocalClientHandlerRetrievingData extends LocalClientHandlerFull { public class LocalClientHandlerRetrievingData extends LocalClientHandlerFull {
public LocalClientHandlerRetrievingData(LocalTeamspeakClientSocket client) { public LocalClientHandlerRetrievingData(LocalTeamspeakClientSocket client) {
super(client); super(client);
} }
@Override
protected void handleCommand(MultiCommand command) throws CommandProcessException {
if (command.getName().equalsIgnoreCase("error")) {
try {
getClient().setState(ClientConnectionState.DISCONNECTED);
} catch (Exception e) {
getClient().getExceptionHandler().accept(e);
}
throw new CommandProcessException(command.simplifyOne().get("msg").getValue());
}
CommandProcessor processor = getClient().getCommandProcessor();
if (processor != null) processor.process(getClient(), command);
}
} }
@@ -205,8 +205,6 @@ public abstract class AbstractTeamspeakClientSocket
} }
protected void onDisconnect() { protected void onDisconnect() {
clientOptions.clear();
clientId = -1; clientId = -1;
readQueue.clear(); readQueue.clear();
@@ -260,7 +260,6 @@ public class LocalTeamspeakClientSocket
* @param timeout timeout, in milliseconds, to complete a connection. * @param timeout timeout, in milliseconds, to complete a connection.
*/ */
public void connect(String hostname, String password, long timeout) throws public void connect(String hostname, String password, long timeout) throws
UnknownHostException,
IOException, IOException,
TimeoutException { TimeoutException {
@@ -651,6 +650,14 @@ public class LocalTeamspeakClientSocket
super.setNickname(nickname); super.setNickname(nickname);
} }
public void setHWID(String hwid) {
setOption("client.hwid", hwid);
}
public String getHWID() {
return getOption("client.hwid", String.class);
}
/** /**
* Commands * Commands
*/ */
@@ -31,132 +31,25 @@ public class ServerConnectionTest {
identity.improveSecurity(10); identity.improveSecurity(10);
client.setIdentity(identity); client.setIdentity(identity);
client.setNickname("Hello from Java"); client.setNickname("Hello from Java");
client.setHWID("JAVAJAVAJAVA");
client.setOption("client.hwid", "JAVAJAVAJAVA");
client.connect( while (true) {
"teamlixo.net", try {
null,
10000L
);
client.addListener(new TS3Listener() { client.connect(
@Override "teamlixo.net",
public void onTextMessage(TextMessageEvent e) { null,
10000L
);
assertEquals(client.getState(), ClientConnectionState.CONNECTED);
} catch (Exception ex) {
ex.printStackTrace();
} }
@Override client.disconnect();
public void onClientJoin(ClientJoinEvent e) {
System.err.println(e.get("cid"));
}
@Override
public void onClientLeave(ClientLeaveEvent e) {
}
@Override
public void onServerEdit(ServerEditedEvent e) {
}
@Override
public void onChannelEdit(ChannelEditedEvent e) {
}
@Override
public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {
}
@Override
public void onClientMoved(ClientMovedEvent e) {
}
@Override
public void onChannelCreate(ChannelCreateEvent e) {
}
@Override
public void onChannelDeleted(ChannelDeletedEvent e) {
}
@Override
public void onChannelMoved(ChannelMovedEvent e) {
}
@Override
public void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {
}
@Override
public void onChannelList(ChannelListEvent e) {
}
@Override
public void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {
}
@Override
public void onChannelGroupList(ChannelGroupListEvent e) {
}
@Override
public void onServerGroupList(ServerGroupListEvent e) {
}
@Override
public void onClientNeededPermissions(ClientNeededPermissionsEvent e) {
}
@Override
public void onClientChannelGroupChanged(ClientChannelGroupChangedEvent e) {
}
@Override
public void onClientChanged(ClientUpdatedEvent e) {
}
@Override
public void onDisconnected(DisconnectedEvent e) {
}
@Override
public void onChannelSubscribed(ChannelSubscribedEvent e) {
}
});
assertEquals(client.getState(), ClientConnectionState.CONNECTED);
client.subscribeAll();
try {
client.setVoiceHandler(packetBody0Voice -> {
System.err.println("clientId=" + packetBody0Voice.getClientId());
System.err.println("packetId=" + packetBody0Voice.getPacketId());
System.err.println("type=" + packetBody0Voice.getCodecType());
System.err.println("len=" + packetBody0Voice.getCodecData().length);
});
} catch (Exception ex) {
ex.printStackTrace();
} }
} }
} }