Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Player joins as side" message now broadcast to all players #12768

Merged
merged 9 commits into from
Jan 9, 2024
22 changes: 14 additions & 8 deletions vassal-app/src/main/java/VASSAL/build/module/PlayerRoster.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ protected void launch() {
a.execute();

c = c.append(a);
gm.getServer().sendToOthers(c);
// how is it if we log ? gm.getServer().sendToOthers(c);
gm.sendAndLog(c);

newSide = getMySide();
fireSideChange(mySide, newSide);
Expand Down Expand Up @@ -478,13 +479,14 @@ public void setup(boolean gameStarting) {
*/
@Override
public void finish() {
final GameModule gm = GameModule.getGameModule();
// In case we set a new password at this step, update the prefs configurer, and write module preferences.
GameModule.getGameModule().getPasswordConfigurer().setValue(GameModule.getUserId());
gm.getPasswordConfigurer().setValue(GameModule.getUserId());
try {
GameModule.getGameModule().getPrefs().save();
gm.getPrefs().save();
}
catch (IOException e) {
GameModule.getGameModule().warn(Resources.getString("PlayerRoster.failed_pref_write", e.getLocalizedMessage()));
gm.warn(Resources.getString("PlayerRoster.failed_pref_write", e.getLocalizedMessage()));
}

// Drop into standard routine, starting with checking that the side is still available (race condition mitigation)
Expand All @@ -493,14 +495,18 @@ public void finish() {

// null is a cancel op - player will not connect to the game
if (newSide != null) {
if (GameModule.getGameModule().isMultiplayerConnected()) {
final Command c = new Chatter.DisplayText(GameModule.getGameModule().getChatter(), Resources.getString(GlobalOptions.getInstance().chatterHTMLSupport() ? "PlayerRoster.joined_side_2" : "PlayerRoster.joined_side", GameModule.getGameModule().getPrefs().getValue(GameModule.REAL_NAME), translateSide(newSide)));
if (gm.isMultiplayerConnected()) {
final Command c = new Chatter.DisplayText(gm.getChatter(), Resources.getString(GlobalOptions.getInstance().chatterHTMLSupport() ? "PlayerRoster.joined_side_2" : "PlayerRoster.joined_side", gm.getPrefs().getValue(GameModule.REAL_NAME), translateSide(newSide)));
c.execute();
// trying with logging in place of gm.getServer().sendToOthers(c);
uckelman marked this conversation as resolved.
Show resolved Hide resolved
gm.sendAndLog(c);

}

final Add a = new Add(this, GameModule.getActiveUserId(), GlobalOptions.getInstance().getPlayerId(), newSide);
a.execute();
GameModule.getGameModule().getServer().sendToOthers(a);
// trying with logging in place of gm.getServer().sendToOthers(a);
gm.sendAndLog(a);

pickedSide = true;
}
Expand Down Expand Up @@ -1149,4 +1155,4 @@ public void validate(Buildable target, ValidationReport report) {
}
}
}
}
}