|
37 | 37 | import lombok.extern.slf4j.Slf4j;
|
38 | 38 | import org.springframework.beans.factory.DisposableBean;
|
39 | 39 | import org.springframework.beans.factory.InitializingBean;
|
| 40 | +import org.springframework.beans.factory.ObjectFactory; |
| 41 | +import org.springframework.beans.factory.annotation.Qualifier; |
40 | 42 | import org.springframework.context.annotation.Lazy;
|
41 | 43 | import org.springframework.scheduling.TaskScheduler;
|
42 | 44 | import org.springframework.stereotype.Component;
|
| 45 | +import org.springframework.web.reactive.function.client.WebClient; |
43 | 46 | import reactor.core.publisher.Flux;
|
44 | 47 | import reactor.core.publisher.Mono;
|
45 | 48 |
|
@@ -70,16 +73,16 @@ public class FafServerAccessor implements InitializingBean, DisposableBean {
|
70 | 73 | private final EventBus eventBus;
|
71 | 74 | private final ClientProperties clientProperties;
|
72 | 75 | private final FafLobbyClient lobbyClient;
|
| 76 | + @Qualifier("userWebClient") |
| 77 | + private final ObjectFactory<WebClient> userWebClientFactory; |
73 | 78 |
|
74 | 79 | @Override
|
75 | 80 | public void afterPropertiesSet() throws Exception {
|
76 | 81 | eventBus.register(this);
|
77 |
| - getEvents(IrcPasswordInfo.class) |
78 |
| - .doOnError(throwable -> log.error("Error processing irc password", throwable)) |
| 82 | + getEvents(IrcPasswordInfo.class).doOnError(throwable -> log.error("Error processing irc password", throwable)) |
79 | 83 | .retry()
|
80 | 84 | .subscribe(this::onIrcPassword);
|
81 |
| - getEvents(NoticeInfo.class) |
82 |
| - .doOnError(throwable -> log.error("Error processing notice", throwable)) |
| 85 | + getEvents(NoticeInfo.class).doOnError(throwable -> log.error("Error processing notice", throwable)) |
83 | 86 | .retry()
|
84 | 87 | .subscribe(this::onNotice);
|
85 | 88 |
|
@@ -119,16 +122,22 @@ public ReadOnlyObjectProperty<ConnectionState> connectionStateProperty() {
|
119 | 122 | }
|
120 | 123 |
|
121 | 124 | public Mono<Player> connectAndLogIn() {
|
122 |
| - Config config = new Config(tokenRetriever.getRefreshedTokenValue(), Version.getCurrentVersion(), clientProperties.getUserAgent(), clientProperties.getServer() |
123 |
| - .getHost(), clientProperties.getServer().getPort() + 1, sessionId -> { |
124 |
| - try { |
125 |
| - return uidService.generate(String.valueOf(sessionId)); |
126 |
| - } catch (IOException e) { |
127 |
| - throw new UIDException("Cannot generate UID", e, "uid.generate.error"); |
128 |
| - } |
129 |
| - }, 1024 * 1024, false, clientProperties.getServer().getRetryAttempts(), clientProperties.getServer() |
130 |
| - .getRetryDelaySeconds()); |
131 |
| - return lobbyClient.connectAndLogin(config); |
| 125 | + return userWebClientFactory.getObject() |
| 126 | + .get() |
| 127 | + .uri("/lobby/access") |
| 128 | + .retrieve() |
| 129 | + .bodyToMono(LobbyAccess.class) |
| 130 | + .map(lobbyAccess -> new Config(tokenRetriever.getRefreshedTokenValue(), Version.getCurrentVersion(), clientProperties.getUserAgent(), lobbyAccess.accessUrl(), this::tryGenerateUid, 1024 * 1024, false, clientProperties.getServer() |
| 131 | + .getRetryAttempts(), clientProperties.getServer().getRetryDelaySeconds())) |
| 132 | + .flatMap(lobbyClient::connectAndLogin); |
| 133 | + } |
| 134 | + |
| 135 | + private String tryGenerateUid(Long sessionId) { |
| 136 | + try { |
| 137 | + return uidService.generate(String.valueOf(sessionId)); |
| 138 | + } catch (IOException e) { |
| 139 | + throw new UIDException("Cannot generate UID", e, "uid.generate.error"); |
| 140 | + } |
132 | 141 | }
|
133 | 142 |
|
134 | 143 | public CompletableFuture<GameLaunchResponse> requestHostGame(NewGameInfo newGameInfo) {
|
|
0 commit comments