1
1
package entralinked .network .http .pgl ;
2
2
3
+ import java .io .ByteArrayInputStream ;
3
4
import java .io .File ;
4
5
import java .io .FileInputStream ;
5
6
import java .io .IOException ;
@@ -355,6 +356,12 @@ private void handleMemoryLink(PglRequest request, Context ctx) throws IOExceptio
355
356
return ;
356
357
}
357
358
359
+ // Version null check because this can happen in specific cases
360
+ if (player .getGameVersion () == null ) {
361
+ writeStatusCode (outputStream , 5 ); // No game save data exists for this Game Sync ID
362
+ return ;
363
+ }
364
+
358
365
// Check if the save file belongs to Black or White
359
366
if (player .getGameVersion ().isVersion2 ()) {
360
367
writeStatusCode (outputStream , 10 ); // Not a Black or White save
@@ -485,13 +492,9 @@ private void handleUploadSaveData(PglRequest request, Context ctx) throws IOExce
485
492
/**
486
493
* POST handler for {@code /dsio/gw?p=account.create.upload}
487
494
*/
488
- private void handleCreateAccount (PglRequest request , Context ctx ) throws IOException {
489
- // It sends the entire save file, but we just skip through it because we don't need anything from it here
490
- ServletInputStream inputStream = ctx .req ().getInputStream ();
491
-
492
- while (!inputStream .isFinished ()) {
493
- inputStream .read ();
494
- }
495
+ private void handleCreateAccount (PglRequest request , Context ctx ) throws IOException {
496
+ // Have to read all the bytes first for some reason
497
+ byte [] bytes = ctx .bodyAsBytes ();
495
498
496
499
// Prepare response
497
500
LEOutputStream outputStream = new LEOutputStream (ctx .outputStream ());
@@ -509,11 +512,19 @@ private void handleCreateAccount(PglRequest request, Context ctx) throws IOExcep
509
512
}
510
513
511
514
// Try to register player
512
- if (playerManager .registerPlayer (request .gameSyncId ()) == null ) {
515
+ Player player = playerManager .registerPlayer (request .gameSyncId (), request .gameVersion ());
516
+
517
+ if (player == null ) {
513
518
writeStatusCode (outputStream , 3 ); // Registration error
514
519
return ;
515
520
}
516
521
522
+ // Try to store save data
523
+ if (!playerManager .storePlayerGameSaveFile (player , new ByteArrayInputStream (bytes ))) {
524
+ writeStatusCode (outputStream , 4 ); // Game save data IO error
525
+ return ;
526
+ }
527
+
517
528
// Write status code
518
529
writeStatusCode (outputStream , 0 );
519
530
}
@@ -534,7 +545,8 @@ private void handleCreateData(PglRequest request, Context ctx) throws IOExceptio
534
545
}
535
546
536
547
// Try to register player
537
- if (playerManager .registerPlayer (gameSyncId ) == null ) {
548
+ // Regrettably, this request does not contain game save & version data.
549
+ if (playerManager .registerPlayer (gameSyncId , null ) == null ) {
538
550
writeStatusCode (outputStream , 3 ); // Registration error
539
551
return ;
540
552
}
0 commit comments