-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIndex.java
More file actions
149 lines (124 loc) · 3.2 KB
/
Copy pathIndex.java
File metadata and controls
149 lines (124 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import UIComp.*;
import URLHandler.*;
import AES.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
class Users{
public String username, email, password;
}
public class Index extends Thread{
static KeyClass aes = new KeyClass();
static UrlTest server = new UrlTest();
static Users user = new Users();
static ArrayList<HashMap<String,String>> chats;
static ArrayList<HashMap<String,String>> contacts;
static boolean loginState = false;
static class DecryptText extends Thread{
ArrayList<HashMap<String,String>> cs;
String keyVal;
public DecryptText(ArrayList<HashMap<String,String>> val, String k){
cs = val;
keyVal = k;
}
public ArrayList<HashMap<String,String>> getText(){
return cs;
}
@Override
public void run(){
for(HashMap<String,String> c:cs){
String t = c.get("text");
t = aes.decrypt(t,keyVal);
c.replace("text", t);
}
}
}
static class LoginScreen extends LoginScreenUI implements ActionListener{
public LoginScreen(){
super();
btn.addActionListener(this);
}
public static String id = "LoginScreen";
public void actionPerformed(ActionEvent e){
user.email = username.getText();
user.password = password.getText();
boolean res = server.login(user.email,user.password);
if(res){
screenSetState(hs.id);
contacts = server.getContacts(user.email);
hs.setContacts(contacts);
username.setText("");
password.setText("");
}
else
this.setError(true);
}
}
static class HomeScreen extends HomeScreenUI implements ActionListener{
public HomeScreen(){
super();
logout.addActionListener(this);
send.addActionListener(this);
}
public static String id = "HomeScreen";
public void actionPerformed(ActionEvent e){
if(e.getSource() == logout){
user.email = null;
user.password = null;
screenSetState(ls.id);
}
else{
String chatText = text.getText();
if(!chatText.isEmpty()){
if(!encrypKey.getText().isEmpty())
chatText = aes.encrypt(chatText,encrypKey.getText());
String modified = chatText.replace(" ","%20");
server.sendChat(user.email,"",modified,selectedChat);
text.setText("");
}
}
}
}
static HomeScreen hs = new HomeScreen();
static LoginScreen ls = new LoginScreen();
public static void screenSetState(String val){
if(val.equals(ls.id)){
loginState = false;
hs.isVisible(false);
ls.isVisible(true);
}else if(val.equals(hs.id)){
ls.isVisible(false);
loginState = true;
hs.isVisible(true);
}
}
public static void main(String ar[]){
screenSetState(ls.id);
Index mainProg = new Index();
mainProg.start();
}
public void run(){
for(;;){
if(loginState){
if(hs.selectedChat!=null){
chats = server.getChats(hs.selectedChat);
if(!hs.encrypKey.getText().isEmpty()){
DecryptText d = new DecryptText(chats,hs.encrypKey.getText());
d.start();
try{
d.join();
}catch (Exception e){
}
chats = d.getText();
}
hs.setChats(chats, user.email);
}
}
//to ensure nothing crashes
try{
Thread.sleep(400);
}catch(InterruptedException e){}
}
}
}