-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert - Use static file for latest version & lobby message (#12496)
- Updates how we fetch "latest version", we go back to reading it from a static file hosted in the code repository. - Format of the code repository latest file 'servers.yml' is updated to have a top level 'message'. This removes the notion of a per-version message. The intent is for us to get off this file soon, the 'message' would one day come from somewhere else. - The fetch of the 'lobby message' is moved back to the file as well. We need to read this information on any successful login to lobby. - Remove dependency on docker compose tasks to run game-headed project. This needs to be redone.
- Loading branch information
1 parent
426b2d2
commit 36af040
Showing
5 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 36 additions & 11 deletions
47
game-app/game-core/src/main/java/org/triplea/live/servers/LiveServersFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,59 @@ | ||
package org.triplea.live.servers; | ||
|
||
import feign.FeignException; | ||
import games.strategy.triplea.settings.ClientSetting; | ||
import games.strategy.engine.framework.system.HttpProxy; | ||
import games.strategy.triplea.UrlConstants; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.triplea.http.client.latest.version.LatestVersionClient; | ||
import org.triplea.http.client.latest.version.LatestVersionResponse; | ||
import org.triplea.io.CloseableDownloader; | ||
import org.triplea.io.ContentDownloader; | ||
import org.triplea.yaml.YamlReader; | ||
|
||
@Slf4j | ||
@UtilityClass | ||
public class LiveServersFetcher { | ||
|
||
/** | ||
* Queries the lobby-server for the latest game engine version. | ||
* | ||
* @return Empty optional if server fails to return a value, otherwise latest game engine version | ||
* as known to the lobby-server. | ||
* Fetches from remote source the latest TripleA version that has been released. This can be used | ||
* to determine if the current version is out of date. | ||
*/ | ||
public static Optional<LatestVersionResponse> latestVersion() { | ||
try { | ||
try (CloseableDownloader downloader = | ||
new ContentDownloader(UrlConstants.LIVE_SERVERS_URI, HttpProxy::addProxy)) { | ||
var inputStream = downloader.getStream(); | ||
final Map<String, Object> yamlProps = YamlReader.readMap(inputStream); | ||
|
||
return Optional.of( | ||
LatestVersionClient.newClient(ClientSetting.lobbyUri.getValueOrThrow()) | ||
.fetchLatestVersion()); | ||
} catch (final FeignException e) { | ||
LatestVersionResponse.builder() | ||
.latestEngineVersion((String) yamlProps.get("latest")) | ||
.downloadUrl(UrlConstants.DOWNLOAD_WEBSITE) | ||
.releaseNotesUrl(UrlConstants.RELEASE_NOTES) | ||
.build()); | ||
} catch (final IOException e) { | ||
log.info( | ||
"Unable to complete engine out-of-date check. " | ||
+ "(No internet connection or server not available?)", | ||
e); | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
/** | ||
* Reads from remote source the "lobby welcome message", this is the lobby-chat message displayed | ||
* first to anyone joining the lobby. | ||
*/ | ||
public static Optional<String> getLobbyMessage() { | ||
try (CloseableDownloader downloader = | ||
new ContentDownloader(UrlConstants.LIVE_SERVERS_URI, HttpProxy::addProxy)) { | ||
var inputStream = downloader.getStream(); | ||
final Map<String, Object> yamlProps = YamlReader.readMap(inputStream); | ||
return Optional.of((String) yamlProps.get("message")); | ||
} catch (IOException e) { | ||
log.info("Unable to fetch lobby welcome message", e); | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters