@EventHandler(priority = EventPriority.HIGH)
	public void onPlayerLogin(final PlayerLoginEvent event)
	{
		switch (event.getResult())
		{
		case ALLOWED:
		case KICK_FULL:
		case KICK_BANNED:
			break;
		default:
			return;
		}

		userMap.addPrejoinedPlayer(event.getPlayer());
		final IUser user = userMap.getUser(event.getPlayer());
		userMap.removePrejoinedPlayer(event.getPlayer());
		user.getData().setNpc(false);

		final long currentTime = System.currentTimeMillis();
		final boolean banExpired = user.checkBanTimeout(currentTime);
		user.checkMuteTimeout(currentTime);
		user.checkJailTimeout(currentTime);

		if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED))
		{
			String banReason = user.getData().getBan().getReason();
			if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban"))
			{
				banReason = _("The Ban Hammer has spoken!");
			}
			if (user.getData().getBan().getTimeout() > 0)
			{
				//TODO: TL This
				banReason += "\n\n" + "Expires in " + DateUtil.formatDateDiff(user.getData().getBan().getTimeout());
			}
			event.disallow(Result.KICK_BANNED, banReason);
			return;
		}

		if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !Permissions.JOINFULLSERVER.isAuthorized(user))
		{
			event.disallow(Result.KICK_FULL, _("Server is full!"));
			return;
		}
		event.allow();

		user.setTimestamp(TimestampType.LOGIN, System.currentTimeMillis());
		user.updateCompass();
		user.queueSave();
	}
  @Override
  public void onPlayerLogin(final PlayerLoginEvent event) {
    if (event.getResult() != Result.ALLOWED
        && event.getResult() != Result.KICK_FULL
        && event.getResult() != Result.KICK_BANNED) {
      LOGGER.log(
          Level.INFO,
          "Disconnecting user "
              + event.getPlayer().toString()
              + " due to "
              + event.getResult().toString());
      return;
    }
    User user = ess.getUser(event.getPlayer());
    user.setNPC(false);

    final long currentTime = System.currentTimeMillis();
    boolean banExpired = user.checkBanTimeout(currentTime);
    user.checkMuteTimeout(currentTime);
    user.checkJailTimeout(currentTime);

    if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) {
      final String banReason = user.getBanReason();
      event.disallow(
          Result.KICK_BANNED,
          banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban")
              ? banReason
              : Util.i18n("defaultBanReason"));
      return;
    }

    if (server.getOnlinePlayers().length >= server.getMaxPlayers()
        && !user.isAuthorized("essentials.joinfullserver")) {
      event.disallow(Result.KICK_FULL, Util.i18n("serverFull"));
      return;
    }
    event.allow();

    user.setLastLogin(System.currentTimeMillis());
    updateCompass(user);
  }
Ejemplo n.º 3
0
 @Override
 public int getMaxPlayers() {
   return server.getMaxPlayers();
 }
Ejemplo n.º 4
0
  public static Object handle(Object obj) {
    if (obj instanceof World.Environment) {
      World.Environment e = (World.Environment) obj;
      if (e == World.Environment.NETHER) {
        return "nether";
      } else {
        return "normal";
      }
    } else if (obj instanceof File) {
      return ((File) obj).toString();
    } else if (obj instanceof Player) {
      Player p = (Player) obj;
      JSONObject o = new JSONObject();

      o.put("name", p.getName());
      o.put("op", p.isOp());
      o.put("health", p.getHealth());
      o.put("ip", p.getAddress().toString());
      o.put("itemInHand", p.getItemInHand());
      o.put("location", p.getLocation());
      o.put("inventory", p.getInventory());
      o.put("sneaking", p.isSneaking());
      o.put("inVehicle", p.isInsideVehicle());
      o.put("sleeping", p.isSleeping());
      o.put("world", p.getServer().getWorlds().indexOf(p.getWorld()));

      return o;
    } else if (obj instanceof Server) {
      Server s = (Server) obj;

      JSONObject o = new JSONObject();

      o.put("maxPlayers", s.getMaxPlayers());
      o.put("players", Arrays.asList(s.getOnlinePlayers()));
      o.put("port", s.getPort());
      o.put("name", s.getName());
      o.put("serverName", s.getServerName());
      o.put("version", s.getVersion());
      o.put("worlds", s.getWorlds());

      return o;
    } else if (obj instanceof World) {
      World w = (World) obj;

      JSONObject o = new JSONObject();

      o.put("environment", w.getEnvironment());
      o.put("fullTime", w.getFullTime());
      o.put("time", w.getTime());
      o.put("name", w.getName());
      o.put("isThundering", w.isThundering());
      o.put("hasStorm", w.hasStorm());

      return o;
    } else if (obj instanceof Plugin) {
      Plugin p = (Plugin) obj;
      PluginDescriptionFile d = p.getDescription();

      JSONObject o = new JSONObject();

      o.put("name", d.getName());
      o.put("description", d.getDescription());
      o.put("authors", d.getAuthors());
      o.put("version", d.getVersion());
      o.put("website", d.getWebsite());
      o.put("enabled", JSONAPI.instance.getServer().getPluginManager().isPluginEnabled(p));

      return o;
    } else if (obj instanceof ItemStack) {
      ItemStack i = (ItemStack) obj;

      JSONObject o = new JSONObject();

      o.put("type", i.getTypeId());
      o.put("durability", i.getDurability());
      o.put("amount", i.getAmount());

      return o;
    } else if (obj instanceof PlayerInventory) {
      PlayerInventory p = (PlayerInventory) obj;

      JSONObject o = new JSONObject();

      JSONObject armor = new JSONObject();
      armor.put("boots", p.getBoots());
      armor.put("chestplate", p.getChestplate());
      armor.put("helmet", p.getHelmet());
      armor.put("leggings", p.getLeggings());

      o.put("armor", armor);
      o.put("hand", p.getItemInHand());
      o.put("inventory", Arrays.asList(p.getContents()));

      return o;
    } else if (obj instanceof Location) {
      Location l = (Location) obj;

      JSONObject o = new JSONObject();

      o.put("x", l.getX());
      o.put("y", l.getY());
      o.put("z", l.getZ());
      o.put("pitch", l.getPitch());
      o.put("yaw", l.getYaw());

      return o;
    } else if (obj instanceof Plugin[]) {
      List<Plugin> l = Arrays.asList((Plugin[]) obj);

      Collections.sort(l, new PluginSorter());

      return l;
    } else if (obj instanceof Object[]) {
      int l = ((Object[]) obj).length;
      JSONArray a = new JSONArray();
      for (int i = 0; i < l; i++) {
        a.add(((Object[]) obj)[i]);
      }

      return a;
    }
    Logger.getLogger("JSONAPI").warning("Uncaugh object! Value:");
    Logger.getLogger("JSONAPI").warning(obj.toString());
    Logger.getLogger("JSONAPI").warning("Type:");
    Logger.getLogger("JSONAPI").warning(obj.getClass().getName());

    return new Object();
  }
Ejemplo n.º 5
0
  public static void handlePlayerLogin(PlayerLoginEvent event) {
    final Server server = TotalFreedomMod.server;
    final Player player = event.getPlayer();
    final String username = player.getName();
    final String ip = event.getAddress().getHostAddress().trim();
    final UUID uuid = TFM_UuidManager.newPlayer(player, ip);

    // Check username length
    if (username.length() < 3 || username.length() > TotalFreedomMod.MAX_USERNAME_LENGTH) {
      event.disallow(
          Result.KICK_OTHER,
          "Your username is an invalid length (must be between 3 and 20 characters long).");
      return;
    }

    // Check username characters
    if (!USERNAME_REGEX.matcher(username).find()) {
      event.disallow(Result.KICK_OTHER, "Your username contains invalid characters.");
      return;
    }

    // Check force-IP match
    if (TFM_ConfigEntry.FORCE_IP_ENABLED.getBoolean()) {
      final String hostname =
          event
              .getHostname()
              .replace(
                  "\u0000FML\u0000",
                  ""); // Forge fix - https://github.com/TotalFreedom/TotalFreedomMod/issues/493
      final String connectAddress = TFM_ConfigEntry.SERVER_ADDRESS.getString();
      final int connectPort = TotalFreedomMod.server.getPort();

      if (!hostname.equalsIgnoreCase(connectAddress + ":" + connectPort)
          && !hostname.equalsIgnoreCase(connectAddress + ".:" + connectPort)) {
        final int forceIpPort = TFM_ConfigEntry.FORCE_IP_PORT.getInteger();
        event.disallow(
            PlayerLoginEvent.Result.KICK_OTHER,
            TFM_ConfigEntry.FORCE_IP_KICKMSG
                .getString()
                .replace(
                    "%address%",
                    TFM_ConfigEntry.SERVER_ADDRESS.getString()
                        + (forceIpPort == TFM_PlayerListener.DEFAULT_PORT
                            ? ""
                            : ":" + forceIpPort)));
        return;
      }
    }

    // Check if player is admin
    // Not safe to use TFM_Util.isSuperAdmin(player) because player.getAddress() will return a null
    // until after player login.
    final boolean isAdmin = TFM_AdminList.isSuperAdminSafe(uuid, ip);

    // Validation below this point
    if (isAdmin) // Player is superadmin
    {
      // Force-allow log in
      event.allow();

      int count = server.getOnlinePlayers().size();
      if (count >= server.getMaxPlayers()) {
        for (Player onlinePlayer : server.getOnlinePlayers()) {
          if (!TFM_AdminList.isSuperAdmin(onlinePlayer)) {
            onlinePlayer.kickPlayer("You have been kicked to free up room for an admin.");
            count--;
          }

          if (count < server.getMaxPlayers()) {
            break;
          }
        }
      }

      if (count >= server.getMaxPlayers()) {
        event.disallow(
            Result.KICK_OTHER, "The server is full and a player could not be kicked, sorry!");
        return;
      }

      return;
    }

    // Player is not an admin
    // Server full check
    if (server.getOnlinePlayers().size() >= server.getMaxPlayers()) {
      event.disallow(Result.KICK_FULL, "Sorry, but this server is full.");
      return;
    }

    // Admin-only mode
    if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) {
      event.disallow(Result.KICK_OTHER, "Server is temporarily open to admins only.");
      return;
    }

    // Lockdown mode
    if (TotalFreedomMod.lockdownEnabled) {
      event.disallow(Result.KICK_OTHER, "Server is currently in lockdown mode.");
      return;
    }

    // Whitelist
    if (isWhitelisted()) {
      if (!getWhitelisted().contains(username.toLowerCase())) {
        event.disallow(Result.KICK_OTHER, "You are not whitelisted on this server.");
        return;
      }
    }

    // UUID ban
    if (TFM_BanManager.isUuidBanned(uuid)) {
      final TFM_Ban ban = TFM_BanManager.getByUuid(uuid);
      event.disallow(Result.KICK_OTHER, ban.getKickMessage());
      return;
    }

    // IP ban
    if (TFM_BanManager.isIpBanned(ip)) {
      final TFM_Ban ban = TFM_BanManager.getByIp(ip);
      event.disallow(Result.KICK_OTHER, ban.getKickMessage());
      return;
    }

    // Permbanned IPs
    for (String testIp : TFM_PermbanList.getPermbannedIps()) {
      if (TFM_Util.fuzzyIpMatch(testIp, ip, 4)) {
        event.disallow(
            Result.KICK_OTHER,
            ChatColor.RED
                + "Your IP address is permanently banned from this server.\n"
                + "Release procedures are available at\n"
                + ChatColor.GOLD
                + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
        return;
      }
    }

    // Permbanned usernames
    for (String testPlayer : TFM_PermbanList.getPermbannedPlayers()) {
      if (testPlayer.equalsIgnoreCase(username)) {
        event.disallow(
            Result.KICK_OTHER,
            ChatColor.RED
                + "Your username is permanently banned from this server.\n"
                + "Release procedures are available at\n"
                + ChatColor.GOLD
                + TFM_ConfigEntry.SERVER_PERMBAN_URL.getString());
        return;
      }
    }
  }