private boolean canRidePlayer(EntityPlayer player) {
   final GameProfile owner = minime.getOwner();
   return owner != null
       && player != null
       && player.getGameProfile().getId().equals(owner.getId())
       && player.ridingEntity == null;
 }
  @Override
  public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(
      GameProfile profile, boolean requireSecure) {
    LogHelper.debug("getTextures, Username: '******'", profile.getName());
    Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures =
        new EnumMap<>(MinecraftProfileTexture.Type.class);

    // Add skin URL to textures map
    Iterator<Property> skinURL =
        profile.getProperties().get(ClientLauncher.SKIN_URL_PROPERTY).iterator();
    Iterator<Property> skinHash =
        profile.getProperties().get(ClientLauncher.SKIN_DIGEST_PROPERTY).iterator();
    if (skinURL.hasNext() && skinHash.hasNext()) {
      String urlValue = skinURL.next().getValue();
      String hashValue = skinHash.next().getValue();
      textures.put(
          MinecraftProfileTexture.Type.SKIN, new MinecraftProfileTexture(urlValue, hashValue));
    }

    // Add cloak URL to textures map
    Iterator<Property> cloakURL =
        profile.getProperties().get(ClientLauncher.CLOAK_URL_PROPERTY).iterator();
    Iterator<Property> cloakHash =
        profile.getProperties().get(ClientLauncher.CLOAK_DIGEST_PROPERTY).iterator();
    if (cloakURL.hasNext() && cloakHash.hasNext()) {
      String urlValue = cloakURL.next().getValue();
      String hashValue = cloakHash.next().getValue();
      textures.put(
          MinecraftProfileTexture.Type.CAPE, new MinecraftProfileTexture(urlValue, hashValue));
    }

    // Return filled textures
    return textures;
  }
Esempio n. 3
0
 /* 25:   */
 /* 26:   */ public String a(SocketAddress paramSocketAddress, GameProfile paramGameProfile)
       /* 27:   */ {
   /* 28:31 */ if ((paramGameProfile.getName().equalsIgnoreCase(b().R()))
       && (a(paramGameProfile.getName()) != null)) {
     /* 29:32 */ return "That name is already taken.";
     /* 30:   */ }
   /* 31:35 */ return super.a(paramSocketAddress, paramGameProfile);
   /* 32:   */ }
Esempio n. 4
0
  @Mod.EventHandler
  public void postInit(FMLPostInitializationEvent event) {
    BCLog.logger.info(
        "BuildCraft's fake player: UUID = "
            + gameProfile.getId().toString()
            + ", name = '"
            + gameProfile.getName()
            + "'!");

    for (Object o : Block.blockRegistry) {
      Block block = (Block) o;

      if (block instanceof BlockFluidBase
          || block instanceof BlockLiquid
          || block instanceof IPlantable) {
        BuildCraftAPI.softBlocks.add(block);
      }
    }

    BuildCraftAPI.softBlocks.add(Blocks.snow);
    BuildCraftAPI.softBlocks.add(Blocks.vine);
    BuildCraftAPI.softBlocks.add(Blocks.fire);
    BuildCraftAPI.softBlocks.add(Blocks.air);

    FMLCommonHandler.instance().bus().register(new TickHandlerCore());

    CropManager.setDefaultHandler(new CropHandlerPlantable());
    CropManager.registerHandler(new CropHandlerReeds());

    BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft());
    BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood());
    BuildCraftAPI.registerWorldProperty("leaves", new WorldPropertyIsLeaf());
    for (int i = 0; i < 4; i++) {
      BuildCraftAPI.registerWorldProperty("ore@hardness=" + i, new WorldPropertyIsOre(i));
    }
    BuildCraftAPI.registerWorldProperty("harvestable", new WorldPropertyIsHarvestable());
    BuildCraftAPI.registerWorldProperty("farmland", new WorldPropertyIsFarmland());
    BuildCraftAPI.registerWorldProperty("shoveled", new WorldPropertyIsShoveled());
    BuildCraftAPI.registerWorldProperty("dirt", new WorldPropertyIsDirt());
    BuildCraftAPI.registerWorldProperty("fluidSource", new WorldPropertyIsFluidSource());

    ColorUtils.initialize();

    actionControl = new IActionExternal[IControllable.Mode.values().length];
    for (IControllable.Mode mode : IControllable.Mode.values()) {
      if (mode != IControllable.Mode.Unknown && mode != IControllable.Mode.Mode) {
        actionControl[mode.ordinal()] = new ActionMachineControl(mode);
      }
    }
  }
  @Override
  public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) {
    // Verify has UUID
    UUID uuid = profile.getUUID();
    LogHelper.debug("fillProfileProperties, UUID: %s", uuid);
    if (uuid == null) {
      return profile;
    }

    // Make profile request
    PlayerProfile pp;
    try {
      pp = new ProfileByUUIDRequest(uuid).request();
    } catch (Exception e) {
      LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e);
      return profile;
    }

    // Verify is found
    if (pp == null) {
      LogHelper.debug(
          "Couldn't fetch profile properties for '%s' as the profile does not exist", profile);
      return profile;
    }

    // Create new game profile from player profile
    LogHelper.debug("Successfully fetched profile properties for '%s'", profile);
    fillTextureProperties(profile, pp);
    return toGameProfile(pp);
  }
  @Override
  public void joinServer(GameProfile profile, String accessToken, String serverID)
      throws AuthenticationException {
    if (!ClientLauncher.isLaunched()) {
      throw new AuthenticationException("Bad Login (Cheater)");
    }

    // Join server
    String username = profile.getName();
    LogHelper.debug(
        "joinServer, Username: '******', Access token: %s, Server ID: %s",
        username, accessToken, serverID);

    // Make joinServer request
    boolean success;
    try {
      success = new JoinServerRequest(username, accessToken, serverID).request();
    } catch (Exception e) {
      throw new AuthenticationUnavailableException(e);
    }

    // Verify is success
    if (!success) {
      throw new AuthenticationException("Bad Login (Clientside)");
    }
  }
 public boolean canSendCommands(GameProfile profile) {
   return this.ops.hasEntry(profile)
       || this.mcServer.isSinglePlayer()
           && this.mcServer.worldServers[0].getWorldInfo().areCommandsAllowed()
           && this.mcServer.getServerOwner().equalsIgnoreCase(profile.getName())
       || this.commandsAllowedForAll;
 }
Esempio n. 8
0
 /**
  * Return a skull that has a custom texture specified by url.
  *
  * @param url skin url
  * @return itemstack
  */
 public static ItemStack getCustomSkull(String url) {
   GameProfile profile = new GameProfile(UUID.randomUUID(), null);
   PropertyMap propertyMap = profile.getProperties();
   if (propertyMap == null) {
     throw new IllegalStateException("Profile doesn't contain a property map");
   }
   String encodedData =
       Base64.encodeBytes(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
   propertyMap.put("textures", new Property("textures", encodedData));
   ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
   ItemMeta headMeta = head.getItemMeta();
   Class<?> headMetaClass = headMeta.getClass();
   Reflections.getField(headMetaClass, "profile", GameProfile.class).set(headMeta, profile);
   head.setItemMeta(headMeta);
   return head;
 }
Esempio n. 9
0
  @Override
  public void onPacketOut(Object packet, Player player) {
    GameProfile profile =
        (GameProfile)
            ReflectionUtils.getPrivateField(
                PACKET_CLASS,
                ReflectionUtils.byClass(PACKET_CLASS, GameProfile.class).getName(),
                packet);

    if (playerHandlers.containsKey(profile.getId())) playerHandlers.remove(profile.getId());

    PlayerHandler handler = new PlayerHandler(player);
    handler.setChannel(super.channel);

    playerHandlers.put(profile.getId(), handler);
  }
Esempio n. 10
0
  @SideOnly(Side.CLIENT)
  public static GameProfile makeOtherPlayerProfile(String strName, String strUUID) {
    GameProfile profile = null;
    for (Object e : FMLClientHandler.instance().getWorldClient().getLoadedEntityList()) {
      if (e instanceof AbstractClientPlayer) {
        GameProfile gp2 = ((AbstractClientPlayer) e).getGameProfile();
        if (gp2.getName().equals(strName)) {
          profile = gp2;
          break;
        }
      }
    }
    if (profile == null) {
      UUID uuid = strUUID.isEmpty() ? UUID.randomUUID() : UUID.fromString(strUUID);
      profile = new GameProfile(uuid, strName);
    }

    PlayerUtil.knownSkins.put(strName, profile);
    return profile;
  }
  @Override
  public GameProfile hasJoinedServer(GameProfile profile, String serverID)
      throws AuthenticationUnavailableException {
    String username = profile.getName();
    LogHelper.debug("checkServer, Username: '******', Server ID: %s", username, serverID);

    // Make checkServer request
    PlayerProfile pp;
    try {
      pp = new CheckServerRequest(username, serverID).request();
    } catch (Exception e) {
      LogHelper.error(e);
      throw new AuthenticationUnavailableException(e);
    }

    // Return profile if found
    return pp == null ? null : toGameProfile(pp);
  }
 public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) {
   PropertyMap properties = profile.getProperties();
   if (pp.skin != null) {
     properties.put(
         ClientLauncher.SKIN_URL_PROPERTY,
         new Property(ClientLauncher.SKIN_URL_PROPERTY, pp.skin.url, ""));
     properties.put(
         ClientLauncher.SKIN_DIGEST_PROPERTY,
         new Property(
             ClientLauncher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), ""));
   }
   if (pp.cloak != null) {
     properties.put(
         ClientLauncher.CLOAK_URL_PROPERTY,
         new Property(ClientLauncher.CLOAK_URL_PROPERTY, pp.cloak.url, ""));
     properties.put(
         ClientLauncher.CLOAK_DIGEST_PROPERTY,
         new Property(
             ClientLauncher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), ""));
   }
 }
  public void initializeConnectionToPlayer(NetworkManager netManager, EntityPlayerMP playerIn) {
    GameProfile var3 = playerIn.getGameProfile();
    PlayerProfileCache var4 = this.mcServer.getPlayerProfileCache();
    GameProfile var5 = var4.func_152652_a(var3.getId());
    String var6 = var5 == null ? var3.getName() : var5.getName();
    var4.func_152649_a(var3);
    NBTTagCompound var7 = this.readPlayerDataFromFile(playerIn);
    playerIn.setWorld(this.mcServer.worldServerForDimension(playerIn.dimension));
    playerIn.theItemInWorldManager.setWorld((WorldServer) playerIn.worldObj);
    String var8 = "local";

    if (netManager.getRemoteAddress() != null) {
      var8 = netManager.getRemoteAddress().toString();
    }

    logger.info(
        playerIn.getName()
            + "["
            + var8
            + "] logged in with entity id "
            + playerIn.getEntityId()
            + " at ("
            + playerIn.posX
            + ", "
            + playerIn.posY
            + ", "
            + playerIn.posZ
            + ")");
    WorldServer var9 = this.mcServer.worldServerForDimension(playerIn.dimension);
    WorldInfo var10 = var9.getWorldInfo();
    BlockPos var11 = var9.getSpawnPoint();
    this.func_72381_a(playerIn, (EntityPlayerMP) null, var9);
    NetHandlerPlayServer var12 = new NetHandlerPlayServer(this.mcServer, netManager, playerIn);
    var12.sendPacket(
        new S01PacketJoinGame(
            playerIn.getEntityId(),
            playerIn.theItemInWorldManager.getGameType(),
            var10.isHardcoreModeEnabled(),
            var9.provider.getDimensionId(),
            var9.getDifficulty(),
            this.getMaxPlayers(),
            var10.getTerrainType(),
            var9.getGameRules().getGameRuleBooleanValue("reducedDebugInfo")));
    var12.sendPacket(
        new S3FPacketCustomPayload(
            "MC|Brand",
            (new PacketBuffer(Unpooled.buffer()))
                .writeString(this.getServerInstance().getServerModName())));
    var12.sendPacket(
        new S41PacketServerDifficulty(var10.getDifficulty(), var10.isDifficultyLocked()));
    var12.sendPacket(new S05PacketSpawnPosition(var11));
    var12.sendPacket(new S39PacketPlayerAbilities(playerIn.capabilities));
    var12.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem));
    playerIn.getStatFile().func_150877_d();
    playerIn.getStatFile().func_150884_b(playerIn);
    this.func_96456_a((ServerScoreboard) var9.getScoreboard(), playerIn);
    this.mcServer.refreshStatusNextTick();
    ChatComponentTranslation var13;

    if (!playerIn.getName().equalsIgnoreCase(var6)) {
      var13 =
          new ChatComponentTranslation(
              "multiplayer.player.joined.renamed", new Object[] {playerIn.getDisplayName(), var6});
    } else {
      var13 =
          new ChatComponentTranslation(
              "multiplayer.player.joined", new Object[] {playerIn.getDisplayName()});
    }

    var13.getChatStyle().setColor(EnumChatFormatting.YELLOW);
    this.sendChatMsg(var13);
    this.playerLoggedIn(playerIn);
    var12.setPlayerLocation(
        playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    this.updateTimeAndWeatherForPlayer(playerIn, var9);

    if (this.mcServer.getResourcePackUrl().length() > 0) {
      playerIn.func_175397_a(
          this.mcServer.getResourcePackUrl(), this.mcServer.getResourcePackHash());
    }

    Iterator var14 = playerIn.getActivePotionEffects().iterator();

    while (var14.hasNext()) {
      PotionEffect var15 = (PotionEffect) var14.next();
      var12.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), var15));
    }

    playerIn.addSelfToInternalCraftingInventory();

    if (var7 != null && var7.hasKey("Riding", 10)) {
      Entity var16 = EntityList.createEntityFromNBT(var7.getCompoundTag("Riding"), var9);

      if (var16 != null) {
        var16.forceSpawn = true;
        var9.spawnEntityInWorld(var16);
        playerIn.mountEntity(var16);
        var16.forceSpawn = false;
      }
    }
  }
 protected GameProfile getOfflineProfile(GameProfile original) {
   UUID var2 =
       UUID.nameUUIDFromBytes(("OfflinePlayer:" + original.getName()).getBytes(Charsets.UTF_8));
   return new GameProfile(var2, original.getName());
 }
 private void handleLoginStart(Channel channel, Object packet) {
   if (PACKET_LOGIN_IN_START.isInstance(packet)) {
     GameProfile profile = getGameProfile.get(packet);
     channelLookup.put(profile.getName(), channel);
   }
 }
Esempio n. 16
0
  protected static LoginResponse authenticateWithAuthlib(
      String user, String pass, String mojangData, String selectedProfileName) {
    String displayName;
    boolean hasMojangData = false;
    boolean hasPassword = false;
    GameProfile selectedProfile = null;
    YggdrasilUserAuthentication authentication =
        (YggdrasilUserAuthentication)
            new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1")
                .createUserAuthentication(Agent.MINECRAFT);
    if (user != null) {
      Logger.logDebug(
          user.contains("@")
              ? "Email address given"
              : "Username given" + " Not 100% sure, mojangdata might contain different username");
      Logger.logInfo("Beginning authlib authentication attempt");
      Logger.logInfo("successfully created YggdrasilAuthenticationService");
      authentication.setUsername(user);
      if (pass != null && !pass.isEmpty()) {
        authentication.setPassword(pass);
        hasPassword = true;
      }
      if (mojangData != null && !mojangData.isEmpty()) {
        Logger.logDebug("mojangData was passed to current method");
        Map<String, Object> m = decode(mojangData);
        if (m != null) {
          Logger.logDebug("Loading mojangData into authlib");
          authentication.loadFromStorage(m);
          hasMojangData = true;
        }
      } else {
        Logger.logDebug("mojangData is null or empty");
      }
      if (authentication.canLogIn()) {
        try {
          authentication.logIn();
        } catch (UserMigratedException e) {
          Logger.logError(e.toString());
          ErrorUtils.tossError(
              "Invalid credentials, please make sure to login with your Mojang account.");
          return null;
        } catch (InvalidCredentialsException e) {
          Logger.logError("Invalid credentials recieved for user: "******"Invalid username or password.");
            return null;
          }
        } catch (AuthenticationUnavailableException e) {
          Logger.logDebug("Error while authenticating, trying offline mode");
          if (hasMojangData) {
            // if the UUID is valid we can proceed to offline mode later
            uniqueID = authentication.getSelectedProfile().getId().toString();
            if (uniqueID != null && !uniqueID.isEmpty()) Logger.logDebug("Setting UUID");
            UserManager.setUUID(user, uniqueID);
          }
          if (uniqueID != null && !uniqueID.isEmpty()) {
            UserManager.setUUID(user, uniqueID);
            Logger.logDebug("Setting UUID and creating and returning new LoginResponse");
            return new LoginResponse(
                Integer.toString(authentication.getAgent().getVersion()),
                "token",
                user,
                null,
                uniqueID,
                authentication);
          }
          ErrorUtils.tossError(
              "Exception occurred, minecraft servers might be down. Check @ help.mojang.com");
          Logger.logDebug("failed", e);
          Logger.logDebug("AuthenticationUnavailableException caused by", e.getCause());
          return null;
        } catch (AuthenticationException e) {
          Logger.logError("Unknown error from authlib:", e);
        } catch (Exception e) {
          Logger.logError("Unknown authentication error occurred", e);
        }
      } else {
        Logger.logDebug("authentication.canLogIn() returned false");
      }

      if (isValid(authentication)) {
        Logger.logDebug("Authentication is valid ");
        displayName = authentication.getSelectedProfile().getName();
        if ((authentication.isLoggedIn()) && (authentication.canPlayOnline())) {
          Logger.logDebug("loggedIn() && CanPlayOnline()");
          if ((authentication instanceof YggdrasilUserAuthentication)) {
            UserManager.setStore(user, encode(authentication.saveForStorage()));
            UserManager.setUUID(
                user,
                authentication
                    .getSelectedProfile()
                    .getId()
                    .toString()); // enables use of offline mode later if needed on newer MC
            // Versions
            Logger.logDebug("Authentication done, returning LoginResponse");
            return new LoginResponse(
                Integer.toString(authentication.getAgent().getVersion()),
                "token",
                displayName,
                authentication.getAuthenticatedToken(),
                authentication.getSelectedProfile().getId().toString(),
                authentication);
          }
        }
        Logger.logDebug(
            "this should never happen: isLoggedIn: "
                + authentication.isLoggedIn()
                + " canPlayOnline(): "
                + authentication.canPlayOnline());
      } else if (authentication.getSelectedProfile() == null
          && (authentication.getAvailableProfiles() != null
              && authentication.getAvailableProfiles().length != 0)) {
        // user has more than one profile
        Logger.logDebug("User has more than one profile: " + toString(authentication));
        for (GameProfile profile : authentication.getAvailableProfiles()) {
          if (selectedProfileName.equals(profile.getName())) {
            Logger.logInfo("Selected profile: " + profile.getName());
            selectedProfile = profile;
          }
        }
        if (selectedProfile == null) {
          Logger.logInfo("Profile not found, defaulting to first");
          selectedProfile = authentication.getAvailableProfiles()[0];
        }
        Logger.logDebug("Authentication done, returning LoginResponse");
        return new LoginResponse(
            Integer.toString(authentication.getAgent().getVersion()),
            "token",
            selectedProfile.getName(),
            authentication.getAuthenticatedToken(),
            selectedProfile.getId().toString(),
            authentication);
      } else if (authentication.getSelectedProfile() == null
          && (authentication.getAvailableProfiles() != null
              && authentication.getAvailableProfiles().length == 0)) {
        Logger.logDebug("No profiles in mojang account: " + toString(authentication));
        ErrorUtils.showClickableMessage(
            "You need to own minecraft to play FTB Modpacks",
            "https://help.mojang.com/customer/portal/articles/1218766-can-only-play-minecraft-demo");
        return null;
      } else {
        Logger.logDebug("this should never happen: " + toString(authentication));
      }

    } else {
      Logger.logDebug("this should never happen");
    }

    if (hasMojangData) {
      Logger.logError(
          "Failed to authenticate with mojang data, attempting to use username & password");
      if (!hasPassword) {
        new PasswordDialog(LaunchFrame.getInstance(), true).setVisible(true);
        if (LaunchFrame.tempPass.isEmpty()) return null;
        pass = LaunchFrame.tempPass;
      }

      LoginResponse l = authenticateWithAuthlib(user, pass, null, selectedProfileName);
      if (l == null) {
        Logger.logError("Failed to login with username & password");
        return null;
      } else {
        Logger.logDebug("authentication ready, returning LoginResponse from authlib");
        return l;
      }
    }
    Logger.logError("Failed to authenticate");
    return null;
  }