Revision 17f9a695
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
39 | 39 |
{ |
40 | 40 |
void receive(String[][][] country, String[][][] name, float[][][] time); |
41 | 41 |
void message(String mess); |
42 |
void serverError(String error); |
|
42 | 43 |
} |
43 | 44 |
|
44 | 45 |
public static final int MAX_PLACES = 10; |
... | ... | |
106 | 107 |
} |
107 | 108 |
|
108 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 |
// TODO: handle the fact that the server might return 'error' (3) or 'name taken' (2) |
|
110 | 110 |
|
111 |
private void fillSubmittedValues() |
|
112 |
{ |
|
113 |
fillDownloadedValues(); |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
private void fillDownloadedValues() |
|
111 |
private boolean fillValues() |
|
119 | 112 |
{ |
120 | 113 |
int begin=-1 ,end, len = mScores.length(); |
114 |
String row; |
|
121 | 115 |
|
122 | 116 |
for(int i=0; i<mTotal; i++) |
123 | 117 |
for(int j=0; j<MAX_SCRAMBLE; j++) |
... | ... | |
132 | 126 |
|
133 | 127 |
try |
134 | 128 |
{ |
135 |
fillRow(mScores.substring(begin+1,end)); |
|
129 |
row = mScores.substring(begin+1,end); |
|
130 |
|
|
131 |
if( row.length()==1 ) |
|
132 |
{ |
|
133 |
mReceiver.serverError(row); |
|
134 |
return false; |
|
135 |
} |
|
136 |
else |
|
137 |
{ |
|
138 |
fillRow(row); |
|
139 |
} |
|
136 | 140 |
} |
137 | 141 |
catch(Exception ex) |
138 | 142 |
{ |
... | ... | |
141 | 145 |
|
142 | 146 |
begin = end; |
143 | 147 |
} |
148 |
|
|
149 |
return true; |
|
144 | 150 |
} |
145 | 151 |
|
146 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
273 | 279 |
return true; |
274 | 280 |
} |
275 | 281 |
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
private String constructDownloadURL() |
|
285 |
{ |
|
286 |
RubikScores scores = RubikScores.getInstance(); |
|
287 |
String name = URLencode(scores.getName()); |
|
288 |
String veri = scores.isVerified() ? name : ""; |
|
289 |
int numRuns = scores.getNumRuns(); |
|
290 |
int numPlay = scores.getNumPlays(); |
|
291 |
|
|
292 |
String url="https://distorted.org/magic/cgi-bin/download.cgi"; |
|
293 |
url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&e="+mVersion+"d"; |
|
294 |
url += "&o="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&l="+MAX_PLACES; |
|
295 |
|
|
296 |
return url; |
|
297 |
} |
|
298 |
|
|
299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
300 |
|
|
301 |
private String constructSubmitURL() |
|
302 |
{ |
|
303 |
RubikScores scores = RubikScores.getInstance(); |
|
304 |
String name = URLencode(scores.getName()); |
|
305 |
String veri = scores.isVerified() ? name : ""; |
|
306 |
int numRuns = scores.getNumRuns(); |
|
307 |
int numPlay = scores.getNumPlays(); |
|
308 |
int deviceID= scores.getDeviceID(); |
|
309 |
String objlist = scores.getUnsubmittedObjlist(); |
|
310 |
String lvllist = scores.getUnsubmittedLevellist(); |
|
311 |
String timlist = scores.getUnsubmittedTimelist(); |
|
312 |
String country = scores.getCountry(); |
|
313 |
int hash = computeHash(name,veri,country,lvllist,objlist,timlist,numRuns); |
|
314 |
|
|
315 |
String url="https://distorted.org/magic/cgi-bin/submit.cgi"; |
|
316 |
url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d"; |
|
317 |
url += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&h="+hash; |
|
318 |
url += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&lo="+MAX_PLACES; |
|
319 |
|
|
320 |
return url; |
|
321 |
} |
|
322 |
|
|
276 | 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
277 | 324 |
|
278 | 325 |
private boolean gottaDownload() |
... | ... | |
287 | 334 |
{ |
288 | 335 |
boolean success=true; |
289 | 336 |
|
290 |
if( mMode==DOWNLOAD && gottaDownload() )
|
|
337 |
try
|
|
291 | 338 |
{ |
292 |
mRunning = true; |
|
293 |
|
|
294 |
try |
|
339 |
if( mMode==DOWNLOAD && gottaDownload() ) |
|
295 | 340 |
{ |
296 |
RubikScores scores = RubikScores.getInstance(); |
|
297 |
String name = URLencode(scores.getName()); |
|
298 |
String veri = scores.isVerified() ? name : ""; |
|
299 |
int numRuns = scores.getNumRuns(); |
|
300 |
int numPlay = scores.getNumPlays(); |
|
301 |
|
|
302 |
String url="https://distorted.org/magic/cgi-bin/download.cgi"; |
|
303 |
url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&e="+mVersion+"d"; |
|
304 |
url += "&o="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&l="+MAX_PLACES; |
|
305 |
|
|
306 |
success = network(url); |
|
341 |
mRunning = true; |
|
342 |
success = network(constructDownloadURL()); |
|
307 | 343 |
} |
308 |
catch( Exception e )
|
|
344 |
if( mMode==SUBMIT )
|
|
309 | 345 |
{ |
310 |
mReceiver.message("Exception downloading records: "+e.getMessage() ); |
|
311 |
} |
|
346 |
mRunning = true; |
|
312 | 347 |
|
313 |
fillDownloadedValues(); |
|
348 |
if( RubikScores.getInstance().thereAreUnsubmittedRecords() ) |
|
349 |
{ |
|
350 |
success = network(constructSubmitURL()); |
|
351 |
} |
|
352 |
} |
|
314 | 353 |
} |
315 |
|
|
316 |
if( mMode==SUBMIT ) |
|
354 |
catch( Exception e ) |
|
317 | 355 |
{ |
318 |
mRunning = true; |
|
319 |
|
|
320 |
try |
|
321 |
{ |
|
322 |
RubikScores scores = RubikScores.getInstance(); |
|
323 |
String name = URLencode(scores.getName()); |
|
324 |
String veri = scores.isVerified() ? name : ""; |
|
325 |
int numRuns = scores.getNumRuns(); |
|
326 |
int numPlay = scores.getNumPlays(); |
|
327 |
int deviceID= scores.getDeviceID(); |
|
328 |
String objlist = scores.getUnsubmittedObjlist(); |
|
329 |
String lvllist = scores.getUnsubmittedLevellist(); |
|
330 |
String timlist = scores.getUnsubmittedTimelist(); |
|
331 |
String country = scores.getCountry(); |
|
332 |
int hash = computeHash(name,veri,country,lvllist,objlist,timlist,numRuns); |
|
333 |
|
|
334 |
String url="https://distorted.org/magic/cgi-bin/submit.cgi"; |
|
335 |
url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d"; |
|
336 |
url += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&h="+hash; |
|
337 |
url += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&lo="+MAX_PLACES; |
|
338 |
|
|
339 |
success = network(url); |
|
340 |
} |
|
341 |
catch( Exception e ) |
|
342 |
{ |
|
343 |
mReceiver.message("Exception submitting records: "+e.getMessage() ); |
|
344 |
} |
|
345 |
|
|
346 |
fillSubmittedValues(); |
|
356 |
mReceiver.message("Exception downloading records: "+e.getMessage() ); |
|
347 | 357 |
} |
348 | 358 |
|
349 |
mRunning = false; |
|
359 |
if( mRunning ) |
|
360 |
{ |
|
361 |
success = fillValues(); |
|
362 |
mRunning = false; |
|
363 |
} |
|
350 | 364 |
|
351 | 365 |
if( success ) |
352 | 366 |
{ |
353 | 367 |
mReceiver.receive(mCountry, mName, mTime); |
368 |
|
|
369 |
if( mMode==SUBMIT ) |
|
370 |
{ |
|
371 |
RubikScores.getInstance().successfulSubmit(); |
|
372 |
} |
|
354 | 373 |
} |
355 | 374 |
} |
356 | 375 |
|
Also available in: Unified diff
progress with submitting one's high scores.