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;
23 public Regapplet applet;
24 public Worker(Regapplet tapplet) {
34 applet.showWordsDiag();
37 applet.showNameDiag();
40 applet.showLoginDiag();
43 applet.showPassDiag();
46 applet.worker.close();
47 applet.workthread = null;
49 if (applet.isStandalone) {
57 if (Regapplet.doRules) {
60 // Hmm. the lines below caused problems on the Mac
61 // Thread z = new Thread(new Seeder()); // Generate numbers in thread
67 applet.showMessage("Connecting to Server...");
70 if (applet.isStandalone) {
71 host = (System.getProperties()).getProperty("host", "");
72 if (host == null || host.equals("")) {
73 System.err.println("Cannot learn host name (application) using localhost");
77 URL cb = applet.getCodeBase();
78 String protocol = cb.getProtocol();
79 if (protocol.equals("file") || protocol.equals("FILE")) {
80 System.err.println("Applet: FILE protocol in use, connecting to localhost");
86 sock = new Socket(host, 9001);
87 } catch (Exception e) {
89 applet.showError1(true);
95 // Thread.sleep(5000);
96 // } catch (java.lang.InterruptedException ae) {
97 // // Ignore exception for now
102 send = new Sender(sock);
103 parse = new Parser(sock, this);
104 parse.encap = send.encap; // Mumble, they need to share
106 break; // We now expect a GETN after connect
107 // applet.showNameDiag();
111 applet.showMessage("Please wait...");
112 send.SendNameData(applet.FirstName.getText(),
113 applet.MiddleName.getText(),
114 applet.LastName.getText(),
115 applet.MITID.getText());
118 applet.showMessage("Please wait...");
119 send.SendWords(applet.Word1.getText(),
120 applet.Word2.getText(),
121 applet.Word3.getText(),
122 applet.Word4.getText(),
123 applet.Word5.getText(),
124 applet.Word6.getText());
127 applet.showMessage("Please wait...");
128 send.SendLogin(applet.LoginName.getText());
131 if (!(applet.Password1.getText().equals(applet.Password2.getText()))) {
132 applet.Password1.setText("");
133 applet.Password2.setText("");
134 applet.showMessage("Entered Passwords do not match, try again");
137 } catch (java.lang.InterruptedException e) {
139 applet.showPassDiag();
142 applet.showMessage("Please wait...");
143 send.SendPassword(applet.Password1.getText());
147 // Add code to parse results and switch on new state
148 } catch (IOException e) {
150 applet.showError(true);
154 } catch (MITCipherException e) {
155 applet.showError(true);
159 // Moby reset applet here too.
160 } catch (RegAppletException a) {
162 applet.showError(true);
167 public void setState(int i) {
170 public void setState(int i, int j) {
174 public void close() {
178 } catch (Exception e) {
183 public void finalize() {
185 System.err.println("Worker Finalized with open socket! Closing it.");