Package org.elip.stewiemaze.shared.entities

Examples of org.elip.stewiemaze.shared.entities.Player


public class PlayerService {
 
 
  public static Player createPlayer(String nickname, String email, String password, Long scoreValue, boolean activated) {
    nickname = removeSpaces(nickname);
    Player player = new Player();
    player.setEmail(email);
    player.setNickname(nickname);
    player.setPassword(password);
    player.setFacebookUser("false");
    player.setAccessToken(null);
    player.setHighscore(scoreValue);
    player.setUserId(null);
    if (activated) {
      player.setActivated("true");
    }
    else {
      player.setActivated("false");
    }
    return player;
  }
View Full Code Here


    return player;
  }
 
  public static Player createFacebookPlayer(String nickname, String userId,String email ,Long scoreValue) {
    nickname = removeSpaces(nickname);
    Player player = new Player();
    player.setEmail(email);
    player.setNickname(nickname);
    player.setHighscore(scoreValue);
    player.setActivated("false");
    player.setFacebookUser("true");
    player.setUserId(userId);
    player.setAccessToken(null);
    player.setPassword(null);
    return player;
  }
View Full Code Here

   */
  private static final long serialVersionUID = 1L;

  @Override
  public Player retrievePlayer(String nickname, String password) {
    Player player = DatastoreHelper.verifyUsernameAndPassword(nickname, password);
    if (player != null) return player;
    return null;
  }
View Full Code Here

  @Override
  public Player retrieveFacebookPlayer(String nickname) {
   
    Logger logger = Logger.getLogger(DatastoreServiceImpl.class.getName());
    logger.fine("Retrieving Player with nickname " + nickname + " from database");
    Player player = DatastoreHelper.getPlayer(nickname);
    logger.fine("got player " + player + " from database");
    if (player != null) return player;
    return null;
  }
View Full Code Here

    catch (FacebookOAuthException e) {
      // accesToken is no longer valid, user removed this app from his preferences
      return null;
    }
   
    Player player = DatastoreHelper.getPlayer(username);
    if (player == null) {
      User user = FacebookHelper.getUser(accessToken);
      Player newFacebookPlayer = PlayerService.createFacebookPlayer(username, user.getId(), user.getEmail(), new Long(0));
      RegisterPlayerService.registerPlayer(newFacebookPlayer);
      DatastoreHelper.updateAccessToken(username, accessToken);
      FacebookHelper.postMessageToWall(username, "just registered to stewiemaze");
    }
    return username;
View Full Code Here

  }
 
  @SuppressWarnings("unused")
  public static void postMessageToWall(String username, String message) {
   
    Player player = DatastoreHelper.getPlayer(username);
   
    Long realScore = player.getHighscore();
   
    String accessToken = player.getAccessToken();
    String score = player.getHighscore() + "";
   
    FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
    FacebookType postScoreToWallResponse = facebookClient.publish("me/feed", FacebookType.class,
        Parameter.with("message", message));
   
View Full Code Here

     
      /* Remove this cookie, it will be replace with the "highscore" cookie */
      CookieUtils.eraseCookie(req, resp, "tempScore");
     
      /* Create a regular player */
      Player player = PlayerService.createPlayer(name, email, password, score, false);
     
      /* Save player to the database, not activated yet */
      RegisterPlayerService.registerPlayer(player);
     
      /* Add cookies so that uppon return to the application the user will be identifeid */
 
View Full Code Here

      accessToken = accessToken.split("&")[0];
     
      /* get the user of this token */
      String username = FacebookHelper.getUsername(accessToken);
     
      Player player = DatastoreHelper.getPlayer(username);
     
      if (player != null) {
        DatastoreHelper.updateAccessToken(username, accessToken);
      logger.fine("posting score " + player.getHighscore() + " for user " + player.getNickname());
        FacebookHelper.postScoreToWall(username, player.getHighscore() + "");
        try {
          logger.fine("publishing score " + player.getHighscore() + " for user " + player.getNickname());
          FacebookHelper.publishScore(player.getHighscore() + "", player.getUserId());
        }
        catch (RuntimeException e) {
          logger.fine("Caught runtime exception while publishing score" + e);
        }
      }
View Full Code Here

   
    /* retrieve the score from the request */
    Cookie score = CookieUtils.getCookie(req, "tempScore");
   
    /* Register the player to the database, still with no permissions */
    Player player = PlayerService.createFacebookPlayer(name, userId,email, Long.valueOf(score.getValue()));
    RegisterPlayerService.registerPlayer(player);
   
    /* delete this cookie since it is now saved in the database */
    CookieUtils.eraseCookie(req, resp, "tempScore");
   
View Full Code Here

 
  public static Player getPlayer(String nickname) {
    nickname = removeSpaces(nickname);
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      Player player = pm.getObjectById(Player.class, nickname);
      return player;
    }
    catch (JDOObjectNotFoundException e) {
      return null;
    }
View Full Code Here

TOP

Related Classes of org.elip.stewiemaze.shared.entities.Player

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.