Exemplo n.º 1
0
  void deleteGame() {

    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            mancalaService.deleteMatch(
                userId,
                matchId,
                new AsyncCallback<Void>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert(messages.deleteMatchError());
                  }

                  @Override
                  public void onSuccess(Void result) {
                    // secured against xsrf attacks
                    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
                    XsrfTokenServiceAsync xsrf =
                        (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
                    ((ServiceDefTarget) xsrf)
                        .setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
                    xsrf.getNewXsrfToken(
                        new AsyncCallback<XsrfToken>() {
                          public void onSuccess(XsrfToken token) {
                            ((HasRpcToken) mancalaService).setRpcToken(token);
                            mancalaService.loadMatches(userId, loadMatchesCallback);
                          }

                          public void onFailure(Throwable caught) {
                            Window.alert("Error retrieving xsrf token! Please try again later.");
                          }
                        });
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
    //
    // graphics.setTurnLabelText(messages.startNewGame());
    // graphics.setSideLabelText("");
    // graphics.setOpponentNameLabelText("");
    // matchId = null;
    // graphics.setStartDateLabelText("");
    // clearBoard();
  }
Exemplo n.º 2
0
  public void updateMatchList() {
    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            mancalaService.loadMatches(userId, loadMatchesCallback);
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }
Exemplo n.º 3
0
  void startAiMatchAsNorth() {
    aiMatch = true;
    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);

            mancalaService.registerAiMatch(
                userId,
                false,
                new AsyncCallback<String>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert(messages.serverError());
                  }

                  @Override
                  public void onSuccess(String result) {
                    String[] tokens = result.split("#");

                    graphics.setTurnLabelText(messages.opponentsTurn());
                    graphics.setOpponentNameLabelText(messages.opponent() + "AI");
                    matchId = Long.valueOf(tokens[1]);
                    graphics.setStartDateLabelText(getCustomLocalDate(Long.valueOf(tokens[3])));
                    graphics.setSideLabelText(messages.playOnNorthSide());

                    setUsersSide(PlayerColor.N);
                    setState(new State());
                    disableBoard();
                    makeAiMove();
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }
  public void deleteProject() {
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {

          @Override
          public void onFailure(Throwable caught) {
            try {
              throw caught;
            } catch (RpcTokenException e) {
              // Can be thrown for several reasons:
              //   - duplicate session cookie, which may be a sign of a cookie
              //     overwrite attack
              //   - XSRF token cannot be generated because session cookie isn't
              //     present
            } catch (Throwable e) {
              // unexpected
            }
          }

          @Override
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) layerRemote).setRpcToken(token);
            layerRemote.deleteProject(
                getSelectionModel().getSelectedItem().getId(),
                new AsyncCallback<Object>() {

                  @Override
                  public void onFailure(Throwable caught) {}

                  @Override
                  public void onSuccess(Object result) {
                    GeoPlatformMessage.infoMessage(
                        LayerModuleConstants.INSTANCE.deleteProjectTitleText(),
                        LayerModuleMessages.INSTANCE.GPProjectSearchPanel_projectRemovedMessage(
                            getSelectionModel().getSelectedItem().getName()));
                    store.remove(getSelectionModel().getSelectedItem());
                  }
                });
          }
        });
  }
Exemplo n.º 5
0
  public void sendMoveToServerAI(Integer chosenIndex, State state) {
    final Integer fChosenIndex = chosenIndex;
    final State fState = state;
    final Graphics graphicsForAnim = (Graphics) graphics;

    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            mancalaService.saveAiMove(
                matchId,
                fChosenIndex + "",
                State.serialize(fState),
                new AsyncCallback<Void>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert(messages.serverError());
                  }

                  @Override
                  public void onSuccess(Void result) {
                    if (fState.getWhoseTurn().equals(getUsersSide().getOpposite())) {
                      graphics.setAiMovesLabelTextTriggerAiMove(
                          messages.aiMakesMove(), graphicsForAnim);
                    }

                    updateMatchList();
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }
Exemplo n.º 6
0
  public void sendMoveToServer(Integer chosenIndex, String stateString) {
    final Integer fChosenIndex = chosenIndex;
    final String fStateString = stateString;

    if (aiMatch) {
      sendMoveToServerAI(chosenIndex, State.deserialize(stateString));
      return;
    }

    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            mancalaService.makeMove(
                userId,
                matchId,
                fChosenIndex,
                fStateString,
                new AsyncCallback<Void>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert("Server error!");
                  }

                  @Override
                  public void onSuccess(Void result) {
                    // updateMatchList();
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }
Exemplo n.º 7
0
  private void startGame(String sendPlayerId, String sendOpponentId, String sendOpponentName) {
    final String fSendPlayerId = sendPlayerId;
    final String fSendOpponentId = sendOpponentId;
    final String fSendOpponentName = sendOpponentName;

    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            // rematch can be treated like a new emailgame
            mancalaService.startGame(
                fSendPlayerId,
                fSendOpponentId,
                fSendOpponentName,
                new AsyncCallback<Boolean>() {

                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert(messages.serverError());
                  }

                  @Override
                  public void onSuccess(Boolean result) {
                    if (result == false) {
                      Window.alert(messages.opponent404(fSendOpponentName));
                    }
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }
Exemplo n.º 8
0
  void changeGame(Long changeToThisMatchId) {
    aiMatch = false;

    final Long matchIDFromList = changeToThisMatchId;
    // secured against xsrf attacks
    // see http://www.gwtproject.org/doc/latest/DevGuideSecurityRpcXsrf.html
    XsrfTokenServiceAsync xsrf = (XsrfTokenServiceAsync) GWT.create(XsrfTokenService.class);
    ((ServiceDefTarget) xsrf).setServiceEntryPoint(GWT.getModuleBaseURL() + "gwt/xsrf");
    xsrf.getNewXsrfToken(
        new AsyncCallback<XsrfToken>() {
          public void onSuccess(XsrfToken token) {
            ((HasRpcToken) mancalaService).setRpcToken(token);
            mancalaService.changeMatch(
                userId,
                matchIDFromList,
                new AsyncCallback<String>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert(messages.loadMatchError());
                  }

                  @Override
                  public void onSuccess(String result) {
                    if (!result.trim().equals("noMatch")) {

                      MatchInfo mI = MatchInfo.deserialize(result);

                      matchId = Long.valueOf(mI.getMatchId());
                      State newMatchState = State.deserialize(mI.getState());

                      String opponentNameFromServer,
                          opponentIdFromServer,
                          opponentRating,
                          opponentRD;
                      if (mI.getNorthPlayerId().equals(userId)) {
                        opponentNameFromServer = mI.getSouthPlayerName();
                        opponentIdFromServer = mI.getSouthPlayerId();
                        opponentRating = mI.getSouthPlayerRating();
                        opponentRD = mI.getSouthPlayerRD();
                      } else {
                        opponentNameFromServer = mI.getNorthPlayerName();
                        opponentIdFromServer = mI.getNorthPlayerId();
                        opponentRating = mI.getNorthPlayerRating();
                        opponentRD = mI.getNorthPlayerRD();
                      }

                      if (opponentNameFromServer.equals("AI")) {
                        aiMatch = true;

                        graphics.setOpponentNameLabelText("AI");
                      } else {
                        graphics.setOpponentNameLabelText(
                            messages.opponent()
                                + opponentNameFromServer
                                + " ("
                                + opponentRating
                                + "|"
                                + opponentRD
                                + ")");
                        opponentId = opponentIdFromServer;
                        opponentName = opponentNameFromServer;
                      }

                      graphics.setStartDateLabelText(
                          "Start: " + getCustomLocalDate(Long.valueOf(mI.getStartDate())));
                      PlayerColor usersSide;
                      if (mI.getUserIdOfWhoseTurnItIs().equals(userId)) {
                        graphics.setTurnLabelText(messages.itsYourTurn());
                        usersSide = newMatchState.getWhoseTurn();
                      } else {
                        graphics.setTurnLabelText(messages.turnOfOpponent(opponentNameFromServer));
                        usersSide = newMatchState.getWhoseTurn().getOpposite();
                      }
                      setUsersSide(usersSide);
                      if (usersSide.isNorth())
                        graphics.setSideLabelText(messages.playOnNorthSide());
                      else graphics.setSideLabelText(messages.playOnSouthSide());
                      setState(newMatchState);

                      if (mI.getUserIdOfWhoseTurnItIs()
                          .equals("AI")) // Can be caused due to un-updated AI turn
                      makeAiMove();
                    }
                  }
                });
          }

          public void onFailure(Throwable caught) {
            Window.alert("Error retrieving xsrf token! Please try again later.");
          }
        });
  }