Skip to content

Commit 8374d7b

Browse files
authored
Add compatibility with ergochat (#3038)
1 parent 1fc4c7b commit 8374d7b

File tree

4 files changed

+22
-60
lines changed

4 files changed

+22
-60
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.faforever.client.chat;
2+
3+
public record IrcChatToken(String value) {
4+
}

src/main/java/com/faforever/client/chat/KittehChatService.java

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import com.faforever.client.remote.FafServerAccessor;
1515
import com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent;
1616
import com.faforever.client.user.LoginService;
17-
import com.faforever.commons.lobby.IrcPasswordInfo;
1817
import com.faforever.commons.lobby.Player.LeaderboardStats;
1918
import com.faforever.commons.lobby.SocialInfo;
2019
import com.google.common.annotations.VisibleForTesting;
2120
import com.google.common.eventbus.EventBus;
2221
import com.google.common.eventbus.Subscribe;
23-
import com.google.common.hash.Hashing;
2422
import javafx.beans.InvalidationListener;
2523
import javafx.beans.WeakInvalidationListener;
2624
import javafx.beans.property.ObjectProperty;
@@ -54,18 +52,18 @@
5452
import org.kitteh.irc.client.library.event.connection.ClientConnectionEndedEvent;
5553
import org.kitteh.irc.client.library.event.connection.ClientConnectionFailedEvent;
5654
import org.kitteh.irc.client.library.event.user.PrivateMessageEvent;
57-
import org.kitteh.irc.client.library.event.user.PrivateNoticeEvent;
5855
import org.kitteh.irc.client.library.event.user.UserQuitEvent;
59-
import org.kitteh.irc.client.library.event.user.WhoisEvent;
60-
import org.kitteh.irc.client.library.feature.auth.NickServ;
56+
import org.kitteh.irc.client.library.feature.auth.SaslPlain;
6157
import org.slf4j.Logger;
6258
import org.slf4j.LoggerFactory;
6359
import org.springframework.beans.factory.DisposableBean;
6460
import org.springframework.beans.factory.InitializingBean;
61+
import org.springframework.beans.factory.ObjectFactory;
62+
import org.springframework.beans.factory.annotation.Qualifier;
6563
import org.springframework.context.annotation.Lazy;
6664
import org.springframework.stereotype.Service;
65+
import org.springframework.web.reactive.function.client.WebClient;
6766

68-
import java.nio.charset.StandardCharsets;
6967
import java.time.Instant;
7068
import java.util.ArrayDeque;
7169
import java.util.ArrayList;
@@ -101,7 +99,8 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa
10199
private final PlayerService playerService;
102100
private final ChatPrefs chatPrefs;
103101
private final FxApplicationThreadExecutor fxApplicationThreadExecutor;
104-
102+
@Qualifier("userWebClient")
103+
private final ObjectFactory<WebClient> userWebClientFactory;
105104

106105
/**
107106
* Maps channels by name.
@@ -114,9 +113,7 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa
114113
String defaultChannelName;
115114
@VisibleForTesting
116115
DefaultClient client;
117-
private NickServ nickServ;
118116
private String username;
119-
private String password;
120117
/**
121118
* A list of channels the server wants us to join.
122119
*/
@@ -192,11 +189,6 @@ private ChatChannelUser initializeUserForChannel(String username, ChatChannel ch
192189
return chatChannelUser;
193190
}
194191

195-
@Subscribe
196-
public void onIrcPassword(IrcPasswordInfo event) {
197-
password = Hashing.md5().hashString(event.getPassword(), StandardCharsets.UTF_8).toString();
198-
}
199-
200192
@Subscribe
201193
public void onPlayerOnline(PlayerOnlineEvent event) {
202194
PlayerBean player = event.player();
@@ -323,31 +315,8 @@ private void onPrivateMessage(PrivateMessageEvent event) {
323315
getOrCreateChannel(user.getNick()).addMessage(new ChatMessage(Instant.now(), user.getNick(), event.getMessage()));
324316
}
325317

326-
@Handler
327-
private void onWhoIs(WhoisEvent event) {
328-
if (event.getWhoisData().getRealName().map(realName -> username.equals(realName)).orElse(false)) {
329-
nickServ.startAuthentication();
330-
}
331-
}
332-
333-
@Handler
334-
private void onNotice(PrivateNoticeEvent event) {
335-
String message = event.getMessage();
336-
337-
if (message.contains("isn't registered")) {
338-
client.sendMessage("NickServ", String.format("register %s %[email protected]", password, client.getNick()));
339-
} else if (message.contains("you are now recognized")) {
340-
client.sendMessage("NickServ", String.format("recover %s", username));
341-
} else if (message.contains("You have regained control")) {
342-
client.setNick(username);
343-
}
344-
}
345-
346318
private void joinAutoChannels() {
347319
log.trace("Joining auto channels: {}", autoChannels);
348-
if (autoChannels == null) {
349-
return;
350-
}
351320
autoChannels.forEach(this::joinChannel);
352321
}
353322

@@ -383,7 +352,6 @@ private void onChatUserLeftChannel(String channelName, String username) {
383352
}
384353

385354
private void onMessage(String message) {
386-
message = message.replace(password, "*****");
387355
ircLog.debug(message);
388356
}
389357

@@ -437,7 +405,6 @@ public void connect() {
437405
username = loginService.getUsername();
438406

439407
client = (DefaultClient) Client.builder()
440-
.user(String.valueOf(loginService.getUserId()))
441408
.realName(username)
442409
.nick(username)
443410
.server()
@@ -451,11 +418,18 @@ public void connect() {
451418
.then()
452419
.build();
453420

454-
nickServ = NickServ.builder(client).account(username).password(password).build();
455-
456-
client.getEventManager().registerEventListener(this);
457-
client.getActorTracker().setQueryChannelInformation(false);
458-
client.connect();
421+
userWebClientFactory.getObject()
422+
.get()
423+
.uri("irc/ergochat/token")
424+
.retrieve()
425+
.bodyToMono(IrcChatToken.class)
426+
.map(IrcChatToken::value)
427+
.subscribe(token -> {
428+
client.getAuthManager().addProtocol(new SaslPlain(client, username, "token:%s".formatted(token)));
429+
client.getEventManager().registerEventListener(this);
430+
client.getActorTracker().setQueryChannelInformation(false);
431+
client.connect();
432+
});
459433
}
460434

461435
@Override

src/main/java/com/faforever/client/remote/FafServerAccessor.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.faforever.commons.lobby.GameLaunchResponse;
2323
import com.faforever.commons.lobby.GameVisibility;
2424
import com.faforever.commons.lobby.GpgGameOutboundMessage;
25-
import com.faforever.commons.lobby.IrcPasswordInfo;
2625
import com.faforever.commons.lobby.MatchmakerState;
2726
import com.faforever.commons.lobby.MessageTarget;
2827
import com.faforever.commons.lobby.NoticeInfo;
@@ -79,9 +78,6 @@ public class FafServerAccessor implements InitializingBean, DisposableBean {
7978
@Override
8079
public void afterPropertiesSet() throws Exception {
8180
eventBus.register(this);
82-
getEvents(IrcPasswordInfo.class).doOnError(throwable -> log.error("Error processing irc password", throwable))
83-
.retry()
84-
.subscribe(this::onIrcPassword);
8581
getEvents(NoticeInfo.class).doOnError(throwable -> log.error("Error processing notice", throwable))
8682
.retry()
8783
.subscribe(this::onNotice);
@@ -250,10 +246,6 @@ private void onNotice(NoticeInfo noticeMessage) {
250246
notificationService.addServerNotification(new ImmediateNotification(i18n.get("messageFromServer"), noticeMessage.getText(), severity, Collections.singletonList(new DismissAction(i18n))));
251247
}
252248

253-
private void onIrcPassword(IrcPasswordInfo ircPasswordInfo) {
254-
eventBus.post(ircPasswordInfo);
255-
}
256-
257249
public void restoreGameSession(int id) {
258250
lobbyClient.restoreGameSession(id);
259251
}

src/test/java/com/faforever/client/chat/KittehChatServiceTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.faforever.client.remote.FafServerAccessor;
1414
import com.faforever.client.test.ServiceTest;
1515
import com.faforever.client.user.LoginService;
16-
import com.faforever.commons.lobby.IrcPasswordInfo;
1716
import com.faforever.commons.lobby.SocialInfo;
1817
import com.google.common.collect.ImmutableSortedSet;
1918
import com.google.common.eventbus.EventBus;
@@ -675,13 +674,6 @@ public void testAddChannelUserListListener() {
675674
verify(listener, times(2)).onChanged(any());
676675
}
677676

678-
@Test
679-
public void testLeaveChannel() {
680-
IrcPasswordInfo event = new IrcPasswordInfo("abc");
681-
instance.onIrcPassword(event);
682-
instance.leaveChannel(new ChatChannel(DEFAULT_CHANNEL_NAME));
683-
}
684-
685677
@Test
686678
public void testSendActionInBackground() throws Exception {
687679
connect();

0 commit comments

Comments
 (0)