]> andersk Git - moira.git/blame - clients/regapplet/regapplet/Worker.java
If we're an applet, try to connect to port 443 on the host we were
[moira.git] / clients / regapplet / regapplet / Worker.java
CommitLineData
1d3501d2 1package regapplet;
2
3import java.awt.*;
4import java.net.*;
5import java.io.*;
6import java.util.Properties;
7import mit.cipher.*;
8
9public 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;
c05c41a2 17 public static final int SENDPIN = 7;
5a62cfa8 18 public static final int CONFIRMLOGIN = 8;
1d3501d2 19 int oldstate = INIT;
20 int state = INIT;
21 int nextstate = INIT;
22 Socket sock = null;
23 Sender send;
24 Parser parse;
25 public Regapplet applet;
26 public Worker(Regapplet tapplet) {
27 applet = tapplet;
28 }
29 public void run () {
30 try {
31 switch (state) {
32 case DIALOG:
33 state = nextstate;
34 switch (state) {
35 case SENDWORDS:
36 applet.showWordsDiag();
37 break;
c05c41a2 38 case SENDPIN:
39 applet.showPinDiag();
40 break;
41 case SENDNAME:
1d3501d2 42 applet.showNameDiag();
43 break;
44 case SENDLOGIN:
45 applet.showLoginDiag();
46 break;
5a62cfa8 47 case CONFIRMLOGIN:
48 applet.showLoginConfirmDiag();
49 break;
1d3501d2 50 case SENDPASSWD:
51 applet.showPassDiag();
52 break;
53 case INIT:
54 applet.worker.close();
55 applet.workthread = null;
56 applet.worker = null;
57 if (applet.isStandalone) {
58 System.exit(0);
59 }
60 applet.showInit();
61 break;
62 }
63 return;
64 case INIT:
65 if (Regapplet.doRules) {
66 state = INIT1;
67 applet.showRules();
68 // Hmm. the lines below caused problems on the Mac
69 // Thread z = new Thread(new Seeder()); // Generate numbers in thread
70 // z.start();
71 return;
72 }
73 // Fall through
74 case INIT1:
75 applet.showMessage("Connecting to Server...");
76 try {
77 String host;
ef8f2d78 78 int port;
1d3501d2 79 if (applet.isStandalone) {
ef8f2d78 80 port = 9001;
1d3501d2 81 host = (System.getProperties()).getProperty("host", "");
82 if (host == null || host.equals("")) {
83 System.err.println("Cannot learn host name (application) using localhost");
84 host = "localhost";
85 }
86 } else {
87 URL cb = applet.getCodeBase();
88 String protocol = cb.getProtocol();
ef8f2d78 89 port = 443; // Use https port for firewall traversal.
1d3501d2 90 if (protocol.equals("file") || protocol.equals("FILE")) {
91 System.err.println("Applet: FILE protocol in use, connecting to localhost");
92 host = "localhost";
93 } else {
94 host = cb.getHost();
95 }
96 }
ef8f2d78 97 sock = new Socket(host, port);
1d3501d2 98 } catch (Exception e) {
99 e.printStackTrace();
100 applet.showError1(true);
101 applet.show();
102 state = DIALOG;
103 nextstate = INIT;
104 return;
105 // try {
106 // Thread.sleep(5000);
107 // } catch (java.lang.InterruptedException ae) {
108 // // Ignore exception for now
109 // }
110 // applet.showInit();
111 // return;
112 }
113 send = new Sender(sock);
114 parse = new Parser(sock, this);
115 parse.encap = send.encap; // Mumble, they need to share
116 // this
117 break; // We now expect a GETN after connect
118 // applet.showNameDiag();
119 // state = SENDNAME;
120 // return;
121 case SENDNAME:
122 applet.showMessage("Please wait...");
123 send.SendNameData(applet.FirstName.getText(),
124 applet.MiddleName.getText(),
125 applet.LastName.getText(),
126 applet.MITID.getText());
127 break;
128 case SENDWORDS:
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());
136 break;
c05c41a2 137 case SENDPIN:
138 applet.showMessage("Please wait...");
139 send.SendPin(applet.Pin.getText());
140 break;
141
1d3501d2 142 case SENDLOGIN:
143 applet.showMessage("Please wait...");
144 send.SendLogin(applet.LoginName.getText());
145 break;
5a62cfa8 146 case CONFIRMLOGIN:
147 applet.showMessage("Please wait...");
148 send.ConfirmLogin(applet.chosenlogin);
149 break;
1d3501d2 150 case SENDPASSWD:
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");
155 try {
156 Thread.sleep(3000);
157 } catch (java.lang.InterruptedException e) {
158 }
159 applet.showPassDiag();
160 return;
161 }
162 applet.showMessage("Please wait...");
163 send.SendPassword(applet.Password1.getText());
164 break;
165 }
166 parse.read();
167 // Add code to parse results and switch on new state
168 } catch (IOException e) {
169 e.printStackTrace();
170 applet.showError(true);
171 state = DIALOG;
172 nextstate = INIT;
173 // Moby reset applet
174 } catch (MITCipherException e) {
ca587527 175 applet.showError(true);
176 state = DIALOG;
177 nextstate = INIT;
1d3501d2 178 e.printStackTrace();
179 // Moby reset applet here too.
180 } catch (RegAppletException a) {
181 a.printStackTrace();
182 applet.showError(true);
183 state = DIALOG;
184 nextstate = INIT;
185 }
186 }
187 public void setState(int i) {
188 state = i;
189 }
190 public void setState(int i, int j) {
191 state = i;
192 nextstate = j;
193 }
194 public void close() {
195 if (sock != null) {
196 try {
197 sock.close();
198 } catch (Exception e) {
199 }
200 sock = null;
201 }
202 }
203 public void finalize() {
204 if (sock != null) {
205 System.err.println("Worker Finalized with open socket! Closing it.");
206 close();
207 }
208 }
209}
This page took 0.317009 seconds and 5 git commands to generate.