|| fc.getSelectedFile() == null) {
// I want a file, y'know!
return;
}
ScenarioLoader sl = new ScenarioLoader(fc.getSelectedFile());
IGame g;
try {
g = sl.createGame();
} catch (Exception e) {
JOptionPane
.showMessageDialog(
frame,
Messages
.getString("MegaMek.HostScenarioAllert.message") + e.getMessage(), Messages.getString("MegaMek.HostScenarioAllert.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
// popup options dialog
GameOptionsDialog god = new GameOptionsDialog(frame, g.getOptions());
god.update(g.getOptions());
god.setEditable(true);
god.setVisible(true);
for (IBasicOption opt : god.getOptions()) {
IOption orig = g.getOptions().getOption(opt.getName());
orig.setValue(opt.getValue());
}
god = null;
// get player types and colors set
Player[] pa = new Player[g.getPlayersVector().size()];
g.getPlayersVector().copyInto(pa);
ScenarioDialog sd = new ScenarioDialog(frame, pa);
sd.setVisible(true);
if (!sd.bSet) {
return;
}
// host with the scenario. essentially copied from host()
HostDialog hd = new HostDialog(frame);
boolean hasSlot = false;
if (!("".equals(sd.localName)))
hasSlot = true;
hd.yourNameF.setText(sd.localName);
hd.setVisible(true);
// verify dialog data
if (hd.playerName == null || hd.serverPass == null || hd.port == 0) {
return;
}
sd.localName = hd.playerName;
// Players should have to enter a non-blank, non-whitespace name.
boolean foundValid = false;
char[] nameChars = hd.playerName.toCharArray();
for (int loop = 0; !foundValid && loop < nameChars.length; loop++) {
if (!Character.isWhitespace(nameChars[loop])) {
foundValid = true;
}
}
if (!foundValid) {
JOptionPane
.showMessageDialog(
frame,
Messages
.getString("MegaMek.HostScenarioAllert1.message"), Messages.getString("MegaMek.HostScenarioAllert1.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
// kick off a RNG check
d6();
// start server
try {
server = new Server(hd.serverPass, hd.port);
} catch (IOException ex) {
System.err.println("could not create server socket on port "
+ hd.port);
StringBuffer error = new StringBuffer();
error.append("Error: could not start server at localhost").append(
":").append(hd.port).append(" (").append(ex.getMessage())
.append(").");
JOptionPane
.showMessageDialog(
frame,
error.toString(),
Messages.getString("MegaMek.HostGameAllert.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
return;
}
server.setGame(g);
// apply any scenario damage
sl.applyDamage(server);
ClientGUI gui = null;
if (!"".equals(sd.localName)) { //$NON-NLS-1$
// initialize game
client = new Client(hd.playerName, "localhost", hd.port); //$NON-NLS-1$
gui = new ClientGUI(client);