summaryrefslogtreecommitdiff
path: root/NET/worlds/console/LoginWizard.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/LoginWizard.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/LoginWizard.java')
-rw-r--r--NET/worlds/console/LoginWizard.java941
1 files changed, 941 insertions, 0 deletions
diff --git a/NET/worlds/console/LoginWizard.java b/NET/worlds/console/LoginWizard.java
new file mode 100644
index 0000000..60d6f69
--- /dev/null
+++ b/NET/worlds/console/LoginWizard.java
@@ -0,0 +1,941 @@
+package NET.worlds.console;
+
+import NET.worlds.core.IniFile;
+import NET.worlds.core.Std;
+import NET.worlds.network.Cache;
+import NET.worlds.network.CacheFile;
+import NET.worlds.network.Galaxy;
+import NET.worlds.network.NetworkObject;
+import NET.worlds.network.RemoteFileConst;
+import NET.worlds.network.URL;
+import NET.worlds.scape.SendURLAction;
+import java.awt.Button;
+import java.awt.CardLayout;
+import java.awt.Checkbox;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.TextField;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.Random;
+import java.util.Vector;
+
+public class LoginWizard extends PolledDialog implements DialogReceiver, DialogDisabled, RemoteFileConst {
+ private static final long serialVersionUID = -1951115972999605117L;
+ private static final int HAVE_USERS = 0;
+ private static final int ACCOUNT_TYPE = 1;
+ private static final int REGWAIT = 2;
+ private static final int WELCOME = 3;
+ private static final int CODEWORD_WAIT = 4;
+ private static final int NEW_USER_INFO = 5;
+ private static final int LOGGING_IN = 7;
+ private static final int NOT_LOGGED_IN = 8;
+ private static final int ERROR = 9;
+ private static final int CONNECTION_DIED = 10;
+ private static final int AUTO_LOGIN_FAILED = 11;
+ private static final int REGWAIT2 = 12;
+ private static final int BAD_PASSWORD = 13;
+ private static final int SCREEN_COUNT = 14;
+ private static final int STATE_GET_INFO = 0;
+ private static final int STATE_SEND_INFO = 1;
+ private static final int STATE_WAIT = 2;
+ private static final int STATE_AUTO_LOGIN = 3;
+ private static final int STATE_LOGGED_IN = 4;
+ private static final String defaultRegisterScriptL = "register" + Console.message(".pl");
+ private static final String defaultRegisterScript = "register.pl";
+ private static final String nameConstraints = Console.message("n-contain-letters");
+ private static final String passwordConstraints1 = Console.message("p-contain-letters");
+ private static final int oldMinPasswordLen = 4;
+ private static final int newMinPasswordLen = 6;
+ private static final String savePasswordText = Console.message("Remember-password");
+ private static final String passwordMismatchText = Console.message("do-not-match");
+ private static final String userNameIniKey = "User";
+ private static final String passwordIniKey = "Password";
+ private static final String serialNumIniKey = "SNum";
+ private static final String handshakeIDIniKey = "handshakeID";
+ private static final String defaultUserIniKey = "DefaultUser";
+ static final int width = 480;
+ static final int height = 280;
+ static final int textWidth = 400;
+ private Galaxy galaxy;
+ private IniFile iniFile;
+ private CardLayout cardLayout = new CardLayout();
+ private int currentScreen = -1;
+ private int lastScreen = -1;
+ private int loginFrom = -1;
+ private int errorFrom;
+ private Panel[] screens = new Panel[14];
+ private boolean queryingServer;
+ private Button createNewUsernameButton;
+ private Button alternateBrowserButton;
+ private Button signInButton;
+ private Button noEmailButton;
+ private Button showRegButton;
+ private Button pwMailbackButtonKnown;
+ private Button typeUsername;
+ private TextField codewordField = null;
+ private TextField newUserName = null;
+ private TextField newPassword1 = null;
+ private TextField newPassword2 = null;
+ private TextField typedUsername = null;
+ private static Font font = new Font(Console.message("GammaTextFont"), 0, 12);
+ private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
+ private TextField knownPassword = null;
+ private Checkbox savePassword = new Checkbox(savePasswordText, true);
+ private Vector<String> users = new Vector<String>();
+ private Vector<String> passwords = new Vector<String>();
+ private int defaultUser;
+ private String loginUserName;
+ private String loginPassword;
+ private String loginSerialNumber;
+ private String newSerialNumber;
+ private String newHandshakeID;
+ private int loginMode;
+ private int loginIndex = 0;
+ private int loginState;
+ private String errMsg;
+ private boolean isDialogDisabled;
+ private Component defComponent;
+ private int id;
+ private static boolean startUp = true;
+ private static boolean firstTimeDone;
+ private static int seq;
+ private CacheFile cf;
+
+ public static boolean isFirstTimeDone() {
+ return firstTimeDone;
+ }
+
+ public boolean safeToQueryServer() {
+ return this.queryingServer;
+ }
+
+ public LoginWizard(Galaxy galaxy, IniFile iniFile) {
+ this(galaxy, iniFile, null);
+ }
+
+ boolean isAnonServer() {
+ return this.galaxy.getGalaxyType() == 4 || this.galaxy.getGalaxyType() == 2;
+ }
+
+ public LoginWizard(Galaxy galaxy, IniFile iniFile, String errMsg) {
+ super(Console.getFrame(), galaxy, "", false);
+ this.galaxy = galaxy;
+ this.iniFile = iniFile;
+ this.errMsg = errMsg;
+ this.id = seq++;
+ this.queryingServer = false;
+ int userNum = 0;
+
+ while (true) {
+ String user = iniFile.getIniString("User" + userNum, "");
+ if (user.length() == 0) {
+ this.defaultUser = iniFile.getIniInt("DefaultUser", 0);
+ this.newSerialNumber = iniFile.getIniString("SNum", "");
+ if (this.newSerialNumber.length() == 0) {
+ this.newSerialNumber = null;
+ }
+
+ this.newHandshakeID = iniFile.getIniString("handshakeID", "");
+ if (this.newHandshakeID.length() == 0) {
+ this.newHandshakeID = null;
+ }
+
+ this.setTitle(Console.message("Logging-in"));
+ this.setLayout(this.cardLayout);
+ this.loginState = 0;
+ if (errMsg != null) {
+ this.currentScreen = 10;
+ } else if (this.users.size() <= 0 && !this.isAnonServer() && IniFile.override().getIniInt("nocreateaccount", 0) != 1) {
+ this.setTitle(Console.message("Setting-Up-Acct"));
+ if (this.newSerialNumber == null) {
+ if (this.newHandshakeID == null) {
+ this.currentScreen = 1;
+ } else {
+ this.currentScreen = 12;
+ }
+ } else {
+ this.currentScreen = 5;
+ }
+ } else {
+ this.currentScreen = 0;
+ }
+
+ startUp = false;
+ if (this.loginState != 3) {
+ this.disableParent();
+ this.ready();
+ }
+
+ return;
+ }
+
+ this.users.addElement(user);
+ this.passwords.addElement(Console.decode(iniFile.getIniString("Password" + userNum, "")));
+ userNum++;
+ }
+ }
+
+ public boolean waitingForConnection() {
+ return this.loginState == 3 || this.loginState == 2;
+ }
+
+ public void setConnected() {
+ int oldState = this.loginState;
+ this.loginState = 4;
+ if (this.loginFrom != 0 || this.users.size() <= this.loginIndex) {
+ this.users.addElement(this.loginUserName);
+ this.passwords.addElement(null);
+ this.iniFile.setIniString("User" + this.loginIndex, this.loginUserName);
+ if (this.loginFrom == 5) {
+ this.iniFile.setIniString("SNum" + this.loginIndex, this.loginSerialNumber);
+ }
+ }
+
+ boolean save = this.savePassword.getState();
+ String pass = this.galaxy.getPassword();
+ if (this.loginPassword != null
+ && pass != null
+ && (save != this.isPasswordSaved(this.loginIndex) || !pass.equals(this.passwords.elementAt(this.loginIndex)))) {
+ String val = save ? pass : null;
+ this.passwords.setElementAt(val, this.loginIndex);
+ this.iniFile.setIniString("Password" + this.loginIndex, Console.encode(val));
+ }
+
+ String name = this.galaxy.getChatname();
+ String nameU = this.galaxy.getUsernameU();
+ if (this.loginFrom != 5 && !name.equals(this.users.elementAt(this.loginIndex))) {
+ this.users.setElementAt(name, this.loginIndex);
+ this.iniFile.setIniString("User" + this.loginIndex, nameU);
+ }
+
+ this.iniFile.setIniInt("DefaultUser", this.loginIndex);
+ this.defaultUser = this.loginIndex;
+ if (this.newSerialNumber != null) {
+ this.newHandshakeID = null;
+ this.newSerialNumber = null;
+ this.iniFile.setIniString("handshakeID", "");
+ this.iniFile.setIniString("SNum", "");
+ }
+
+ if (this.loginFrom != 0) {
+ this.selectScreen(3);
+ } else if (oldState != 3) {
+ this.done(true);
+ } else {
+ assert Main.isMainThread();
+
+ this.galaxy.dialogDone(this, true);
+ firstTimeDone = true;
+ }
+ }
+
+ public void loginError(String errMsg) {
+ this.removeScreen(8);
+ if (errMsg == null) {
+ errMsg = Console.message("Unknown-error");
+ }
+
+ this.errMsg = errMsg;
+ if (this.loginState == 3) {
+ this.currentScreen = 11;
+ this.disableParent();
+ this.ready();
+ } else {
+ if (this.loginFrom == -1) {
+ this.loginFrom = 0;
+ }
+
+ this.selectScreen(8);
+ }
+
+ this.loginState = 0;
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ if (this.defComponent != null) {
+ this.defComponent.requestFocus();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+ @Override
+ protected void activeCallback() {
+ if (this.loginState == 1) {
+ this.loginState = 2;
+ this.galaxy.setAuthInfo(this.loginUserName, null, this.loginPassword, null, this.loginSerialNumber, this.loginMode);
+ }
+ }
+
+ @Override
+ protected void build() {
+ this.selectScreen(this.currentScreen);
+ }
+
+ @Override
+ public Dimension size() {
+ return new Dimension(480, 280);
+ }
+
+ private void selectScreen(int which) {
+ String name = "" + which;
+ if (this.screens[which] == null) {
+ this.add(name, this.screens[which] = this.buildScreen(which));
+ }
+
+ this.cardLayout.show(this, name);
+ if (this.lastScreen != which && this.lastScreen >= 0 && this.screens[this.lastScreen] != null) {
+ this.removeScreen(this.lastScreen);
+ }
+
+ this.currentScreen = which;
+ this.lastScreen = which;
+ if (which == 2) {
+ new SendURLAction(this.getRegisterScriptName()).startBrowser();
+ } else if (which == 4) {
+ new LoginWizard.AwaitCodeword(this.codewordField.getText());
+ }
+ }
+
+ private Panel buildScreen(int which) {
+ GridBagLayout gbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ Panel p = new Panel(gbag);
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 0;
+ switch (which) {
+ case 0:
+ return this.buildKnownUsersScreen(p, gbag, c);
+ case 1:
+ return this.buildAccountTypeScreen(p, gbag, c);
+ case 2:
+ return this.buildRegWait(p, gbag, c);
+ case 3:
+ return this.buildWelcome(p, gbag, c);
+ case 4:
+ return this.buildCodewordWaitScreen(p, gbag, c);
+ case 5:
+ return this.buildNewUserInfoScreen(p, gbag, c);
+ case 6:
+ default:
+ return null;
+ case 7:
+ return this.buildLoggingInScreen(p, gbag, c);
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ return this.buildErrorScreen(p, gbag, c, which);
+ case 12:
+ return this.buildRegWait2(p, gbag, c);
+ }
+ }
+
+ private void removeScreen(int screen) {
+ if (this.screens[screen] != null) {
+ this.remove(this.screens[screen]);
+ this.screens[screen] = null;
+ }
+ }
+
+ private void selectErrorScreen(String msg) {
+ this.errMsg = msg;
+ this.errorFrom = this.currentScreen;
+ this.selectScreen(9);
+ }
+
+ private Panel buildKnownUsersScreen(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ this.typedUsername = new TextField(16);
+ this.knownPassword = new TextField(12);
+ this.knownPassword.setEchoChar('*');
+ Panel tmp = new Panel();
+ String enterText = Console.message("one-username");
+ if (this.isAnonServer()) {
+ enterText = Console.message("a-username");
+ }
+
+ TextCanvas text = new TextCanvas(enterText, 400);
+ tmp.add(text);
+ add(p, tmp, gbag, c);
+ if (this.createNewUsernameButton == null) {
+ this.createNewUsernameButton = new Button(Console.message("Create-Username"));
+ }
+
+ if (this.pwMailbackButtonKnown == null) {
+ this.pwMailbackButtonKnown = new Button(Console.message("Remind-Me"));
+ }
+
+ if (this.defaultUser < this.users.size()) {
+ String pass = this.passwords.elementAt(this.defaultUser);
+ boolean knowPassword = pass != null;
+ this.knownPassword.setText(knowPassword ? pass : "");
+ this.savePassword.setState(knowPassword);
+ this.typedUsername.setText(this.users.elementAt(this.defaultUser));
+ }
+
+ tmp = new Panel(new GridLayout(2, 2));
+ Label uName = new Label(Console.message("Username"), 1);
+ uName.setFont(font);
+ this.typedUsername.setFont(font);
+ this.knownPassword.setFont(font);
+ tmp.add(uName);
+ tmp.add(this.typedUsername);
+ if (this.isAnonServer()) {
+ this.knownPassword.setText(Console.message("anonymous"));
+ add(p, tmp, gbag, c);
+ } else {
+ Label pWord = new Label(Console.message("Password"), 1);
+ pWord.setFont(font);
+ tmp.add(pWord);
+ tmp.add(this.knownPassword);
+ add(p, tmp, gbag, c);
+ this.savePassword.setFont(font);
+ add(p, this.savePassword, gbag, c);
+ }
+
+ tmp = new Panel();
+ String help = Console.message("youve-upgraded");
+ if (this.iniFile.getIniString("AutoLogin", "").equals("") && this.iniFile.getIniString("User1", "").equals("")) {
+ help = "";
+ }
+
+ String instr = Console.message("first-time-user" + help);
+ if (this.isAnonServer()) {
+ instr = help;
+ }
+
+ text = new TextCanvas(instr, 400);
+ tmp.add(text);
+ add(p, tmp, gbag, c);
+ if (!this.isAnonServer() && IniFile.override().getIniInt("nocreateaccount", 0) != 1) {
+ this.addButtons(
+ p,
+ gbag,
+ this.users.size() > 0 ? Console.message("Cancel") : "<< " + Console.message("Back"),
+ this.createNewUsernameButton,
+ this.pwMailbackButtonKnown,
+ Console.message("Sign-In")
+ );
+ } else {
+ this.addButtons(p, gbag, Console.message("Cancel"), null, null, Console.message("Sign-In"));
+ }
+
+ if (this.knownPassword.getText().length() == 0) {
+ if (this.typedUsername.getText().length() == 0) {
+ this.defComponent = this.typedUsername;
+ } else {
+ this.defComponent = this.knownPassword;
+ }
+ }
+
+ return p;
+ }
+
+ private void validateKnownUserInfo() {
+ if (this.acceptLoginUserName(this.typedUsername.getText()) && this.acceptLoginPassword(this.knownPassword.getText(), this.loginUserName, 4)) {
+ this.loginSerialNumber = null;
+ this.loginMode = 2;
+ this.loginIndex = 0;
+ this.doLogin();
+ }
+ }
+
+ private Panel buildAccountTypeScreen(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ TextCanvas text = new TextCanvas(Console.message("first-time-user2"), 400);
+ add(p, text, gbag, c);
+ if (this.alternateBrowserButton == null) {
+ this.alternateBrowserButton = new Button(Console.message("Alt-Browser"));
+ }
+
+ if (this.signInButton == null) {
+ this.signInButton = new Button(Console.message("Sign-In"));
+ }
+
+ return this.addButtons(p, gbag, Console.message("Cancel"), this.signInButton, this.alternateBrowserButton, Console.message("Next"));
+ }
+
+ private Panel buildRegWaitCommon(Panel p, GridBagLayout gbag, GridBagConstraints c, int which) {
+ String start = "";
+ if (which == 0) {
+ start = Console.message("registration");
+ }
+
+ TextCanvas text = new TextCanvas(start + Console.message("completed"), 400);
+ add(p, text, gbag, c);
+ Panel tmp = new Panel(new GridLayout());
+ Label code = new Label(Console.message("Codeword"), 1);
+ code.setFont(font);
+ tmp.add(code);
+ this.codewordField = new TextField(10);
+ if (this.newSerialNumber != null) {
+ this.codewordField.setText(this.newSerialNumber);
+ }
+
+ this.codewordField.setFont(font);
+ tmp.add(this.codewordField);
+ add(p, tmp, gbag, c);
+ String browserSpecific = new String();
+ if (WebBrowser.isDisabled()) {
+ if (which == 0) {
+ browserSpecific = browserSpecific + Console.message("manually-view");
+ } else {
+ browserSpecific = browserSpecific + Console.message("just-view");
+ }
+
+ browserSpecific = browserSpecific + this.getRegisterScriptName();
+ } else {
+ browserSpecific = browserSpecific + Console.message("click-Back");
+ }
+
+ if (this.users.size() == 0) {
+ String ifText = Console.message("within-20");
+ if (which == 1) {
+ ifText = Console.message("Show-Reg-Form1");
+ }
+
+ text = new TextCanvas(new String(ifText + browserSpecific), 400);
+ add(p, text, gbag, c);
+ } else if (which == 1) {
+ text = new TextCanvas(Console.message("Show-Reg-Form1"), 400);
+ add(p, text, gbag, c);
+ }
+
+ if (this.noEmailButton == null) {
+ this.noEmailButton = new Button(Console.message("Didnt-Get-Email"));
+ }
+
+ if (this.showRegButton == null) {
+ this.showRegButton = new Button(Console.message("Show-Reg-Form3"));
+ }
+
+ Button showReg = which == 0 ? null : this.showRegButton;
+ return this.addButtons(p, gbag, "<< " + Console.message("Back"), showReg, this.noEmailButton, Console.message("Next") + " >>");
+ }
+
+ private Panel buildRegWait(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ return this.buildRegWaitCommon(p, gbag, c, 0);
+ }
+
+ private Panel buildRegWait2(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ return this.buildRegWaitCommon(p, gbag, c, 1);
+ }
+
+ private Panel buildWelcome(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ add(p, new Label(""), gbag, c);
+ Object[] arguments = new Object[]{new String(Std.getProductName())};
+ add(p, new Label(MessageFormat.format(Console.message("Youre-signed"), arguments), 1), gbag, c);
+ Panel tmp = new Panel();
+ TextCanvas text = new TextCanvas(Console.message("Use-arrow-keys2"), 400);
+ tmp.add(text);
+ add(p, tmp, gbag, c);
+ add(p, new Label(""), gbag, c);
+ return this.addButtons(p, gbag, null, null, null, Console.message("Enter-Worlds"));
+ }
+
+ private static boolean isMadeOf(String test, String set) {
+ char[] testChars = test.toCharArray();
+
+ for (int i = 0; i < testChars.length; i++) {
+ if (set.indexOf(testChars[i]) == -1) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private Panel buildCodewordWaitScreen(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ TextCanvas text = new TextCanvas(Console.message("Checking-codeword"), 400);
+ add(p, text, gbag, c);
+ return this.addButtons(p, gbag, Console.message("Cancel"), null, null, null);
+ }
+
+ private Panel buildNewUserInfoScreen(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ this.newUserName = new TextField(16);
+ this.newPassword1 = new TextField(12);
+ this.newPassword2 = new TextField(12);
+ Object[] arguments = new Object[]{new String(Std.getProductName())};
+ TextCanvas text = new TextCanvas(MessageFormat.format(Console.message("Enter-username"), arguments), 400);
+ text.setFont(font);
+ add(p, text, gbag, c);
+ Panel tmp = new Panel();
+ tmp.setFont(font);
+ tmp.add(new Label(Console.message("Type-username")));
+ tmp.add(this.newUserName);
+ add(p, tmp, gbag, c);
+ text = new TextCanvas(Console.message("Enter-password"), 400);
+ add(p, text, gbag, c);
+ tmp = new Panel(new GridLayout(2, 2));
+ tmp.setFont(font);
+ tmp.add(new Label(Console.message("Type-password"), 1));
+ this.newPassword1.setEchoChar('*');
+ tmp.add(this.newPassword1);
+ tmp.add(new Label(Console.message("Re-type-password"), 1));
+ this.newPassword2.setEchoChar('*');
+ tmp.add(this.newPassword2);
+ add(p, tmp, gbag, c);
+ add(p, this.savePassword, gbag, c);
+ return this.addButtons(
+ p, gbag, this.newHandshakeID == null ? Console.message("Finish-Later") : "<< " + Console.message("Back"), null, null, Console.message("Next") + " >>"
+ );
+ }
+
+ private void validateNewUserInfo() {
+ if (this.acceptLoginUserName(this.newUserName.getText()) && this.acceptLoginPassword(this.newPassword1.getText(), this.newUserName.getText(), 6)) {
+ if (!this.loginPassword.equals(this.newPassword2.getText())) {
+ this.selectErrorScreen(passwordMismatchText);
+ } else {
+ this.loginMode = 1;
+ this.loginSerialNumber = this.newSerialNumber;
+ this.loginIndex = 0;
+ this.doLogin();
+ }
+ }
+ }
+
+ private Panel buildLoggingInScreen(Panel p, GridBagLayout gbag, GridBagConstraints c) {
+ Label logging = new Label(Console.message("Logging-in-wait"));
+ logging.setFont(font);
+ add(p, logging, gbag, c);
+ return p;
+ }
+
+ private Panel buildErrorScreen(Panel p, GridBagLayout gbag, GridBagConstraints c, int which) {
+ this.errMsg = this.errMsg.replace('\n', ' ').replace('\t', '\n');
+ TextCanvas text = new TextCanvas(this.errMsg, 400);
+ this.errMsg = null;
+ add(p, text, gbag, c);
+ return this.addButtons(p, gbag, which != 9 && which != 8 ? Console.message("Continue") : "<< " + Console.message("Back"), null, null, null);
+ }
+
+ private boolean acceptLoginPassword(String password, String username, int minLength) {
+ if (FriendsListPart.isValidUserName(password) && password.length() >= minLength) {
+ this.loginPassword = password;
+ return true;
+ } else {
+ Object[] arguments = new Object[]{new String("" + minLength)};
+ String text = Console.message("password-not-valid") + MessageFormat.format(passwordConstraints1, arguments);
+ this.selectErrorScreen(text);
+ return false;
+ }
+ }
+
+ private boolean acceptLoginUserName(String name) {
+ if (!FriendsListPart.isValidUserName(name)) {
+ this.selectErrorScreen(Console.message("username-not-valid") + nameConstraints + " - " + name);
+ return false;
+ } else {
+ this.loginUserName = name;
+ return true;
+ }
+ }
+
+ private void doLogin() {
+ this.loginFrom = this.currentScreen;
+ this.selectScreen(7);
+ this.loginState = 1;
+ }
+
+ private boolean isPasswordSaved(int user) {
+ return user < this.passwords.size() && this.passwords.elementAt(user) != null;
+ }
+
+ private static void add(Container cont, Component comp, GridBagLayout gbag, GridBagConstraints c) {
+ gbag.setConstraints(comp, c);
+ cont.add(comp);
+ }
+
+ private Panel addButtons(Panel p, GridBagLayout gbag, String prev, Button mid1, Button mid2, String next) {
+ Panel buttons = new Panel();
+ buttons.setFont(bfont);
+ if (prev != null) {
+ buttons.add(new BackButton(prev));
+ }
+
+ if (mid1 != null) {
+ buttons.add(mid1);
+ }
+
+ if (mid2 != null) {
+ buttons.add(mid2);
+ }
+
+ if (next != null) {
+ buttons.add(this.defComponent = new ForwardButton(next));
+ }
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.anchor = 14;
+ add(p, buttons, gbag, c);
+ return p;
+ }
+
+ private String getScriptServer() {
+ Enumeration<NetworkObject> e = this.galaxy.getConsoles();
+
+ assert e.hasMoreElements();
+
+ this.queryingServer = true;
+ String ret = ((Console)e.nextElement()).getScriptServer();
+ this.queryingServer = false;
+ System.out.println("Scriptserver is " + ret);
+ return ret;
+ }
+
+ private String getRegisterScriptName() {
+ if (this.newHandshakeID == null) {
+ int id = new Random(((long)Startup.getVolumeInfo() << 30) + (int)(Math.random() * 1.0737418E9F)).nextInt();
+ if (id < 0) {
+ id = -id;
+ }
+
+ this.newHandshakeID = "" + id;
+ this.iniFile.setIniString("handshakeID", this.newHandshakeID);
+ }
+
+ IniFile ini = IniFile.override();
+ String url = ini.getIniString("register", "");
+ if (url.equals("")) {
+ url = defaultRegisterScriptL;
+ if (Console.wasHttpNoSuchFile(url)) {
+ url = "register.pl";
+ }
+
+ ini = new IniFile("InstalledWorlds");
+ String w = ini.getIniString("InstalledWorld0", "");
+ if (!w.equals("")) {
+ String fn = URL.make("home:" + w + "/register.txt").unalias();
+ DataInputStream in = null;
+
+ try {
+ in = new DataInputStream(new FileInputStream(fn));
+ String line = in.readLine();
+ if (line != null) {
+ url = line;
+ }
+ } catch (IOException var15) {
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException var14) {
+ }
+ }
+ }
+ }
+
+ return new String(this.getScriptServer() + url + "?id=" + this.newHandshakeID);
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ Object target = event.target;
+ if (target instanceof ForwardButton) {
+ if (this.currentScreen == 0) {
+ this.validateKnownUserInfo();
+ } else if (this.currentScreen == 1) {
+ WebBrowser.setDisabled(false);
+ this.selectScreen(2);
+ } else if (this.currentScreen == 2 || this.currentScreen == 12) {
+ this.selectScreen(4);
+ } else if (this.currentScreen == 5) {
+ this.validateNewUserInfo();
+ } else if (this.currentScreen == 3) {
+ this.done(true);
+ }
+ } else if (target instanceof BackButton) {
+ if (this.currentScreen == 0) {
+ if (this.users.size() > 0) {
+ this.done(false);
+ } else {
+ this.selectScreen(1);
+ }
+ } else if (this.currentScreen == 1) {
+ if (this.users.size() == 0) {
+ this.done(false);
+ } else {
+ this.selectScreen(0);
+ }
+ } else if (this.currentScreen == 2 || this.currentScreen == 12) {
+ this.selectScreen(this.users.size() > 0 ? 0 : 1);
+ } else if (this.currentScreen == 5) {
+ if (this.newSerialNumber != null && this.newSerialNumber.length() > 6 && this.newHandshakeID != null) {
+ this.selectScreen(12);
+ } else if (this.users.size() > 0) {
+ this.selectScreen(0);
+ } else {
+ this.done(false);
+ }
+ } else if (this.currentScreen == 4) {
+ if (this.cf != null) {
+ this.cf.close();
+ }
+
+ this.selectScreen(12);
+ } else if (this.currentScreen == 8) {
+ this.selectScreen(this.loginFrom);
+ } else if (this.currentScreen == 9) {
+ this.selectScreen(this.errorFrom);
+ } else if (this.currentScreen == 11 || this.currentScreen == 10) {
+ this.selectScreen(0);
+ }
+ } else if (target == this.pwMailbackButtonKnown) {
+ new SendURLAction(this.getScriptServer() + "emailback.pl", true).startBrowser();
+ } else if (target == this.typedUsername) {
+ this.knownPassword.requestFocus();
+ } else if (target == this.knownPassword) {
+ this.validateKnownUserInfo();
+ } else if (target == this.createNewUsernameButton) {
+ String redir = IniFile.override().getIniString("CreateUserRedirect", "Fred");
+ if (redir.equals("Fred")) {
+ if (this.newHandshakeID != null) {
+ this.selectScreen(12);
+ } else if (this.newSerialNumber == null) {
+ this.selectScreen(2);
+ } else {
+ this.selectScreen(5);
+ }
+ } else {
+ new SendURLAction(URL.make(redir)).startBrowser();
+ }
+ } else if (target == this.alternateBrowserButton) {
+ WebBrowser.setDisabled(true);
+ this.selectScreen(2);
+ } else if (target == this.signInButton) {
+ this.selectScreen(0);
+ } else {
+ if (target != this.noEmailButton && target != this.showRegButton) {
+ return false;
+ }
+
+ this.selectScreen(2);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ if (key == 10) {
+ this.action(event, null);
+ return true;
+ } else {
+ return super.keyDown(event, key);
+ }
+ }
+
+ @Override
+ public boolean handleEvent(Event event) {
+ if (this.isDialogDisabled) {
+ return false;
+ } else {
+ return event.id == 201 && this.loginState == 2 ? true : super.handleEvent(event);
+ }
+ }
+
+ @Override
+ protected boolean done(boolean confirmed) {
+ boolean ret = super.done(confirmed);
+ firstTimeDone = true;
+ return ret;
+ }
+
+ @Override
+ public void dialogDone(Object who, boolean confirmed) {
+ }
+
+ @Override
+ public void dialogDisable(boolean disable) {
+ this.isDialogDisabled = disable;
+ super.dialogDisable(disable);
+ }
+
+ @Override
+ public String toString() {
+ return "LoginWizard" + this.id;
+ }
+
+ class AwaitCodeword extends Thread {
+ public AwaitCodeword(String cw) {
+ if (cw.length() > 6) {
+ LoginWizard.this.selectScreen(5);
+ LoginWizard.this.newSerialNumber = cw;
+ LoginWizard.this.iniFile.setIniString("SNum", LoginWizard.this.newSerialNumber);
+ } else {
+ LoginWizard.this.cf = Cache.getFile(
+ URL.make(LoginWizard.this.getScriptServer() + "codeword.pl?id=" + LoginWizard.this.newHandshakeID + "&codeword=" + cw)
+ );
+ this.setDaemon(true);
+ this.start();
+ }
+ }
+
+ @Override
+ public void run() {
+ LoginWizard.this.cf.waitUntilLoaded();
+ if (LoginWizard.this.cf.isActive()) {
+ if (LoginWizard.this.cf.error()) {
+ LoginWizard.this.currentScreen = 12;
+ LoginWizard.this.selectErrorScreen(Console.message("Error-accessing"));
+ } else {
+ DataInputStream in = null;
+
+ label114: {
+ try {
+ in = new DataInputStream(new FileInputStream(LoginWizard.this.cf.getLocalName()));
+ String line = in.readLine();
+ if (!line.startsWith("1,0,") && !line.startsWith("1,1,")) {
+ break label114;
+ }
+
+ LoginWizard.this.newSerialNumber = line.substring(4);
+ LoginWizard.this.iniFile.setIniString("SNum", LoginWizard.this.newSerialNumber);
+ LoginWizard.this.newHandshakeID = null;
+ LoginWizard.this.iniFile.setIniString("handshakeID", "");
+ LoginWizard.this.selectScreen(5);
+ LoginWizard.this.cf.close();
+ } catch (FileNotFoundException var14) {
+ break label114;
+ } catch (IOException var15) {
+ break label114;
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException var13) {
+ }
+ }
+
+ return;
+ }
+
+ LoginWizard.this.currentScreen = 12;
+ LoginWizard.this.selectErrorScreen(Console.message("codeword-no-match"));
+ }
+
+ LoginWizard.this.cf.close();
+ }
+ }
+ }
+}