Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit cee0a4d

Browse files
committed
added new event, started with captain mode, bug fixes, updated
1 parent 258a250 commit cee0a4d

27 files changed

Lines changed: 535 additions & 282 deletions

StreamRaidersBot/Bot/src/include/Http.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.net.URISyntaxException;
77
import java.nio.charset.StandardCharsets;
88
import java.util.ArrayList;
9-
import java.util.List;
109
import java.util.regex.Pattern;
1110
import java.util.stream.Collectors;
1211

@@ -87,7 +86,7 @@ public NoConnectionException(Exception e) {
8786
private String url = "";
8887
private BasicHeader[] headers = new BasicHeader[0];
8988
private String[][] urlArgs = new String[0][0];
90-
private List<NameValuePair> encArgs = new ArrayList<NameValuePair>();
89+
private ArrayList<NameValuePair> encArgs = new ArrayList<NameValuePair>();
9190

9291
public void setUrl(String url) {
9392
this.url = url;
@@ -112,6 +111,12 @@ public void addEncArg(String name, String value) {
112111
encArgs.add(new BasicNameValuePair(name, value));
113112
}
114113

114+
public void remEncArg(String name) {
115+
encArgs.removeIf(nvp -> {
116+
return nvp.getName().equals(name);
117+
});
118+
}
119+
115120
public String getEncArg(String name) {
116121
for(NameValuePair bnvp : encArgs)
117122
if(bnvp.getName().equals(name))

StreamRaidersBot/Bot/src/program/Captain.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

StreamRaidersBot/Bot/src/program/ConfigsV2.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,11 @@ public Str(String con) {
192192

193193
public static final Str dungeonSlot = new Str("dungeonSlot");
194194
public static final Str lname = new Str("name");
195-
//public static final Str canBuyChest = new Str("canBuyChest");
196-
//public static final Str canBuyEventChest = new Str("canBuyEventChest");
197195
public static final Str userAgent = new Str("userAgent");
198196
public static final Str proxyDomain = new Str("proxyDomain");
199197
public static final Str proxyUser = new Str("proxyUser");
200198
public static final Str proxyPass = new Str("proxyPass");
199+
public static final Str captainTeam = new Str("captainTeam"); //TODO rem after event
201200

202201
public static String getStr(String cid, String lay, Str con) {
203202
if(lay.equals("(all)")) {

StreamRaidersBot/Bot/src/program/Donators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public String getEur() {
2424
public static final List<Don> dons = Collections.unmodifiableList(new ArrayList<Don>() {
2525
private static final long serialVersionUID = 1L;
2626
{
27+
add(new Don("DJ Lively Pants", 15000, 0, "Thanks for such a great way for me to not waste time during the day! And your community on Discord is fantastic. Thanks BearHugsByDay!"));
2728
add(new Don("Skyzor", 5266, 0, "Real men support"));
2829
add(new Don("Obelisk", 2201, 0, "thanks for taking the time from your schedule to make this :)"));
2930
add(new Don("Snugsel", 2000, 0, ""));

StreamRaidersBot/Bot/src/program/Map.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.gson.JsonPrimitive;
1010

1111
import include.Json;
12+
import program.viewer.Raid;
1213

1314
public class Map {
1415

@@ -46,7 +47,7 @@ private int hl() {
4647

4748
public Map(JsonObject mapData, Raid raid, JsonObject plan, String name, List<String> userIds, String cid, int slot) {
4849
if(mapData == null)
49-
new run.Run.StreamRaidersException("Map -> const: err=mapData is null, mapName="+name, cid, slot);
50+
new run.StreamRaidersException("Map -> const: err=mapData is null, mapName="+name, cid, slot);
5051
this.cid = cid;
5152
this.slot = slot;
5253
this.name = name;

StreamRaidersBot/Bot/src/program/SRR.java

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,38 @@ public void setUserAgent(String ua) {
3838
userAgent = ua;
3939
}
4040

41-
private String cookies = "";
42-
private String userId = null;
43-
private String isCaptain = "";
41+
private final String cookies;
42+
private String viewerUserId = null;
43+
private String captainUserId = null;
44+
private boolean playsAsCaptain;
45+
private boolean canPlayAsCaptain;
4446
private String gameDataVersion = "";
4547
private String clientVersion = "";
46-
private String clientPlatform = "WebGL";
48+
private static final String clientPlatform = "WebGL";
4749

48-
public String getUserId() {
49-
return userId;
50+
public String getViewerUserId() {
51+
return viewerUserId;
52+
}
53+
54+
public String getCaptainUserId() {
55+
return captainUserId;
56+
}
57+
58+
public boolean canPlayCaptain() {
59+
return canPlayAsCaptain;
60+
}
61+
62+
public boolean playsAsCaptain() {
63+
return playsAsCaptain;
5064
}
5165

5266
private static List<String> userIds = new ArrayList<String>();
5367

54-
public static List<String> getUserIds() {
68+
public static List<String> getViewerUserIds() {
5569
return userIds;
5670
}
5771

58-
synchronized public static void addUserId(String uid) {
72+
synchronized public static void addViewerUserId(String uid) {
5973
if(!userIds.contains(uid))
6074
userIds.add(uid);
6175
}
@@ -102,13 +116,12 @@ public SRR(String cid, String clientVersion) throws NoConnectionException, Outda
102116
this.cookies = ConfigsV2.getPStr(cid, ConfigsV2.cookies);
103117
this.clientVersion = clientVersion;
104118
reload();
105-
addUserId(userId);
119+
addViewerUserId(viewerUserId);
106120
}
107121

108122
public String reload() throws NoConnectionException, OutdatedDataException, NotAuthorizedException {
109-
userId = null;
123+
viewerUserId = null;
110124
gameDataVersion = "";
111-
isCaptain = "";
112125
JsonObject raw = Json.parseObj(getUser());
113126
JsonObject info = raw.getAsJsonObject("info");
114127
String datapath = info.get("dataPath").getAsString();
@@ -134,10 +147,23 @@ private void constructor(JsonObject getUser) throws NotAuthorizedException {
134147
this.gameDataVersion = getUser.getAsJsonObject("info").get("dataVersion").getAsString();
135148
try {
136149
JsonObject data = getUser.getAsJsonObject("data");
137-
this.isCaptain = "0";
138-
this.userId = data.get("userId").getAsString();
139-
if(userId.endsWith("c"))
140-
userId = data.get("otherUserId").getAsString();
150+
canPlayAsCaptain = data.get("hasCaptainPrivileges").getAsBoolean();
151+
if(!canPlayAsCaptain) {
152+
this.viewerUserId = data.get("userId").getAsString();
153+
playsAsCaptain = false;
154+
} else {
155+
String uid = data.get("userId").getAsString();
156+
String oid = data.get("otherUserId").getAsString();
157+
if(data.get("isCaptain").getAsInt() == 0) {
158+
playsAsCaptain = false;
159+
captainUserId = oid;
160+
viewerUserId = uid;
161+
} else {
162+
playsAsCaptain = true;
163+
captainUserId = uid;
164+
viewerUserId = oid;
165+
}
166+
}
141167
} catch (ClassCastException e) {
142168
JsonElement err = getUser.get(SRC.errorMessage);
143169
if(err.isJsonPrimitive() && err.getAsString().equals("User is not authorized.")) {
@@ -149,13 +175,26 @@ private void constructor(JsonObject getUser) throws NotAuthorizedException {
149175
}
150176

151177

152-
153178
public Http getPost(String cn) {
154179
return getPost(cn, true);
155180
}
156181

157182

158183
private Http getPost(String cn, boolean addUser) {
184+
Http post = getPurePost(cn);
185+
186+
if(viewerUserId != null && addUser) {
187+
post.addEncArg("userId", playsAsCaptain ? viewerUserId : captainUserId);
188+
post.addEncArg("isCaptain", playsAsCaptain ? "1" : "0");
189+
}
190+
post.addEncArg("gameDataVersion", gameDataVersion);
191+
post.addEncArg("clientVersion", clientVersion);
192+
post.addEncArg("clientPlatform", clientPlatform);
193+
194+
return post;
195+
}
196+
197+
private Http getPurePost(String cn) {
159198
Http post = new Http();
160199
if(proxyDomain != null)
161200
post.setProxy(proxyDomain, proxyPort, proxyUser, proxyPass);
@@ -166,18 +205,12 @@ private Http getPost(String cn, boolean addUser) {
166205
post.setUrl("https://www.streamraiders.com/api/game/");
167206
post.addUrlArg("cn", cn);
168207

169-
if(userId != null && addUser) {
170-
post.addEncArg("userId", userId);
171-
post.addEncArg("isCaptain", isCaptain);
172-
}
173-
post.addEncArg("gameDataVersion", gameDataVersion);
174208
post.addEncArg("command", cn);
175-
post.addEncArg("clientVersion", clientVersion);
176-
post.addEncArg("clientPlatform", clientPlatform);
177209

178210
return post;
179211
}
180212

213+
181214
private String sendPost(Http post) throws NoConnectionException {
182215
String p;
183216
try {
@@ -211,6 +244,10 @@ public String getUser() throws NoConnectionException {
211244
return sendPost(post);
212245
}
213246

247+
public String switchUserAccountType() throws NoConnectionException {
248+
return sendPost(getPurePost("switchUserAccountType"));
249+
}
250+
214251

215252
public String unlockUnit(String unitType) throws NoConnectionException {
216253
Http post = getPost("unlockUnit");
@@ -286,7 +323,7 @@ public String grantEventReward(String eventId, String rewardTier, boolean collec
286323
public String getUserEventProgression() throws NoConnectionException {
287324
Http post = getPost("getUserEventProgression", false);
288325
post.addEncArg("userId", "");
289-
post.addEncArg("isCaptain", isCaptain);
326+
post.addEncArg("isCaptain", playsAsCaptain ? "1" : "0");
290327
return sendPost(post);
291328
}
292329

@@ -315,7 +352,7 @@ public String leaveCaptain(String captainId) throws NoConnectionException {
315352

316353

317354

318-
public String getCaptainsForSearch(int page, String seed, boolean fav, boolean live, String mode, boolean searchForCaptain, String name) throws NoConnectionException {
355+
public String getCaptainsForSearch(String page, String resultsPerPage, String seed, boolean fav, boolean live, String mode, boolean searchForCaptain, String name) throws NoConnectionException {
319356
JsonObject filter = new JsonObject();
320357
filter.addProperty("ambassadors", "false");
321358
filter.addProperty("favorite", (fav ? "true" : "false"));
@@ -325,8 +362,8 @@ public String getCaptainsForSearch(int page, String seed, boolean fav, boolean l
325362
filter.addProperty("mode", mode);
326363

327364
Http post = getPost("getCaptainsForSearch");
328-
post.addEncArg("page", ""+page);
329-
post.addEncArg("resultsPerPage", "30");
365+
post.addEncArg("page", page);
366+
post.addEncArg("resultsPerPage", resultsPerPage);
330367
post.addEncArg("filters", filter.toString());
331368
post.addEncArg("seed", seed==null?"0":seed);
332369

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package program.viewer;
2+
3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
6+
import program.SRC;
7+
8+
public class CaptainData {
9+
10+
private final JsonObject cap;
11+
12+
public CaptainData(JsonObject cap) {
13+
this.cap = cap;
14+
}
15+
16+
public String get(String con) {
17+
if(!cap.has(con))
18+
return null;
19+
JsonElement je = cap.get(con);
20+
if(!je.isJsonPrimitive())
21+
return null;
22+
return je.getAsString();
23+
}
24+
25+
@Override
26+
public String toString() {
27+
return get(SRC.Captain.twitchDisplayName);
28+
}
29+
30+
}

StreamRaidersBot/Bot/src/program/Raid.java renamed to StreamRaidersBot/Bot/src/program/viewer/Raid.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package program;
1+
package program.viewer;
22

33
import java.util.Hashtable;
44

@@ -8,6 +8,10 @@
88

99
import include.Json;
1010
import include.Time;
11+
import program.Debug;
12+
import program.Options;
13+
import program.SRC;
14+
import program.Store;
1115

1216
public class Raid {
1317

StreamRaidersBot/Bot/src/run/BotListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import com.google.gson.JsonObject;
66

7-
import program.Raid;
7+
import program.viewer.Raid;
88

99
public interface BotListener {
1010
/**
@@ -59,7 +59,7 @@ public default void onProfileLoadComplete(String cid, int pos) {}
5959
* will be called if a profile failed to load
6060
* @param cid profile id
6161
* @param pos a instance unique number assigned to the profile starting from 0 and counting up. Can change when restarted, but keeps the order in which the profiles where added.
62-
* @param e Exception thrown [{@link program.Run.SilentException}, {@link program.SRR.NotAuthorizedException}, {@link program.SRR.NotAuthorizedException}, {@link program.SRR.OutdatedDataException}, {@link java.lang.Exception}]
62+
* @param e Exception thrown [{@link run.Viewer.Run.SilentException}, {@link program.SRR.NotAuthorizedException}, {@link program.SRR.NotAuthorizedException}, {@link program.SRR.OutdatedDataException}, {@link java.lang.Exception}]
6363
*/
6464
public default void onProfileLoadError(String cid, int pos, Exception e) {}
6565

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package run;
2+
3+
public class Captain {
4+
5+
}

0 commit comments

Comments
 (0)