Merge pull request #125 from yushijinhun/develop

Release v1.1.37
This commit is contained in:
Haowei Wen 2021-06-12 03:40:17 +08:00 committed by GitHub
commit b4a58d23da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 5 deletions

View file

@ -44,6 +44,7 @@ import java.util.Set;
import java.util.stream.Stream;
import moe.yushi.authlibinjector.httpd.DefaultURLRedirector;
import moe.yushi.authlibinjector.httpd.LegacySkinAPIFilter;
import moe.yushi.authlibinjector.httpd.PrivilegesFilter;
import moe.yushi.authlibinjector.httpd.QueryProfileFilter;
import moe.yushi.authlibinjector.httpd.QueryUUIDsFilter;
import moe.yushi.authlibinjector.httpd.URLFilter;
@ -239,6 +240,12 @@ public final class AuthlibInjector {
log(INFO, "Disabled Mojang namespace");
}
boolean polyfillPrivilegesApi = !Boolean.TRUE.equals(config.getMeta().get("feature.privileges_api"));
if (polyfillPrivilegesApi) {
log(INFO, "Polyfill privileges API");
filters.add(new PrivilegesFilter());
}
return filters;
}

View file

@ -37,6 +37,7 @@ public class DefaultURLRedirector implements URLRedirector {
domainMapping.put("authserver.mojang.com", "authserver");
domainMapping.put("sessionserver.mojang.com", "sessionserver");
domainMapping.put("skins.minecraft.net", "skins");
domainMapping.put("api.minecraftservices.com", "minecraftservices");
}
@Override

View file

@ -0,0 +1,61 @@
/*
* Copyright (C) 2021 Haowei Wen <yushijinhun@gmail.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package moe.yushi.authlibinjector.httpd;
import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_JSON;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Response;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Status;
import moe.yushi.authlibinjector.internal.org.json.simple.JSONObject;
public class PrivilegesFilter implements URLFilter {
private final Map<String, Boolean> privileges = new LinkedHashMap<>();
public PrivilegesFilter() {
privileges.put("onlineChat", true);
privileges.put("multiplayerServer", true);
privileges.put("multiplayerRealms", true);
privileges.put("telemetry", false);
}
@Override
public boolean canHandle(String domain) {
return domain.equals("api.minecraftservices.com");
}
@Override
public Optional<Response> handle(String domain, String path, IHTTPSession session) throws IOException {
if (domain.equals("api.minecraftservices.com") && path.equals("/privileges") && session.getMethod().equals("GET")) {
JSONObject response = new JSONObject();
JSONObject privilegesJson = new JSONObject();
privileges.forEach((name, enabled) -> {
JSONObject privilegeJson = new JSONObject();
privilegeJson.put("enabled", enabled);
privilegesJson.put(name, privilegeJson);
});
response.put("privileges", privilegesJson);
return Optional.of(Response.newFixedLength(Status.OK, CONTENT_TYPE_JSON, response.toJSONString()));
} else {
return Optional.empty();
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Haowei Wen <yushijinhun@gmail.com> and contributors
* Copyright (C) 2021 Haowei Wen <yushijinhun@gmail.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -206,16 +206,18 @@ public class Response implements Closeable {
protected long sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw, long defaultSize) {
String contentLengthString = getHeader("content-length");
long size = defaultSize;
if (contentLengthString != null) {
if (contentLengthString == null) {
pw.print("Content-Length: " + defaultSize + "\r\n");
return defaultSize;
} else {
long size = defaultSize;
try {
size = Long.parseLong(contentLengthString);
} catch (NumberFormatException ex) {
log(ERROR, "content-length was not number " + contentLengthString);
}
return size;
}
pw.print("Content-Length: " + size + "\r\n");
return size;
}
private void sendBodyWithCorrectTransferAndEncoding(OutputStream outputStream, long pending) throws IOException {