optdlg = null;
}
public void loadGame() {
FileDialog fd = new FileDialog(frame, Messages
.getString("MegaMek.SaveGameDialog.title"), FileDialog.LOAD); //$NON-NLS-1$
fd.setDirectory("savegames"); //$NON-NLS-1$
// limit file-list to savedgames only
fd.setFilenameFilter(new FilenameFilter() {
public boolean accept(File dir, String name) {
return (null != name && name.endsWith(".sav")); //$NON-NLS-1$
}
});
// Using the FilenameFilter class would be the appropriate way to
// filter for certain extensions, but it's broken under windoze. See
// http://developer.java.sun.com/developer/bugParade/bugs/4031440.html
// for details. The hack below is better than nothing.
// New note: Since we have a dedicated save dir now, I'm commenting
// this out.
// fd.setFile("*.sav"); //$NON-NLS-1$
fd.setVisible(true);
if (fd.getFile() == null) {
return;
}
HostDialog hd = new HostDialog(frame);
hd.setVisible(true);
if (hd.name == null || hd.serverPass == null || hd.port == 0) {
return;
}
// Players should have to enter a non-blank, non-whitespace name.
boolean foundValid = false;
char[] nameChars = hd.name.toCharArray();
for (int loop = 0; !foundValid && loop < nameChars.length; loop++) {
if (!Character.isWhitespace(nameChars[loop])) {
foundValid = true;
}
}
if (!foundValid) {
new AlertDialog(
frame,
Messages.getString("MegaMek.PlayerNameAlert1.title"), Messages.getString("MegaMek.PlayerNameAlert1.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
// kick off a RNG check
megamek.common.Compute.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(").");
new AlertDialog(
frame,
Messages.getString("MegaMek.HostGameAllert.title"), error.toString()).setVisible(true); //$NON-NLS-1$
return;
}
if (!server.loadGame(new File(fd.getDirectory(), fd.getFile()))) {
new AlertDialog(
frame,
Messages.getString("MegaMek.LoadGameAlert.title"), Messages.getString("MegaMek.LoadGameAlert.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$
server.die();
server = null;