home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.BorderLayout;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.GridLayout;
- import java.awt.Panel;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Random;
-
- public class afkal extends Applet {
- private static final int defaultBorderWidth = 5;
- private static final int defaultVGap = 4;
- private static final int defaultHGap = 4;
- private String encSuccessfulURL;
- private URL successfulURL;
- private String successfulTarget;
- private URL unsuccessfulURL;
- private String unsuccessfulTarget;
- private int numButtons;
- private String passSequence;
- private int numRows;
- private int numCols;
- private int borderWidth;
- private int hGap;
- private int vGap;
- private String regUser;
- private String serialID;
- private int CRC;
- private String prevErrMsg;
- private String key = new String();
- private imagebut[] buttons;
- Panel punchButtonPanel;
- private String currentSequence;
- private AudioClip clickSound;
-
- void addToKey(String var1) {
- String var10001 = this.key;
- this.key = var10001 + var1;
- }
-
- private void printErrMsg(String var1) {
- ((Applet)this).showStatus(var1);
- System.err.println(var1);
- this.prevErrMsg = var1;
- throw new IllegalArgumentException();
- }
-
- private String computeHash(String var1) {
- hasher var2 = new hasher();
- var2.init();
- ((mdigest)var2).updateASCII(var1);
- var2.finish();
- return var2.digout();
- }
-
- private void readParameters() {
- this.regUser = ((Applet)this).getParameter("regUser");
- if (this.regUser == null || this.regUser.equals("Unregistered") && !((Applet)this).getDocumentBase().toExternalForm().substring(0, 5).equals("file:")) {
- this.notRegistered();
- }
-
- this.generateCRC(this.regUser);
- this.addToKey(this.regUser);
-
- try {
- this.numButtons = Integer.parseInt(((Applet)this).getParameter("numButtons"));
- } catch (Exception var9) {
- this.printErrMsg("Invalid number of buttons passed to A.F.K.A.L applet");
- }
-
- try {
- this.numRows = Integer.parseInt(((Applet)this).getParameter("numRows"));
- } catch (Exception var8) {
- this.printErrMsg("Invalid number of rows passed to A.F.K.A.L applet");
- }
-
- try {
- this.numCols = Integer.parseInt(((Applet)this).getParameter("numCols"));
- } catch (Exception var7) {
- this.printErrMsg("Invalid number of columns passed to A.F.K.A.L applet");
- }
-
- if (this.numButtons != this.numRows * this.numCols) {
- this.printErrMsg("Number of rows and columns are not suitable for this number of buttons");
- }
-
- this.encSuccessfulURL = ((Applet)this).getParameter("successfulURL");
- if (this.encSuccessfulURL == null) {
- this.printErrMsg("Missing successful URL passed to A.F.K.A.L applet");
- }
-
- try {
- this.unsuccessfulURL = new URL(((Applet)this).getParameter("unsuccessfulURL"));
- } catch (MalformedURLException var6) {
- this.printErrMsg("Bad unsuccessful URL passed to A.F.K.A.L applet");
- }
-
- this.generateCRC(((Applet)this).getParameter("unsuccessfulURL"));
- this.addToKey(((Applet)this).getParameter("unsuccessfulURL"));
- this.passSequence = ((Applet)this).getParameter("passSequence");
- if (this.passSequence == null) {
- this.printErrMsg("No pass sequence passed to A.F.K.A.L applet");
- }
-
- this.generateCRC(this.passSequence);
- this.addToKey(this.passSequence);
-
- try {
- this.hGap = Integer.parseInt(((Applet)this).getParameter("hGap"));
- } catch (NumberFormatException var5) {
- this.hGap = 4;
- }
-
- try {
- this.vGap = Integer.parseInt(((Applet)this).getParameter("vGap"));
- } catch (NumberFormatException var4) {
- this.vGap = 4;
- }
-
- try {
- this.borderWidth = Integer.parseInt(((Applet)this).getParameter("borderWidth"));
- } catch (NumberFormatException var3) {
- this.borderWidth = 5;
- }
-
- String var1 = ((Applet)this).getParameter("background");
- if (var1 != null) {
- try {
- ((Component)this).setBackground(new Color(Integer.parseInt(var1, 16)));
- } catch (NumberFormatException var2) {
- ((Applet)this).showStatus("A bad background color value was passed to the applet");
- System.err.println("A bad background color value was passed to the applet");
- }
- }
-
- this.successfulTarget = ((Applet)this).getParameter("successfulTarget");
- if (this.successfulTarget == null) {
- this.successfulTarget = "_self";
- }
-
- this.unsuccessfulTarget = ((Applet)this).getParameter("unsuccessfulTarget");
- if (this.unsuccessfulTarget == null) {
- this.unsuccessfulTarget = "_self";
- }
-
- }
-
- private void generateCRC(String var1) {
- for(int var2 = 0; var2 < var1.length(); ++var2) {
- this.CRC += var1.charAt(var2);
- }
-
- }
-
- private void shuffleButtons() {
- Random var1 = new Random();
- boolean[] var2 = new boolean[this.numButtons];
-
- for(int var3 = 0; var3 < this.numButtons; ++var3) {
- var2[var3] = false;
- }
-
- this.punchButtonPanel.removeAll();
-
- for(int var5 = 0; var5 < this.numButtons; ++var5) {
- int var4;
- for(var4 = (int)(var1.nextDouble() * (double)this.numButtons); var2[var4]; var4 = (int)(var1.nextDouble() * (double)this.numButtons)) {
- }
-
- var2[var4] = true;
- this.punchButtonPanel.add(this.buttons[var4]);
- }
-
- this.punchButtonPanel.layout();
- this.punchButtonPanel.validate();
- }
-
- private boolean validateSequence() {
- return this.passSequence.equals(this.computeHash(this.currentSequence));
- }
-
- private void layoutMain() {
- this.punchButtonPanel = new Panel();
- this.punchButtonPanel.setLayout(new GridLayout(this.numRows, this.numCols, this.hGap, this.vGap));
-
- for(int var1 = 0; var1 < this.numButtons; ++var1) {
- this.punchButtonPanel.add(this.buttons[var1]);
- }
-
- Panel var4 = new Panel();
- Button var2 = new Button("OK");
- Button var3 = new Button("Reset");
- ((Container)var4).add(var2);
- ((Container)var4).add(var3);
- ((Container)this).setLayout(new BorderLayout());
- ((Container)this).add("Center", this.punchButtonPanel);
- ((Container)this).add("South", var4);
- }
-
- private void notRegistered() {
- this.printErrMsg("A.F.K.A.L has not been registered and will only run locally");
- }
-
- private String decode(String var1) {
- encoder var2 = new encoder(this.key);
- return var2.decodeFromHexStr(var1);
- }
-
- private boolean checkCRC(String var1) {
- String var2 = Integer.toString(this.CRC);
- if (var2.length() != var1.length()) {
- return false;
- } else {
- String var3 = new String();
-
- for(int var4 = 0; var4 < var2.length(); ++var4) {
- var3 = var3 + (char)(65 + Character.digit(var2.charAt(var4), 10));
- }
-
- return var3.equals(var1);
- }
- }
-
- public void start() {
- if (this.prevErrMsg != null) {
- ((Applet)this).showStatus(this.prevErrMsg);
- System.err.println(this.prevErrMsg);
- } else {
- this.resetSequence();
- ((Applet)this).showStatus("Shuffling buttons...");
- this.shuffleButtons();
- ((Applet)this).showStatus("");
- }
-
- }
-
- public String getAppletInfo() {
- return "A.F.K.A.L V1.0 (c) 1997 Sausage Software";
- }
-
- public void init() {
- this.clickSound = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), "click.au");
-
- try {
- this.readParameters();
- this.buttons = new imagebut[this.numButtons];
-
- for(int var1 = 0; var1 < this.numButtons; ++var1) {
- String var2 = ((Applet)this).getParameter("image" + var1);
- if (var2 == null) {
- this.printErrMsg("Not enough image filenames passed to A.F.K.A.L applet");
- }
-
- this.generateCRC(var2);
- this.addToKey(var2);
- this.buttons[var1] = new imagebut(var2, var1, this.borderWidth, this.clickSound, this);
- }
-
- this.serialID = ((Applet)this).getParameter("serialID");
- if (this.serialID == null || !this.regUser.equals("Unregistered") && !this.checkCRC(this.serialID)) {
- this.badSerial();
- }
-
- this.addToKey(this.serialID);
-
- try {
- this.successfulURL = new URL(this.decode(this.encSuccessfulURL));
- } catch (MalformedURLException var3) {
- this.printErrMsg("Bad successful URL passed to A.F.K.A.L applet");
- }
-
- this.layoutMain();
- this.currentSequence = null;
- } catch (IllegalArgumentException var5) {
- while(true) {
- try {
- Thread.sleep(Long.MAX_VALUE);
- } catch (InterruptedException var4) {
- }
- }
- }
- }
-
- public boolean handleEvent(Event var1) {
- if (var1.id == 1001) {
- if (var1.target instanceof imagebut) {
- imagebut var2 = (imagebut)var1.target;
- if (this.currentSequence == null) {
- this.currentSequence = "" + var2.getButtonNum();
- } else {
- String var10001 = this.currentSequence;
- this.currentSequence = var10001 + "+" + var2.getButtonNum();
- }
- }
-
- if (var1.target instanceof Button) {
- if (((Button)var1.target).getLabel().equals("Reset")) {
- this.resetSequence();
- } else if (this.currentSequence != null) {
- if (this.validateSequence()) {
- ((Applet)this).showStatus("Trying to connect to " + this.successfulURL);
- if (!this.successfulTarget.equals("_self")) {
- this.resetSequence();
- this.shuffleButtons();
- }
-
- ((Applet)this).getAppletContext().showDocument(this.successfulURL, this.successfulTarget);
- } else {
- ((Applet)this).showStatus("Trying to connect to " + this.unsuccessfulURL);
- if (!this.unsuccessfulTarget.equals("_self")) {
- this.resetSequence();
- this.shuffleButtons();
- }
-
- ((Applet)this).getAppletContext().showDocument(this.unsuccessfulURL, this.unsuccessfulTarget);
- }
- }
- }
- }
-
- return super.handleEvent(var1);
- }
-
- private void badSerial() {
- this.printErrMsg("A.F.K.A.L applet's serial ID is invalid. Rerun the Windows frontend to generate a new serial ID");
- }
-
- public void resetSequence() {
- this.currentSequence = null;
- }
- }
-