1414import com .faforever .client .remote .FafServerAccessor ;
1515import com .faforever .client .ui .tray .event .UpdateApplicationBadgeEvent ;
1616import com .faforever .client .user .LoginService ;
17- import com .faforever .commons .lobby .IrcPasswordInfo ;
1817import com .faforever .commons .lobby .Player .LeaderboardStats ;
1918import com .faforever .commons .lobby .SocialInfo ;
2019import com .google .common .annotations .VisibleForTesting ;
2120import com .google .common .eventbus .EventBus ;
2221import com .google .common .eventbus .Subscribe ;
23- import com .google .common .hash .Hashing ;
2422import javafx .beans .InvalidationListener ;
2523import javafx .beans .WeakInvalidationListener ;
2624import javafx .beans .property .ObjectProperty ;
5452import org .kitteh .irc .client .library .event .connection .ClientConnectionEndedEvent ;
5553import org .kitteh .irc .client .library .event .connection .ClientConnectionFailedEvent ;
5654import org .kitteh .irc .client .library .event .user .PrivateMessageEvent ;
57- import org .kitteh .irc .client .library .event .user .PrivateNoticeEvent ;
5855import 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 ;
6157import org .slf4j .Logger ;
6258import org .slf4j .LoggerFactory ;
6359import org .springframework .beans .factory .DisposableBean ;
6460import org .springframework .beans .factory .InitializingBean ;
61+ import org .springframework .beans .factory .ObjectFactory ;
62+ import org .springframework .beans .factory .annotation .Qualifier ;
6563import org .springframework .context .annotation .Lazy ;
6664import org .springframework .stereotype .Service ;
65+ import org .springframework .web .reactive .function .client .WebClient ;
6766
68- import java .nio .charset .StandardCharsets ;
6967import java .time .Instant ;
7068import java .util .ArrayDeque ;
7169import 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
0 commit comments