Skip to content

Commit 6f6a32b

Browse files
author
lorenzo-patane
committed
All
0 parents  commit 6f6a32b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2964
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target/
2+
.idea/
3+
outputs/
4+
*.iml
5+
*.iws
6+
.DS_Store
7+
*.txt
8+
*.json
9+
/src/test/

pom.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<properties>
8+
<maven.compiler.source>1.8</maven.compiler.source>
9+
<maven.compiler.target>1.8</maven.compiler.target>
10+
</properties>
11+
12+
<groupId>quboScanner</groupId>
13+
<artifactId>quboScanner</artifactId>
14+
<version>1</version>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.google.code.gson</groupId>
19+
<artifactId>gson</artifactId>
20+
<version>2.8.5</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>net.java.dev.jna</groupId>
24+
<artifactId>jna-platform</artifactId>
25+
<version>5.5.0</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>com.formdev</groupId>
30+
<artifactId>flatlaf</artifactId>
31+
<version>0.21</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.intellij</groupId>
35+
<artifactId>forms_rt</artifactId>
36+
<version>7.0.3</version>
37+
</dependency>
38+
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
39+
<dependency>
40+
<groupId>commons-cli</groupId>
41+
<artifactId>commons-cli</artifactId>
42+
<version>1.4</version>
43+
</dependency>
44+
</dependencies>
45+
<build>
46+
<plugins>
47+
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-assembly-plugin</artifactId>
51+
<version>2.4.1</version>
52+
<configuration>
53+
<!-- get all project dependencies -->
54+
<descriptorRefs>
55+
<descriptorRef>jar-with-dependencies</descriptorRef>
56+
</descriptorRefs>
57+
<!-- MainClass in mainfest make a executable jar -->
58+
<archive>
59+
<manifest>
60+
<mainClass>qubo.Main</mainClass>
61+
</manifest>
62+
</archive>
63+
64+
</configuration>
65+
<executions>
66+
<execution>
67+
<id>make-assembly</id>
68+
<!-- bind to the packaging phase -->
69+
<phase>package</phase>
70+
<goals>
71+
<goal>single</goal>
72+
</goals>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-jar-plugin</artifactId>
79+
<configuration>
80+
<archive>
81+
<manifest>
82+
<mainClass>qubo.Main</mainClass>
83+
</manifest>
84+
</archive>
85+
</configuration>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
</project>

setup.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#quboScanner setup - @zreply on Telegram - quboscanner.tk
2+
3+
if [ $# -eq 0 ]
4+
then
5+
echo "No arguments supplied, please insert rar package and restart"
6+
exit 0
7+
fi
8+
9+
sudo apt update
10+
sudo apt upgrade -y
11+
sudo apt install default-jre -y
12+
sudo apt install unrar -y
13+
unrar $1
14+
chmod +x start.sh
15+
./start.sh -hwid

src/main/java/mcping/MCPing.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package mcping;
2+
3+
import java.io.IOException;
4+
import java.net.InetSocketAddress;
5+
import com.google.gson.Gson;
6+
import mcping.data.*;
7+
8+
public class MCPing {
9+
10+
private final static Gson gson = new Gson();
11+
12+
public FinalResponse getPing(PingOptions options) throws IOException {
13+
Pinger a = new Pinger();
14+
a.setAddress(new InetSocketAddress(options.getHostname(),options.getPort()));
15+
a.setTimeout(options.getTimeout());
16+
String json = a.fetchData();
17+
if(json != null){
18+
if(json.contains("{")){
19+
if(json.contains("\"modid\"")){ //è un forge response
20+
return gson.fromJson(json, ForgeResponse.class).toFinalResponse();
21+
}
22+
else if(json.contains("\"extra\"")){ // è un extra response
23+
return gson.fromJson(json,ExtraResponse.class).toFinalResponse();
24+
}
25+
else if(json.contains("\"text\"")){ //è un new response
26+
return gson.fromJson(json,NewResponse.class).toFinalResponse();
27+
}
28+
else { //è un old response
29+
return gson.fromJson(json,OldResponse.class).toFinalResponse();
30+
}
31+
}
32+
}
33+
return null;
34+
}
35+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package mcping;
2+
3+
public class PingOptions {
4+
5+
private String hostname;
6+
private int port;
7+
private int timeout;
8+
//private String charset = "UTF-8";
9+
10+
public PingOptions setHostname(String hostname) {
11+
this.hostname = hostname;
12+
return this;
13+
}
14+
15+
public PingOptions setPort(int port) {
16+
this.port = port;
17+
return this;
18+
}
19+
20+
public PingOptions setTimeout(int timeout) {
21+
this.timeout = timeout;
22+
return this;
23+
}
24+
25+
/*public PingOptions setCharset(String charset) {
26+
this.charset = charset;
27+
return this;
28+
}*/
29+
30+
String getHostname() {
31+
return this.hostname;
32+
}
33+
34+
int getPort() {
35+
return this.port;
36+
}
37+
38+
public int getTimeout() {
39+
return this.timeout;
40+
}
41+
42+
/*public String getCharset() {
43+
return this.charset;
44+
}*/
45+
46+
}

src/main/java/mcping/Pinger.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package mcping;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.DataInputStream;
5+
import java.io.DataOutputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.OutputStream;
9+
import java.net.InetSocketAddress;
10+
import java.net.Socket;
11+
12+
class Pinger
13+
{
14+
private InetSocketAddress host;
15+
private int timeout;
16+
17+
void setAddress(InetSocketAddress host)
18+
{
19+
this.host = host;
20+
}
21+
void setTimeout(int timeout)
22+
{
23+
this.timeout = timeout;
24+
}
25+
26+
private int readVarInt(DataInputStream in) throws IOException {
27+
int i = 0;
28+
int j = 0;
29+
int k;
30+
do
31+
{
32+
k = in.readByte();
33+
i |= (k & 0x7F) << j++ * 7;
34+
if (j > 5) {
35+
//throw new RuntimeException("VarInt too big");
36+
return -1;
37+
}
38+
} while ((k & 0x80) == 128);
39+
return i;
40+
}
41+
42+
private void writeVarInt(DataOutputStream out, int paramInt) throws IOException {
43+
for (;;)
44+
{
45+
if ((paramInt & 0xFFFFFF80) == 0)
46+
{
47+
out.writeByte(paramInt);
48+
return;
49+
}
50+
out.writeByte(paramInt & 0x7F | 0x80);
51+
paramInt >>>= 7;
52+
}
53+
}
54+
55+
public String fetchData() throws IOException {
56+
Socket socket = new Socket();
57+
socket.setSoTimeout(this.timeout);
58+
socket.connect(this.host, this.timeout);
59+
OutputStream outputStream = socket.getOutputStream();
60+
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
61+
InputStream inputStream = socket.getInputStream();
62+
ByteArrayOutputStream b = new ByteArrayOutputStream();
63+
DataOutputStream handshake = new DataOutputStream(b);
64+
handshake.writeByte(0);
65+
writeVarInt(handshake, 4);
66+
writeVarInt(handshake, this.host.getHostString().length());
67+
handshake.writeBytes(this.host.getHostString());
68+
handshake.writeShort(this.host.getPort());
69+
writeVarInt(handshake, 1);
70+
writeVarInt(dataOutputStream, b.size());
71+
dataOutputStream.write(b.toByteArray());
72+
dataOutputStream.writeByte(1);
73+
dataOutputStream.writeByte(0);
74+
DataInputStream dataInputStream = new DataInputStream(inputStream);
75+
int size = readVarInt(dataInputStream);
76+
if(size == -1) return null;
77+
int id = readVarInt(dataInputStream);
78+
if (id == -1) {
79+
return null;
80+
}
81+
if (id != 0) {
82+
return null;
83+
}
84+
int length = readVarInt(dataInputStream);
85+
if(length == -1) {
86+
return null;
87+
}
88+
if (length == 0) {
89+
return null;
90+
}
91+
byte[] in = new byte[length];
92+
dataInputStream.readFully(in);
93+
94+
b.close();
95+
dataInputStream.close();
96+
handshake.close();
97+
dataOutputStream.close();
98+
outputStream.close();
99+
inputStream.close();
100+
socket.close();
101+
return new String(in); //ritorna il json
102+
}
103+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mcping.data;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import mcping.rawData.ExtraDescription;
5+
6+
public class ExtraResponse extends MCResponse {
7+
8+
@SerializedName("description")
9+
private ExtraDescription description;
10+
11+
public FinalResponse toFinalResponse(){
12+
return new FinalResponse(players,version,favicon,description.getText());
13+
}
14+
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mcping.data;
2+
3+
import mcping.rawData.Players;
4+
import mcping.rawData.Version;
5+
6+
public class FinalResponse extends MCResponse {
7+
8+
private final String description;
9+
10+
11+
public FinalResponse(Players players, Version version,String favicon,String description){
12+
this.description = description;
13+
this.favicon = favicon;
14+
this.players = players;
15+
this.version = version;
16+
}
17+
18+
public Players getPlayers() {
19+
return players;
20+
}
21+
22+
public Version getVersion() {
23+
return version;
24+
}
25+
26+
public String getDescription() {
27+
return description;
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package mcping.data;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import mcping.rawData.ForgeDescription;
5+
import mcping.rawData.ForgeModInfo;
6+
import mcping.rawData.Players;
7+
import mcping.rawData.Version;
8+
9+
public class ForgeResponse {
10+
11+
@SerializedName("description")
12+
private ForgeDescription description;
13+
14+
@SerializedName("players")
15+
private Players players;
16+
17+
@SerializedName("version")
18+
private Version version;
19+
20+
@SerializedName("modinfo")
21+
private ForgeModInfo modinfo;
22+
23+
public FinalResponse toFinalResponse(){
24+
version.setName(version.getName() + " FML with " + modinfo.getNMods() + " mods");
25+
return new FinalResponse(players,version,"",description.getTranslate());
26+
}
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mcping.data;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import mcping.rawData.Players;
5+
import mcping.rawData.Version;
6+
7+
class MCResponse {
8+
@SerializedName("players")
9+
Players players;
10+
@SerializedName("version")
11+
Version version;
12+
@SerializedName("favicon")
13+
String favicon;
14+
}

0 commit comments

Comments
 (0)