Skip to content

Commit

Permalink
Support 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshimichi0915 committed Nov 6, 2023
1 parent 426ec2f commit 59fc4d1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Upload Build Artifacts
uses: actions/upload-artifact@v2
with:
name: artifact
path: build/libs/*.jar
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Upload Build Artifacts
uses: actions/upload-artifact@v2
with:
name: artifact
path: build/libs/*.jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It is known that this program may cause some issues on Windows.
In order to use this program with masscan, you can use the following command:

```bash
masscan -c masscan.conf 2>/dev/null | java -jar threescan.jar masscan stdin 5000 250 <username> <uuid> > output.txt 2>error.txt
masscan -c masscan.conf 2>/dev/null | java -jar threescan.jar masscan stdin 200 2000 <username> <uuid> > output.txt 2>error.txt
```

where
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'net.toshimichi'
version '1.0.0'
version '1.0.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.toshimichi.threescan.packet;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.UUID;

@Getter
@AllArgsConstructor
public class C2S764LoginPacket implements C2SPacket {

private String name;
private UUID playerUniqueId;

@Override
public int getId() {
return 0x00;
}

@Override
public void write(ByteBuffer buffer) throws IOException {
Protocol.putString(buffer, name);
Protocol.putUUID(buffer, playerUniqueId);
}
}
14 changes: 10 additions & 4 deletions src/main/java/net/toshimichi/threescan/scanner/ChannelScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void cancel(ScanContext context, boolean reused) throws IOException {
public void run() {
try (Selector selector = Selector.open()) {
boolean hasKeys = false;
while (!stopped || queue.size() > 0 || hasKeys) {
while (!stopped || !queue.isEmpty() || hasKeys) {
ScanContext poll;
boolean empty;
synchronized (queue) {
Expand All @@ -100,8 +100,8 @@ public void run() {
}

selector.selectNow();
hasKeys = selector.selectedKeys().size() > 0;
hasKeys = !selector.selectedKeys().isEmpty();

Iterator<SelectionKey> iter = selector.selectedKeys().iterator();
while (iter.hasNext()) {
SelectionKey key = iter.next();
Expand All @@ -122,8 +122,14 @@ public void run() {
}

if (key.isReadable()) {
context.setReadMs(System.currentTimeMillis());
int prevPos = context.getReadBuffer().position();
PacketData buf = context.readPacket();

int pos = context.getReadBuffer().position();
if (prevPos != pos) {
context.setReadMs(System.currentTimeMillis());
}

if (buf != null) {
packetHandler.onPacketReceived(context, buf);
context.getReadBuffer().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void stop() throws InterruptedException {

@Override
public void run() {
while (!stopped || queue.size() > 0) {
while (!stopped || !queue.isEmpty()) {
long currentMs = System.currentTimeMillis();
if (queue.isEmpty()) {
lastMs = currentMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.toshimichi.threescan.packet.C2S759LoginPacket;
import net.toshimichi.threescan.packet.C2S760LoginPacket;
import net.toshimichi.threescan.packet.C2S761LoginPacket;
import net.toshimichi.threescan.packet.C2S764LoginPacket;
import net.toshimichi.threescan.packet.C2SHandshakePacket;
import net.toshimichi.threescan.packet.C2SLoginPacket;
import net.toshimichi.threescan.packet.C2SStatusPacket;
Expand Down Expand Up @@ -47,7 +48,9 @@ public void onConnected(ScanContext context) throws IOException {
case LOGIN -> {
int protocol = context.getScanResult().getProtocol();
context.writePacket(new C2SHandshakePacket(protocol, target.getHost(), target.getPort(), state.getId()));
if (protocol >= 761) {
if (protocol >= 764) {
context.writePacket(new C2S764LoginPacket(name, uniqueId));
} else if (protocol >= 761) {
context.writePacket(new C2S761LoginPacket(name, uniqueId));
} else if (protocol == 760) {
context.writePacket(new C2S760LoginPacket(name, uniqueId));
Expand Down

0 comments on commit 59fc4d1

Please sign in to comment.