Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit fd52fe0

Browse files
committed
Push current Server version
1 parent aeb8f31 commit fd52fe0

File tree

4 files changed

+119
-71
lines changed

4 files changed

+119
-71
lines changed

copenJSParser/src/main/kotlin/io/crawleyyou/Main.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ var hashMaps = mutableListOf(protocolVersionHashMap, maxPlayerHashMap, protocolH
2020

2121
fun main(args: Array<String>) {
2222
try {
23-
println("Trying mode ${args[1]} with file ${args[0]}")
24-
copenJSParser(args[0], args[1].toInt())
23+
println("Starting mode ${args[1]} with file ${args[0]}")
24+
copenJSParser(args[0], args[1].toInt(), args[2])
2525
} catch (e: Exception) {
2626
println("No input file/mode specified using sample file and starting scanner mode: copenJS")
2727
copenJSParser(Paths.get("").toAbsolutePath().parent.toString() + "/scan.json", 0)
2828
}
2929
}
3030

3131
@Suppress("ClassName")
32-
class copenJSParser (fileLocation: String, mode: Int) {
32+
class copenJSParser (fileLocation: String, mode: Int, extra: String? = "null") {
3333
init {
3434
when (mode) {
3535
0 -> {
36-
ServerReader(fileLocation)
36+
ServerReader(fileLocation, extra)
3737
}
3838
1 -> {
3939
GraphReader(fileLocation)
@@ -44,8 +44,9 @@ class copenJSParser (fileLocation: String, mode: Int) {
4444
}
4545
}
4646
@Suppress("FunctionName")
47-
private fun ServerReader(args: String) {
47+
private fun ServerReader(args: String, startFrom: String?) {
4848
var count = 0
49+
var startStatus = false
4950
try {
5051
val client = Socket("localhost", 9532)
5152
println("Reading file: $args " + LocalDateTime.now().toString())
@@ -55,9 +56,14 @@ class copenJSParser (fileLocation: String, mode: Int) {
5556
json.forEach { data ->
5657
count++
5758
val ip = data.split('"')[0]
58-
println("Current IP: $ip")
59-
client.outputStream.write(ip.toByteArray())
60-
TimeUnit.MILLISECONDS.sleep(5)
59+
if (startFrom == ip) {
60+
startStatus = true
61+
}
62+
else if (startStatus) {
63+
println("Current IP: $ip")
64+
client.outputStream.write(ip.toByteArray())
65+
TimeUnit.MILLISECONDS.sleep(10)
66+
}
6167
}
6268
println("$count IP's processed. " + LocalDateTime.now().toString())
6369
}
326 Bytes
Binary file not shown.

src/libs/thread.mjs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,55 @@ const currentThread = process.argv[2]
66

77
console.log("Thread " + currentThread + " started")
88
process.on("message", (data) => {
9-
var ip = data.ip
109
var time = data.time
11-
try {
12-
protocol.GetServerData(ip.toString(), 25565).then(async (data) => {
10+
switch (data.mode) {
11+
case "ping":
12+
process.send({status: "ping", thread: currentThread, time: time })
13+
break;
14+
case "search":
15+
var ip = data.ip
1316
try {
14-
process.send({ ip: ip.toString(), status: "success", thread: currentThread, time: time})
15-
if (data.players.online > 0 ) await webhook(ip.toString(), data.version.name, await protocol.ProtocolTOVersion(data.version.protocol), "Full motd data will be in released with database. ", data.latency, "https://minecraft.global/images/icons/default_favicon.png", new Date().toISOString(), data.players.max, data.players.online, ((data.modinfo?.type ?? false) === "FML") ? true : false)
16-
await Database.MongoLogger({
17-
IP: ip.toString(),
18-
Version: data.version.name,
19-
Protocol: data.version.protocol,
20-
ProtocolVersion: await protocol.ProtocolTOVersion(data.version.protocol),
21-
Motd: data.description,
22-
Latency: data.latency,
23-
Favicon: data.favicon,
24-
Timestamp: new Date().toISOString(),
25-
MaxPlayer: data.players.max,
26-
OnlinePlayer: data.players.online,
27-
Players: data.players.sample,
28-
Modinfo: data.modinfo
29-
}, "Servers")
17+
protocol.GetServerData(ip.toString(), 25565).then(async (data) => {
18+
try {
19+
process.send({ ip: ip.toString(), status: "success", thread: currentThread, time: time })
20+
if (data.players.online > 0) await webhook(ip.toString(), data.version.name, await protocol.ProtocolTOVersion(data.version.protocol), "Full motd data will be in released with database. ", data.latency, "https://minecraft.global/images/icons/default_favicon.png", new Date().toISOString(), data.players.max, data.players.online, ((data.modinfo?.type ?? false) === "FML") ? true : false)
21+
Database.MongoLogger({
22+
IP: ip.toString(),
23+
Version: data.version.name,
24+
Protocol: data.version.protocol,
25+
ProtocolVersion: await protocol.ProtocolTOVersion(data.version.protocol),
26+
Motd: data.description,
27+
Latency: data.latency,
28+
Favicon: data.favicon,
29+
Timestamp: new Date().toISOString(),
30+
MaxPlayer: data.players.max,
31+
OnlinePlayer: data.players.online,
32+
Players: data.players.sample,
33+
Modinfo: data.modinfo
34+
}, "Servers")
35+
}
36+
catch (err) {
37+
// console.log(err)
38+
// console.log("This servers data is compromised IP: " + ip.toString())
39+
Database.MongoLogger({
40+
IP: ip.toString(),
41+
Timestamp: new Date().toISOString()
42+
}, "Compromised-Servers")
43+
process.send({ ip: ip.toString(), status: "success", thread: currentThread, time: time })
44+
}
45+
}).catch((err) => {
46+
//console.log(err)
47+
process.send({ ip: ip.toString(), status: "error", thread: currentThread, time: time })
48+
})
49+
} catch (err) {
50+
console.log("An unknown error occured")
51+
//console.log(err)
52+
process.send({ ip: ip.toString(), status: "error", thread: currentThread, time: time })
3053
}
31-
catch (err) {
32-
console.log(err)
33-
console.log("This servers data is compromised IP: " + ip.toString())
34-
await Database.MongoLogger({
35-
IP: ip.toString(),
36-
Timestamp: new Date().toISOString()
37-
}, "Compromised-Servers")
38-
process.send({ ip: ip.toString(), status: "success", thread: currentThread, time: time})
39-
}
40-
}).catch((err) => {
41-
process.send({ ip: ip.toString(), status: "error", thread: currentThread, time: time})
42-
})
43-
} catch (err) {
44-
console.log("An unknown error occured")
45-
console.log(err)
46-
process.send({ ip: ip.toString(), status: "error", thread: currentThread, time: time})
54+
break;
55+
default:
56+
return 0
4757
}
4858
})
4959

50-
Database.Connect()
60+
Database.Connect()

src/scanner.mjs

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ const getColor = (data, mode) => {
4545
return colors[1]
4646
}
4747
case "status":
48-
if (data === 0) {
49-
return colors[2] + "Idle"
50-
}
51-
else if (data >= 1) {
52-
return colors[1] + "Working"
53-
}
54-
else {
48+
if (data.extra > 5) {
5549
return colors[0] + "Error"
50+
} else {
51+
if (data.data === 0) {
52+
return colors[2] + "Idle"
53+
}
54+
else if (data.data >= 1) {
55+
return colors[1] + "Working"
56+
}
57+
else {
58+
return colors[0] + "Error"
59+
}
5660
}
5761
default:
5862
return null
@@ -65,12 +69,12 @@ const Main = async () => {
6569
console.log("There is " + os.availableParallelism() + " thread available on this server.")
6670
currData.subprocesses = os.availableParallelism()
6771
for (var i = 0; i < os.availableParallelism(); i++) {
68-
processList.push(cprocess.fork("./libs/thread.mjs", [i]))
69-
logger.debug("Process: " + processList[i].pid + " started")
70-
assignedList.push([i, { currentIp: "", lastresponsetext: 0, status: "Idle", assigned: 0, finds: 0, total: 0 }])
72+
processList.push([cprocess.fork("./libs/thread.mjs", [i]), []])
73+
logger.debug("Process: " + processList[i][0].pid + " started")
74+
assignedList.push([i, { currentIp: "", lastresponsetext: 0, status: "Idle", assigned: 0, finds: 0, total: 0, currentPings: 0 }])
7175
}
7276
for (var i = 0; i < processList.length; i++) {
73-
processList[i].on("message", (data) => {
77+
processList[i][0].on("message", (data) => {
7478
var x = assignedList.findIndex((sarray) => {
7579
const [number] = sarray
7680
return number === parseInt(data.thread)
@@ -81,63 +85,91 @@ const Main = async () => {
8185
assignedList[x][1].finds++
8286
assignedList[x][1].assigned--
8387
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
84-
logger.debug(processList[assignedList[x][0]].pid + " processed data from ip: " + assignedList[x][1].currentIp);
88+
assignedList[x][1].currentIp = data.ip
89+
logger.debug(processList[assignedList[x][0]][0].pid + " processed data from ip: " + assignedList[x][1].currentIp);
8590
}
8691
else if (data.status === "error") {
8792
currData.assigned--
8893
assignedList[x][1].assigned--
8994
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
90-
logger.debug(processList[assignedList[x][0]].pid + " failed to processing ip: " + assignedList[x][1].currentIp);
95+
assignedList[x][1].currentIp = data.ip
96+
logger.debug(processList[assignedList[x][0]][0].pid + " failed to processing ip: " + assignedList[x][1].currentIp);
97+
}
98+
else if (data.status === "ping") {
99+
assignedList[x][1].currentPings = 0
100+
logger.info(processList[assignedList[x][0]][0].pid + " responded to ping request.")
91101
}
92102
})
93103
}
94104
console.log("Parser will be started in 3 seconds...")
95105
setTimeout(() => {
96-
// startParser()
106+
//startParser('java -Xmx5G -jar ' + process.cwd() + '/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar')
97107
setInterval(async () => {
98108
assignedList.sort((a, b) => { return a[0] - b[0] })
99109
let defaultText = `Main Process: \n Current IP/s: ${currData.total - currData.totalLast} IP/s \n Total Assigned: ${currData.assigned} \n Total TCP Restarts: ${currData.tcpRestarts} \n Total Finds & Total Try: ${currData.finds} & ${currData.total} \n Current Rate: ${((currData.finds / currData.total) * 100).toFixed(2)}% \n Total Sub-Processes: ${currData.subprocesses} \n Current IP: ${currData.lastIp} \nSub-Processes: `
100110
assignedList.forEach(async (data, n) => {
101-
defaultText += "\n Process processNumber: Current IP: currentIP Last Response: lastResponseText Status: statusText Total Assigned: assignedInt Total Finds: findInt ".replace("processNumber", n.toString()).replace("findInt", data[1].finds).replace("assignedInt", data[1].assigned).replace("currentIP", data[1].currentIp).replace("lastResponseText", `${getColor(data[1].lastresponsetext, "ms")}${data[1].lastresponsetext}ms\x1b[0m`).replace("statusText", `${getColor(data[1].assigned, "status")}\x1b[0m`)
111+
defaultText += "\n Process processNumber: Current IP: currentIP Last Response: lastResponseText Status: statusText Total Assigned: assignedInt Total Finds: findInt ".replace("processNumber", n.toString()).replace("findInt", data[1].finds).replace("assignedInt", data[1].assigned).replace("currentIP", data[1].currentIp).replace("lastResponseText", `${getColor(data[1].lastresponsetext, "ms")}${data[1].lastresponsetext}ms\x1b[0m`).replace("statusText", `${getColor({ data: data[1].assigned, extra: data[1].currentPings }, "status")}\x1b[0m`)
102112
})
103113
text.text = defaultText
104114
currData.totalLast = currData.total
105115
}, 1000)
106116
setTimeout(() => {
107117
text.start()
108118
}, 1000)
119+
setInterval(async () => {
120+
for (var i = 0; i < processList.length; i++) {
121+
if (assignedList[i][1].currentPings < 6) {
122+
assignedList[i][1].currentPings++
123+
processList[assignedList[i][0]][0].send({ mode: "ping", time: Date.now() })
124+
}
125+
else {
126+
logger.warn(processList[assignedList[i][0]][0].pid + " didnt responded ping requests for an entire minute.")
127+
}
128+
}
129+
}, 10000)
109130
}, 3000)
110131
})
111132
server.on("connection", function (socket) {
112133
socket.on('error', function (err) {
113134
console.log("Client lost connection")
114135
logger.warn("The client lost the connection " + err)
136+
startParser('java -Xmx5G -jar ' + process.cwd() + '/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar "' + currData.lastIp + '"')
115137
})
116-
socket.on('end', function (data) {
138+
socket.on('end', function () {
117139
console.log("Client disconnected")
118-
logger.warn("The client end " + err)
140+
logger.warn("The client end ")
119141
})
120142
socket.on("data", async function (ip) {
121143
assignedList.sort((a, b) => { return a[1].assigned - b[1].assigned })
122-
processList[assignedList[0][0]].send({ ip: ip.toString(), time: Date.now() })
123-
logger.debug(processList[assignedList[0][0]].pid + " assigned to " + ip.toString());
124-
assignedList[0][1].currentIp = ip.toString()
125-
assignedList[0][1].assigned++
126-
assignedList[0][1].total++
127-
currData.lastIp = ip.toString()
128-
currData.total++
129-
currData.assigned++
144+
var x = 0
145+
while (assignedList[x][1]?.currentPings > 5 && x < os.availableParallelism()) {
146+
x++
147+
}
148+
if (x === os.availableParallelism()) {
149+
logger.fatal("All Processes are down!")
150+
}
151+
else {
152+
processList[assignedList[x][0]][0].send({ mode: "search", ip: ip.toString(), time: Date.now() })
153+
logger.debug(processList[assignedList[x][0]][0].pid + " assigned to " + ip.toString());
154+
assignedList[x][1].assigned++
155+
assignedList[x][1].total++
156+
currData.lastIp = ip.toString()
157+
currData.total++
158+
currData.assigned++
159+
}
130160
})
131161
})
132162
}
133163

134-
const startParser = async () => {
135-
exec('java -Xmx4096m -jar ' + process.cwd() + '/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar', (error, stderr) => {
164+
const startParser = async (startup) => {
165+
exec(startup, (error, stderr) => {
136166
if (error) {
137167
console.error(`exec error: ${error}`);
168+
logger.error("exec error: " + error)
138169
return;
139170
}
140171
console.error(`stderr: ${stderr}`);
172+
logger.error("stderr: " + stderr)
141173
})
142174
}
143175

0 commit comments

Comments
 (0)