Skip to content

Commit

Permalink
Merge pull request #5232 from RPTools/release-1.16
Browse files Browse the repository at this point in the history
Merge Latest 1.16 changes into Develop
  • Loading branch information
kwvanderlinde authored Feb 13, 2025
2 parents 58c9f4f + e8e4579 commit d8a0cbf
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void onClose(int code, String reason, boolean remote) {
@Override
public void onError(Exception ex) {
lastError = "WebSocket error: " + ex.toString() + "\n";
log.error("S " + lastError);
log.error("S " + lastError, ex);
// onClose will be called after this method
}
};
Expand Down Expand Up @@ -147,7 +147,7 @@ public void onDataChannelOpened(WebRTCConnection connection) {
try {
fireClientConnect(connection);
} catch (Exception e) {
log.error(e);
log.error("Unexpected error while handling new data channel", e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public class MapTool {
try {
var connections = DirectConnection.create("local");
var playerDB = new PersonalServerPlayerDatabase(new LocalPlayer());
var campaign = CampaignFactory.createBasicCampaign();
var campaign = CampaignFactory.createEmptyCampaign();
var policy = new ServerPolicy();

server = new MapToolServer(null, new Campaign(campaign), null, false, policy, playerDB);
Expand Down
45 changes: 0 additions & 45 deletions src/main/java/net/rptools/maptool/client/swing/ResourceLoader.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private Container createContentPane() {
infoTextArea.setWrapStyleWord(true);
infoTextArea.setFont(new Font("Monospaced", Font.PLAIN, 13));
infoTextArea.setText(I18N.getText("action.gatherDebugInfoWait"));
EventQueue.invokeLater(new InfoTextSwingWorker());
new InfoTextSwingWorker().execute();

JScrollPane scrollPane = new JScrollPane(infoTextArea);
scrollPane.setHorizontalScrollBarPolicy(31);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/rptools/maptool/model/CampaignFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
package net.rptools.maptool.model;

public class CampaignFactory {
/**
* @return A new campaign with no zones or properties.
*/
public static Campaign createEmptyCampaign() {
return new Campaign();
}

public static Campaign createBasicCampaign() {
Campaign campaign = new Campaign();
campaign.initDefault();
Expand Down
53 changes: 38 additions & 15 deletions src/main/java/net/rptools/maptool/model/ZoneFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,67 @@
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import javax.annotation.Nullable;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.AppPreferences;
import net.rptools.maptool.client.AppUtil;
import net.rptools.maptool.model.drawing.DrawableColorPaint;
import net.rptools.maptool.model.drawing.DrawablePaint;
import net.rptools.maptool.model.drawing.DrawableTexturePaint;
import net.rptools.maptool.util.ImageManager;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ZoneFactory {
private static final Logger log = LogManager.getLogger(ZoneFactory.class);

public static final String DEFAULT_MAP_NAME = "Grasslands";
public static MD5Key defaultImageId;
private static final DrawableColorPaint fallbackBackgroundPaint =
new DrawableColorPaint(Color.LIGHT_GRAY);
private static @Nullable MD5Key defaultImageId;

private static DrawablePaint getDefaultBackgroundPaint() {
if (defaultImageId != null) {
return new DrawableTexturePaint(defaultImageId);
}

static {
// TODO: I really don't like this being hard wired this way, need to make it a preference or
// something
// something
File grassImage =
new File(AppUtil.getAppHome("resource/Default/Textures").getAbsolutePath() + "/Grass.png");
if (grassImage.exists()) {
try {
Asset asset =
Asset.createImageAsset(DEFAULT_MAP_NAME, FileUtils.readFileToByteArray(grassImage));
defaultImageId = asset.getMD5Key();
if (!grassImage.exists()) {
log.warn(
"Unable to load the default background texture: file {} does not exist",
grassImage.getPath());
return fallbackBackgroundPaint;
}

MD5Key imageId;
try {
Asset asset =
Asset.createImageAsset(DEFAULT_MAP_NAME, FileUtils.readFileToByteArray(grassImage));
imageId = asset.getMD5Key();

// Make sure the image is loaded to avoid a flash screen when it becomes visible
ImageManager.getImageAndWait(asset.getMD5Key());
} catch (IOException ioe) {
ioe.printStackTrace();
}
// Make sure the image is loaded to avoid a flash screen when it becomes visible
ImageManager.getImageAndWait(asset.getMD5Key());
} catch (IOException ioe) {
log.error("Error reading default background image", ioe);
return fallbackBackgroundPaint;
}

defaultImageId = imageId;
return new DrawableTexturePaint(defaultImageId);
}

public static Zone createZone() {

Zone zone = new Zone();

zone.setName(DEFAULT_MAP_NAME);
zone.setBackgroundPaint(new DrawableTexturePaint(defaultImageId));

var backgroundPaint = getDefaultBackgroundPaint();
zone.setBackgroundPaint(backgroundPaint);

zone.setFogPaint(new DrawableColorPaint(Color.black));

zone.setVisible(AppPreferences.newMapsVisible.get());
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/net/rptools/maptool/server/ServerHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,19 @@ private void sendAsymmetricKeyAuthType()
} else {
sendErrorResponseAndNotify(HandshakeResponseCodeMsg.INVALID_PUBLIC_KEY);
}
} else {
CipherUtil.Key publicKey = playerDatabase.getPublicKey(player, playerPublicKeyMD5).get();
String password = new PasswordGenerator().getPassword();
handshakeChallenges[0] =
HandshakeChallenge.createAsymmetricChallenge(player.getName(), password, publicKey);

var authTypeMsg =
UseAuthTypeMsg.newBuilder()
.setAuthType(AuthTypeEnum.ASYMMETRIC_KEY)
.addChallenge(ByteString.copyFrom(handshakeChallenges[0].getChallenge()));
var handshakeMsg = HandshakeMsg.newBuilder().setUseAuthTypeMsg(authTypeMsg).build();
sendMessage(State.AwaitingClientPublicKeyAuth, handshakeMsg);
}
CipherUtil.Key publicKey = playerDatabase.getPublicKey(player, playerPublicKeyMD5).get();
String password = new PasswordGenerator().getPassword();
handshakeChallenges[0] =
HandshakeChallenge.createAsymmetricChallenge(player.getName(), password, publicKey);

var authTypeMsg =
UseAuthTypeMsg.newBuilder()
.setAuthType(AuthTypeEnum.ASYMMETRIC_KEY)
.addChallenge(ByteString.copyFrom(handshakeChallenges[0].getChallenge()));
var handshakeMsg = HandshakeMsg.newBuilder().setUseAuthTypeMsg(authTypeMsg).build();
sendMessage(State.AwaitingClientPublicKeyAuth, handshakeMsg);
}

@Override
Expand Down

0 comments on commit d8a0cbf

Please sign in to comment.