Check-in modifications made by HGM so far
[capablanca.git] / lasker-2.2.3 / src / obsproc.c
index 952a6de..3a7a990 100644 (file)
@@ -422,7 +422,7 @@ int com_moves(int p, param_list param)
       g = pp->game;
     } else if (pp->num_observe) {
       for (g = 0; g < pp->num_observe; g++) {
-       pprintf(p, "%s\n", movesToString(pp->observe_list[g], 0));
+       pprintf_noformat(p, "%s\n", movesToString(pp->observe_list[g], 0));
       }
       return COM_OK;
     } else {
@@ -444,7 +444,7 @@ int com_moves(int p, param_list param)
     pprintf(p, "Sorry, that is a private game.\n");
     return COM_OK;
   }
-  pprintf(p, "%s\n", movesToString(g, 0));     /* pgn may break interfaces? */
+  pprintf_noformat(p, "%s\n", movesToString(g, 0));    /* pgn may break interfaces? */
   return COM_OK;
 }
 
@@ -455,8 +455,13 @@ int com_mailmoves(int p, param_list param)
   int p1;
   char subj[81];
 
-  if (!CheckPFlag(p, PFLAG_REG)) {
-    pprintf (p,"Unregistered players cannot use mailmoves.\n");
+  if (param[1].type == TYPE_NULL) {
+    if (!CheckPFlag(p, PFLAG_REG)) {
+      pprintf (p,"Unregistered players must specify their e-mail address.\n");
+      return COM_OK;
+    }
+  } else if(!safestring(param[1].val.string)) {
+    pprintf (p,"Bad e-mail address.\n");
     return COM_OK;
   }
 
@@ -481,7 +486,9 @@ int com_mailmoves(int p, param_list param)
     return COM_OK;
   }
   sprintf(subj, "FICS game report %s vs %s", game_globals.garray[g].white_name, game_globals.garray[g].black_name);
-  if (mail_string_to_user(p, subj,
+  if (param[1].type == TYPE_NULL ? mail_string_to_user(p, subj,
+                          movesToString(g, CheckPFlag(p, PFLAG_PGN))) :
+               mail_string_to_address(param[1].val.string, subj,
                           movesToString(g, CheckPFlag(p, PFLAG_PGN)))) {
     pprintf(p, "Moves NOT mailed, perhaps your address is incorrect.\n");
   } else {
@@ -627,6 +634,7 @@ void ExamineScratch(int p,  param_list param,int setup)
     pprintf(p, "Loading from catagory: %s, board: %s.\n", category, board);
   }
 
+  game_globals.garray[g].FENstartPos[0] = 0; // [HGM] new shuffle game
   if (setup) {
     board_clear(&game_globals.garray[g].game_state);
     game_globals.garray[g].status = GAME_SETUP;
@@ -667,6 +675,7 @@ static int ExamineStored(FILE * fp, int p, char type)
   gg = &game_globals.garray[g];
   category[0] = '\0';
   board[0] = '\0';
+  game_globals.garray[g].FENstartPos[0] = 0; // [HGM] make new shuffle for now
   if (board_init(g,&gg->game_state, category, board)) {
     pprintf(p, "PROBLEM LOADING BOARD. Examine Aborted.\n");
     d_printf( "CHESSD: PROBLEM LOADING BOARD %s %s. Examine Aborted.\n",
@@ -683,6 +692,18 @@ static int ExamineStored(FILE * fp, int p, char type)
       game_remove(g);
       return -1;
     }
+
+    // [HGM] OK, we retreived the game info, which includes variant name as "category/board"
+    // So now we set up the board again, this time for the proper variant (and proper shuffle)
+    sscanf(gg->variant, "%s/%s", category, board);
+    if(category[0] && !board[0]) strcpy(board, "0");
+    if (board_init(g,&gg->game_state, category, board)) {
+      pprintf(p, "PROBLEM LOADING BOARD. Examine Aborted.\n");
+      d_printf( "CHESSD: PROBLEM LOADING BOARD %s %s. Examine Aborted.\n",
+              category, board);
+      game_remove(g);
+      return -1;
+    }
   } else if (ReadGameAttrs(fp, g) < 0) {
     pprintf(p, "Gamefile is corrupt; please notify an admin.\n");
     game_remove(g);
@@ -702,7 +723,6 @@ static int ExamineStored(FILE * fp, int p, char type)
 
   pp->side = WHITE;    /* oh well... */
   pp->game = g;
-
   send_boards(g);
   if (CheckPFlag(p, PFLAG_OPEN)) /* was open */
     announce_notavail(p);
@@ -1043,9 +1063,14 @@ static void stored_mail_moves(int p, int mail, param_list param)
   char fileName2[MAX_FILENAME_SIZE];
   FILE* fpGame;
   
- if (mail && !CheckPFlag(p, PFLAG_REG)) {
-    pprintf (p,"Unregistered players cannot use mailstored.\n");
-    return;
+  if (param[2].type == TYPE_NULL) {
+    if (!CheckPFlag(p, PFLAG_REG)) {
+      pprintf (p,"Unregistered players must specify their e-mail address.\n");
+      return COM_OK;
+    }
+  } else if(!safestring(param[2].val.string)) {
+    pprintf (p,"Bad e-mail address.\n");
+    return COM_OK;
   }
 
   if (!FindPlayer(p, param[0].val.word, &wp, &wconnected))
@@ -1125,13 +1150,15 @@ static void stored_mail_moves(int p, int mail, param_list param)
           } else {
             sprintf(subj, "FICS adjourned game %s vs %s", game_globals.garray[g].white_name, game_globals.garray[g].black_name);
           }
-        if (mail_string_to_user(p, subj,
+        if (param[2].type == TYPE_NULL ? mail_string_to_user(p, subj,
+                                movesToString(g, CheckPFlag(p, PFLAG_PGN))) :
+                        mail_string_to_address(param[2].val.string, subj,
                                 movesToString(g, CheckPFlag(p, PFLAG_PGN))))
          pprintf(p, "Moves NOT mailed, perhaps your address is incorrect.\n");
         else
          pprintf(p, "Moves mailed.\n");
       } else {
-        pprintf(p, "%s\n", movesToString(g, 0));
+        pprintf_noformat(p, "%s\n", movesToString(g, 0));
       } /* Do smoves */
     }
   }