Revision 286d73ae
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
38 | 38 |
void exception(String exception); |
39 | 39 |
} |
40 | 40 |
|
41 |
public static final int MAX_PLACES = 12;
|
|
41 |
public static final int MAX_PLACES = 10;
|
|
42 | 42 |
|
43 | 43 |
private static final int DOWNLOAD = 0; |
44 | 44 |
private static final int SUBMIT = 1; |
45 | 45 |
private static final int IDLE = 2; |
46 | 46 |
|
47 |
private static final String URL ="http://koltunski.pl/rubik/cgi-bin"; |
|
48 |
|
|
49 | 47 |
private final String[] hex = { |
50 | 48 |
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", |
51 | 49 |
"%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", |
... | ... | |
111 | 109 |
{ |
112 | 110 |
end = mScores.indexOf('\n', begin+1); |
113 | 111 |
if( end<0 ) end = len; |
114 |
fillRow(mScores.substring(begin+1,end)); |
|
112 |
|
|
113 |
try |
|
114 |
{ |
|
115 |
fillRow(mScores.substring(begin+1,end)); |
|
116 |
} |
|
117 |
catch(Exception ex) |
|
118 |
{ |
|
119 |
// faulty row - ignore |
|
120 |
} |
|
121 |
|
|
115 | 122 |
begin = end; |
116 | 123 |
} |
117 | 124 |
} |
... | ... | |
124 | 131 |
int s2 = row.indexOf(' ',s1+1); |
125 | 132 |
int s3 = row.indexOf(' ',s2+1); |
126 | 133 |
int s4 = row.indexOf(' ',s3+1); |
127 |
int s5 = row.indexOf(' ',s4+1); |
|
128 |
int s6 = row.length(); |
|
134 |
int s5 = row.length(); |
|
129 | 135 |
|
130 | 136 |
if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 ) |
131 | 137 |
{ |
132 |
int size = Integer.parseInt( row.substring(0,s1) );
|
|
138 |
int object = RubikObjectList.unpackObjectFromString( row.substring(0,s1) );
|
|
133 | 139 |
|
134 |
if( size>=0 && size<mTotal )
|
|
140 |
if( object>=0 && object<mTotal )
|
|
135 | 141 |
{ |
136 | 142 |
int level = Integer.parseInt( row.substring(s1+1,s2) ); |
137 |
int place = Integer.parseInt( row.substring(s2+1,s3) ); |
|
138 |
String name = row.substring(s3+1, s4); |
|
139 |
int time = Integer.parseInt( row.substring(s4+1,s5) ); |
|
140 |
String country = row.substring(s5+1, s6); |
|
143 |
String name = row.substring(s2+1, s3); |
|
144 |
int time = Integer.parseInt( row.substring(s3+1,s4) ); |
|
145 |
String country = row.substring(s4+1, s5); |
|
141 | 146 |
|
142 |
if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
|
|
147 |
if(level>0 && level<=MAX_SCRAMBLE)
|
|
143 | 148 |
{ |
144 |
int p = mPlaces[size][level];
|
|
145 |
mPlaces[size][level]++;
|
|
149 |
int p = mPlaces[object][level];
|
|
150 |
mPlaces[object][level]++;
|
|
146 | 151 |
|
147 |
if( p!=place ) android.util.Log.e("downloader", "size="+size+" level="+level+" p="+p+" place="+place); |
|
148 |
|
|
149 |
mCountry[size][level][place] = country; |
|
150 |
mName [size][level][place] = name; |
|
151 |
mTime [size][level][place] = ((float)time)/10.0f; |
|
152 |
mCountry[object][level-1][p] = country; |
|
153 |
mName [object][level-1][p] = name; |
|
154 |
mTime [object][level-1][p] = ((float)(time/100))/10.0f; |
|
152 | 155 |
} |
153 | 156 |
} |
154 | 157 |
} |
... | ... | |
195 | 198 |
|
196 | 199 |
private boolean doDownload() |
197 | 200 |
{ |
198 |
String message=URL+"/download.cgi?n="+URLencode(mUserName)+"&r="+mNumRuns+"&e="+mVersion+"d"; |
|
201 |
String message="https://distorted.org/magic/cgi-bin/download.cgi"; |
|
202 |
message += "?n="+URLencode(mUserName)+"&r="+mNumRuns+"&e="+mVersion+"d"; |
|
203 |
message += "&o="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&l="+MAX_PLACES; |
|
199 | 204 |
|
200 | 205 |
try |
201 | 206 |
{ |
... | ... | |
270 | 275 |
{ |
271 | 276 |
mRunning = true; |
272 | 277 |
success = doDownload(); |
273 |
fillValues(); |
|
274 | 278 |
} |
275 | 279 |
} |
276 | 280 |
catch( Exception e ) |
... | ... | |
278 | 282 |
mReceiver.exception("Exception downloading records: "+e.getMessage() ); |
279 | 283 |
} |
280 | 284 |
|
285 |
fillValues(); |
|
286 |
|
|
281 | 287 |
mRunning = false; |
282 | 288 |
|
283 | 289 |
if( success ) |
Also available in: Unified diff
Port the downloading into the new 'magic' server.