Skip to content

Commit

Permalink
Fix entering more than 40 chars worth of emails to dice server.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine committed Jul 23, 2023
1 parent 84d2843 commit b6da81b
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package games.strategy.engine.framework.startup.ui.posted.game;

import games.strategy.engine.data.properties.GameProperties;
import games.strategy.engine.player.Player;
import games.strategy.engine.random.IRemoteDiceServer;
import games.strategy.engine.random.MartiDiceRoller;
import games.strategy.engine.random.PbemDiceRoller;
Expand All @@ -10,6 +11,7 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.net.URI;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
Expand Down Expand Up @@ -255,10 +257,8 @@ private void checkFieldsAndNotify() {
}

public boolean areFieldsValid() {
final boolean toValid =
!toAddress.getText().isEmpty() && PlayerEmailValidation.isValid(toAddress.getText());
final boolean ccValid =
!ccAddress.getText().isEmpty() && PlayerEmailValidation.isValid(ccAddress.getText());
final boolean toValid = !toAddress.getText().isEmpty() && validateEmailAddresses(toAddress.getText());
final boolean ccValid = !ccAddress.getText().isEmpty() && validateEmailAddresses(ccAddress.getText());

final boolean allValid = toValid && ccValid;
testDiceButton.setEnabled(allValid);
Expand All @@ -275,6 +275,10 @@ public boolean areFieldsValid() {
return allValid;
}

private boolean validateEmailAddresses(String addresses) {
return Arrays.stream(addresses.split("\\s+")).allMatch(PlayerEmailValidation::isValid);
}

public void applyToGameProperties(final GameProperties properties) {
properties.set(IRemoteDiceServer.GAME_NAME, gameId.getText());
properties.set(IRemoteDiceServer.EMAIL_1, toAddress.getText());
Expand Down

0 comments on commit b6da81b

Please sign in to comment.