Skip to content

Commit

Permalink
v1.14 patch 2
Browse files Browse the repository at this point in the history
  • Loading branch information
StupidRepo committed Jul 17, 2023
1 parent 274e93e commit 1309281
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
All notable changes to this project will be documented in `CHANGELOG.md`.
## Added
* `PopupHandler` - stops me from duplicating a bunch of code just for settings.
* [TODOs][todos] to changelog.

## Modified
* Thread handling has been modified to be (potentially) faster and use less lines of code.
* Thread handling has been modified to be (potentially) faster (again) and use less lines of code.

## Removed
* Hits feature
* 1 unused import
* 1 unused import
* (potentially) more comments

## TODOs
[ ] - Optimise IP generation and inital scanning code. (1)

[todos]: https://github.com/StupidRepo/MCScanner/blob/main/CHANGELOG.md#todos
47 changes: 30 additions & 17 deletions src/com/stupidrepo/mcscanner/MCScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static void main(String[] var0) throws IllegalArgumentException, IllegalA
int maxRange = 255;
int port = 25565;

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

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

ArrayList < Thread > threadList = new ArrayList < Thread > ();
ArrayList < String > ips = new ArrayList < String > ();

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

frame.setVisible(true);

// TODO: Optimise this code. (1)

ExecutorService executor = Executors.newFixedThreadPool(threads.get());

for (int i = minimumRange; i <= maxRange; ++i) {
for (int j = 0; j <= 255; ++j) {
for (int k = 0; k <= 255; ++k) {
for (int l = 0; l <= 255; ++l) {
String ip = i + "." + j + "." + k + "." + l;
Thread scannerThread = new Thread(new ScannerThread(ip, port, timeout, databaseHandler));
threadList.add(scannerThread);
executor.execute(scannerThread);

if (threadList.size() >= threads.get()) {
for (Thread nextThread: threadList) {
try {
nextThread.join();
++scanned;
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing*256 + " (" + (scanned / (progressThing*256)) * 100 + "%)");
} catch (InterruptedException timeout2) {
// eh
}
}
threadList.clear();
}
ips.add(ip);
}
}
}
}

for (int i = 0; i < ips.size(); ++i) {
int randomIndex = (int)(Math.random() * ips.size());
String temp = ips.get(i);
ips.set(i, ips.get(randomIndex));
ips.set(randomIndex, temp);
}

for(String ip: ips) {
Thread scannerThread = new Thread(new ScannerThread(ip, port, timeout, databaseHandler));
threadList.add(scannerThread);
executor.execute(scannerThread);

if (threadList.size() >= threads.get()) {
for (Thread nextThread: threadList) {
try {
nextThread.join();
++scanned;
scannedLabel.setText("Scanned: " + scanned + "/" + progressThing*256 + " (" + (scanned / (progressThing*256)) * 100 + "%)");
} catch (InterruptedException timeout2) {
// eh
}
}
threadList.clear();
}
}

Expand Down

0 comments on commit 1309281

Please sign in to comment.