@Override
 public synchronized boolean updatePassword(final PlayerAuth auth) {
   if (!cache.containsKey(auth.getNickname())) {
     return false;
   }
   final String oldHash = cache.get(auth.getNickname()).getHash();
   cache.get(auth.getNickname()).setHash(auth.getHash());
   exec.execute(
       new Runnable() {
         @Override
         public void run() {
           if (!source.updatePassword(auth)) {
             if (cache.containsKey(auth.getNickname())) {
               cache.get(auth.getNickname()).setHash(oldHash);
             }
           }
         }
       });
   return true;
 }
Exemple #2
0
 @Override
 public synchronized boolean saveAuth(PlayerAuth auth) {
   if (isAuthAvailable(auth.getNickname())) {
     return false;
   }
   BufferedWriter bw = null;
   try {
     bw = new BufferedWriter(new FileWriter(source, true));
     bw.write(
         auth.getNickname()
             + ":"
             + auth.getHash()
             + ":"
             + auth.getIp()
             + ":"
             + auth.getLastLogin()
             + ":"
             + auth.getQuitLocX()
             + ":"
             + auth.getQuitLocY()
             + ":"
             + auth.getQuitLocZ()
             + ":"
             + auth.getWorld()
             + ":"
             + auth.getEmail()
             + "\n");
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } finally {
     if (bw != null) {
       try {
         bw.close();
       } catch (IOException ex) {
       }
     }
   }
   return true;
 }
Exemple #3
0
 @Override
 public synchronized boolean updatePassword(PlayerAuth auth) {
   if (!isAuthAvailable(auth.getNickname())) {
     return false;
   }
   PlayerAuth newAuth = null;
   BufferedReader br = null;
   try {
     br = new BufferedReader(new FileReader(source));
     String line;
     while ((line = br.readLine()) != null) {
       String[] args = line.split(":");
       if (args[0].equals(auth.getNickname())) {
         switch (args.length) {
           case 4:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       auth.getHash(),
                       args[2],
                       Long.parseLong(args[3]),
                       0,
                       0,
                       0,
                       "world",
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 7:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       auth.getHash(),
                       args[2],
                       Long.parseLong(args[3]),
                       Double.parseDouble(args[4]),
                       Double.parseDouble(args[5]),
                       Double.parseDouble(args[6]),
                       "world",
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 8:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       auth.getHash(),
                       args[2],
                       Long.parseLong(args[3]),
                       Double.parseDouble(args[4]),
                       Double.parseDouble(args[5]),
                       Double.parseDouble(args[6]),
                       args[7],
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 9:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       auth.getHash(),
                       args[2],
                       Long.parseLong(args[3]),
                       Double.parseDouble(args[4]),
                       Double.parseDouble(args[5]),
                       Double.parseDouble(args[6]),
                       args[7],
                       args[8],
                       args[0]);
               break;
             }
           default:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       auth.getHash(),
                       args[2],
                       0,
                       0,
                       0,
                       0,
                       "world",
                       "*****@*****.**",
                       args[0]);
               break;
             }
         }
         break;
       }
     }
   } catch (FileNotFoundException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return false;
   } finally {
     if (br != null) {
       try {
         br.close();
       } catch (IOException ex) {
       }
     }
   }
   if (newAuth != null) {
     removeAuth(auth.getNickname());
     saveAuth(newAuth);
   }
   return true;
 }