Ejemplo n.º 1
0
  @Override
  public boolean updateSession(final PlayerAuth auth) {
    if (!cache.containsKey(auth.getNickname())) {
      return false;
    }
    PlayerAuth cachedAuth = cache.get(auth.getNickname());
    final String oldIp = cachedAuth.getIp();
    final long oldLastLogin = cachedAuth.getLastLogin();
    final String oldRealName = cachedAuth.getRealName();

    cachedAuth.setIp(auth.getIp());
    cachedAuth.setLastLogin(auth.getLastLogin());
    cachedAuth.setRealName(auth.getRealName());
    exec.execute(
        new Runnable() {
          @Override
          public void run() {
            if (!source.updateSession(auth)) {
              if (cache.containsKey(auth.getNickname())) {
                PlayerAuth cachedAuth = cache.get(auth.getNickname());
                cachedAuth.setIp(oldIp);
                cachedAuth.setLastLogin(oldLastLogin);
                cachedAuth.setRealName(oldRealName);
              }
            }
          }
        });
    return true;
  }
Ejemplo n.º 2
0
 @Override
 public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
   List<String> result = new ArrayList<>();
   for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
     PlayerAuth p = stringPlayerAuthEntry.getValue();
     if (p.getIp().equals(auth.getIp())) result.add(p.getNickname());
   }
   return result;
 }
Ejemplo n.º 3
0
 @Override
 public List<String> getAllAuthsByName(PlayerAuth auth) {
   BufferedReader br = null;
   List<String> countIp = new ArrayList<>();
   try {
     br = new BufferedReader(new FileReader(source));
     String line;
     while ((line = br.readLine()) != null) {
       String[] args = line.split(":");
       if (args.length > 3 && args[2].equals(auth.getIp())) {
         countIp.add(args[0]);
       }
     }
     return countIp;
   } catch (FileNotFoundException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return new ArrayList<>();
   } catch (IOException ex) {
     ConsoleLogger.showError(ex.getMessage());
     return new ArrayList<>();
   } finally {
     if (br != null) {
       try {
         br.close();
       } catch (IOException ex) {
       }
     }
   }
 }
Ejemplo n.º 4
0
 @Override
 public boolean equals(Object obj) {
   if (!(obj instanceof PlayerAuth)) {
     return false;
   }
   PlayerAuth other = (PlayerAuth) obj;
   return other.getIp().equals(this.ip) && other.getNickname().equals(this.nickname);
 }
Ejemplo n.º 5
0
 /**
  * Method set.
  *
  * @param auth PlayerAuth
  */
 public void set(PlayerAuth auth) {
   this.setEmail(auth.getEmail());
   this.setPassword(auth.getPassword());
   this.setIp(auth.getIp());
   this.setLastLogin(auth.getLastLogin());
   this.setNickname(auth.getNickname());
   this.setQuitLocX(auth.getQuitLocX());
   this.setQuitLocY(auth.getQuitLocY());
   this.setQuitLocZ(auth.getQuitLocZ());
   this.setWorld(auth.getWorld());
   this.setRealName(auth.getRealName());
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
  public void process() {
    if (AuthMePlayerListener.gameMode.containsKey(name)) AuthMePlayerListener.gameMode.remove(name);
    AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
    BukkitScheduler sched = plugin.getServer().getScheduler();

    if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
      return;
    }

    if (plugin.ess != null && Settings.disableSocialSpy) {
      plugin.ess.getUser(player).setSocialSpyEnabled(false);
    }

    if (!plugin.canConnect()) {
      final GameMode gM = AuthMePlayerListener.gameMode.get(name);
      sched.scheduleSyncDelayedTask(
          plugin,
          new Runnable() {

            @Override
            public void run() {
              AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
              player.setGameMode(gM);
              player.kickPlayer("Server is loading, please wait before joining!");
            }
          });
      return;
    }

    final String ip = plugin.getIP(player);
    if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) {
      final GameMode gM = AuthMePlayerListener.gameMode.get(name);
      sched.scheduleSyncDelayedTask(
          plugin,
          new Runnable() {

            @Override
            public void run() {
              AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
              player.setGameMode(gM);
              player.kickPlayer("You are not the Owner of this account, please try another name!");
              if (Settings.banUnsafeIp) plugin.getServer().banIP(ip);
            }
          });
      return;
    }
    if (Settings.getMaxJoinPerIp > 0
        && !plugin.authmePermissible(player, "authme.allow2accounts")
        && !ip.equalsIgnoreCase("127.0.0.1")
        && !ip.equalsIgnoreCase("localhost")) {
      if (plugin.hasJoinedIp(player.getName(), ip)) {
        sched.scheduleSyncDelayedTask(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                player.kickPlayer("A player with the same IP is already in game!");
              }
            });
        return;
      }
    }
    final Location spawnLoc = plugin.getSpawnLocation(player);
    final boolean isAuthAvailable = database.isAuthAvailable(name);
    if (isAuthAvailable) {
      if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
        sched.scheduleSyncDelayedTask(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
                Utils.forceGM(player);
              }
            });
      }
      if (!Settings.noTeleport)
        if (Settings.isTeleportToSpawnEnabled
            || (Settings.isForceSpawnLocOnJoinEnabled
                && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
          sched.scheduleSyncDelayedTask(
              plugin,
              new Runnable() {

                @Override
                public void run() {
                  SpawnTeleportEvent tpEvent =
                      new SpawnTeleportEvent(
                          player,
                          player.getLocation(),
                          spawnLoc,
                          PlayerCache.getInstance().isAuthenticated(name));
                  plugin.getServer().getPluginManager().callEvent(tpEvent);
                  if (!tpEvent.isCancelled()) {
                    if (player.isOnline() && tpEvent.getTo() != null) {
                      if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo());
                    }
                  }
                }
              });
        }
      placePlayerSafely(player, spawnLoc);
      LimboCache.getInstance().updateLimboPlayer(player);
      // protect inventory
      if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
        ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
        plugin.getServer().getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
          plugin.inventoryProtector.sendInventoryPacket(player);
          if (!Settings.noConsoleSpam)
            ConsoleLogger.info(
                "ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
        }
      }
    } else {
      if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
        sched.scheduleSyncDelayedTask(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
                Utils.forceGM(player);
              }
            });
      }
      if (!Settings.unRegisteredGroup.isEmpty()) {
        Utils.setGroup(player, Utils.GroupType.UNREGISTERED);
      }
      if (!Settings.isForcedRegistrationEnabled) {
        return;
      }
      if (!Settings.noTeleport)
        if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled
            || (Settings.isForceSpawnLocOnJoinEnabled
                && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
          sched.scheduleSyncDelayedTask(
              plugin,
              new Runnable() {

                @Override
                public void run() {
                  SpawnTeleportEvent tpEvent =
                      new SpawnTeleportEvent(
                          player,
                          player.getLocation(),
                          spawnLoc,
                          PlayerCache.getInstance().isAuthenticated(name));
                  plugin.getServer().getPluginManager().callEvent(tpEvent);
                  if (!tpEvent.isCancelled()) {
                    if (player.isOnline() && tpEvent.getTo() != null) {
                      if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo());
                    }
                  }
                }
              });
        }
    }
    String[] msg;
    if (Settings.emailRegistration) {
      msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_email_msg");
    } else {
      msg = isAuthAvailable ? m.send("login_msg") : m.send("reg_msg");
    }
    int time = Settings.getRegistrationTimeout * 20;
    int msgInterval = Settings.getWarnMessageInterval;
    if (time != 0) {
      BukkitTask id =
          sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), time);
      if (!LimboCache.getInstance().hasLimboPlayer(name))
        LimboCache.getInstance().addLimboPlayer(player);
      LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
    }
    if (!LimboCache.getInstance().hasLimboPlayer(name))
      LimboCache.getInstance().addLimboPlayer(player);
    if (isAuthAvailable) {
      Utils.setGroup(player, GroupType.NOTLOGGEDIN);
    } else {
      Utils.setGroup(player, GroupType.UNREGISTERED);
    }
    sched.scheduleSyncDelayedTask(
        plugin,
        new Runnable() {

          @Override
          public void run() {
            if (player.isOp()) player.setOp(false);
            if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
              player.setAllowFlight(true);
              player.setFlying(true);
            }
            player.setNoDamageTicks(Settings.getRegistrationTimeout * 20);
            if (Settings.useEssentialsMotd) player.performCommand("motd");
            if (Settings.applyBlindEffect)
              player.addPotionEffect(
                  new PotionEffect(
                      PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
            if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
              player.setWalkSpeed(0.0f);
              player.setFlySpeed(0.0f);
            }
          }
        });
    if (Settings.isSessionsEnabled
        && isAuthAvailable
        && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) {
      if (plugin.sessions.containsKey(name)) plugin.sessions.get(name).cancel();
      plugin.sessions.remove(name);
      PlayerAuth auth = database.getAuth(name);
      if (auth != null && auth.getIp().equals(ip)) {
        m.send(player, "valid_session");
        PlayerCache.getInstance().removePlayer(name);
        database.setUnlogged(name);
        plugin.management.performLogin(player, "dontneed", true);
      } else if (Settings.sessionExpireOnIpChange) {
        PlayerCache.getInstance().removePlayer(name);
        database.setUnlogged(name);
        m.send(player, "invalid_session");
      }
      return;
    }
    BukkitTask msgT =
        sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
    LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
  }
Ejemplo n.º 8
0
 @Override
 public boolean updateSession(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].equalsIgnoreCase(auth.getNickname())) {
         switch (args.length) {
           case 4:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       args[1],
                       auth.getIp(),
                       auth.getLastLogin(),
                       0,
                       0,
                       0,
                       "world",
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 7:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       args[1],
                       auth.getIp(),
                       auth.getLastLogin(),
                       Double.parseDouble(args[4]),
                       Double.parseDouble(args[5]),
                       Double.parseDouble(args[6]),
                       "world",
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 8:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       args[1],
                       auth.getIp(),
                       auth.getLastLogin(),
                       Double.parseDouble(args[4]),
                       Double.parseDouble(args[5]),
                       Double.parseDouble(args[6]),
                       args[7],
                       "*****@*****.**",
                       args[0]);
               break;
             }
           case 9:
             {
               newAuth =
                   new PlayerAuth(
                       args[0],
                       args[1],
                       auth.getIp(),
                       auth.getLastLogin(),
                       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],
                       args[1],
                       auth.getIp(),
                       auth.getLastLogin(),
                       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;
 }