Skip to content

Commit

Permalink
Use external reconnect for manual reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Oct 16, 2023
1 parent 8374d7b commit 3cea443
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/faforever/client/chat/KittehChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa
private final List<String> autoChannels = new ArrayList<>();
private final Queue<String> bufferedChannels = new ArrayDeque<>();

private boolean autoReconnect;

@Override
public void afterPropertiesSet() {
eventBus.register(this);
Expand Down Expand Up @@ -338,6 +340,9 @@ private void joinBufferedChannels() {

private void onDisconnected() {
channels.values().forEach(ChatChannel::clearUsers);
if (autoReconnect) {
connect();
}
}

private void onChatUserLeftChannel(String channelName, String username) {
Expand Down Expand Up @@ -399,6 +404,8 @@ private void populateColor(ChatChannelUser chatChannelUser) {

@Override
public void connect() {
log.info("Connecting to IRC");
autoReconnect = true;
Irc irc = clientProperties.getIrc();
this.defaultChannelName = irc.getDefaultChannel();

Expand Down Expand Up @@ -434,6 +441,7 @@ public void connect() {

@Override
public void disconnect() {
autoReconnect = false;
log.info("Disconnecting from IRC");
client.shutdown("Goodbye");
}
Expand Down Expand Up @@ -527,11 +535,8 @@ public ConnectionState getConnectionState() {

@Override
public void reconnect() {
if (client.isConnectionAlive()) {
client.reconnect();
} else {
client.connect();
}
disconnect();
connect();
}

@Override
Expand Down

0 comments on commit 3cea443

Please sign in to comment.