mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] Реализация profileByUUID/profileByUsername на вебсокетах
This commit is contained in:
parent
ae3e824c91
commit
27ab69cd78
4 changed files with 70 additions and 12 deletions
|
@ -19,6 +19,9 @@
|
||||||
import ru.gravit.launchserver.socket.websocket.json.admin.AddLogListenerResponse;
|
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.admin.ExecCommandResponse;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.auth.*;
|
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.LauncherResponse;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse;
|
import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse;
|
||||||
import ru.gravit.launchserver.socket.websocket.json.update.UpdateResponse;
|
import ru.gravit.launchserver.socket.websocket.json.update.UpdateResponse;
|
||||||
|
@ -82,6 +85,9 @@ public void registerResponses() {
|
||||||
registerResponse("addLogListener", AddLogListenerResponse.class);
|
registerResponse("addLogListener", AddLogListenerResponse.class);
|
||||||
registerResponse("update", UpdateResponse.class);
|
registerResponse("update", UpdateResponse.class);
|
||||||
registerResponse("restoreSession", RestoreSessionResponse.class);
|
registerResponse("restoreSession", RestoreSessionResponse.class);
|
||||||
|
registerResponse("batchProfileByUsername", BatchProfileByUsername.class);
|
||||||
|
registerResponse("profileByUsername", ProfileByUsername.class);
|
||||||
|
registerResponse("profileByUUID", ProfileByUUIDResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||||
|
|
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
|
import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
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.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -14,15 +17,27 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class BatchProfileByUsernameRequest extends Request<BatchProfileByUsernameRequestEvent> {
|
public final class BatchProfileByUsernameRequest extends Request<BatchProfileByUsernameRequestEvent> implements RequestInterface {
|
||||||
private final String[] usernames;
|
class Entry {
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
String username;
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
String client;
|
||||||
|
}
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
private final Entry[] list;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public BatchProfileByUsernameRequest(LauncherConfig config, String... usernames) throws IOException {
|
public BatchProfileByUsernameRequest(LauncherConfig config, String... usernames) throws IOException {
|
||||||
super(config);
|
super(config);
|
||||||
this.usernames = usernames.clone();
|
this.list = new Entry[usernames.length];
|
||||||
IOHelper.verifyLength(this.usernames.length, SerializeLimits.MAX_BATCH_SIZE);
|
for(int i=0;i<usernames.length;++i)
|
||||||
for (String username : this.usernames)
|
{
|
||||||
|
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);
|
VerifyHelper.verifyUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +45,10 @@ public BatchProfileByUsernameRequest(LauncherConfig config, String... usernames)
|
||||||
public BatchProfileByUsernameRequest(String... usernames) throws IOException {
|
public BatchProfileByUsernameRequest(String... usernames) throws IOException {
|
||||||
this(null, usernames);
|
this(null, usernames);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public BatchProfileByUsernameRequestEvent requestWebSockets() throws IOException, InterruptedException {
|
||||||
|
return (BatchProfileByUsernameRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getLegacyType() {
|
public Integer getLegacyType() {
|
||||||
|
@ -38,19 +57,24 @@ public Integer getLegacyType() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BatchProfileByUsernameRequestEvent requestDo(HInput input, HOutput output) throws IOException {
|
protected BatchProfileByUsernameRequestEvent requestDo(HInput input, HOutput output) throws IOException {
|
||||||
output.writeLength(usernames.length, SerializeLimits.MAX_BATCH_SIZE);
|
output.writeLength(list.length, SerializeLimits.MAX_BATCH_SIZE);
|
||||||
for (String username : usernames) {
|
for (Entry username : list) {
|
||||||
output.writeString(username, SerializeLimits.MAX_LOGIN);
|
output.writeString(username.username, SerializeLimits.MAX_LOGIN);
|
||||||
output.writeString("", SerializeLimits.MAX_CLIENT);
|
output.writeString(username.client, SerializeLimits.MAX_CLIENT);
|
||||||
}
|
}
|
||||||
output.flush();
|
output.flush();
|
||||||
|
|
||||||
// Read profiles response
|
// Read profiles response
|
||||||
PlayerProfile[] profiles = new PlayerProfile[usernames.length];
|
PlayerProfile[] profiles = new PlayerProfile[list.length];
|
||||||
for (int i = 0; i < profiles.length; i++)
|
for (int i = 0; i < profiles.length; i++)
|
||||||
profiles[i] = input.readBoolean() ? new PlayerProfile(input) : null;
|
profiles[i] = input.readBoolean() ? new PlayerProfile(input) : null;
|
||||||
|
|
||||||
// Return result
|
// Return result
|
||||||
return new BatchProfileByUsernameRequestEvent(profiles);
|
return new BatchProfileByUsernameRequestEvent(profiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "batchProfileByUsername";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
|
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
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.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -15,7 +18,8 @@
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
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;
|
private final UUID uuid;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -29,6 +33,11 @@ public ProfileByUUIDRequest(UUID uuid) {
|
||||||
this(null, uuid);
|
this(null, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfileByUUIDRequestEvent requestWebSockets() throws IOException, InterruptedException {
|
||||||
|
return (ProfileByUUIDRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getLegacyType() {
|
public Integer getLegacyType() {
|
||||||
return RequestType.PROFILE_BY_UUID.getNumber();
|
return RequestType.PROFILE_BY_UUID.getNumber();
|
||||||
|
@ -43,4 +52,9 @@ protected ProfileByUUIDRequestEvent requestDo(HInput input, HOutput output) thro
|
||||||
// Return profile
|
// Return profile
|
||||||
return input.readBoolean() ? new ProfileByUUIDRequestEvent(new PlayerProfile(input)) : null;
|
return input.readBoolean() ? new ProfileByUUIDRequestEvent(new PlayerProfile(input)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "profileByUUID";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.LauncherConfig;
|
import ru.gravit.launcher.LauncherConfig;
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
import ru.gravit.launcher.request.RequestType;
|
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.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
|
@ -14,7 +17,8 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
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;
|
private final String username;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -28,6 +32,11 @@ public ProfileByUsernameRequest(String username) {
|
||||||
this(null, username);
|
this(null, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfileByUsernameRequestEvent requestWebSockets() throws IOException, InterruptedException {
|
||||||
|
return (ProfileByUsernameRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getLegacyType() {
|
public Integer getLegacyType() {
|
||||||
return RequestType.PROFILE_BY_USERNAME.getNumber();
|
return RequestType.PROFILE_BY_USERNAME.getNumber();
|
||||||
|
@ -41,4 +50,9 @@ protected ProfileByUsernameRequestEvent requestDo(HInput input, HOutput output)
|
||||||
// Return profile
|
// Return profile
|
||||||
return input.readBoolean() ? new ProfileByUsernameRequestEvent(new PlayerProfile(input)) : null;
|
return input.readBoolean() ? new ProfileByUsernameRequestEvent(new PlayerProfile(input)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "profileByUsername";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue