Запрос ChangeServer

This commit is contained in:
Gravit 2018-11-06 18:57:19 +07:00
parent f79799bee1
commit 9e2a154c50
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 75 additions and 2 deletions

View file

@ -50,6 +50,7 @@ public static void registerResponses() {
registerResponse(RequestType.PROFILES.getNumber(), ProfilesResponse::new);
registerResponse(RequestType.SERVERAUTH.getNumber(), AuthServerResponse::new);
registerResponse(RequestType.SETPROFILE.getNumber(), SetProfileResponse::new);
registerResponse(RequestType.CHANGESERVER.getNumber(),ChangeServerResponse::new);
}

View file

@ -0,0 +1,28 @@
package ru.gravit.launchserver.response.auth;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.response.Response;
public class ChangeServerResponse extends Response {
public static boolean needChange = false;
public static String address;
public static int port;
public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
super(server, session, input, output, ip);
}
@Override
public void reply() throws Exception {
writeNoError(output);
output.writeBoolean(needChange);
//if true
if(needChange)
{
output.writeString(address,255);
output.writeInt(port);
}
}
}

View file

@ -0,0 +1,44 @@
package ru.gravit.launcher.request.auth;
import jdk.nashorn.internal.ir.RuntimeNode;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType;
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.utils.helper.IOHelper;
import java.net.InetSocketAddress;
public class ChangeServerRequest extends Request<ChangeServerRequest.Result> {
@Override
public Integer getType() {
return RequestType.CHANGESERVER.getNumber();
}
public boolean change(Result result)
{
if(!result.needChange) return false;
Launcher.getConfig().address = InetSocketAddress.createUnresolved( result.address, result.port);
return true;
}
@Override
protected Result requestDo(HInput input, HOutput output) throws Exception {
readError(input);
Result result = new Result();
result.needChange = input.readBoolean();
if(result.needChange)
{
result.address = input.readString(255);
result.port = input.readInt();
}
if(result.needChange) change(result);
return result;
}
public class Result
{
public boolean needChange;
public String address;
public int port;
}
}

View file

@ -31,7 +31,7 @@ public static AutogenConfig getAutogenConfig() {
// Instance
@LauncherAPI
public final InetSocketAddress address;
public InetSocketAddress address;
@LauncherAPI
public final String projectname;
public final int clientPort;

View file

@ -11,7 +11,7 @@ public enum RequestType implements EnumSerializer.Itf {
LEGACYLAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests
AUTH(4), JOIN_SERVER(5), CHECK_SERVER(6), // Auth requests
PROFILE_BY_USERNAME(7), PROFILE_BY_UUID(8), BATCH_PROFILE_BY_USERNAME(9), // Profile requests
PROFILES(10),SERVERAUTH(11), SETPROFILE(12),LAUNCHER(13),
PROFILES(10),SERVERAUTH(11), SETPROFILE(12),LAUNCHER(13),CHANGESERVER(14),
CUSTOM(255); // Custom requests
private static final EnumSerializer<RequestType> SERIALIZER = new EnumSerializer<>(RequestType.class);