add src files decompiled via jad
[rsa2client.git] / src / mcsClient / McsClient.java
1 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.kpdus.com/jad.html
3 // Decompiler options: packimports(3) fieldsfirst nonlb space 
4
5 package mcsClient;
6
7 import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
8 import java.awt.*;
9 import java.io.IOException;
10 import java.io.PrintStream;
11 import java.net.URL;
12 import java.util.LinkedList;
13 import java.util.StringTokenizer;
14 import javax.swing.*;
15
16 // Referenced classes of package mcsClient:
17 //            McsTargetSize, McsVersion, LockingKeyStateManager, McsTcpConnection, 
18 //            LiveVideoPanel, McsKeyAdapter, McsMouseAdapter, McsMouseMotionAdapter, 
19 //            DatagramReader, McsToolBar, MessageReader, KeepAlive
20
21 public class McsClient extends JApplet {
22
23     private static final int FIXED_SIZE = 1;
24     private static final int FULL_SCREEN = 2;
25     private static final int SCROLL_SCREEN = 3;
26     private static final int DEFAULT_REMOTE_PORT = 2000;
27     private static final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
28     private static final Dimension maxTargetSize = new Dimension(1024, 768);
29     private static int screenWidth;
30     private static int screenHeight;
31     private McsTargetSize mcsTargetSize;
32     private LinkedList datagramList;
33     private McsVersion mcsVersion;
34     private LockingKeyStateManager lockingKeyStateManager;
35     private McsTcpConnection mcsTcpConnection;
36     private McsKeyAdapter mcsKeyAdapter;
37     private LiveVideoPanel liveVideoPanel;
38     private McsMouseAdapter mcsMouseAdapter;
39     private McsMouseMotionAdapter mcsMouseMotionAdapter;
40     private DatagramReader datagramReader;
41     private MessageReader messageReader;
42     private KeepAlive keepAlive;
43     private boolean isStandalone;
44     private ThreadGroup threadGroup;
45     private static final String START = "Show Remote Console";
46     private static final String STOP = "Hide Remote Console";
47     private JButton button;
48     private static final boolean TCP = false;
49     private boolean blueScreenDump;
50     private boolean encryptVideo;
51
52     public McsClient() {
53         mcsTargetSize = new McsTargetSize(1024, 768);
54         datagramList = new LinkedList();
55         mcsVersion = new McsVersion();
56         lockingKeyStateManager = new LockingKeyStateManager();
57         isStandalone = true;
58         blueScreenDump = false;
59         encryptVideo = false;
60     }
61
62     public void init() {
63         try {
64             UIManager.setLookAndFeel(new WindowsLookAndFeel());
65         }
66         catch (Exception exception) { }
67         System.out.println("MCS v.3.6 initialized");
68         isStandalone = false;
69         String s = getParameter("host");
70         if (s == null)
71             s = getCodeBase().getHost();
72         String s1 = s;
73         String s2 = getParameter("bluescreen");
74         if (s2 != null && s2.equalsIgnoreCase("true"))
75             blueScreenDump = true;
76         String s3 = getParameter("userid");
77         if (s3 == null)
78             s3 = "";
79         String s4 = s3;
80         String s5 = getParameter("enc");
81         if (s5 != null && s5.equalsIgnoreCase("on"))
82             encryptVideo = true;
83         String s6 = getParameter("ac");
84         if (s6 == null)
85             s6 = "";
86         String s7 = s6;
87         getContentPane().setBackground(Color.WHITE);
88         begin(s1, s4, s7, false);
89     }
90
91     public void stop() {
92         System.out.println("Stopping applet");
93         if (threadGroup != null)
94             threadGroup.interrupt();
95         if (mcsTcpConnection != null) {
96             mcsTcpConnection.close();
97             mcsTcpConnection = null;
98         }
99     }
100
101     public void begin(String s, String s1, String s2, boolean flag) {
102         int i = 2000;
103         StringTokenizer stringtokenizer = new StringTokenizer(s, ":");
104         String s3 = stringtokenizer.nextToken();
105         if (stringtokenizer.hasMoreTokens())
106             try {
107                 i = Integer.parseInt(stringtokenizer.nextToken());
108             }
109             catch (NumberFormatException numberformatexception) {
110                 i = 2000;
111             }
112         mcsTcpConnection = new McsTcpConnection(s3, i, encryptVideo, s2);
113         if (!mcsTcpConnection.connected()) {
114             if (isStandalone)
115                 System.exit(0);
116             stop();
117             return;
118         }
119         sendUsernameToServer(s1, s2);
120         liveVideoPanel = new LiveVideoPanel(mcsTcpConnection, datagramList, mcsTargetSize, lockingKeyStateManager);
121         mcsKeyAdapter = new McsKeyAdapter(mcsTcpConnection, lockingKeyStateManager);
122         mcsMouseAdapter = new McsMouseAdapter(mcsTcpConnection, liveVideoPanel);
123         mcsMouseMotionAdapter = new McsMouseMotionAdapter(mcsTcpConnection, mcsKeyAdapter);
124         if (!blueScreenDump) {
125             liveVideoPanel.addMouseListener(mcsMouseAdapter);
126             liveVideoPanel.addMouseMotionListener(mcsMouseMotionAdapter);
127             liveVideoPanel.addKeyListener(mcsKeyAdapter);
128             liveVideoPanel.addMouseWheelListener(mcsMouseAdapter);
129         }
130         liveVideoPanel.setPreferredSize(maxTargetSize);
131         liveVideoPanel.setFocusTraversalKeysEnabled(false);
132         datagramReader = new DatagramReader(mcsTcpConnection, liveVideoPanel, datagramList, s3, i, flag);
133         if (!blueScreenDump) {
134             McsToolBar mcstoolbar = new McsToolBar(mcsKeyAdapter, liveVideoPanel);
135             mcstoolbar.setFloatable(false);
136             mcstoolbar.setVisible(false);
137             McsToolBar mcstoolbar1 = new McsToolBar(s3, mcsKeyAdapter, liveVideoPanel, datagramReader, mcstoolbar);
138             getContentPane().add(mcstoolbar1, "North");
139             getContentPane().add(mcstoolbar, "West");
140         }
141         getContentPane().add(liveVideoPanel);
142         liveVideoPanel.requestFocusInWindow();
143         if (!datagramReader.initialized()) {
144             if (isStandalone)
145                 System.exit(0);
146             stop();
147             return;
148         }
149         messageReader = new MessageReader(mcsTcpConnection, mcsVersion, lockingKeyStateManager);
150         keepAlive = new KeepAlive(mcsTcpConnection, blueScreenDump);
151         threadGroup = new ThreadGroup("MCS Threads");
152         threadGroup.setDaemon(true);
153         (new Thread(threadGroup, liveVideoPanel, "liveVideoPanel thread")).start();
154         Thread thread = new Thread(threadGroup, datagramReader, "datagramReader thread");
155         thread.setPriority(thread.getPriority() + 2);
156         thread.start();
157         Thread thread1 = new Thread(threadGroup, messageReader, "messageReader thread");
158         if (flag)
159             thread1.setPriority(thread1.getPriority() + 2);
160         thread1.start();
161         Thread thread2 = new Thread(threadGroup, keepAlive, "keepAlive thread");
162         thread2.setPriority(thread2.getPriority() + 2);
163         thread2.start();
164         sendVersionToServer();
165         System.out.println("Command KVM Server to start sending images");
166         sendStartSendingToServer(mcsTcpConnection.getDetectedPPP());
167     }
168
169     private void sendUsernameToServer(String s, String s1) {
170         if (s1 == null)
171             s1 = "";
172         char ac[] = (s + ":" + s1).toCharArray();
173         int ai[] = new int[2 + ac.length];
174         ai[0] = ai.length * 4;
175         ai[1] = 11;
176         for (int i = 0; i < ac.length; i++)
177             ai[2 + i] = ac[i];
178
179         try {
180             mcsTcpConnection.sendMessage(ai);
181         }
182         catch (IOException ioexception) {
183             System.err.println("Could not send user name.");
184             stop();
185         }
186     }
187
188     private void sendVersionToServer() {
189         int ai[] = new int[4];
190         ai[0] = ai.length * 4;
191         ai[1] = 13;
192         ai[2] = mcsVersion.getClientMajorRev();
193         ai[3] = mcsVersion.getClientMinorRev();
194         try {
195             mcsTcpConnection.sendMessage(ai);
196         }
197         catch (IOException ioexception) {
198             System.err.println("Could not send version.");
199             stop();
200         }
201     }
202
203     private void sendStartSendingToServer(boolean flag) {
204         int ai[] = new int[3];
205         ai[0] = ai.length * 4;
206         if (blueScreenDump)
207             ai[1] = 24;
208         else
209         if (!flag)
210             ai[1] = 0;
211         else
212             ai[1] = 1;
213         ai[2] = 0;
214         try {
215             mcsTcpConnection.sendMessage(ai);
216         }
217         catch (IOException ioexception) {
218             System.err.println("Could not send start sending to server.");
219             stop();
220         }
221     }
222
223     public boolean isVideoEncrypted() {
224         return encryptVideo;
225     }
226
227 }