-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.js
78 lines (67 loc) · 1.96 KB
/
client.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
//Dependencies
const ReadLine = require("readline").createInterface({
input: process.stdin,
output: process.stdout
})
const Request = require("request")
//Variables
const Self_Args = process.argv.slice(2)
var NodeChat_Client_Data = {}
NodeChat_Client_Data.messages = ""
//Main
Chat()
async function Chat(){
MR()
ReadLine.question("> ", message =>{
if(message == ""){
Chat()
return
}
Request(`${Self_Args[2]}/chat?username=${Self_Args[0]}&message=${message}&password=${Self_Args[1]}`, {
headers: {
"Bypass-Tunnel-Reminder": true
}
},function(err, res, body){
if(err){
console.log("Something went wrong while requesting to the server.")
Chat()
return
}
if(body == "Done!"){
Main()
return
}else{
console.log("Something went wrong while requesting to the server.")
Chat()
return
}
})
})
}
//Messages reciever
function MR(){
setInterval(function(){
Request(`${Self_Args[2]}/58721516/messages`, {
headers: {
"Bypass-Tunnel-Reminder": true
}
},function(err, res, body){
if(err){
console.log("Looks like the server is died.")
process.exit()
}
if(body == ""){
return
}
if(NodeChat_Client_Data.messages.length == 0){
NodeChat_Client_Data.messages = body
}else{
if(NodeChat_Client_Data.messages != body){
var new_message = body.slice(body.indexOf(NodeChat_Client_Data.messages), body.length)
console.log(new_message)
NodeChat_Client_Data.messages = body
}
}
})
}, 1000)
}