Exemplo n.º 1
0
  public Country geolocAndGetCountry(final String customerRemoteAddr) throws Exception {
    if (StringUtils.isNotEmpty(customerRemoteAddr)) {
      if (!unknownValueList.contains(customerRemoteAddr)) {
        try {
          final InetAddress address = InetAddress.getByName(customerRemoteAddr);

          final DatabaseReader databaseReader =
              new DatabaseReader.Builder(getCountryDataBase()).build();
          final CountryResponse countryResponse = databaseReader.country(address);
          if (countryResponse != null) {
            return countryResponse.getCountry();
          }
        } catch (AddressNotFoundException e) {
          logger.warn("Geoloc country, can't find this address: '" + customerRemoteAddr + "'");
        } catch (FileNotFoundException e) {
          logger.error("Geoloc country, can't find database MaxMind", e);
        } catch (Exception e) {
          logger.error(
              "Geoloc country, exception to find country with this address: '"
                  + customerRemoteAddr
                  + "'",
              e);
        }
      } else {
        logger.debug(
            "Geoloc country, can't find address (private navigation): '"
                + customerRemoteAddr
                + "'");
      }
    } else {
      logger.debug("Geoloc country, can't find address, value is empty.");
    }
    return null;
  }
Exemplo n.º 2
0
  public String lookupCountry(InetAddress addr) {
    CountryResponse response = null;

    try {
      response = reader.country(addr);
    } catch (Exception e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("No country found for: " + addr);
      }
      return null;
    }
    return response.getCountry().getIsoCode();
  }
Exemplo n.º 3
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerLogin(final PlayerLoginEvent event) {
    if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
      return;
    }

    if (plugin.getGeoIpConfig().isEnabled()
        && !event.getPlayer().hasPermission("bm.exempt.country")) {
      try {
        CountryResponse countryResponse =
            plugin.getGeoIpConfig().getCountryDatabase().country(event.getAddress());

        if (!plugin.getGeoIpConfig().isCountryAllowed(countryResponse)) {
          Message message =
              Message.get("deniedCountry")
                  .set("country", countryResponse.getCountry().getName())
                  .set("countryIso", countryResponse.getCountry().getIsoCode());
          event.disallow(PlayerLoginEvent.Result.KICK_BANNED, message.toString());
          return;
        }

      } catch (IOException | GeoIp2Exception e) {
      }
    }

    if (plugin.getConfiguration().getMaxOnlinePerIp() > 0) {
      long ip = IPUtils.toLong(event.getAddress());
      int count = 0;

      for (Player player : plugin.getServer().getOnlinePlayers()) {
        if (IPUtils.toLong(player.getAddress().getAddress()) == ip) {
          count++;
        }
      }

      if (count >= plugin.getConfiguration().getMaxOnlinePerIp()) {
        event.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.getString("deniedMaxIp"));
        return;
      }
    }

    if (!plugin.getConfiguration().isDuplicateIpCheckEnabled()) {
      return;
    }

    plugin
        .getServer()
        .getScheduler()
        .runTaskLaterAsynchronously(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                final long ip = IPUtils.toLong(event.getAddress());
                final UUID uuid = event.getPlayer().getUniqueId();
                List<PlayerData> duplicates = plugin.getPlayerBanStorage().getDuplicates(ip);

                if (duplicates.isEmpty()) {
                  return;
                }

                if (plugin.getConfiguration().isDenyAlts()) {
                  try {
                    denyAlts(duplicates, uuid);
                  } catch (SQLException e) {
                    PluginLogger.warn(e);
                  }
                }

                if (plugin.getConfiguration().isPunishAlts()) {
                  try {
                    punishAlts(duplicates, uuid);
                  } catch (SQLException e) {
                    PluginLogger.warn(e);
                  }
                }

                StringBuilder sb = new StringBuilder();

                for (PlayerData player : duplicates) {
                  if (player.getUUID().equals(uuid)) {
                    continue;
                  }

                  sb.append(player.getName());
                  sb.append(", ");
                }

                if (sb.length() == 0) {
                  return;
                }
                if (sb.length() >= 2) {
                  sb.setLength(sb.length() - 2);
                }

                Message message = Message.get("duplicateIP");
                message.set("player", event.getPlayer().getName());
                message.set("players", sb.toString());

                CommandUtils.broadcast(message.toString(), "bm.notify.duplicateips");
              }
            },
            20L);
  }