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

Commit 4723f1b

Browse files
authored
Merge pull request #40 from C0mm4nd/master
Added clusters
2 parents 6ce797b + 6b3cb82 commit 4723f1b

File tree

6 files changed

+332
-0
lines changed

6 files changed

+332
-0
lines changed

src/main/java/me/checkium/vhackapi/Utils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class Utils {
3737
* Unknown - maybe the charset?
3838
*/
3939
private static final byte[] byt;
40+
41+
public static boolean debug = false;
4042

4143
static {
4244
assertionstatus = !Utils.class.desiredAssertionStatus();
@@ -113,6 +115,12 @@ public static String StringRequest(String format, String data, String php)
113115
InputStream is;
114116
try {
115117
is = new URL(Utils.generateURL(format, data, php)).openStream();
118+
if(debug == true){
119+
120+
URL url = new URL(Utils.generateURL(format, data, php));
121+
System.out.println(url.toString());
122+
123+
}
116124
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
117125
jsonText = Utils.readJson(rd);
118126
} catch (IOException e) {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package me.checkium.vhackapi.cluster;
2+
3+
import org.json.JSONArray;
4+
import org.json.JSONObject;
5+
6+
import me.checkium.vhackapi.Utils;
7+
8+
public class Cluster {
9+
10+
private JSONObject cData;
11+
12+
public Cluster(JSONObject cData){
13+
14+
this.cData = cData;
15+
16+
}
17+
18+
public String getClusterName(){
19+
20+
return cData.getString("cName");
21+
22+
}
23+
24+
public String getClusterTag(){
25+
26+
return cData.getString("cTag");
27+
28+
}
29+
30+
public String getClustetLeader(){
31+
32+
return cData.getString("cLeader");
33+
34+
}
35+
36+
public int getNumberOfMembers(){
37+
38+
return cData.getInt("cMemeber");
39+
40+
}
41+
42+
public int getMaxNumberOfMemebers(){
43+
44+
return cData.getInt("cMaxMember");
45+
46+
}
47+
48+
public ClusterMember[] getClusterMemebers(){
49+
50+
JSONObject usersRaw = Utils.JSONRequest("user::::pass::::uhash", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash, "vh_getClusterMember.php");
51+
JSONArray usersRaw2 = usersRaw.getJSONArray("users");
52+
ClusterMember[] members = new ClusterMember[usersRaw2.length()];
53+
for(int i = 0; i<usersRaw2.length(); i++){
54+
55+
JSONObject jo = usersRaw2.getJSONObject(i);
56+
members[i] = new ClusterMember(jo);
57+
58+
}
59+
return members;
60+
61+
}
62+
63+
public ClusterMember[] getClusterRequests(){
64+
65+
try{
66+
JSONObject jo = Utils.JSONRequest("user::::pass::::uhash", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash, "vh_getClusterRequests.php");
67+
JSONArray ja = jo.getJSONArray("requests");
68+
ClusterMember[] applicants = new ClusterMember[ja.length()];
69+
for(int i = 0; i<ja.length(); i++){
70+
71+
JSONObject jo2 = ja.getJSONObject(i);
72+
applicants[i] = new ClusterMember(jo2);
73+
74+
}
75+
return applicants;
76+
} catch(Exception e) {
77+
return null;
78+
}
79+
80+
}
81+
82+
public void kickClusterMember(ClusterMember m){
83+
84+
try{
85+
Utils.JSONRequest("user::::pass::::uhash::::user2kick", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash + "::::" + m.getID(), "vh_clusterKick.php");
86+
} catch(Exception e) {
87+
88+
}
89+
90+
}
91+
92+
public void promoteClusterMember(ClusterMember m){
93+
94+
try{
95+
Utils.JSONRequest("user::::pass::::uhash::::uid", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash + "::::" + m.getID(), "vh_clusterPromote.php");
96+
} catch(Exception e){
97+
98+
}
99+
100+
}
101+
public int getClusterMoney(){
102+
103+
return cData.getInt("cMoney");
104+
105+
}
106+
107+
public int getClusterScore(){
108+
109+
return cData.getInt("cScore");
110+
111+
}
112+
113+
public int getClusterReps(){
114+
115+
return cData.getInt("cElo");
116+
117+
}
118+
119+
public int getNumberOfRequests(){
120+
121+
return cData.getInt("cReqs");
122+
123+
}
124+
125+
//Too slow, needs working
126+
/*public String[] getClusterMessages(){
127+
128+
JSONArray messagesArray = cData.getJSONArray("messages");
129+
String[] messages = new String[messagesArray.length() - 1];
130+
for(int i = (messagesArray.length() - 1); i >= 0; i--){
131+
132+
int i2 = 0;
133+
JSONObject messageRaw = messagesArray.getJSONObject(i);
134+
String dateAuthor = messageRaw.getString("from");
135+
String message = messageRaw.getString("message");
136+
String format = dateAuthor + ": " + message;
137+
messages[i2] = format;
138+
i++;
139+
140+
}
141+
return messages;
142+
143+
}*/
144+
145+
public void chat(String msg){
146+
147+
Utils.JSONRequest("user::::pass::::uhash::::msg", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash + "::::" + msg, "vh_clusterMessage.php");
148+
149+
}
150+
151+
public void addClusterSlot(){
152+
153+
Utils.JSONRequest("user::::pass::::uhash", ClusterManager.username + "::::" + ClusterManager.password + "::::" + ClusterManager.uhash, "vh_addClusterSlot.php");
154+
155+
}
156+
157+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.checkium.vhackapi.cluster;
2+
3+
import org.json.JSONObject;
4+
5+
import me.checkium.vhackapi.Utils;
6+
7+
public class ClusterManager {
8+
9+
JSONObject cData;
10+
protected static String username, password, uhash;
11+
12+
public ClusterManager(String username, String password, String uhash){
13+
14+
ClusterManager.username = username;
15+
ClusterManager.password = password;
16+
ClusterManager.uhash = uhash;
17+
this.cData = getClusterData();
18+
19+
}
20+
21+
public JSONObject getClusterData(){
22+
23+
try{
24+
JSONObject cData = Utils.JSONRequest("user::::pass::::uhash", username + "::::" + password + "::::" + uhash, "vh_ClusterData.php");
25+
return cData;
26+
} catch(Exception e) {
27+
return null;
28+
}
29+
30+
}
31+
32+
public Cluster getCluster(){
33+
34+
return new Cluster(cData);
35+
36+
}
37+
38+
public Cluster createCluster(String cName, String cID){
39+
40+
try{
41+
Utils.JSONRequest("user::::pass::::uhash::::cname::::cid", username + "::::" + password + "::::" + uhash + "::::" + cName + "::::" + cID, "vh_clusterAdd.php");
42+
return new Cluster(getClusterData());
43+
} catch(Exception e) {
44+
45+
return null;
46+
47+
}
48+
49+
}
50+
51+
public Cluster joinCluster(String cName){
52+
53+
try{
54+
Utils.JSONRequest("user::::pass::::uhash::::cname", username + "::::" + password + "::::" + uhash + "::::" + cName, "vh_clusterJoin.php");
55+
return new Cluster(getClusterData());
56+
} catch(Exception e) {
57+
58+
return null;
59+
60+
}
61+
62+
}
63+
64+
public void leaveCluster(){
65+
66+
try{
67+
Utils.JSONRequest("user::::pass::::uhash", username + "::::" + password + "::::" + uhash, "vh_clusterLeave.php");
68+
} catch(Exception e) {
69+
70+
}
71+
72+
}
73+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package me.checkium.vhackapi.cluster;
2+
3+
import org.json.JSONObject;
4+
5+
public class ClusterMember {
6+
7+
String username, lastactive;
8+
ClusterRank rank;
9+
int score, reps, userid;
10+
11+
public ClusterMember(JSONObject memberData){
12+
13+
this.username = memberData.getString("username");
14+
this.lastactive = memberData.getString("userlastactive");
15+
this.score = memberData.getInt("userscore");
16+
this.reps = memberData.getInt("userelo");
17+
this.userid = memberData.getInt("userid");
18+
int rank = memberData.getInt("userposition");
19+
switch(rank){
20+
21+
case 1: this.rank = ClusterRank.MEMBER; break;
22+
case 2: this.rank = ClusterRank.COLEADER; break;
23+
case 3: this.rank = ClusterRank.LEADER; break;
24+
25+
}
26+
27+
}
28+
29+
public String getUsername(){
30+
31+
return username;
32+
33+
}
34+
35+
public String getLastActivity(){
36+
37+
return lastactive;
38+
39+
}
40+
41+
public int getID(){
42+
43+
return userid;
44+
45+
}
46+
47+
public int getScore(){
48+
49+
return score;
50+
51+
}
52+
53+
public int getReps(){
54+
55+
return reps;
56+
57+
}
58+
59+
public ClusterRank getRank(){
60+
61+
return rank;
62+
63+
}
64+
65+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.checkium.vhackapi.cluster;
2+
3+
public enum ClusterRank {
4+
5+
MEMBER ("Member"),
6+
LEADER ("Leader"),
7+
COLEADER ("Co-Leader");
8+
9+
String tostring;
10+
11+
ClusterRank(String tostring){
12+
13+
this.tostring = tostring;
14+
15+
}
16+
17+
public String toString(){
18+
19+
return tostring;
20+
21+
}
22+
23+
}

src/main/java/me/checkium/vhackapi/vHackAPI.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.checkium.vhackapi.Spyware.SpywareManager;
88
import me.checkium.vhackapi.botnet.BotnetManager;
99
import me.checkium.vhackapi.chat.Chat;
10+
import me.checkium.vhackapi.cluster.ClusterManager;
1011
import me.checkium.vhackapi.console.Console;
1112
import me.checkium.vhackapi.others.PackageOpener;
1213
import me.checkium.vhackapi.upgrades.UpgradeManager;
@@ -37,6 +38,11 @@ public BotnetManager getBotnetManager() {
3738
BotnetManager manager = new BotnetManager(username, password, userHash);
3839
return manager;
3940
}
41+
42+
public ClusterManager getClusterManager() {
43+
ClusterManager manager = new ClusterManager(username, password, userHash);
44+
return manager;
45+
}
4046

4147
public String getStats(Stats stat) {
4248
fetchStats();

0 commit comments

Comments
 (0)