[FEATURE] Перенос RequestEvent

This commit is contained in:
Gravit 2019-01-28 22:28:12 +07:00
parent 751048ab3e
commit 1ce4b6f11b
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
18 changed files with 146 additions and 108 deletions

View file

@ -1,11 +1,9 @@
package ru.gravit.launchserver.socket.websocket.json.auth; package ru.gravit.launchserver.socket.websocket.json.auth;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.OshiHWID;
import ru.gravit.launcher.events.request.AuthRequestEvent;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.hwid.HWIDException;
@ -50,7 +48,7 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception {
try { try {
Result result = new Result(); AuthRequestEvent result = new AuthRequestEvent();
String ip = IOHelper.getIP(ctx.channel().remoteAddress()); String ip = IOHelper.getIP(ctx.channel().remoteAddress());
if (LaunchServer.server.limiter.isLimit(ip)) { if (LaunchServer.server.limiter.isLimit(ip)) {
AuthProvider.authError(LaunchServer.server.config.authRejectString); AuthProvider.authError(LaunchServer.server.config.authRejectString);
@ -104,13 +102,4 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
} }
} }
public class Result {
public Result() {
}
public String error;
public ClientPermissions permissions;
public PlayerProfile playerProfile;
public String accessToken;
}
} }

View file

@ -1,7 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.auth; package ru.gravit.launchserver.socket.websocket.json.auth;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.events.request.CheckServerEvent;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
@ -10,8 +10,6 @@
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.util.UUID;
public class CheckServerResponse implements JsonResponseInterface { public class CheckServerResponse implements JsonResponseInterface {
public String serverID; public String serverID;
public String username; public String username;
@ -24,7 +22,7 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) {
Result result = new Result(); CheckServerEvent result = new CheckServerEvent();
try { try {
result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID); result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID);
if(result.uuid != null) if(result.uuid != null)
@ -37,13 +35,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error"));
return; return;
} }
service.sendObject(ctx, new Result()); service.sendObject(ctx, new CheckServerEvent());
} }
public class Result {
public String type = "success";
public String requesttype = "checkServer";
public UUID uuid;
public PlayerProfile playerProfile;
}
} }

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.auth; package ru.gravit.launchserver.socket.websocket.json.auth;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.JoinServerRequestEvent;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.AuthException;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
@ -31,17 +32,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error"));
return; return;
} }
service.sendObject(ctx, new Result(success)); service.sendObject(ctx, new JoinServerRequestEvent(success));
} }
public class Result {
public String type = "success";
public String requesttype = "checkServer";
public Result(boolean allow) {
this.allow = allow;
}
public boolean allow;
}
} }

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.auth; package ru.gravit.launchserver.socket.websocket.json.auth;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.ProfilesRequestEvent;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
@ -22,17 +23,6 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
return; return;
} }
service.sendObject(ctx, new Result((List<ClientProfile>) LaunchServer.server.getProfiles())); service.sendObject(ctx, new ProfilesRequestEvent((List<ClientProfile>) LaunchServer.server.getProfiles()));
}
public class Result
{
List<ClientProfile> profiles;
public Result(List<ClientProfile> profiles) {
this.profiles = profiles;
}
String requesttype = "profilesList";
String error;
} }
} }

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.profile; package ru.gravit.launchserver.socket.websocket.json.profile;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
@ -23,7 +24,7 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
Result result = new Result(); BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent();
result.playerProfiles = new PlayerProfile[list.length]; result.playerProfiles = new PlayerProfile[list.length];
for(int i=0;i<list.length;++i) for(int i=0;i<list.length;++i)
{ {
@ -32,10 +33,4 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
} }
service.sendObject(ctx, result); service.sendObject(ctx, result);
} }
public class Result
{
String requesttype = "batchProfileByUsername";
String error;
PlayerProfile[] playerProfiles;
}
} }

View file

@ -1,13 +1,13 @@
package ru.gravit.launchserver.socket.websocket.json.profile; package ru.gravit.launchserver.socket.websocket.json.profile;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;
import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.profiles.Texture;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.WebSocketService;
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
import ru.gravit.launchserver.socket.websocket.json.auth.ProfilesResponse;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.io.IOException; import java.io.IOException;
@ -47,16 +47,6 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
String username = LaunchServer.server.config.authHandler.uuidToUsername(uuid); String username = LaunchServer.server.config.authHandler.uuidToUsername(uuid);
service.sendObject(ctx, new Result(getProfile(LaunchServer.server,uuid,username,this.client))); service.sendObject(ctx, new ProfileByUUIDRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
}
public class Result
{
String requesttype = "profileByUUID";
String error;
PlayerProfile playerProfile;
public Result(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
} }
} }

View file

@ -1,7 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.profile; package ru.gravit.launchserver.socket.websocket.json.profile;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.WebSocketService;
@ -22,16 +22,6 @@ public String getType() {
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(username); UUID uuid = LaunchServer.server.config.authHandler.usernameToUUID(username);
service.sendObject(ctx, new Result(getProfile(LaunchServer.server,uuid,username,this.client))); service.sendObject(ctx, new ProfileByUsernameRequestEvent(getProfile(LaunchServer.server,uuid,username,this.client)));
}
public class Result
{
String requesttype = "profileByUsername";
String error;
PlayerProfile playerProfile;
public Result(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
} }
} }

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.update; package ru.gravit.launchserver.socket.websocket.json.update;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.LauncherRequestEvent;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.WebSocketService;
@ -29,37 +30,25 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
if (launcher_type == 1) // JAR if (launcher_type == 1) // JAR
{ {
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest(); byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL));
if (Arrays.equals(bytes, hash)) { if (Arrays.equals(bytes, hash)) {
client.checkSign = true; client.checkSign = true;
service.sendObject(ctx, new Result(false, JAR_URL)); service.sendObject(ctx, new LauncherRequestEvent(false, JAR_URL));
} else { } else {
service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, JAR_URL));
} }
} else if (launcher_type == 2) //EXE } else if (launcher_type == 2) //EXE
{ {
byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest(); byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest();
if (hash == null) service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, EXE_URL));
if (Arrays.equals(bytes, hash)) { if (Arrays.equals(bytes, hash)) {
client.checkSign = true; client.checkSign = true;
service.sendObject(ctx, new Result(false, EXE_URL)); service.sendObject(ctx, new LauncherRequestEvent(false, EXE_URL));
} else { } else {
service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, EXE_URL));
} }
} else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error")); } else service.sendObject(ctx, new WebSocketService.ErrorResult("Request launcher type error"));
} }
public class Result {
public String type = "success";
public String requesttype = "launcherUpdate";
public String url;
public Result(boolean needUpdate, String url) {
this.needUpdate = needUpdate;
this.url = url;
}
public boolean needUpdate;
}
} }

View file

@ -1,6 +1,7 @@
package ru.gravit.launchserver.socket.websocket.json.update; package ru.gravit.launchserver.socket.websocket.json.update;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import ru.gravit.launcher.events.request.UpdateListRequestEvent;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
@ -22,18 +23,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
return; return;
} }
HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object; HashedDir hdir = LaunchServer.server.updatesDirMap.get(dir).object;
service.sendObject(ctx, new Result(hdir)); service.sendObject(ctx, new UpdateListRequestEvent(hdir));
} }
class Result {
public final String type;
public final String requesttype;
public final HashedDir dir;
Result(HashedDir dir) {
this.dir = dir;
type = "success";
requesttype = "updateList";
}
}
} }

View file

@ -0,0 +1,14 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.ClientPermissions;
import ru.gravit.launcher.profiles.PlayerProfile;
public class AuthRequestEvent {
public AuthRequestEvent() {
}
public String error;
public ClientPermissions permissions;
public PlayerProfile playerProfile;
public String accessToken;
}

View file

@ -0,0 +1,10 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.profiles.PlayerProfile;
public class BatchProfileByUsernameRequestEvent
{
public String requesttype = "batchProfileByUsername";
public String error;
public PlayerProfile[] playerProfiles;
}

View file

@ -0,0 +1,12 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.profiles.PlayerProfile;
import java.util.UUID;
public class CheckServerEvent {
public String type = "success";
public String requesttype = "checkServer";
public UUID uuid;
public PlayerProfile playerProfile;
}

View file

@ -0,0 +1,12 @@
package ru.gravit.launcher.events.request;
public class JoinServerRequestEvent {
public String type = "success";
public String requesttype = "checkServer";
public JoinServerRequestEvent(boolean allow) {
this.allow = allow;
}
public boolean allow;
}

View file

@ -0,0 +1,14 @@
package ru.gravit.launcher.events.request;
public class LauncherRequestEvent {
public String type = "success";
public String requesttype = "launcherUpdate";
public String url;
public LauncherRequestEvent(boolean needUpdate, String url) {
this.needUpdate = needUpdate;
this.url = url;
}
public boolean needUpdate;
}

View file

@ -0,0 +1,14 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.profiles.PlayerProfile;
public class ProfileByUUIDRequestEvent
{
String requesttype = "profileByUUID";
String error;
PlayerProfile playerProfile;
public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
}

View file

@ -0,0 +1,14 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.profiles.PlayerProfile;
public class ProfileByUsernameRequestEvent
{
String requesttype = "profileByUsername";
String error;
PlayerProfile playerProfile;
public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
}

View file

@ -0,0 +1,17 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.profiles.ClientProfile;
import java.util.List;
public class ProfilesRequestEvent
{
List<ClientProfile> profiles;
public ProfilesRequestEvent(List<ClientProfile> profiles) {
this.profiles = profiles;
}
String requesttype = "profilesList";
String error;
}

View file

@ -0,0 +1,15 @@
package ru.gravit.launcher.events.request;
import ru.gravit.launcher.hasher.HashedDir;
public class UpdateListRequestEvent {
public final String type;
public final String requesttype;
public final HashedDir dir;
public UpdateListRequestEvent(HashedDir dir) {
this.dir = dir;
type = "success";
requesttype = "updateList";
}
}