Skip to content

Commit 1309281

Browse files
committed
v1.14 patch 2
1 parent 274e93e commit 1309281

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
All notable changes to this project will be documented in `CHANGELOG.md`.
33
## Added
44
* `PopupHandler` - stops me from duplicating a bunch of code just for settings.
5+
* [TODOs][todos] to changelog.
56

67
## Modified
7-
* Thread handling has been modified to be (potentially) faster and use less lines of code.
8+
* Thread handling has been modified to be (potentially) faster (again) and use less lines of code.
89

910
## Removed
1011
* Hits feature
11-
* 1 unused import
12+
* 1 unused import
13+
* (potentially) more comments
14+
15+
## TODOs
16+
[ ] - Optimise IP generation and inital scanning code. (1)
17+
18+
[todos]: https://github.com/StupidRepo/MCScanner/blob/main/CHANGELOG.md#todos

src/com/stupidrepo/mcscanner/MCScanner.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public static void main(String[] var0) throws IllegalArgumentException, IllegalA
2626
int maxRange = 255;
2727
int port = 25565;
2828

29-
// TODO: Optimize all of this code.
3029
Logger logger = Logger.getLogger("com.stupidrepo.mcscanner");
3130

3231
float version = 1.14f;
@@ -59,6 +58,7 @@ public static void main(String[] var0) throws IllegalArgumentException, IllegalA
5958
double progressThing = (maxRange - minimumRange + 1) * 256 * 256;
6059

6160
ArrayList < Thread > threadList = new ArrayList < Thread > ();
61+
ArrayList < String > ips = new ArrayList < String > ();
6262

6363
JLabel scannedLabel = new JLabel("Scanned: 0/" + progressThing * 256);
6464
scannedLabel.setHorizontalAlignment(0);
@@ -69,31 +69,44 @@ public static void main(String[] var0) throws IllegalArgumentException, IllegalA
6969

7070
frame.setVisible(true);
7171

72+
// TODO: Optimise this code. (1)
73+
7274
ExecutorService executor = Executors.newFixedThreadPool(threads.get());
7375

7476
for (int i = minimumRange; i <= maxRange; ++i) {
7577
for (int j = 0; j <= 255; ++j) {
7678
for (int k = 0; k <= 255; ++k) {
7779
for (int l = 0; l <= 255; ++l) {
7880
String ip = i + "." + j + "." + k + "." + l;
79-
Thread scannerThread = new Thread(new ScannerThread(ip, port, timeout, databaseHandler));
80-
threadList.add(scannerThread);
81-
executor.execute(scannerThread);
82-
83-
if (threadList.size() >= threads.get()) {
84-
for (Thread nextThread: threadList) {
85-
try {
86-
nextThread.join();
87-
++scanned;
88-
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing*256 + " (" + (scanned / (progressThing*256)) * 100 + "%)");
89-
} catch (InterruptedException timeout2) {
90-
// eh
91-
}
92-
}
93-
threadList.clear();
94-
}
81+
ips.add(ip);
82+
}
83+
}
84+
}
85+
}
86+
87+
for (int i = 0; i < ips.size(); ++i) {
88+
int randomIndex = (int)(Math.random() * ips.size());
89+
String temp = ips.get(i);
90+
ips.set(i, ips.get(randomIndex));
91+
ips.set(randomIndex, temp);
92+
}
93+
94+
for(String ip: ips) {
95+
Thread scannerThread = new Thread(new ScannerThread(ip, port, timeout, databaseHandler));
96+
threadList.add(scannerThread);
97+
executor.execute(scannerThread);
98+
99+
if (threadList.size() >= threads.get()) {
100+
for (Thread nextThread: threadList) {
101+
try {
102+
nextThread.join();
103+
++scanned;
104+
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing*256 + " (" + (scanned / (progressThing*256)) * 100 + "%)");
105+
} catch (InterruptedException timeout2) {
106+
// eh
95107
}
96108
}
109+
threadList.clear();
97110
}
98111
}
99112

0 commit comments

Comments
 (0)