1
|
package org.distorted.sokoban;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.InputStream;
|
5
|
import java.io.BufferedInputStream;
|
6
|
import java.io.UnsupportedEncodingException;
|
7
|
import java.net.HttpURLConnection;
|
8
|
import java.net.URL;
|
9
|
|
10
|
import android.util.Log;
|
11
|
|
12
|
///////////////////////////////////////////////////////////////////
|
13
|
|
14
|
public class SokobanRecords implements Runnable
|
15
|
{
|
16
|
private static final String TAG_RECORDS = "SokobanRecords";
|
17
|
|
18
|
public static final int MAX_PLACES = 9;
|
19
|
public static final int DOWNLOADR = 0;
|
20
|
public static final int DOWNLOADL = 1;
|
21
|
public static final int SUBMITR = 2;
|
22
|
public static final int SUBMITL = 3;
|
23
|
public static final int IDLE = 4;
|
24
|
|
25
|
private static final int MAX_SUBMIT = 10;
|
26
|
|
27
|
private static boolean mRunning;
|
28
|
private static boolean mDirtyRecords;
|
29
|
private static int mode;
|
30
|
|
31
|
private static int lv;
|
32
|
private static int mCols;
|
33
|
|
34
|
private static final String URL = "https://distorted.org/sokoban/cgi-bin";
|
35
|
private static String iso = null;
|
36
|
private String name,veri;
|
37
|
private String mLevel;
|
38
|
|
39
|
private static SokobanLevels mLevels=null;
|
40
|
|
41
|
private static final String[] hex = {
|
42
|
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
|
43
|
"%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
|
44
|
"%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
|
45
|
"%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
|
46
|
"%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
|
47
|
"%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f",
|
48
|
"%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
|
49
|
"%38", "%39", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f",
|
50
|
"%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
|
51
|
"%48", "%49", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f",
|
52
|
"%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
|
53
|
"%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f",
|
54
|
"%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
|
55
|
"%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f",
|
56
|
"%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
|
57
|
"%78", "%79", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f",
|
58
|
"%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
|
59
|
"%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
|
60
|
"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
|
61
|
"%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
|
62
|
"%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
|
63
|
"%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
|
64
|
"%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
|
65
|
"%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
|
66
|
"%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
|
67
|
"%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
|
68
|
"%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
|
69
|
"%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
|
70
|
"%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
|
71
|
"%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
|
72
|
"%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
|
73
|
"%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
|
74
|
};
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////
|
77
|
|
78
|
public SokobanRecords()
|
79
|
{
|
80
|
mRunning = false;
|
81
|
mDirtyRecords= true;
|
82
|
mode = IDLE;
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////
|
86
|
|
87
|
public static void setLevels(SokobanLevels sl)
|
88
|
{
|
89
|
mLevels = sl;
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////
|
93
|
|
94
|
private boolean start()
|
95
|
{
|
96
|
if( !mRunning )
|
97
|
{
|
98
|
mRunning = true;
|
99
|
Thread networkThrd = new Thread(this);
|
100
|
networkThrd.start();
|
101
|
return true;
|
102
|
}
|
103
|
|
104
|
return false;
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////
|
108
|
|
109
|
public void run()
|
110
|
{
|
111
|
try
|
112
|
{
|
113
|
String message="";
|
114
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
115
|
int run = db.getNumRunnings();
|
116
|
|
117
|
if(mode==SUBMITR)
|
118
|
{
|
119
|
int hash = computeSubmitHash(name,veri,getSMSC(),lv,run);
|
120
|
message=URL+"/submitr.cgi";
|
121
|
message+=("?l="+generateLevelsList(lv));
|
122
|
message+=("&m="+generateMovesList(lv));
|
123
|
message+=("&t="+generateTimesList(lv));
|
124
|
message+=("&v="+URLencode(veri));
|
125
|
message+=("&n="+URLencode(name));
|
126
|
message+=("&s="+URLencode(getSMSC()));
|
127
|
message+=("&h="+hash);
|
128
|
message+=("&r="+run);
|
129
|
message+=("&p="+db.getNumPlayings());
|
130
|
message+=("&i="+db.getId());
|
131
|
message+=("&e="+SokobanCanvas.mVersionStr+"a");
|
132
|
}
|
133
|
else if(mode==DOWNLOADR)
|
134
|
{
|
135
|
message=URL+"/downloadr.cgi";
|
136
|
message+="?n="+URLencode(veri);
|
137
|
message+="&r="+run;
|
138
|
message+="&e="+SokobanCanvas.mVersionStr+"a";
|
139
|
}
|
140
|
else if(mode==SUBMITL )
|
141
|
{
|
142
|
message=URL+"/submitl.cgi";
|
143
|
message+="?n="+URLencode(name);
|
144
|
message+="&l="+(SokobanLevels.getIntrinsic()-(SokobanDatabase.BUILTIN_LEVELS-1));
|
145
|
message+="&s="+URLencode(getSMSC());
|
146
|
message+="&w="+(mLevel.length()/mCols);
|
147
|
message+="&c="+mCols;
|
148
|
message+="&p="+mLevel;
|
149
|
message+="&r="+run;
|
150
|
message+="&e="+SokobanCanvas.mVersionStr+"a";
|
151
|
}
|
152
|
else if(mode==DOWNLOADL)
|
153
|
{
|
154
|
message=URL+"/downloadl.cgi";
|
155
|
message+="?n="+URLencode(name);
|
156
|
message+="&l="+(SokobanLevels.getIntrinsic()-(SokobanDatabase.BUILTIN_LEVELS-1));
|
157
|
message+="&x="+SokobanLevels.bDrawnX1; //12 x
|
158
|
message+="&y="+SokobanLevels.bDrawnY2; //18
|
159
|
message+="&r="+run;
|
160
|
message+="&e="+SokobanCanvas.mVersionStr+"a";
|
161
|
}
|
162
|
|
163
|
String data = download(message);
|
164
|
|
165
|
if(mode==SUBMITR)
|
166
|
{
|
167
|
parseResponse(data);
|
168
|
fillData(data);
|
169
|
}
|
170
|
else if(mode==DOWNLOADR)
|
171
|
{
|
172
|
fillData(data);
|
173
|
SokobanCanvas.getMenu().downloadRecordsReady();
|
174
|
}
|
175
|
else if(mode==SUBMITL)
|
176
|
{
|
177
|
int numDownloaded = getResponseNum(data);
|
178
|
fillLevelsData(data);
|
179
|
SokobanCanvas.getMenu().downloadLevelsReady(numDownloaded);
|
180
|
SokobanLevels.getInstance().rollbackCreated();
|
181
|
}
|
182
|
else if(mode==DOWNLOADL)
|
183
|
{
|
184
|
int numDownloaded = getResponseNum(data);
|
185
|
fillLevelsData(data);
|
186
|
SokobanCanvas.getMenu().downloadLevelsReady(numDownloaded);
|
187
|
}
|
188
|
}
|
189
|
catch( IOException ioe )
|
190
|
{
|
191
|
if( mode==SUBMITR ) SokobanCanvas.setState(SokobanCanvas.STATE_FAIL);
|
192
|
if( mode==SUBMITL ) SokobanCanvas.setState(SokobanCanvas.STATE_FAIC);
|
193
|
if( mode==DOWNLOADR) SokobanCanvas.setState(SokobanCanvas.STATE_FAID);
|
194
|
if( mode==DOWNLOADL) SokobanCanvas.setState(SokobanCanvas.STATE_FAIE);
|
195
|
SokobanCanvas.setRepaint();
|
196
|
}
|
197
|
catch( SecurityException ioe )
|
198
|
{
|
199
|
SokobanCanvas.setState(SokobanCanvas.STATE_SECU);
|
200
|
SokobanCanvas.getMenu().comeBackTo( mode==SUBMITR ? SokobanCanvas.STATE_PLAY:SokobanCanvas.STATE_MAIN);
|
201
|
SokobanCanvas.setRepaint();
|
202
|
}
|
203
|
|
204
|
mRunning = false;
|
205
|
mode = IDLE;
|
206
|
}
|
207
|
|
208
|
///////////////////////////////////////////////////////////////////
|
209
|
|
210
|
private String getSMSC()
|
211
|
{
|
212
|
if( iso==null) iso = SokobanCanvas.getIso();
|
213
|
return iso;
|
214
|
}
|
215
|
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////
|
218
|
|
219
|
private int getResponseNum(String data)
|
220
|
{
|
221
|
int newline = data.indexOf('\n',1);
|
222
|
if( newline<0 ) newline = data.length();
|
223
|
|
224
|
int ret=-1;
|
225
|
|
226
|
try
|
227
|
{
|
228
|
ret= Integer.parseInt(data.substring(0, newline));
|
229
|
}
|
230
|
catch(NumberFormatException nfe)
|
231
|
{
|
232
|
Log.e(TAG_RECORDS, "exception trying to parse "+data);
|
233
|
}
|
234
|
|
235
|
return ret;
|
236
|
}
|
237
|
|
238
|
///////////////////////////////////////////////////////////////////
|
239
|
|
240
|
private void parseResponse(String data)
|
241
|
{
|
242
|
int responseNum = getResponseNum(data);
|
243
|
|
244
|
switch(responseNum)
|
245
|
{
|
246
|
case 0: SokobanCanvas.setState(SokobanCanvas.STATE_RECO);// success
|
247
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
248
|
db.setVeri(name);
|
249
|
submitLevelsList(lv);
|
250
|
break;
|
251
|
case -2: SokobanMenu.setAction(SokobanMenu.ACTION_SUBR);
|
252
|
SokobanCanvas.setState(SokobanCanvas.STATE_EXIS);// name exists
|
253
|
break;
|
254
|
case -3: // wrong hash
|
255
|
default: SokobanCanvas.setState(SokobanCanvas.STATE_FAIL);// other error
|
256
|
}
|
257
|
|
258
|
SokobanCanvas.setRepaint();
|
259
|
}
|
260
|
|
261
|
///////////////////////////////////////////////////////////////////
|
262
|
|
263
|
private int computeSubmitHash(String n, String v, String s, int lvl, int r)
|
264
|
{
|
265
|
byte[] raw;
|
266
|
int ret=0;
|
267
|
|
268
|
try { raw = n.getBytes("UTF-8"); }
|
269
|
catch(UnsupportedEncodingException ex) { raw = n.getBytes( ); }
|
270
|
|
271
|
for(int i=0;i<raw.length;i++) ret += i*(raw[i] <0 ? ((int)raw[i]+256):raw[i]);
|
272
|
|
273
|
try { raw = v.getBytes("UTF-8"); }
|
274
|
catch(UnsupportedEncodingException ex) { raw = v.getBytes( ); }
|
275
|
|
276
|
for(int i=0;i<raw.length;i++) ret += i*(raw[i] <0 ? ((int)raw[i]+256):raw[i]);
|
277
|
|
278
|
try { raw = s.getBytes("UTF-8"); }
|
279
|
catch(UnsupportedEncodingException ex) { raw = s.getBytes( ); }
|
280
|
|
281
|
for(int i=0;i<raw.length;i++) ret += i*(raw[i] <0 ? ((int)raw[i]+256):raw[i]);
|
282
|
|
283
|
int num=0, move, time;
|
284
|
SokobanLevel sl = SokobanLevels.getLevel(lvl);
|
285
|
if( sl!=null )
|
286
|
{
|
287
|
move = sl.getMyMoves();
|
288
|
time = sl.getMyTime();
|
289
|
ret += (lvl+1)*time;
|
290
|
ret += (lvl+2)*move;
|
291
|
}
|
292
|
|
293
|
for(int i=0; num<MAX_SUBMIT; i++)
|
294
|
{
|
295
|
if( i==lvl ) continue;
|
296
|
sl = SokobanLevels.getLevel(i);
|
297
|
if( sl==null ) break;
|
298
|
|
299
|
if( !sl.isSubmitted() )
|
300
|
{
|
301
|
move = sl.getMyMoves();
|
302
|
time = sl.getMyTime();
|
303
|
|
304
|
if( move<SokobanDatabase.INVALID )
|
305
|
{
|
306
|
ret += (i+1)*time;
|
307
|
ret += (i+2)*move;
|
308
|
num++;
|
309
|
}
|
310
|
}
|
311
|
}
|
312
|
|
313
|
ret += 41*r;
|
314
|
ret %= 541;
|
315
|
|
316
|
return ret<0 ? -ret:ret;
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////
|
320
|
|
321
|
private void fillLevelsData( String data )
|
322
|
{
|
323
|
int len = data.length();
|
324
|
int begin=-1 ,end;
|
325
|
|
326
|
while( begin<len )
|
327
|
{
|
328
|
end = data.indexOf('\n', begin+1);
|
329
|
if( end<0 ) end = len;
|
330
|
|
331
|
fillLevelsRow(data.substring(begin+1,end));
|
332
|
begin = end;
|
333
|
}
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////
|
337
|
|
338
|
public void fillLevelsRow(String row)
|
339
|
{
|
340
|
int s1 = row.indexOf(' ', 0);
|
341
|
int s2 = row.indexOf(' ',s1+1);
|
342
|
int s3 = row.indexOf(' ',s2+1);
|
343
|
int s4 = row.indexOf(' ',s3+1);
|
344
|
int s5 = row.indexOf(' ',s4+1);
|
345
|
int s6 = row.length();
|
346
|
|
347
|
if( s6>s5 && s5>s4 & s4>s3 && s3>s2 && s2>s1 && s1>0 )
|
348
|
{
|
349
|
try
|
350
|
{
|
351
|
int level= Integer.parseInt( row.substring( 0,s1) );
|
352
|
String n = row.substring(s1+1,s2);
|
353
|
String c = row.substring(s2+1,s3);
|
354
|
// int rows = Integer.parseInt( row.substring(s3+1,s4) );
|
355
|
int cols = Integer.parseInt( row.substring(s4+1,s5) );
|
356
|
String p = row.substring(s5+1,s6);
|
357
|
|
358
|
SokobanLevel sl = new SokobanLevel(n,c,SokobanDatabase.INVALID, SokobanDatabase.INVALID,null,false,cols,p);
|
359
|
mLevels.addLevel(sl, SokobanDatabase.BUILTIN_LEVELS+level-1);
|
360
|
sl.setDirty();
|
361
|
}
|
362
|
catch( Exception ex ) { System.out.println("Exception trying to fillLevelsRow: "+ex.toString()); }
|
363
|
}
|
364
|
}
|
365
|
|
366
|
///////////////////////////////////////////////////////////////////
|
367
|
|
368
|
private void fillData( String data )
|
369
|
{
|
370
|
int len = data.length();
|
371
|
int begin=-1 ,end;
|
372
|
|
373
|
while( begin<len )
|
374
|
{
|
375
|
end = data.indexOf('\n', begin+1);
|
376
|
if( end<0 ) end = len;
|
377
|
|
378
|
fillRow(data.substring(begin+1,end));
|
379
|
begin = end;
|
380
|
}
|
381
|
|
382
|
mDirtyRecords = false;
|
383
|
}
|
384
|
|
385
|
///////////////////////////////////////////////////////////////////
|
386
|
|
387
|
public void fillRow(String row)
|
388
|
{
|
389
|
int s1 = row.indexOf(' ', 0);
|
390
|
int s2 = row.indexOf(' ',s1+1);
|
391
|
int s3 = row.indexOf(' ',s2+1);
|
392
|
int s4 = row.indexOf(' ',s3+1);
|
393
|
int s5 = row.indexOf(' ',s4+1);
|
394
|
int s6 = row.length();
|
395
|
|
396
|
if( s6>s5 && s5>s4 & s4>s3 && s3>s2 && s2>s1 && s1>0 )
|
397
|
{
|
398
|
try
|
399
|
{
|
400
|
int l = Integer.parseInt(row.substring( 0,s1));
|
401
|
int m = Integer.parseInt(row.substring(s1+1,s2));
|
402
|
int t = Integer.parseInt(row.substring(s2+1,s3));
|
403
|
int p = Integer.parseInt(row.substring(s3+1,s4));
|
404
|
String n = row.substring(s4+1,s5);
|
405
|
String c = row.substring(s5+1,s6);
|
406
|
|
407
|
mLevels.fillLevelInfo(l,m,t,p,n,c);
|
408
|
}
|
409
|
catch( Exception ex ) { Log.e(TAG_RECORDS, "Exception trying to fillRow: "+ex.toString()); }
|
410
|
}
|
411
|
}
|
412
|
|
413
|
///////////////////////////////////////////////////////////////////
|
414
|
|
415
|
public void downloadLevels()
|
416
|
{
|
417
|
mode = DOWNLOADL;
|
418
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
419
|
name = db.getName();
|
420
|
start();
|
421
|
}
|
422
|
|
423
|
///////////////////////////////////////////////////////////////////
|
424
|
|
425
|
public void downloadRecords()
|
426
|
{
|
427
|
if( mDirtyRecords )
|
428
|
{
|
429
|
mode = DOWNLOADR;
|
430
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
431
|
name = db.getName();
|
432
|
veri = db.getVeri();
|
433
|
start();
|
434
|
}
|
435
|
}
|
436
|
|
437
|
///////////////////////////////////////////////////////////////////
|
438
|
|
439
|
public boolean submitRecord(int lvl)
|
440
|
{
|
441
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
442
|
name = db.getName();
|
443
|
if( name==null || name.length()==0 ) return false;
|
444
|
veri = db.getVeri();
|
445
|
mode = SUBMITR;
|
446
|
lv = lvl;
|
447
|
|
448
|
start();
|
449
|
return true;
|
450
|
}
|
451
|
|
452
|
///////////////////////////////////////////////////////////////////
|
453
|
|
454
|
public boolean submitLevel(int cols, String level)
|
455
|
{
|
456
|
SokobanDatabase db = SokobanDatabase.getInstance();
|
457
|
name = db.getName();
|
458
|
if( name==null || name.length()==0 ) return false;
|
459
|
veri = db.getVeri();
|
460
|
mode = SUBMITL;
|
461
|
mCols = cols;
|
462
|
mLevel= level;
|
463
|
|
464
|
start();
|
465
|
return true;
|
466
|
}
|
467
|
|
468
|
///////////////////////////////////////////////////////////////////
|
469
|
|
470
|
public void abortNetworkTransaction()
|
471
|
{
|
472
|
mRunning = false;
|
473
|
}
|
474
|
|
475
|
///////////////////////////////////////////////////////////////////
|
476
|
|
477
|
public boolean isDirtyRecords()
|
478
|
{
|
479
|
return mDirtyRecords;
|
480
|
}
|
481
|
|
482
|
///////////////////////////////////////////////////////////////////
|
483
|
|
484
|
public void setDirty()
|
485
|
{
|
486
|
mDirtyRecords=true;
|
487
|
}
|
488
|
|
489
|
///////////////////////////////////////////////////////////////////
|
490
|
|
491
|
private static String URLencode(String s)
|
492
|
{
|
493
|
if( s==null ) return "";
|
494
|
|
495
|
StringBuilder sbuf = new StringBuilder();
|
496
|
int len = s.length();
|
497
|
|
498
|
for (int i = 0; i < len; i++)
|
499
|
{
|
500
|
int ch = s.charAt(i);
|
501
|
|
502
|
if ('A' <= ch && ch <= 'Z') sbuf.append((char)ch);
|
503
|
else if ('a' <= ch && ch <= 'z') sbuf.append((char)ch);
|
504
|
else if ('0' <= ch && ch <= '9') sbuf.append((char)ch);
|
505
|
else if (ch == ' ' ) sbuf.append('+');
|
506
|
else if (ch == '-' || ch == '_'
|
507
|
|| ch == '.' || ch == '!'
|
508
|
|| ch == '~' || ch == '*'
|
509
|
|| ch == '\'' || ch == '('
|
510
|
|| ch == ')' ) sbuf.append((char)ch);
|
511
|
else if (ch <= 0x007f) sbuf.append(hex[ch]);
|
512
|
else if (ch <= 0x07FF)
|
513
|
{
|
514
|
sbuf.append(hex[0xc0 | (ch >> 6)]);
|
515
|
sbuf.append(hex[0x80 | (ch & 0x3F)]);
|
516
|
}
|
517
|
else
|
518
|
{
|
519
|
sbuf.append(hex[0xe0 | (ch >> 12)]);
|
520
|
sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
|
521
|
sbuf.append(hex[0x80 | (ch & 0x3F)]);
|
522
|
}
|
523
|
}
|
524
|
|
525
|
return sbuf.toString();
|
526
|
}
|
527
|
|
528
|
///////////////////////////////////////////////////////////////////
|
529
|
|
530
|
private static void submitLevelsList(int lvl)
|
531
|
{
|
532
|
int num=0;
|
533
|
SokobanLevel sl = SokobanLevels.getLevel(lvl);
|
534
|
if( sl!=null )
|
535
|
{
|
536
|
sl.setSubmitted(true);
|
537
|
sl.setDirty();
|
538
|
}
|
539
|
|
540
|
for(int i=0; num<MAX_SUBMIT; i++)
|
541
|
{
|
542
|
if( i==lvl ) continue;
|
543
|
sl = SokobanLevels.getLevel(i);
|
544
|
if( sl==null ) break;
|
545
|
|
546
|
if( !sl.isSubmitted() && sl.getMyMoves()<SokobanDatabase.INVALID )
|
547
|
{
|
548
|
sl.setSubmitted(true);
|
549
|
sl.setDirty();
|
550
|
num++;
|
551
|
}
|
552
|
}
|
553
|
}
|
554
|
|
555
|
///////////////////////////////////////////////////////////////////
|
556
|
|
557
|
private static String generateMovesList(int lvl)
|
558
|
{
|
559
|
int move, num=0;
|
560
|
SokobanLevel sl = SokobanLevels.getLevel(lvl);
|
561
|
String ret= (sl==null ? "" : sl.getMyMoves()+"");
|
562
|
|
563
|
for(int i=0; num<MAX_SUBMIT; i++)
|
564
|
{
|
565
|
if( i==lvl ) continue;
|
566
|
sl = SokobanLevels.getLevel(i);
|
567
|
if( sl==null ) break;
|
568
|
|
569
|
if( !sl.isSubmitted() )
|
570
|
{
|
571
|
move = sl.getMyMoves();
|
572
|
|
573
|
if( move<SokobanDatabase.INVALID )
|
574
|
{
|
575
|
ret += (","+move);
|
576
|
num++;
|
577
|
}
|
578
|
}
|
579
|
}
|
580
|
|
581
|
return ret;
|
582
|
}
|
583
|
|
584
|
///////////////////////////////////////////////////////////////////
|
585
|
|
586
|
private static String generateTimesList(int lvl)
|
587
|
{
|
588
|
int time, num=0;
|
589
|
SokobanLevel sl = SokobanLevels.getLevel(lvl);
|
590
|
String ret= (sl==null ? "" : sl.getMyTime()+"");
|
591
|
|
592
|
for(int i=0; num<MAX_SUBMIT; i++)
|
593
|
{
|
594
|
if( i==lvl ) continue;
|
595
|
sl = SokobanLevels.getLevel(i);
|
596
|
if( sl==null ) break;
|
597
|
|
598
|
if( !sl.isSubmitted() )
|
599
|
{
|
600
|
time = sl.getMyTime();
|
601
|
|
602
|
if( time<SokobanDatabase.INVALID )
|
603
|
{
|
604
|
ret += (","+time);
|
605
|
num++;
|
606
|
}
|
607
|
}
|
608
|
}
|
609
|
|
610
|
return ret;
|
611
|
}
|
612
|
|
613
|
///////////////////////////////////////////////////////////////////
|
614
|
|
615
|
private static String generateLevelsList(int lvl)
|
616
|
{
|
617
|
String ret=lvl+"";
|
618
|
SokobanLevel sl;
|
619
|
int num=0;
|
620
|
|
621
|
for(int i=0; num<MAX_SUBMIT; i++)
|
622
|
{
|
623
|
if( i==lvl ) continue;
|
624
|
sl = SokobanLevels.getLevel(i);
|
625
|
if( sl==null ) break;
|
626
|
|
627
|
if( !sl.isSubmitted() && sl.getMyMoves()<SokobanDatabase.INVALID )
|
628
|
{
|
629
|
ret+=(","+i);
|
630
|
num++;
|
631
|
}
|
632
|
}
|
633
|
|
634
|
return ret;
|
635
|
}
|
636
|
|
637
|
|
638
|
///////////////////////////////////////////////////////////////////
|
639
|
|
640
|
private String download(String url) throws IOException, SecurityException
|
641
|
{
|
642
|
URL connectURL = new URL(url);
|
643
|
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
|
644
|
|
645
|
conn.setDoInput(true);
|
646
|
conn.setDoOutput(true);
|
647
|
conn.setRequestMethod("GET");
|
648
|
conn.connect();
|
649
|
conn.getOutputStream().flush();
|
650
|
|
651
|
InputStream is=null;
|
652
|
try
|
653
|
{
|
654
|
is = new BufferedInputStream(conn.getInputStream());
|
655
|
int ch;
|
656
|
StringBuffer sb = new StringBuffer();
|
657
|
|
658
|
while( ( ch = is.read() ) != -1 )
|
659
|
{
|
660
|
sb.append( (char)ch );
|
661
|
}
|
662
|
return sb.toString();
|
663
|
}
|
664
|
catch(Exception e)
|
665
|
{
|
666
|
Log.e(TAG_RECORDS, "biffed it getting HTTPResponse");
|
667
|
}
|
668
|
finally
|
669
|
{
|
670
|
try
|
671
|
{
|
672
|
if (is != null)
|
673
|
is.close();
|
674
|
}
|
675
|
catch (Exception e) {}
|
676
|
}
|
677
|
|
678
|
return "";
|
679
|
}
|
680
|
|
681
|
///////////////////////////////////////////////////////////////////
|
682
|
// end of SokobanRecords
|
683
|
}
|