Skip to content

Commit

Permalink
Merge remote-tracking branch 'downstream/tmp' into tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
simon33-2 committed Apr 22, 2017
2 parents 28f8fd7 + f371df9 commit ec9546b
Show file tree
Hide file tree
Showing 16 changed files with 691 additions and 676 deletions.
2 changes: 1 addition & 1 deletion dice_servers/tripleawarclub.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ message.maxlength=200
# we do not report dice, but instead show the error message.
error.start=fatal error:
error.end=!
infotext=Enter your your email address in the "To" field, and you opponents in in the "CC" field, you may enter multiple addresses each separated by a space.<br> \nVisit http://dice.tripleawarclub.org to register your email addresses, this must be done to receive dice emails.<br> \nIf this is a league match you must enter a Game ID or Challenge ID, as requested by your tournament organizer
infotext=Enter your your email address in the "To" field, and you opponents in in the "CC" field, you may enter multiple addresses each separated by a space.<br> \nVisit https://dice.tripleawarclub.org to register your email addresses, this must be done to receive dice emails.<br> \nIf this is a league match you must enter a Game ID or Challenge ID, as requested by your tournament organizer
gameid=true
163 changes: 89 additions & 74 deletions src/main/java/games/strategy/engine/data/GameParser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void rollInSeperateThread() throws IllegalStateException {
appendText(" 2: Firewall could be blocking TripleA from connecting to the Dice Server\n");
appendText(" 3: The e-mail address does not exist\n");
appendText(" 4: An unknown error, please see the error console and consult the forums for help\n");
appendText(" Visit http://tripleadev.org for extra help\n");
appendText(" Visit https://forums.triplea-game.org for extra help\n");
if (text != null) {
appendText("Text from dice server:\n" + text + "\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -14,13 +15,23 @@

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HttpContext;

import games.strategy.debug.ClientLogger;
import games.strategy.engine.ClientContext;
Expand Down Expand Up @@ -119,9 +130,10 @@ public String postRequest(final int max, final int numDice, final String subject
if (message.length() > maxLength) {
message = message.substring(0, maxLength - 1);
}
try (CloseableHttpClient httpClient = HttpClients.createDefault();) {
HttpPost httpPost = new HttpPost(m_props.getProperty("path"));
List<NameValuePair> params = new ArrayList<>(8);
try (CloseableHttpClient httpClient =
HttpClientBuilder.create().setRedirectStrategy(new AdvancedRedirectStrategy()).build()) {
final HttpPost httpPost = new HttpPost(m_props.getProperty("path"));
final List<NameValuePair> params = new ArrayList<>(8);
params.add(new BasicNameValuePair("numdice", "" + numDice));
params.add(new BasicNameValuePair("numsides", "" + max));
params.add(new BasicNameValuePair("modroll", "No"));
Expand All @@ -136,14 +148,11 @@ public String postRequest(final int max, final int numDice, final String subject
// rather than sending out email for each roll
httpPost.addHeader("X-Triplea-Game-UUID", gameUUID);
final String host = m_props.getProperty("host");
int port = 80;
if (m_props.getProperty("port") != null) {
port = Integer.parseInt(m_props.getProperty("port"));
}
HttpHost hostConfig = new HttpHost(host, port);
final int port = Integer.parseInt(m_props.getProperty("port", "80"));
final HttpHost hostConfig = new HttpHost(host, port);
HttpProxy.addProxy(httpPost);
try (CloseableHttpResponse response = httpClient.execute(hostConfig, httpPost);) {
HttpEntity entity = response.getEntity();
final HttpEntity entity = response.getEntity();
return Util.getStringFromInputStream(entity.getContent());
}
}
Expand Down Expand Up @@ -247,3 +256,28 @@ public String getHelpText() {
return getInfoText();
}
}


class AdvancedRedirectStrategy extends LaxRedirectStrategy {
@Override
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
final URI uri = getLocationURI(request, response, context);
final String method = request.getRequestLine().getMethod();
if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
return new HttpHead(uri);
} else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) {
return new HttpGet(uri);
} else {
final int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_PERMANENTLY
|| status == HttpStatus.SC_MOVED_TEMPORARILY) {
return RequestBuilder.copy(request).setUri(uri).build();
} else {
return new HttpGet(uri);
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/games/strategy/triplea/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ private static List<String> getPaths(final String mapName) {

// clicking github 'clone or download' and downloading the zip gives a zip that ends with "-master.zip"
candidates.add(new File(ClientFileSystemHelper.getUserMapsFolder(), normalizeMapZipName(mapName) + "-master.zip"));
candidates.add(new File(ClientFileSystemHelper.getUserMapsFolder(), mapName + "-master.zip"));
candidates.add(new File(ClientFileSystemHelper.getUserMapsFolder(), zipName));
candidates.add(new File(ClientFileSystemHelper.getUserMapsFolder(), normalizedZipName));

final Optional<File> match = candidates.stream().filter(file -> file.exists()).findFirst();
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/games/strategy/triplea/delegate/BattleDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ public void start() {
}
m_battleTracker.fightAirRaidsAndStrategicBombing(m_bridge);
m_battleTracker.fightAutoKills(m_bridge);
int amphibCount = 0;
IBattle lastAmphib = null;
for( final Territory t : m_battleTracker.getPendingBattleSites(false) ) { // Loop through normal combats i.e. not bombing or air raid
final IBattle battle = m_battleTracker.getPendingBattle(t, false, BattleType.NORMAL);
if (!(battle instanceof MustFightBattle) ) {
continue;
}

if( battle.isAmphibious() ) {
amphibCount++;
lastAmphib = battle; // Otherwise store it to see if it can be fought later i.e. if there's only one
}
}

// Fight amphibious assault if there is one remaining. Fight naval battles in random order if prerequisites first.
if( amphibCount == 1 ) {
// are there battles that must occur first
for( final IBattle seaBattle : m_battleTracker.getDependentOn( lastAmphib ) ) {
if( seaBattle instanceof MustFightBattle && seaBattle != null ) {
seaBattle.fight( m_bridge );
}
}
lastAmphib.fight( m_bridge );

}
m_battleTracker.fightBattleIfOnlyOne(m_bridge);
}

/**
Expand Down Expand Up @@ -253,9 +279,9 @@ public IDelegateBridge getBattleBridge() {
}

/**
* Add bombardment units to battles.
* Add bombardment units to battles. Made public for test purposes only
*/
private void addBombardmentSources() {
void addBombardmentSources() {
final PlayerID attacker = m_bridge.getPlayerID();
final ITripleAPlayer remotePlayer = getRemotePlayer();
final Match<Unit> ownedAndCanBombard =
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/games/strategy/triplea/delegate/BattleTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,18 @@ public void fightAutoKills(final IDelegateBridge bridge) {
});
}

/**
* Fight battle if only one.
*/
public void fightBattleIfOnlyOne(final IDelegateBridge bridge) {
final Collection<Territory> territories = getPendingBattleSites(false);
if (territories.size() == 1) {
final IBattle battle = getPendingBattle(territories.iterator().next(), false, BattleType.NORMAL);
battle.fight(bridge);
}
}


@Override
public String toString() {
return "BattleTracker:" + "\n" + "Conquered:" + m_conquered + "\n" + "Blitzed:" + m_blitzed + "\n" + "Fought:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ public abstract class DependentBattle extends AbstractBattle {
super(battleSite, attacker, battleTracker, isBombingRun, battleType, data);
}

public Collection<Territory> getAttackingFrom() {
return m_attackingFrom;
}
abstract public Collection<Territory> getAttackingFrom();

public Map<Territory, Collection<Unit>> getAttackingFromMap() {
return m_attackingFromMap;
}
abstract public Map<Territory, Collection<Unit>> getAttackingFromMap();

/**
* @return territories where there are amphibious attacks.
*/
public Collection<Territory> getAmphibiousAttackTerritories() {
return m_amphibiousAttackFrom;
}
abstract public Collection<Territory> getAmphibiousAttackTerritories();
}
18 changes: 18 additions & 0 deletions src/main/java/games/strategy/triplea/delegate/MustFightBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ public MustFightBattle(final Territory battleSite, final PlayerID attacker, fina
}
}

@Override
public Collection<Territory> getAttackingFrom() {
return m_attackingFrom;
}

@Override
public Map<Territory, Collection<Unit>> getAttackingFromMap() {
return m_attackingFromMap;
}

/**
* @return territories where there are amphibious attacks.
*/
@Override
public Collection<Territory> getAmphibiousAttackTerritories() {
return m_amphibiousAttackFrom;
}

public void resetDefendingUnits(final PlayerID attacker, final GameData data) {
m_defendingUnits.clear();
m_defendingUnits.addAll(m_battleSite.getUnits().getMatches(Matches.enemyUnit(attacker, data)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public NonFightingBattle(final Territory battleSite, final PlayerID attacker, fi
super(battleSite, attacker, battleTracker, false, BattleType.NORMAL, data);
}

@Override
public Collection<Territory> getAttackingFrom() {
return m_attackingFrom;
}

@Override
public Map<Territory, Collection<Unit>> getAttackingFromMap() {
return m_attackingFromMap;
}

/**
* @return territories where there are amphibious attacks.
*/
@Override
public Collection<Territory> getAmphibiousAttackTerritories() {
return m_amphibiousAttackFrom;
}

@Override
public Change addAttackChange(final Route route, final Collection<Unit> units,
final HashMap<Unit, HashSet<Unit>> targets) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/games/strategy/ui/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static Image getBanner(final String text) {
* Finds a land territory name or some sea zone name where the point is contained in according to the territory name
* -> polygons map.
*
* @param p A point on the map.
* @param java.awt.point p - a point on the map
* @param terrPolygons a map territory name -> polygons
* @return Optional&lt;String>
*/
Expand All @@ -162,9 +162,9 @@ public static Optional<String> findTerritoryName(final Point p, final Map<String
* Finds a land territory name or some sea zone name where the point is contained in according to the territory name
* -> polygons map. If no land or sea territory has been found a default name is returned.
*
* @param p A point on the map.
* @param java.awt.point p - a point on the map
* @param terrPolygons a map territory name -> polygons
* @param defaultTerrName Default territory name that gets returns if nothing was found.
* @param String defaultTerrName - default territory name that gets returns if nothing was found
* @return found territory name of defaultTerrName
*/
public static String findTerritoryName(final Point p, final Map<String, List<Polygon>> terrPolygons,
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/tools/map/xml/creator/MapXmlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public class MapXmlHelper {
public static final String XML_ATTR_VALUE_PLAYER_OPTIONAL_NAME_FALSE = "false";
public static final String XML_ATTR_VALUE_OPTION_NAME_CANAL_NAME = "canalName";
public static final String XML_ATTR_VALUE_OPTION_NAME_LAND_TERRITORIES = "landTerritories";
public static final String XML_ATTR_VALUE_PROPERTY_NAME_MAP_NAME = "mapName";
public static final String XML_ATTR_VALUE_PROPERTY_NAME_NOTES = "notes";


Expand Down Expand Up @@ -640,8 +639,7 @@ private static void parsePropertyNode(final Node property) {
final HashMap<String, String> propertyAttr = getAttributesMap(property.getAttributes());
final ArrayList<String> settingValues = new ArrayList<>();
final String propertyName = propertyAttr.get(XML_ATTR_PROPERTY_NAME_NAME);
if (propertyName.equals(XML_ATTR_VALUE_PROPERTY_NAME_NOTES)
|| propertyName.equals(XML_ATTR_VALUE_PROPERTY_NAME_MAP_NAME)) {
if (propertyName.equals(XML_ATTR_VALUE_PROPERTY_NAME_NOTES)) {
final NodeList propertyListChildNodes = property.getChildNodes();
for (int prop_i = 0; prop_i < propertyListChildNodes.getLength(); ++prop_i) {
final Node subProperty = propertyListChildNodes.item(prop_i);
Expand Down Expand Up @@ -967,7 +965,6 @@ private static void appendPropertyList(final Document doc, final Element game) {
if (getMapXMLFile() != null) {
propertyList.appendChild(doc.createComment(" Map Name: also used for map utils when asked "));
final Element property = doc.createElement(XML_NODE_NAME_PROPERTY);
property.setAttribute(XML_ATTR_PROPERTY_NAME_NAME, XML_ATTR_VALUE_PROPERTY_NAME_MAP_NAME);
final String fileName = getMapXMLFile().getName();
property.setAttribute(XML_ATTR_PROPERTY_NAME_VALUE, fileName.substring(0, fileName.lastIndexOf(".") - 1));
property.setAttribute(XML_ATTR_PROPERTY_NAME_EDITABLE, Constants.PROPERTY_FALSE);
Expand Down
Loading

0 comments on commit ec9546b

Please sign in to comment.