[FEATURE] Реализация profileByUUID/profileByUsername на вебсокетах

This commit is contained in:
Gravit 2019-04-04 14:02:42 +07:00
parent ae3e824c91
commit 27ab69cd78
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 70 additions and 12 deletions

View file

@ -19,6 +19,9 @@
import ru.gravit.launchserver.socket.websocket.json.admin.AddLogListenerResponse;
import ru.gravit.launchserver.socket.websocket.json.admin.ExecCommandResponse;
import ru.gravit.launchserver.socket.websocket.json.auth.*;
import ru.gravit.launchserver.socket.websocket.json.profile.BatchProfileByUsername;
import ru.gravit.launchserver.socket.websocket.json.profile.ProfileByUUIDResponse;
import ru.gravit.launchserver.socket.websocket.json.profile.ProfileByUsername;
import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse;
import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse;
import ru.gravit.launchserver.socket.websocket.json.update.UpdateResponse;
@ -82,6 +85,9 @@ public void registerResponses() {
registerResponse("addLogListener", AddLogListenerResponse.class);
registerResponse("update", UpdateResponse.class);
registerResponse("restoreSession", RestoreSessionResponse.class);
registerResponse("batchProfileByUsername", BatchProfileByUsername.class);
registerResponse("profileByUsername", ProfileByUsername.class);
registerResponse("profileByUUID", ProfileByUUIDResponse.class);
}
public void sendObject(ChannelHandlerContext ctx, Object obj) {

View file

@ -2,10 +2,13 @@
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -14,15 +17,27 @@
import java.io.IOException;
public final class BatchProfileByUsernameRequest extends Request<BatchProfileByUsernameRequestEvent> {
private final String[] usernames;
public final class BatchProfileByUsernameRequest extends Request<BatchProfileByUsernameRequestEvent> implements RequestInterface {
class Entry {
@LauncherNetworkAPI
String username;
@LauncherNetworkAPI
String client;
}
@LauncherNetworkAPI
private final Entry[] list;
@LauncherAPI
public BatchProfileByUsernameRequest(LauncherConfig config, String... usernames) throws IOException {
super(config);
this.usernames = usernames.clone();
IOHelper.verifyLength(this.usernames.length, SerializeLimits.MAX_BATCH_SIZE);
for (String username : this.usernames)
this.list = new Entry[usernames.length];
for(int i=0;i<usernames.length;++i)
{
this.list[i].client = "";
this.list[i].username = usernames[i];
}
IOHelper.verifyLength(usernames.length, SerializeLimits.MAX_BATCH_SIZE);
for (String username : usernames)
VerifyHelper.verifyUsername(username);
}
@ -30,6 +45,10 @@ public BatchProfileByUsernameRequest(LauncherConfig config, String... usernames)
public BatchProfileByUsernameRequest(String... usernames) throws IOException {
this(null, usernames);
}
@Override
public BatchProfileByUsernameRequestEvent requestWebSockets() throws IOException, InterruptedException {
return (BatchProfileByUsernameRequestEvent) LegacyRequestBridge.sendRequest(this);
}
@Override
public Integer getLegacyType() {
@ -38,19 +57,24 @@ public Integer getLegacyType() {
@Override
protected BatchProfileByUsernameRequestEvent requestDo(HInput input, HOutput output) throws IOException {
output.writeLength(usernames.length, SerializeLimits.MAX_BATCH_SIZE);
for (String username : usernames) {
output.writeString(username, SerializeLimits.MAX_LOGIN);
output.writeString("", SerializeLimits.MAX_CLIENT);
output.writeLength(list.length, SerializeLimits.MAX_BATCH_SIZE);
for (Entry username : list) {
output.writeString(username.username, SerializeLimits.MAX_LOGIN);
output.writeString(username.client, SerializeLimits.MAX_CLIENT);
}
output.flush();
// Read profiles response
PlayerProfile[] profiles = new PlayerProfile[usernames.length];
PlayerProfile[] profiles = new PlayerProfile[list.length];
for (int i = 0; i < profiles.length; i++)
profiles[i] = input.readBoolean() ? new PlayerProfile(input) : null;
// Return result
return new BatchProfileByUsernameRequestEvent(profiles);
}
@Override
public String getType() {
return "batchProfileByUsername";
}
}

View file

@ -3,10 +3,13 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -15,7 +18,8 @@
import java.util.Objects;
import java.util.UUID;
public final class ProfileByUUIDRequest extends Request<ProfileByUUIDRequestEvent> {
public final class ProfileByUUIDRequest extends Request<ProfileByUUIDRequestEvent> implements RequestInterface {
@LauncherNetworkAPI
private final UUID uuid;
@LauncherAPI
@ -29,6 +33,11 @@ public ProfileByUUIDRequest(UUID uuid) {
this(null, uuid);
}
@Override
public ProfileByUUIDRequestEvent requestWebSockets() throws IOException, InterruptedException {
return (ProfileByUUIDRequestEvent) LegacyRequestBridge.sendRequest(this);
}
@Override
public Integer getLegacyType() {
return RequestType.PROFILE_BY_UUID.getNumber();
@ -43,4 +52,9 @@ protected ProfileByUUIDRequestEvent requestDo(HInput input, HOutput output) thro
// Return profile
return input.readBoolean() ? new ProfileByUUIDRequestEvent(new PlayerProfile(input)) : null;
}
@Override
public String getType() {
return "profileByUUID";
}
}

View file

@ -3,10 +3,13 @@
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
@ -14,7 +17,8 @@
import java.io.IOException;
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> {
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> implements RequestInterface {
@LauncherNetworkAPI
private final String username;
@LauncherAPI
@ -28,6 +32,11 @@ public ProfileByUsernameRequest(String username) {
this(null, username);
}
@Override
public ProfileByUsernameRequestEvent requestWebSockets() throws IOException, InterruptedException {
return (ProfileByUsernameRequestEvent) LegacyRequestBridge.sendRequest(this);
}
@Override
public Integer getLegacyType() {
return RequestType.PROFILE_BY_USERNAME.getNumber();
@ -41,4 +50,9 @@ protected ProfileByUsernameRequestEvent requestDo(HInput input, HOutput output)
// Return profile
return input.readBoolean() ? new ProfileByUsernameRequestEvent(new PlayerProfile(input)) : null;
}
@Override
public String getType() {
return "profileByUsername";
}
}