mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-04 15:31:53 +03:00
RequestAuthHandler: UUIDtoUsername вроде бы сделан
This commit is contained in:
parent
b4ead749e1
commit
9543cbe68d
1 changed files with 38 additions and 3 deletions
|
@ -1,29 +1,42 @@
|
|||
package ru.gravit.launchserver.auth.handler;
|
||||
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/*
|
||||
* author sasha0552
|
||||
*
|
||||
*/
|
||||
|
||||
public final class RequestAuthHandler extends AuthHandler {
|
||||
// Из конфига строки
|
||||
private String url;
|
||||
private transient Pattern pattern;
|
||||
private String urlGetUUID;
|
||||
private String urlUpdateAccessToken;
|
||||
private String urlUpdateServerID;
|
||||
private String response;
|
||||
|
||||
// Поля
|
||||
private String username;
|
||||
private String uuid;
|
||||
private String accessToken;
|
||||
private String serverID;
|
||||
|
||||
private transient Pattern pattern;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
//TODO добавить ошибки к строкам из конфига
|
||||
if (url == null) LogHelper.error("[Verify][AuthHandler] url cannot be null");
|
||||
if (response == null) LogHelper.error("[Verify][AuthHandler] response cannot be null");
|
||||
pattern = Pattern.compile(response);
|
||||
|
@ -31,6 +44,28 @@ public void init() {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
// Do nothing
|
||||
// Ничего не делать
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uuidToUsername(UUID uuid) throws IOException {
|
||||
URL url;
|
||||
HttpURLConnection conn;
|
||||
BufferedReader rd;
|
||||
String line;
|
||||
String result = "";
|
||||
try {
|
||||
url = new URL(format("%s?uuid=%s",urlGetUUID,uuid));
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
while ((line = rd.readLine()) != null) {
|
||||
// Пусто
|
||||
}
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
LogHelper.error("[Request AuthHandler] Error get username by UUID");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue