Search in sources :

Example 1 with Version

use of games.strategy.util.Version in project triplea by triplea-game.

the class GameParser method parseInfo.

private void parseInfo(final Node info) {
    final String gameName = ((Element) info).getAttribute("name");
    data.setGameName(gameName);
    final String version = ((Element) info).getAttribute("version");
    data.setGameVersion(new Version(version));
}
Also used : Version(games.strategy.util.Version) GameEngineVersion(games.strategy.engine.GameEngineVersion) Element(org.w3c.dom.Element)

Example 2 with Version

use of games.strategy.util.Version in project triplea by triplea-game.

the class LobbyLoginValidator method authenticateUser.

@Nullable
private String authenticateUser(final Map<String, String> response, final User user) {
    if (response == null) {
        return "No Client Properties";
    }
    final String clientVersionString = response.get(LOBBY_VERSION);
    if (clientVersionString == null) {
        return "No Client Version";
    }
    final Version clientVersion = new Version(clientVersionString);
    if (!clientVersion.equals(LobbyServer.LOBBY_VERSION)) {
        return "Wrong version, we require " + LobbyServer.LOBBY_VERSION.toString() + " but trying to log in with " + clientVersionString;
    }
    for (final String s : getBadWords()) {
        if (user.getUsername().toLowerCase().contains(s.toLowerCase())) {
            return ErrorMessages.THATS_NOT_A_NICE_NAME;
        }
    }
    if (!MacFinder.isValidHashedMacAddress(user.getHashedMacAddress())) {
        // Must have been tampered with
        return ErrorMessages.INVALID_MAC;
    }
    final Tuple<Boolean, Timestamp> macBanned = bannedMacDao.isMacBanned(user.getHashedMacAddress());
    if (macBanned.getFirst()) {
        return ErrorMessages.YOU_HAVE_BEEN_BANNED + " " + getBanDurationBreakdown(macBanned.getSecond());
    }
    // test for username ban after testing normal bans, because if it is only a username ban then the user should know
    // they can change their name
    final Tuple<Boolean, Timestamp> usernameBanned = bannedUsernameDao.isUsernameBanned(user.getUsername());
    if (usernameBanned.getFirst()) {
        return ErrorMessages.USERNAME_HAS_BEEN_BANNED + " " + getBanDurationBreakdown(usernameBanned.getSecond());
    }
    if (response.containsKey(REGISTER_NEW_USER_KEY)) {
        return createUser(response, user);
    }
    final UserType userType = getUserTypeFor(response);
    switch(userType) {
        case ANONYMOUS:
            return authenticateAnonymousUser(response, user);
        case REGISTERED:
            return authenticateRegisteredUser(response, user);
        default:
            throw new AssertionError("unknown user type: " + userType);
    }
}
Also used : Version(games.strategy.util.Version) Timestamp(java.sql.Timestamp) Nullable(javax.annotation.Nullable)

Example 3 with Version

use of games.strategy.util.Version in project triplea by triplea-game.

the class ClientLoginValidator method verifyConnection.

@Override
public String verifyConnection(final Map<String, String> propertiesSentToClient, final Map<String, String> propertiesReadFromClient, final String clientName, final String hashedMac, final SocketAddress remoteAddress) {
    final String versionString = propertiesReadFromClient.get(ClientLogin.ENGINE_VERSION_PROPERTY);
    if (versionString == null || versionString.length() > 20 || versionString.trim().length() == 0) {
        return "Invalid version " + versionString;
    }
    // check for version
    final Version clientVersion = new Version(versionString);
    if (!GameEngineVersion.of(ClientContext.engineVersion()).isCompatibleWithEngineVersion(clientVersion)) {
        return String.format("Client is using %s but the server requires a version compatible with version %s", clientVersion, ClientContext.engineVersion());
    }
    final String realName = clientName.split(" ")[0];
    if (serverMessenger.isUsernameMiniBanned(realName)) {
        return ErrorMessages.YOU_HAVE_BEEN_BANNED;
    }
    final String remoteIp = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
    if (serverMessenger.isIpMiniBanned(remoteIp)) {
        return ErrorMessages.YOU_HAVE_BEEN_BANNED;
    }
    if (hashedMac == null) {
        return ErrorMessages.UNABLE_TO_OBTAIN_MAC;
    } else if (!MacFinder.isValidHashedMacAddress(hashedMac)) {
        return ErrorMessages.INVALID_MAC;
    } else if (serverMessenger.isMacMiniBanned(hashedMac)) {
        return ErrorMessages.YOU_HAVE_BEEN_BANNED;
    }
    if (Boolean.TRUE.toString().equals(propertiesSentToClient.get(PASSWORD_REQUIRED_PROPERTY))) {
        final String errorMessage = authenticate(propertiesSentToClient, propertiesReadFromClient);
        if (!Objects.equals(errorMessage, ErrorMessages.NO_ERROR)) {
            // sleep on average 2 seconds
            // try to prevent flooding to guess the password
            Interruptibles.sleep((long) (4_000 * Math.random()));
            return errorMessage;
        }
    }
    return ErrorMessages.NO_ERROR;
}
Also used : GameEngineVersion(games.strategy.engine.GameEngineVersion) Version(games.strategy.util.Version)

Example 4 with Version

use of games.strategy.util.Version in project triplea by triplea-game.

the class GameRunner method main.

/**
 * Launches the "main" TripleA gui enabled game client.
 * No args will launch a client, additional args can be supplied to specify additional behavior.
 * Warning: game engine code invokes this method to spawn new game clients.
 */
public static void main(final String[] args) throws InterruptedException {
    LoggingConfiguration.initialize();
    ClientSetting.initialize();
    if (!ClientSetting.USE_EXPERIMENTAL_JAVAFX_UI.booleanValue()) {
        SwingAction.invokeAndWait(() -> {
            LookAndFeel.setupLookAndFeel();
            ErrorConsole.createConsole();
            ErrorMessage.INSTANCE.init();
        });
    }
    if (!new ArgParser(COMMAND_LINE_ARGS).handleCommandLineArgs(args)) {
        usage();
        return;
    }
    if (HttpProxy.isUsingSystemProxy()) {
        HttpProxy.updateSystemProxy();
    }
    final Version engineVersion = ClientContext.engineVersion();
    System.out.println("TripleA engine version " + engineVersion.getExactVersion());
    if (ClientSetting.USE_EXPERIMENTAL_JAVAFX_UI.booleanValue()) {
        Application.launch(TripleA.class, args);
    } else {
        SwingUtilities.invokeLater(() -> {
            setupPanelModel.showSelectType();
            mainFrame = newMainFrame();
        });
        showMainFrame();
        LocalSystemChecker.launch();
        UpdateChecks.launch();
    }
}
Also used : Version(games.strategy.util.Version) GameEngineVersion(games.strategy.engine.GameEngineVersion)

Example 5 with Version

use of games.strategy.util.Version in project triplea by triplea-game.

the class DownloadFileDescriptionTest method testIsTool.

@Test
public void testIsTool() {
    final DownloadFileDescription testObj = new DownloadFileDescription("", "", "", new Version(0, 0), DownloadFileDescription.DownloadType.MAP_TOOL, DownloadFileDescription.MapCategory.EXPERIMENTAL);
    assertThat(testObj.isMapTool(), is(true));
}
Also used : Version(games.strategy.util.Version) Test(org.junit.jupiter.api.Test)

Aggregations

Version (games.strategy.util.Version)19 Test (org.junit.jupiter.api.Test)7 GameEngineVersion (games.strategy.engine.GameEngineVersion)5 LobbyServerProperties (games.strategy.engine.lobby.client.login.LobbyServerProperties)3 File (java.io.File)3 IOException (java.io.IOException)2 List (java.util.List)2 JSONArray (com.github.openjson.JSONArray)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ClientLogger (games.strategy.debug.ClientLogger)1 ClientContext (games.strategy.engine.ClientContext)1 ClientFileSystemHelper (games.strategy.engine.ClientFileSystemHelper)1 GameData (games.strategy.engine.data.GameData)1 GameDescription (games.strategy.engine.lobby.server.GameDescription)1 ResourceLoader (games.strategy.triplea.ResourceLoader)1 ClientSetting (games.strategy.triplea.settings.ClientSetting)1 SwingComponents (games.strategy.ui.SwingComponents)1 ObjectInputStream (java.io.ObjectInputStream)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1