-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.js
194 lines (140 loc) · 6.59 KB
/
chat.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
function check_chat(id) {
var http = new XMLHttpRequest();
var url = "https://openseed.vagueentertainment.com:8675/corescripts/chats.php";
// console.log(url)
http.onreadystatechange = function() {
if (http.readyState == 4) {
//console.log(http.responseText);
//userid = http.responseText;
if(http.responseText == 100) {
console.log("Incorrect DevID");
} else if(http.responseText == 101) {
console.log("Incorrect AppID");
} else {
console.log(http.responseText);
}
}
}
http.open('POST', url.trim(), true);
//http.send(null);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("devid=" + devId + "&appid=" + appId + "&id="+ id + "&type=check" );
}
function retrieve_chat(room,theid) {
remote = 1;
//console.log("sending to server: "+currentmessage+" : "+mesgdate);
var http = new XMLHttpRequest();
var url = "https://openseed.vagueentertainment.com:8675/corescripts/chats.php";
// console.log(url)
http.onreadystatechange = function() {
if (http.readyState == 4) {
//console.log(http.responseText);
//userid = http.responseText;
if(http.responseText == 100) {
console.log("Incorrect DevID");
} else if(http.responseText == 101) {
console.log("Incorrect AppID");
} else {
//console.log(http.responseText);
var raw = http.responseText;
if(raw == "1") {
//console.log("up to date");
// remote = 0;
} else {
//console.log("from server: "+raw);
var fromserver = raw.split("><");
var sync = 1;
while(sync < fromserver.length) {
var messageblock = fromserver[sync].split("::");
var lr = 0;
save_chat(messageblock[0],messageblock[1],messageblock[2],messageblock[3],messageblock[4],messageblock[5],messageblock[6],messageblock[7],messageblock[8],messageblock[9]);
if(messageblock[8].search("<background;;") == -1){
currentmessage = messageblock[8];
}
sync = sync + 1;
}
}
}
}
}
http.open('POST', url.trim(), true);
//http.send(null);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("&id="+ theid +"&devid=" + devId + "&appid=" + appId + "&room="+ room + "&message="+currentmessage+"&date="+mesgdate+"&type=retrieve" );
}
function send_chat(room,message) {
var http = new XMLHttpRequest();
var url = "https://openseed.vagueentertainment.com:8675/corescripts/chats.php";
// console.log(url)
http.onreadystatechange = function() {
if (http.readyState == 4) {
console.log(http.responseText);
//userid = http.responseText;
if(http.responseText == 100) {
console.log("Incorrect DevID");
} else if(http.responseText == 101) {
console.log("Incorrect AppID");
} else {
// console.log(http.responseText);
//createdb();
}
}
}
http.open('POST', url.trim(), true);
//http.send(null);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("&id="+ id + "&devid=" +devId+ "&appid="+appId+"&message=" + message + "&name="+ username + "&part_id="+part_id+ "&part_names="+part_names+ "&part_avatar="+part_avatar+ "&speaker=" + username +"&date="+mesgdate+"&room="+ room + "&avatar="+ avatar1 + "&type=sending");
}
function retrieve_users(search) {
var http = new XMLHttpRequest();
var url = "https://openseed.vagueentertainment.com:8675/corescripts/chats.php";
// console.log(url)
http.onreadystatechange = function() {
if (http.readyState == 4) {
//console.log(http.responseText);
//userid = http.responseText;
if(http.responseText == 100) {
console.log("Incorrect DevID");
} else if(http.responseText == 101) {
console.log("Incorrect AppID");
} else {
//console.log(http.responseText);
var server = http.responseText;
var fromserver = server.split("><");
var users = 0;
findpeeps.clear();
while(users < fromserver.length - 1) {
findpeeps.append({
name:fromserver[users].split("::")[1],
theid:fromserver[users].split("::")[0],
avatar:"default",
lastseen:"yesterday"
});
users = users +1;
}
}
}
}
http.open('POST', url.trim(), true);
//http.send(null);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("devid=" + devId + "&appid=" + appId + "&id="+ id +"&search="+search+"&type=users" );
}
function save_chat(theid,name,avatar1,part_id,part_names,part_avatar,roomid,mesgdate,themessage,thespeaker) {
var db = Sql.LocalStorage.openDatabaseSync("UserInfo", "1.0", "Local UserInfo", 1);
var data = [theid,name,avatar1,part_id,part_names,part_avatar,roomid,mesgdate,themessage.replace(/\'/g,"'"),thespeaker];
var userStr = "INSERT INTO CHATS VALUES(?,?,?,?,?,?,?,?,?,?)";
var testStr = "SELECT * FROM CHATS WHERE id='"+theid+"' AND date='"+mesgdate+"' AND message='"+themessage.replace(/\'/g,"'")+"'";
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS CHATS (id TEXT, name TEXT,avatar TEXT,part_id TEXT, part_names TEXT,part_avatar TEXT,roomid TEXT,date TEXT,message TEXT,speaker TEXT)');
var pull = tx.executeSql(testStr);
if(pull.rows.length == 0) {
tx.executeSql(userStr,data);
}
});
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS AREAS (id TEXT, roomid TEXT,party INT,lastdate TEXT,lastmessage TEXT)');
var updateArea = "UPDATE AREAS SET lastdate='"+Date()+"',party='"+part_id.split(";").length+"',lastmessage='"+currentmessage.replace(/\'/g,"'")+"' WHERE roomid='"+roomid+"'";
tx.executeSql(updateArea);
});
}