6 import java.util.Properties;
9 public class Worker implements Runnable {
10 public static final int SENDNAME = 0;
11 public static final int SENDWORDS = 1;
12 public static final int SENDLOGIN = 2;
13 public static final int SENDPASSWD = 3;
14 public static final int INIT = 4;
15 public static final int DIALOG = 5;
16 public static final int INIT1 = 6;
17 public static final int SENDPIN = 7;
18 public static final int CONFIRMLOGIN = 8;
25 public Regapplet applet;
26 public Worker(Regapplet tapplet) {
36 applet.showWordsDiag();
42 applet.showNameDiag();
45 applet.showLoginDiag();
48 applet.showLoginConfirmDiag();
51 applet.showPassDiag();
54 applet.worker.close();
55 applet.workthread = null;
57 if (applet.isStandalone) {
65 if (Regapplet.doRules) {
68 // Hmm. the lines below caused problems on the Mac
69 // Thread z = new Thread(new Seeder()); // Generate numbers in thread
75 applet.showMessage("Connecting to Server...");
79 if (applet.isStandalone) {
81 host = (System.getProperties()).getProperty("host", "");
82 if (host == null || host.equals("")) {
83 System.err.println("Cannot learn host name (application) using localhost");
87 URL cb = applet.getCodeBase();
88 String protocol = cb.getProtocol();
89 port = 443; // Use https port for firewall traversal.
90 if (protocol.equals("file") || protocol.equals("FILE")) {
91 System.err.println("Applet: FILE protocol in use, connecting to localhost");
97 sock = new Socket(host, port);
98 } catch (Exception e) {
100 applet.showError1(true);
106 // Thread.sleep(5000);
107 // } catch (java.lang.InterruptedException ae) {
108 // // Ignore exception for now
110 // applet.showInit();
113 send = new Sender(sock);
114 parse = new Parser(sock, this);
115 parse.encap = send.encap; // Mumble, they need to share
117 break; // We now expect a GETN after connect
118 // applet.showNameDiag();
122 applet.showMessage("Please wait...");
123 send.SendNameData(applet.FirstName.getText(),
124 applet.MiddleName.getText(),
125 applet.LastName.getText(),
126 applet.MITID.getText());
129 applet.showMessage("Please wait...");
130 send.SendWords(applet.Word1.getText(),
131 applet.Word2.getText(),
132 applet.Word3.getText(),
133 applet.Word4.getText(),
134 applet.Word5.getText(),
135 applet.Word6.getText());
138 applet.showMessage("Please wait...");
139 send.SendPin(applet.Pin.getText());
143 applet.showMessage("Please wait...");
144 send.SendLogin(applet.LoginName.getText());
147 applet.showMessage("Please wait...");
148 send.ConfirmLogin(applet.chosenlogin);
151 if (!(applet.Password1.getText().equals(applet.Password2.getText()))) {
152 applet.Password1.setText("");
153 applet.Password2.setText("");
154 applet.showMessage("Entered Passwords do not match, try again");
157 } catch (java.lang.InterruptedException e) {
159 applet.showPassDiag();
162 applet.showMessage("Please wait...");
163 send.SendPassword(applet.Password1.getText());
167 // Add code to parse results and switch on new state
168 } catch (IOException e) {
170 applet.showError(true);
174 } catch (MITCipherException e) {
175 applet.showError(true);
179 // Moby reset applet here too.
180 } catch (RegAppletException a) {
182 applet.showError(true);
187 public void setState(int i) {
190 public void setState(int i, int j) {
194 public void close() {
198 } catch (Exception e) {
203 public void finalize() {
205 System.err.println("Worker Finalized with open socket! Closing it.");