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

Fix reading player names from savegames #5322

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions megamek/src/megamek/client/ui/swing/MegaMekGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ public String getDescription() {

final Vector<String> playerNames = new Vector<>();

// Handrolled extraction, as we require Server initialization to use XStream and
// don't need
// Handrolled extraction, as we require Server initialization to use XStream and don't need
// the additional overhead of initializing everything twice
try (InputStream is = new FileInputStream(fc.getSelectedFile())) {
InputStream gzi;
Expand Down Expand Up @@ -639,28 +638,37 @@ private boolean validateSaveVersion(final Node n) {
}
}

private void parsePlayerNames(final Node n, final Vector<String> playerNames) {
if (!n.hasChildNodes()) {
private void parsePlayerNames(final Node nodePlayers, final Vector<String> playerNames) {
if (!nodePlayers.hasChildNodes()) {
return;
}

final NodeList nl = n.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
final Node n2 = nl.item(i);
if ((n2.getNodeType() != Node.ELEMENT_NODE) || !n2.hasChildNodes()
|| !Player.class.getName().equals(n2.getNodeName())) {
final NodeList nodePlayersChildren = nodePlayers.getChildNodes();
for (int i = 0; i < nodePlayersChildren.getLength(); i++) {
final Node nodeEntry = nodePlayersChildren.item(i);
if ((nodeEntry.getNodeType() != Node.ELEMENT_NODE) || !nodeEntry.hasChildNodes()
|| !"entry".equals(nodeEntry.getNodeName())) {
continue;
}

final NodeList nl2 = n2.getChildNodes();
for (int j = 0; j < nl2.getLength(); j++) {
final Node n3 = nl2.item(j);
if (n3.getNodeType() != Node.ELEMENT_NODE) {
final NodeList nodeEntryChildren = nodeEntry.getChildNodes();
for (int k = 0; k < nodeEntryChildren.getLength(); k++) {
final Node nodePlayerClass = nodeEntryChildren.item(k);
if ((nodePlayerClass.getNodeType() != Node.ELEMENT_NODE) || !nodePlayerClass.hasChildNodes()
|| !Player.class.getName().equals(nodePlayerClass.getNodeName())) {
continue;
}

if ("name".equals(n3.getNodeName())) {
playerNames.add(n3.getTextContent());
final NodeList nodePlayerClassChildren = nodePlayerClass.getChildNodes();
for (int j = 0; j < nodePlayerClassChildren.getLength(); j++) {
final Node n3 = nodePlayerClassChildren.item(j);
if (n3.getNodeType() != Node.ELEMENT_NODE) {
continue;
}

if ("name".equals(n3.getNodeName())) {
playerNames.add(n3.getTextContent());
}
}
}
}
Expand Down
Loading