diff --git a/src/main/java/com/faforever/client/chat/IrcChatToken.java b/src/main/java/com/faforever/client/chat/IrcChatToken.java new file mode 100644 index 0000000000..5890d78b1e --- /dev/null +++ b/src/main/java/com/faforever/client/chat/IrcChatToken.java @@ -0,0 +1,4 @@ +package com.faforever.client.chat; + +public record IrcChatToken(String value) { +} diff --git a/src/main/java/com/faforever/client/chat/KittehChatService.java b/src/main/java/com/faforever/client/chat/KittehChatService.java index 86d5e7ed8a..0febf10a9d 100644 --- a/src/main/java/com/faforever/client/chat/KittehChatService.java +++ b/src/main/java/com/faforever/client/chat/KittehChatService.java @@ -14,13 +14,11 @@ import com.faforever.client.remote.FafServerAccessor; import com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent; import com.faforever.client.user.LoginService; -import com.faforever.commons.lobby.IrcPasswordInfo; import com.faforever.commons.lobby.Player.LeaderboardStats; import com.faforever.commons.lobby.SocialInfo; import com.google.common.annotations.VisibleForTesting; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import com.google.common.hash.Hashing; import javafx.beans.InvalidationListener; import javafx.beans.WeakInvalidationListener; import javafx.beans.property.ObjectProperty; @@ -54,18 +52,18 @@ import org.kitteh.irc.client.library.event.connection.ClientConnectionEndedEvent; import org.kitteh.irc.client.library.event.connection.ClientConnectionFailedEvent; import org.kitteh.irc.client.library.event.user.PrivateMessageEvent; -import org.kitteh.irc.client.library.event.user.PrivateNoticeEvent; import org.kitteh.irc.client.library.event.user.UserQuitEvent; -import org.kitteh.irc.client.library.event.user.WhoisEvent; -import org.kitteh.irc.client.library.feature.auth.NickServ; +import org.kitteh.irc.client.library.feature.auth.SaslPlain; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; -import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayDeque; import java.util.ArrayList; @@ -101,7 +99,8 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa private final PlayerService playerService; private final ChatPrefs chatPrefs; private final FxApplicationThreadExecutor fxApplicationThreadExecutor; - + @Qualifier("userWebClient") + private final ObjectFactory userWebClientFactory; /** * Maps channels by name. @@ -114,9 +113,7 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa String defaultChannelName; @VisibleForTesting DefaultClient client; - private NickServ nickServ; private String username; - private String password; /** * A list of channels the server wants us to join. */ @@ -192,11 +189,6 @@ private ChatChannelUser initializeUserForChannel(String username, ChatChannel ch return chatChannelUser; } - @Subscribe - public void onIrcPassword(IrcPasswordInfo event) { - password = Hashing.md5().hashString(event.getPassword(), StandardCharsets.UTF_8).toString(); - } - @Subscribe public void onPlayerOnline(PlayerOnlineEvent event) { PlayerBean player = event.player(); @@ -323,31 +315,8 @@ private void onPrivateMessage(PrivateMessageEvent event) { getOrCreateChannel(user.getNick()).addMessage(new ChatMessage(Instant.now(), user.getNick(), event.getMessage())); } - @Handler - private void onWhoIs(WhoisEvent event) { - if (event.getWhoisData().getRealName().map(realName -> username.equals(realName)).orElse(false)) { - nickServ.startAuthentication(); - } - } - - @Handler - private void onNotice(PrivateNoticeEvent event) { - String message = event.getMessage(); - - if (message.contains("isn't registered")) { - client.sendMessage("NickServ", String.format("register %s %s@users.faforever.com", password, client.getNick())); - } else if (message.contains("you are now recognized")) { - client.sendMessage("NickServ", String.format("recover %s", username)); - } else if (message.contains("You have regained control")) { - client.setNick(username); - } - } - private void joinAutoChannels() { log.trace("Joining auto channels: {}", autoChannels); - if (autoChannels == null) { - return; - } autoChannels.forEach(this::joinChannel); } @@ -383,7 +352,6 @@ private void onChatUserLeftChannel(String channelName, String username) { } private void onMessage(String message) { - message = message.replace(password, "*****"); ircLog.debug(message); } @@ -437,7 +405,6 @@ public void connect() { username = loginService.getUsername(); client = (DefaultClient) Client.builder() - .user(String.valueOf(loginService.getUserId())) .realName(username) .nick(username) .server() @@ -451,11 +418,18 @@ public void connect() { .then() .build(); - nickServ = NickServ.builder(client).account(username).password(password).build(); - - client.getEventManager().registerEventListener(this); - client.getActorTracker().setQueryChannelInformation(false); - client.connect(); + userWebClientFactory.getObject() + .get() + .uri("irc/ergochat/token") + .retrieve() + .bodyToMono(IrcChatToken.class) + .map(IrcChatToken::value) + .subscribe(token -> { + client.getAuthManager().addProtocol(new SaslPlain(client, username, "token:%s".formatted(token))); + client.getEventManager().registerEventListener(this); + client.getActorTracker().setQueryChannelInformation(false); + client.connect(); + }); } @Override diff --git a/src/main/java/com/faforever/client/remote/FafServerAccessor.java b/src/main/java/com/faforever/client/remote/FafServerAccessor.java index 7bc8da408d..4a939f1de4 100644 --- a/src/main/java/com/faforever/client/remote/FafServerAccessor.java +++ b/src/main/java/com/faforever/client/remote/FafServerAccessor.java @@ -22,7 +22,6 @@ import com.faforever.commons.lobby.GameLaunchResponse; import com.faforever.commons.lobby.GameVisibility; import com.faforever.commons.lobby.GpgGameOutboundMessage; -import com.faforever.commons.lobby.IrcPasswordInfo; import com.faforever.commons.lobby.MatchmakerState; import com.faforever.commons.lobby.MessageTarget; import com.faforever.commons.lobby.NoticeInfo; @@ -79,9 +78,6 @@ public class FafServerAccessor implements InitializingBean, DisposableBean { @Override public void afterPropertiesSet() throws Exception { eventBus.register(this); - getEvents(IrcPasswordInfo.class).doOnError(throwable -> log.error("Error processing irc password", throwable)) - .retry() - .subscribe(this::onIrcPassword); getEvents(NoticeInfo.class).doOnError(throwable -> log.error("Error processing notice", throwable)) .retry() .subscribe(this::onNotice); @@ -250,10 +246,6 @@ private void onNotice(NoticeInfo noticeMessage) { notificationService.addServerNotification(new ImmediateNotification(i18n.get("messageFromServer"), noticeMessage.getText(), severity, Collections.singletonList(new DismissAction(i18n)))); } - private void onIrcPassword(IrcPasswordInfo ircPasswordInfo) { - eventBus.post(ircPasswordInfo); - } - public void restoreGameSession(int id) { lobbyClient.restoreGameSession(id); } diff --git a/src/test/java/com/faforever/client/chat/KittehChatServiceTest.java b/src/test/java/com/faforever/client/chat/KittehChatServiceTest.java index 2d796418fb..52aa0711d9 100644 --- a/src/test/java/com/faforever/client/chat/KittehChatServiceTest.java +++ b/src/test/java/com/faforever/client/chat/KittehChatServiceTest.java @@ -13,7 +13,6 @@ import com.faforever.client.remote.FafServerAccessor; import com.faforever.client.test.ServiceTest; import com.faforever.client.user.LoginService; -import com.faforever.commons.lobby.IrcPasswordInfo; import com.faforever.commons.lobby.SocialInfo; import com.google.common.collect.ImmutableSortedSet; import com.google.common.eventbus.EventBus; @@ -675,13 +674,6 @@ public void testAddChannelUserListListener() { verify(listener, times(2)).onChanged(any()); } - @Test - public void testLeaveChannel() { - IrcPasswordInfo event = new IrcPasswordInfo("abc"); - instance.onIrcPassword(event); - instance.leaveChannel(new ChatChannel(DEFAULT_CHANNEL_NAME)); - } - @Test public void testSendActionInBackground() throws Exception { connect();