use of org.spongepowered.api.profile.property.ProfileProperty in project SkinsRestorerX by DoNotSpamPls.
the class SkinCommand method execute.
@Override
public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
if (!(source instanceof Player)) {
source.sendMessage(Text.builder("This command is only for players!").color(TextColors.RED).build());
return CommandResult.empty();
}
Player p = (Player) source;
String name = p.getName().toLowerCase();
String skin = args.<String>getOne("skin").get().toLowerCase();
Collection<ProfileProperty> props = p.getProfile().getPropertyMap().get("textures");
Optional<String> uid = MojangAPI.getUUID(skin);
if (!uid.isPresent()) {
p.sendMessage(Text.builder("This player does not exist, or is not premium.").color(TextColors.RED).build());
return CommandResult.empty();
}
Optional<ProfileProperty> textures = MojangAPI.getSkinProperty(uid.get());
if (!textures.isPresent()) {
p.sendMessage(Text.builder("Could not get player's skin data (Rate Limited ?).").color(TextColors.RED).build());
return CommandResult.empty();
}
props.clear();
props.add(textures.get());
if (!name.equalsIgnoreCase(skin))
SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(skin);
else
SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(null);
SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Value").setValue(textures.get().getValue());
SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Signature").setValue(textures.get().getSignature().get());
SkinsRestorer.getInstance().saveConfigs();
p.sendMessage(Text.builder("Your skin has been changed.").color(TextColors.DARK_BLUE).build());
return CommandResult.success();
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class CodecPlayOutTabListEntries method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutTabListEntries message) throws CodecException {
ByteBuffer buf = context.byteBufAlloc().buffer();
List<Entry> entries = message.getEntries();
int type = this.typeLookup.get(entries.get(0).getClass());
buf.writeVarInt(type);
buf.writeVarInt(entries.size());
for (Entry entry : entries) {
buf.writeUniqueId(entry.getGameProfile().getUniqueId());
switch(type) {
case ADD:
buf.writeString(entry.getGameProfile().getName().orElse("unknown"));
Collection<ProfileProperty> properties = entry.getGameProfile().getPropertyMap().values();
buf.writeVarInt(properties.size());
for (ProfileProperty property : properties) {
buf.writeString(property.getName());
buf.writeString(property.getValue());
Optional<String> signature = property.getSignature();
boolean flag = signature.isPresent();
buf.writeBoolean(flag);
if (flag) {
buf.writeString(signature.get());
}
}
buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
buf.writeVarInt(entry.getPing());
Text displayName = entry.getDisplayName();
boolean flag = displayName != null;
buf.writeBoolean(flag);
if (flag) {
buf.write(Types.TEXT, displayName);
}
break;
case UPDATE_GAME_MODE:
buf.writeVarInt(((LanternGameMode) entry.getGameMode()).getInternalId());
break;
case UPDATE_LATENCY:
buf.writeVarInt(entry.getPing());
break;
case UPDATE_DISPLAY_NAME:
Text displayName0 = entry.getDisplayName();
boolean flag0 = displayName0 != null;
buf.writeBoolean(flag0);
if (flag0) {
buf.write(Types.TEXT, displayName0);
}
break;
case REMOVE:
break;
}
}
return buf;
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class HandlerHandshakeIn method handle.
@Override
public void handle(NetworkContext context, MessageHandshakeIn message) {
final Optional<ProtocolState> optNextState = ProtocolState.getFromId(message.getNextState());
final NetworkSession session = context.getSession();
if (!optNextState.isPresent()) {
session.disconnect(t("Unknown protocol state! (%s)", message.getNextState()));
return;
}
final ProtocolState nextState = optNextState.get();
session.setProtocolState(nextState);
if (!nextState.equals(ProtocolState.LOGIN) && !nextState.equals(ProtocolState.STATUS)) {
session.disconnect(t("Received a unexpected handshake message! (%s)", nextState));
return;
}
final ProxyType proxyType = Lantern.getGame().getGlobalConfig().getProxyType();
String hostname = message.getHostname();
InetSocketAddress virtualAddress;
switch(proxyType) {
case WATERFALL:
case BUNGEE_CORD:
String[] split = hostname.split("\0\\|", 2);
// Check for a fml marker
session.getChannel().attr(NetworkSession.FML_MARKER).set(split.length == 2 == split[1].contains(FML_MARKER));
split = split[0].split("\00");
if (split.length == 3 || split.length == 4) {
virtualAddress = new InetSocketAddress(split[1], message.getPort());
final UUID uniqueId = UUIDHelper.fromFlatString(split[2]);
final Multimap<String, ProfileProperty> properties;
if (split.length == 4) {
try {
properties = LanternProfileProperty.createPropertiesMapFromJson(GSON.fromJson(split[3], JsonArray.class));
} catch (Exception e) {
session.disconnect(t("Invalid %s proxy data format.", proxyType.getName()));
throw new CodecException(e);
}
} else {
properties = LinkedHashMultimap.create();
}
session.getChannel().attr(HandlerLoginStart.SPOOFED_GAME_PROFILE).set(new LanternGameProfile(uniqueId, null, properties));
} else {
session.disconnect(t("Please enable client detail forwarding (also known as \"ip forwarding\") on " + "your proxy if you wish to use it on this server, and also make sure that you joined through the proxy."));
return;
}
break;
case LILY_PAD:
try {
final JsonObject jsonObject = GSON.fromJson(hostname, JsonObject.class);
final String securityKey = Lantern.getGame().getGlobalConfig().getProxySecurityKey();
// Validate the security key
if (!securityKey.isEmpty() && !jsonObject.get("s").getAsString().equals(securityKey)) {
session.disconnect(t("Proxy security key mismatch"));
Lantern.getLogger().warn("Proxy security key mismatch for the player {}", jsonObject.get("n").getAsString());
return;
}
final String name = jsonObject.get("n").getAsString();
final UUID uniqueId = UUIDHelper.fromFlatString(jsonObject.get("u").getAsString());
final Multimap<String, ProfileProperty> properties = LinkedHashMultimap.create();
if (jsonObject.has("p")) {
final JsonArray jsonArray = jsonObject.getAsJsonArray("p");
for (int i = 0; i < jsonArray.size(); i++) {
final JsonObject property = jsonArray.get(i).getAsJsonObject();
final String propertyName = property.get("n").getAsString();
final String propertyValue = property.get("v").getAsString();
final String propertySignature = property.has("s") ? property.get("s").getAsString() : null;
properties.put(propertyName, new LanternProfileProperty(propertyName, propertyValue, propertySignature));
}
}
session.getChannel().attr(HandlerLoginStart.SPOOFED_GAME_PROFILE).set(new LanternGameProfile(uniqueId, name, properties));
session.getChannel().attr(NetworkSession.FML_MARKER).set(false);
final int port = jsonObject.get("rP").getAsInt();
final String host = jsonObject.get("h").getAsString();
virtualAddress = new InetSocketAddress(host, port);
} catch (Exception e) {
session.disconnect(t("Invalid %s proxy data format.", proxyType.getName()));
throw new CodecException(e);
}
break;
case NONE:
int index = hostname.indexOf(FML_MARKER);
session.getChannel().attr(NetworkSession.FML_MARKER).set(index != -1);
if (index != -1) {
hostname = hostname.substring(0, index);
}
virtualAddress = new InetSocketAddress(hostname, message.getPort());
break;
default:
throw new IllegalStateException("The proxy type " + proxyType + " isn't implemented");
}
session.setVirtualHost(virtualAddress);
session.setProtocolVersion(message.getProtocolVersion());
if (nextState == ProtocolState.LOGIN) {
final int protocol = Lantern.getGame().getPlatform().getMinecraftVersion().getProtocol();
if (message.getProtocolVersion() < protocol) {
session.disconnect(t("multiplayer.disconnect.outdated_client", Lantern.getGame().getPlatform().getMinecraftVersion().getName()));
} else if (message.getProtocolVersion() > protocol) {
session.disconnect(t("multiplayer.disconnect.outdated_server", Lantern.getGame().getPlatform().getMinecraftVersion().getName()));
}
}
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class GameProfileQuery method queryProfileByUUID.
static GameProfile queryProfileByUUID(UUID uniqueId, boolean signed) throws IOException, ProfileNotFoundException {
final URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + UUIDHelper.toFlatString(uniqueId) + (signed ? "?unsigned=false" : ""));
int attempts = 0;
while (true) {
final URLConnection uc = url.openConnection();
final InputStream is = uc.getInputStream();
// Can be empty if the unique id invalid is
if (is.available() == 0) {
throw new ProfileNotFoundException("Failed to find a profile with the uuid: " + uniqueId);
}
// If it fails too many times, just leave it
if (++attempts > 6) {
throw new IOException("Failed to retrieve the profile after 6 attempts: " + uniqueId);
}
final JsonObject json = GSON.fromJson(new InputStreamReader(is), JsonObject.class);
if (json.has("error")) {
// Too many requests, lets wait for 10 seconds
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new IOException("Something interrupted the next attempt delay.");
}
continue;
}
final String name = json.get("name").getAsString();
final Multimap<String, ProfileProperty> properties;
if (json.has("properties")) {
properties = LanternProfileProperty.createPropertiesMapFromJson(json.get("properties").getAsJsonArray());
} else {
properties = LinkedHashMultimap.create();
}
return new LanternGameProfile(uniqueId, name, properties);
}
}
use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.
the class LanternGameProfile method toContainer.
@Override
public DataContainer toContainer() {
final DataContainer container = DataContainer.createNew().set(UNIQUE_ID, this.uniqueId.toString());
if (this.name != null) {
container.set(NAME, this.name);
}
if (!this.properties.isEmpty()) {
final DataContainer propertiesMap = DataContainer.createNew();
for (String key : this.properties.keySet()) {
final List<DataContainer> entries = new ArrayList<>();
for (ProfileProperty property : this.properties.get(key)) {
final DataContainer entry = DataContainer.createNew().set(VALUE, property.getValue());
property.getSignature().ifPresent(signature -> entry.set(SIGNATURE, signature));
entries.add(entry);
}
propertiesMap.set(DataQuery.of(key), entries);
}
container.set(PROPERTIES, propertiesMap);
}
return container;
}
Aggregations