Package de.creepsmash.server.model

Examples of de.creepsmash.server.model.Player


      EntityManager entityManager =
        PersistenceManager.getInstance().getEntityManager();
      EntityTransaction entityTransaction = entityManager
        .getTransaction();
      entityTransaction.begin();   
      Player player = new Player();
      player.setName(playerName);
      player.setPassword(password);
      player.setEmail(email);
      player.setElopoints(500);
      player.setOldElopoints(500);
      entityManager.persist(player);
      entityManager.flush();
      entityTransaction.commit();
    } catch (Exception e) {
      logger.error("registration failed");
View Full Code Here


    EntityManager entityManager =
      PersistenceManager.getInstance().getEntityManager();
    EntityTransaction entityTransaction = entityManager
      .getTransaction();
    entityTransaction.begin();   
    Player player = entityManager.find(Player.class, playerName);
    if (player != null) {
      if ((oldPassword != null) && (oldPassword.length() > 0)
          && (password != null) && (password.length() > 0)) {
        if (player.getPassword().equals(oldPassword)) {
          player.setPassword(password);
          update = true;
        }
      }
      if ((mail != null) && (mail.length() > 0)) {
        player.setEmail(mail);
        update = true;
      } else {
        logger.error("password not changed, "
             + "because old password was wrong");
      }
View Full Code Here

    IConstants.ResponseType responseType = IConstants.ResponseType.failed;
    EntityManager entityManager =
      PersistenceManager.getInstance().getEntityManager();
    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();
    Player player = entityManager.find(Player.class, playerName);
    if (player != null) {
      entityManager.remove(player);
      responseType = IConstants.ResponseType.ok;
    }
    entityTransaction.commit();
View Full Code Here

   * @return the lobby, of null if the login failed
   */
  public Lobby login(String playerName, String password) {
   
   
    Player player = null;
     
    EntityManager entityManager = PersistenceManager.getInstance().getEntityManager();
   

    try {
      player = entityManager.find(Player.class, playerName);
    } catch(PersistenceException e){
      logger.info("Connection lost ? " + e.getMessage());
    }
   
    if ((player != null)) {
      for (String UserName : this.loggedIn) {
        if (UserName.equalsIgnoreCase(player.getName())) {
          logger.info(player.getName() + " tried to log in twice");
          return null;
        }
      }
    }
   
    if ((player != null) && (player.getPassword().equals(password)) && !player.isBlocked()) {
      this.loggedIn.add(player.getName());
      logger.info(player.getName() + " logged in successfully");
      return this.lobby;
    }
   
    logger.info("login failed");
    return null;
View Full Code Here

    Set<String> playerNames = new HashSet<String>();
    Query query = entityManager.createQuery(QUERY_ALL_PLAYERS);
    List< ? > resultList = query.getResultList();
    if ((resultList != null) && (resultList.size() > 0)) {
      for (Object o : resultList) {
        Player player = (Player) o;
        playerNames.add(player.getName());
      }
    }
    return playerNames;
  }
View Full Code Here

    Set<Player> players = new HashSet<Player>();
    Query query = entityManager.createQuery(QUERY_ALL_PLAYERS);
    List< ? > resultList = query.getResultList();
    if ((resultList != null) && (resultList.size() > 0)) {
      for (Object o : resultList) {
        Player player = (Player) o;
        players.add(player);
      }
    }
    return players;
  }
View Full Code Here

     
    }
   
    if ((resultList != null) && (resultList.size() > 0)) {
      for (Object o : resultList) {
        Player player = (Player) o;
        players.add(player);
      }
    }
    return players;
  }
View Full Code Here

   * @return the player with playerName
   */
  public static Player getPlayer(String playerName) {
    EntityManager entityManager =
      PersistenceManager.getInstance().getEntityManager();
    Player player = null;
    try {
     
      player = entityManager.find(Player.class, playerName);
     
    }catch(PersistenceException e){
View Full Code Here

   * @param playerName the playername.
   * @return true if the password was successfully reset.
   */
  public boolean resetPassword(String playerName) {
    boolean result = false;
    Player player = getPlayer(playerName);
    if ((player != null)
        && (player.getEmail() != null)
        && (player.getEmail().length() > 0)
        && (this.mailhostName != null)
        && (this.authMailUsername != null)
        && (this.authMailPassword != null)) {
      EntityManager entityManager =
        PersistenceManager.getInstance().getEntityManager();
      EntityTransaction entityTransaction = entityManager
        .getTransaction();
      entityTransaction.begin()
      player.setPassword(randomString(8));
      entityManager.merge(player);
      entityManager.flush();
      entityTransaction.commit();     
      sendMail(player.getEmail(), "CreepSmash - new password for "
          + playerName, "Hi "
          + playerName
          + "! \n\r Here is Your new password "
          + "for playing CreepSmash on "
          + "www.creepsmash.de . "
          + "\n\r new password: "
          + player.getPassword(),
          this.authMailUsername,
          this.authMailUsername,
          this.authMailPassword,
          this.mailhostName);   
      result = true;
View Full Code Here

  private synchronized PlayersMessage playersMessage() {
    Hashtable<String, Integer> playerNames = new Hashtable<String, Integer>();
    try {
      for (Client client : this.clients) {
        if (client.check()) {
          Player player =
            AuthenticationService.getPlayer(client.getUserName())
         
          playerNames.put(client.getUserName(), player.getElopoints() - 500);
         
        } else {
          logger.info("PlayersMessage/leaveLobby: " + client.getUserName());
          this.leaveLobby(client);
        }
View Full Code Here

TOP

Related Classes of de.creepsmash.server.model.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.