@@ -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
0 commit comments