Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 122-search-irc-filt…
Browse files Browse the repository at this point in the history
…er-enhancement
  • Loading branch information
Cheyans committed Nov 26, 2015
2 parents 52d6bc3 + ad58c00 commit 3e84a49
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.faforever.client.task.TaskService;
import com.faforever.client.user.UserService;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.hash.Hashing;
import javafx.application.Platform;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
Expand Down Expand Up @@ -41,7 +42,6 @@
import javax.annotation.Resource;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -54,9 +54,9 @@
import static com.faforever.client.chat.ChatColorMode.CUSTOM;
import static com.faforever.client.chat.ChatColorMode.RANDOM;
import static com.faforever.client.task.AbstractPrioritizedTask.Priority.HIGH;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javafx.collections.FXCollections.observableHashMap;
import static javafx.collections.FXCollections.synchronizedObservableMap;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;

public class PircBotXChatService implements ChatService, Listener, OnChatConnectedListener,
OnChatUserListListener, OnChatUserJoinedChannelListener, OnChatUserQuitListener, OnChatDisconnectedListener,
Expand Down Expand Up @@ -453,7 +453,7 @@ private void init() {
.setServer(environment.getProperty("irc.host"), environment.getProperty("irc.port", int.class))
.setSocketFactory(new UtilSSLSocketFactory().trustAllCertificates())
.setAutoSplitMessage(true)
.setEncoding(StandardCharsets.UTF_8)
.setEncoding(UTF_8)
.setAutoReconnect(false)
.addListener(this)
.setSocketTimeout(SOCKET_TIMEOUT)
Expand All @@ -464,7 +464,7 @@ private void init() {

@Override
public void onConnected() {
sendMessageInBackground("NICKSERV", "IDENTIFY " + md5Hex(userService.getPassword()))
sendMessageInBackground("NICKSERV", "IDENTIFY " + Hashing.md5().hashString(userService.getPassword(), UTF_8))
.thenAccept(s1 -> {
ircConnectedLatch.countDown();
pircBotX.sendIRC().joinChannel(defaultChannelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -83,6 +84,8 @@ public class CreateGameController {
PreferencesService preferencesService;
@Resource
I18n i18n;
@Resource
Locale locale;
@VisibleForTesting
FilteredList<MapInfoBean> filteredMaps;

Expand Down Expand Up @@ -223,8 +226,8 @@ private void initRatingBoundaries() {
int lastGameMinRating = preferencesService.getPreferences().getLastGameMinRating();
int lastGameMaxRating = preferencesService.getPreferences().getLastGameMaxRating();

minRankingTextField.setText(String.valueOf(lastGameMinRating));
maxRankingTextField.setText(String.valueOf(lastGameMaxRating));
minRankingTextField.setText(String.format(locale, "%d", lastGameMinRating));
maxRankingTextField.setText(String.format(locale, "%d", lastGameMaxRating));

minRankingTextField.textProperty().addListener((observable, oldValue, newValue) -> {
preferencesService.getPreferences().setLastGameMinRating(Integer.parseInt(newValue));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/faforever/client/login/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.faforever.client.user.UserService;
import com.faforever.client.util.JavaFxUtil;
import com.google.common.base.Strings;
import com.google.common.hash.Hashing;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand All @@ -16,7 +17,6 @@
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,6 +27,7 @@
import static com.faforever.client.fx.WindowDecorator.WindowButtonType.CLOSE;
import static com.faforever.client.fx.WindowDecorator.WindowButtonType.MINIMIZE;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.nio.charset.StandardCharsets.UTF_8;

public class LoginController {

Expand Down Expand Up @@ -138,7 +139,7 @@ void loginButtonClicked() {
String username = usernameInput.getText();
String password = passwordInput.getText();

password = DigestUtils.sha256Hex(password);
password = Hashing.sha256().hashString(password, UTF_8).toString();

boolean autoLogin = autoLoginCheckBox.isSelected();

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/faforever/client/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;

import static com.faforever.client.fx.WindowDecorator.WindowButtonType.CLOSE;
Expand Down Expand Up @@ -195,6 +196,8 @@ public class MainController implements OnLobbyConnectedListener, OnLobbyConnecti
UserMenuController userMenuController;
@Resource
Stage stage;
@Resource
Locale locale;

@VisibleForTesting
Popup persistentNotificationsPopup;
Expand Down Expand Up @@ -353,7 +356,7 @@ private void updateNotificationsButton(Collection<? extends PersistentNotificati
JavaFxUtil.assertApplicationThread();

int numberOfNotifications = notifications.size();
notificationsButton.setText(String.valueOf(numberOfNotifications));
notificationsButton.setText(String.format(locale, "%d", numberOfNotifications));

Severity highestSeverity = null;
for (PersistentNotification notification : notifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.task.AbstractPrioritizedTask;
import com.google.common.hash.Hashing;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.io.BufferedReader;
Expand Down Expand Up @@ -93,7 +93,7 @@ private boolean areLocalFilesPatched() throws IOException {

byte[] bytesOfFileToCheck = Files.readAllBytes(fileToCheck);

String actualMd5 = DigestUtils.md5DigestAsHex(bytesOfFileToCheck);
String actualMd5 = Hashing.md5().hashBytes(bytesOfFileToCheck).toString();
if (!actualMd5.equals(expectedMd5)) {
logger.info("At least one binary file is out of date: {}. Expected checksum: {} but got: {}", fileName, expectedMd5, actualMd5);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.task.AbstractPrioritizedTask;
import com.faforever.client.util.OperatingSystem;
import com.google.common.hash.Hashing;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -13,7 +14,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.util.DigestUtils;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
Expand Down Expand Up @@ -129,7 +129,7 @@ protected void copyGameFilesToFafBinDirectory(MigrationData migrationData) throw

private Path getPatchFile(byte[] bytesOfFileToPatch) {
Path patchSourceDirectory = binaryPatchRepoDirectory.resolve(BINARY_PATCH_DIRECTORY);
return patchSourceDirectory.resolve(DigestUtils.md5DigestAsHex(bytesOfFileToPatch));
return patchSourceDirectory.resolve(Hashing.md5().hashBytes(bytesOfFileToPatch).toString());
}

private void patchFile(Path fileToPatch, byte[] bytesOfFileToPatch, Path patchFile) throws IOException, CompressorException, InvalidHeaderException {
Expand All @@ -145,7 +145,7 @@ private void patchFile(Path fileToPatch, byte[] bytesOfFileToPatch, Path patchFi
}

private void verifyPatchedFile(String expectedMd5AfterPatch, Path fileToPatch) throws IOException {
String md5OfPatchedFile = DigestUtils.md5DigestAsHex(Files.readAllBytes(fileToPatch));
String md5OfPatchedFile = Hashing.md5().hashBytes(Files.readAllBytes(fileToPatch)).toString();

if (!md5OfPatchedFile.equals(expectedMd5AfterPatch)) {
throw new PatchingFailedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import com.faforever.client.task.ResourceLocks;
import com.faforever.client.util.ByteCopier;
import com.faforever.client.util.OperatingSystem;
import com.google.common.hash.Hashing;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import net.dongliu.vcdiff.VcdiffDecoder;
import net.dongliu.vcdiff.exception.VcdiffDecodeException;
import org.apache.commons.codec.digest.DigestUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -220,10 +220,8 @@ private void requestFiles(String targetDirectoryName, String fileGroup) throws I
updateServerAccessor.modPatchTo(targetDirectoryName, filename, modVersions);
}
} else {
try (InputStream inputStream = Files.newInputStream(fileToPatch)) {
String currentMd5 = DigestUtils.md5Hex(inputStream);
updateServerAccessor.update(targetDirectoryName, filename, currentMd5);
}
String currentMd5 = com.google.common.io.Files.hash(fileToPatch.toFile(), Hashing.md5()).toString();
updateServerAccessor.update(targetDirectoryName, filename, currentMd5);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -96,6 +97,8 @@ public class Ranked1v1Controller {
LeaderboardService leaderboardService;
@Resource
I18n i18n;
@Resource
Locale locale;

@VisibleForTesting
HashMap<Faction, ToggleButton> factionsToButtons;
Expand Down Expand Up @@ -230,7 +233,7 @@ private void updateRating(PlayerInfoBean player) {
} else {
ratingProgressIndicator.setVisible(false);
ratingLabel.setVisible(true);
ratingLabel.setText(String.valueOf(rating));
ratingLabel.setText(String.format(locale, "%d", rating));

updateRatingHint(rating);
}
Expand Down Expand Up @@ -283,7 +286,7 @@ private void plotRatingDistributions(List<RatingDistribution> ratingDistribution
series.getData().addAll(ratingDistributionMap.stream()
.map(item -> {
int maxRating = item.getMaxRating();
XYChart.Data<String, Integer> data = new XYChart.Data<>(String.valueOf(maxRating), item.getPlayers());
XYChart.Data<String, Integer> data = new XYChart.Data<>(String.format(locale, "%d", maxRating), item.getPlayers());
if (maxRating == RatingUtil.getRoundedLeaderboardRating(player)) {
data.nodeProperty().addListener((observable, oldValue, newValue) -> {
newValue.pseudoClassStateChanged(NOTIFICATION_HIGHLIGHTED_PSEUDO_CLASS, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -83,6 +84,8 @@ public class ReplayVaultController {
FxmlLoader fxmlLoader;
@Resource
ApplicationContext applicationContext;
@Resource
Locale locale;

@VisibleForTesting
TreeItem<ReplayInfoBean> localReplaysRoot;
Expand Down Expand Up @@ -208,7 +211,7 @@ public String toString(Number object) {
if (object.intValue() == 0) {
return "";
}
return String.valueOf(object.intValue());
return String.format(locale, "%d", object.intValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.faforever.client.test.AbstractPlainJavaFxTest;
import com.faforever.client.user.UserService;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.hash.Hashing;
import javafx.beans.property.MapProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleMapProperty;
Expand All @@ -21,7 +22,6 @@
import javafx.collections.ObservableSet;
import javafx.concurrent.Task;
import javafx.scene.paint.Color;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -55,6 +55,7 @@

import java.io.IOException;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -657,7 +658,7 @@ public void testOnConnected() throws Exception {
mockTaskService();
instance.onConnected();

String md5Password = DigestUtils.md5Hex(password);
String md5Password = Hashing.md5().hashString(password, StandardCharsets.UTF_8).toString();
verify(outputIrc).message("NICKSERV", String.format("IDENTIFY %s", md5Password));

assertTrue("Channel has not been joined within timeout", latch.await(TIMEOUT, TIMEOUT_UNIT));
Expand Down

0 comments on commit 3e84a49

Please sign in to comment.