Package marauroa.server.game.db

Examples of marauroa.server.game.db.AccountDAO


   */
  @Test
  public void testPerform() throws Throwable {
    DBTransaction transaction = TransactionPool.get().beginWork();
    try {
      AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
      CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
      BanAction ban = new BanAction();
      Player player = PlayerTestHelper.createPlayer("bob");
      RPAction action = new RPAction();
      action.put("target", player.getName());
      action.put("hours", -1);
      action.put("reason", "Because we were testing banning");
     
      // I don't know if this is still needed.
      if (!accountDAO.hasPlayer(transaction, player.getName())) {
        accountDAO.addPlayer(transaction, player.getName(), new byte[0], "schnubbel");
      }
     
      // we do a character check now. Made the the character name and the account name the same
      if (!characterDAO.hasCharacter(transaction, player.getName(), player.getName())) {
        characterDAO.addCharacter(transaction,  player.getName(), player.getName(), player);
      }

      System.out.println(DAORegister.get().get(CharacterDAO.class).getAccountName(transaction, player.getName()));
      accountDAO.setAccountStatus(transaction, player.getName(), "active");
      assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));

      TransactionPool.get().commit(transaction);

      ban.perform(player , action);

      transaction = TransactionPool.get().beginWork();

      assertEquals("banned", accountDAO.getAccountStatus(transaction, player.getName()));
 
      // just undo the changes so the next test starts clean
      TransactionPool.get().rollback(transaction);
    } catch (Throwable e) {
      TransactionPool.get().rollback(transaction);
View Full Code Here


   */
  @Test
  public void testCommandCenterPerform() throws Throwable {
    DBTransaction transaction = TransactionPool.get().beginWork();
    try {
      AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
      CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
     
      Player player = PlayerTestHelper.createPlayer("bobby");
      Player admin = PlayerTestHelper.createPlayer("admin");
      RPAction action = new RPAction();
      action.put("type", "ban");
      action.put("target", player.getName());
      action.put("hours",  -1);
      action.put("reason", "whynot");
      if (!accountDAO.hasPlayer(transaction, player.getName())) {
        accountDAO.addPlayer(transaction, player.getName(), new byte[0], "schnubbel");
      }

      accountDAO.setAccountStatus(transaction, player.getName(), "active");
      if (!accountDAO.hasPlayer(transaction, admin.getName())) {
        accountDAO.addPlayer(transaction, admin.getName(), new byte[0], "schnubbel");
      }
      // we do a character check now. Made the the character name and the account name the same
        if (!characterDAO.hasCharacter(transaction, player.getName(), player.getName())) {
        characterDAO.addCharacter(transaction,  player.getName(), player.getName(), player);
        }
       
      accountDAO.setAccountStatus(transaction, admin.getName(), "active");
 
      assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));

      TransactionPool.get().commit(transaction);

      assertFalse(CommandCenter.execute(admin , action));
      admin.clearEvents();
      admin.setAdminLevel(5000);
      assertTrue(CommandCenter.execute(admin , action));
     
      transaction = TransactionPool.get().beginWork();
      System.out.println(admin.events().get(0).toString());
      assertEquals("banned", accountDAO.getAccountStatus(transaction, player.getName()));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));
      assertFalse(admin.events().isEmpty());
      assertThat(admin.events().get(0).toString(), containsString("RPEvent private_text with Attributes of Class(private_text): "));
      assertThat(admin.events().get(0).toString(), containsString("[text=You have banned account bobby (character: bobby) until end of time for: whynot]"));
      assertThat(admin.events().get(0).toString(), containsString("[texttype=PRIVMSG]"));
 
View Full Code Here

   */
  @Test
  public void testWithoutCharacter() throws Throwable {
    DBTransaction transaction = TransactionPool.get().beginWork();
    try {
      AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
     
      Player player = PlayerTestHelper.createPlayer("bobbby");
      Player admin = PlayerTestHelper.createPlayer("admin");
      RPAction action = new RPAction();
      action.put("type", "ban");
      action.put("target", player.getName());
      action.put("hours",  -1);
      action.put("reason", "Because I can't type the correct name");
      if (!accountDAO.hasPlayer(transaction, player.getName())) {
        accountDAO.addPlayer(transaction, player.getName(), new byte[0], "schnubbel");
      }

      accountDAO.setAccountStatus(transaction, player.getName(), "active");
      if (!accountDAO.hasPlayer(transaction, admin.getName())) {
        accountDAO.addPlayer(transaction, admin.getName(), new byte[0], "schnubbel");
      }
       
      accountDAO.setAccountStatus(transaction, admin.getName(), "active");
 
      assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));

      TransactionPool.get().commit(transaction);

      assertFalse(CommandCenter.execute(admin , action));
      admin.clearEvents();
      admin.setAdminLevel(5000);
      assertTrue(CommandCenter.execute(admin , action));
     
      transaction = TransactionPool.get().beginWork();
      System.out.println(admin.events().get(0).toString());
      assertFalse("banned".equals(accountDAO.getAccountStatus(transaction, player.getName())));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));
      assertFalse(admin.events().isEmpty());
      assertThat(admin.events().get(0).toString(), containsString("RPEvent private_text with Attributes of Class(private_text): "));
      assertThat(admin.events().get(0).toString(), containsString("[text=No such character]"));
      assertThat(admin.events().get(0).toString(), containsString("[texttype=ERROR]"));
 
View Full Code Here

   */
  @Test
  public void testTemporaryBan() throws Throwable {
    DBTransaction transaction = TransactionPool.get().beginWork();
    try {
      AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
      CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
     
      Player player = PlayerTestHelper.createPlayer("bobby");
      Player admin = PlayerTestHelper.createPlayer("admin");
      RPAction action = new RPAction();
      action.put("type", "ban");
      action.put("target", player.getName());
      action.put("hours"1);
      action.put("reason", "We want to test the temporary bans");
      if (!accountDAO.hasPlayer(transaction, player.getName())) {
        accountDAO.addPlayer(transaction, player.getName(), new byte[0], "schnubbel");
      }

      accountDAO.setAccountStatus(transaction, player.getName(), "active");
      if (!accountDAO.hasPlayer(transaction, admin.getName())) {
        accountDAO.addPlayer(transaction, admin.getName(), new byte[0], "schnubbel");
      }
      // we do a character check now. Made the the character name and the account name the same
        if (!characterDAO.hasCharacter(transaction, player.getName(), player.getName())) {
        characterDAO.addCharacter(transaction,  player.getName(), player.getName(), player);
        }
       
      accountDAO.setAccountStatus(transaction, admin.getName(), "active");
 
      assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));

      TransactionPool.get().commit(transaction);

      assertFalse(CommandCenter.execute(admin , action));
      admin.clearEvents();
      admin.setAdminLevel(5000);
      assertTrue(CommandCenter.execute(admin , action));
     
      transaction = TransactionPool.get().beginWork();
      System.out.println(admin.events().get(0).toString());
      assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
      assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));
      assertFalse(admin.events().isEmpty());
      assertThat(admin.events().get(0).toString(), containsString("RPEvent private_text with Attributes of Class(private_text): "));
      // not sure of a good way to reliably test the timestamping
      assertThat(admin.events().get(0).toString(), containsString("[text=You have banned account bobby (character: bobby) until "));
      assertThat(admin.events().get(0).toString(), containsString("for: We want to test the temporary bans"));
View Full Code Here

   * @return Result.OK_CREATED on success
   */
  private AccountResult insertIntoDatabase() {
    final TransactionPool transactionPool = SingletonRepository.getTransactionPool();
    final DBTransaction transaction = transactionPool.beginWork();
    final AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);

    try {
      if (accountDAO.hasPlayer(transaction, username)) {
        logger.warn("Account already exist: " + username);
        transactionPool.commit(transaction);
        return new AccountResult(Result.FAILED_PLAYER_EXISTS, username);
      }

      accountDAO.addPlayer(transaction, username, Hash.hash(password), email);

      transactionPool.commit(transaction);
      return new AccountResult(Result.OK_CREATED, username);
    } catch (final SQLException e) {
      logger.warn("SQL exception while trying to create a new account", e);
View Full Code Here

TOP

Related Classes of marauroa.server.game.db.AccountDAO

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.