-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsockets.js
170 lines (159 loc) · 5.25 KB
/
sockets.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
//fetch
const get = require('./js/get');
//dictionaries
const randomWords = require('random-words');
const listIta60000 = require('./lists/60000_parole');
// Function to check the formattin of the hostname
function checkHost(serverhost) {
if (!serverhost.endsWith('/')) {
serverhost = `${serverhost}/`
}
if (!serverhost.startsWith('http://') && !serverhost.startsWith('https://')) {
serverhost = `http://${serverhost}`
}
return serverhost;
}
// sockets
module.exports = (io) => {
//Setup socket connection
let commands = io.of('/c')
commands.on('connection',(from) => {
console.log('User connected')
//rename bot
from.on('renamemyself',(data) => {
let {apikey,serverhost,serverid,newname} = data
console.log(`Rename request nename: ${newname}`)
serverhost = checkHost(serverhost);
get(apikey,serverhost,`clientupdate?client_nickname=${newname}`,serverid).then(data => {
from.emit('renamemyself',data)
})
})
//get servers list
from.on('serverlist',(data) => {
let {apikey,serverhost} = data
console.log('Server list request')
serverhost = checkHost(serverhost);
get(apikey,serverhost,"serverlist").then(data => {
from.emit('serverlist',data)
})
})
//get client list
from.on('clientlist',(data) => {
let {apikey,serverhost,serverid} = data
console.log('Client list request')
serverhost = checkHost(serverhost);
get(apikey,serverhost,"clientlist",serverid).then(data => {
from.emit('clientlist',data)
})
})
from.on('spampoker',async (data) => {
let {apikey,serverhost,serverid,pokermode,pokercount,pokertext,pokerclient,textorpoke} = data
console.log(`Pokerspammer started: who:${pokerclient} | ${pokermode} | count: ${pokercount} | text: ${pokertext}`)
serverhost = await checkHost(serverhost);
if (pokercount > 500) {
from.emit('spampoker',{body:[],status:{code:1,message:"Too much pokes"}})
return
}
for (let i = 0; i < pokercount; i++) {
switch (pokermode) {
case "randomwordsEN":
pokertext = randomWords()
break;
case "randomwordsIT":
pokertext = listIta60000[Math.floor(Math.random() * listIta60000.length)]
break;
case "randomNumbers":
pokertext = Math.floor(Math.random() * 9999999)
pokertext = `${pokertext}${pokertext}${pokertext}${pokertext}${pokertext}${pokertext}${pokertext}`
break;
case "randomchars":
pokertext = ""
for (let i = 0; i < 100; i++) {
pokertext += String.fromCharCode((Math.floor(Math.random() * 25)) +65)
}
break;
default:
break;
}
let url = `clientpoke?clid=${pokerclient}&msg=${pokertext}`//sendtextmessage targetmode=1 target=542 msg=Hello\sWorld!
if (textorpoke == "private") {
url = `sendtextmessage?targetmode=1&target=${pokerclient}&msg=${pokertext}`
}
let a = await get(apikey,serverhost,url,serverid).then(data => {
if (data.status.code != 0) {
from.emit('spampoker',data)
return true
}
return false
})
if (a) return
await new Promise(r => setTimeout(r, 50));
}
from.emit('spampoker',{body:[],status:{code:0,message:""}})
})
from.on('mover',async (data) => {
let {apikey,serverhost,serverid,moveruser,movermode,movercount} = data
console.log('mover request')
serverhost = await checkHost(serverhost);
if (movercount > 500) {
from.emit('mover',{body:[],status:{code:1,message:"Too much moves"}})
return
}
let channellist = await get(apikey,serverhost,"channellist",serverid).then((data) => {return data})
let channelid = 0
if (movermode == "carousel") {
for (let i = 0; i < channellist.body.length; i++) {
channelid = channellist.body[i].cid;
let a = await get(apikey,serverhost,`clientmove?clid=${moveruser}&cid=${channelid}`,serverid).then(data => {
if (data.status.code != 0) {
if (data.status.code == 770) return false
from.emit('mover',data)
return true
}
return false
})
if (a) return
await new Promise(r => setTimeout(r, 200));
}
for (let i = channellist.body.length - 1; i >= 0; i--) {
channelid = channellist.body[i].cid;
let a = await get(apikey,serverhost,`clientmove?clid=${moveruser}&cid=${channelid}`,serverid).then(data => {
if (data.status.code != 0) {
if (data.status.code == 770) return false
from.emit('mover',data)
return true
}
return false
})
if (a) return
await new Promise(r => setTimeout(r, 200));
}
} else {
for (let i = 0; i < movercount; i++) {
switch (movermode) {
case "random":
channelid = channellist.body[Math.floor((Math.random() * channellist.body.length))].cid
break;
default:
break;
}
if (channelid == 0 ) {
from.emit('mover',{body:[],status:{code:1,message:"Channel not found"}})
return
}
let a = await get(apikey,serverhost,`clientmove?clid=${moveruser}&cid=${channelid}`,serverid).then(data => {
if (data.status.code != 0) {
if (data.status.code == 770) return false
from.emit('mover',data)
return true
}
return false
})
if (a) return
await new Promise(r => setTimeout(r, 200));
}
}
from.emit('mover',{body:[],status:{code:0,message:""}})
})
})
};