mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] clientData доступен всем Response по умолчанию
This commit is contained in:
parent
124f1ddbeb
commit
96254b11ea
19 changed files with 61 additions and 55 deletions
|
@ -4,12 +4,13 @@
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class PingResponse extends Response {
|
public final class PingResponse extends Response {
|
||||||
public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) {
|
public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, id, input, output, ip);
|
super(server, id, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse;
|
||||||
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
|
import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse;
|
||||||
import ru.gravit.launchserver.response.update.*;
|
import ru.gravit.launchserver.response.update.*;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -21,13 +22,13 @@ public abstract class Response {
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Factory<R> {
|
public interface Factory<R> {
|
||||||
|
|
||||||
Response newResponse(LaunchServer server, long id, HInput input, HOutput output, String ip);
|
Response newResponse(LaunchServer server, long id, HInput input, HOutput output, String ip, Client clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Integer, Factory<?>> RESPONSES = new ConcurrentHashMap<>(8);
|
private static final Map<Integer, Factory<?>> RESPONSES = new ConcurrentHashMap<>(8);
|
||||||
|
|
||||||
public static Response getResponse(int type, LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public static Response getResponse(int type, LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
return RESPONSES.get(type).newResponse(server, session, input, output, ip);
|
return RESPONSES.get(type).newResponse(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerResponse(int type, Factory<?> factory) {
|
public static void registerResponse(int type, Factory<?> factory) {
|
||||||
|
@ -72,15 +73,18 @@ public static void requestError(String message) throws RequestException {
|
||||||
|
|
||||||
protected final String ip;
|
protected final String ip;
|
||||||
|
|
||||||
|
protected final Client clientData;
|
||||||
|
|
||||||
|
|
||||||
protected final long session;
|
protected final long session;
|
||||||
|
|
||||||
protected Response(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
protected Response(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
this.clientData = clientData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class ExecCommandResponse extends Response {
|
public class ExecCommandResponse extends Response {
|
||||||
public ExecCommandResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public ExecCommandResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,8 +31,8 @@ private static String echo(int length) {
|
||||||
return new String(chars);
|
return new String(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public AuthResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AuthContext {
|
public static class AuthContext {
|
||||||
|
@ -81,7 +81,6 @@ public void reply() throws Exception {
|
||||||
debug("Login: '%s', Password: '%s'", login, echo(password.length()));
|
debug("Login: '%s', Password: '%s'", login, echo(password.length()));
|
||||||
AuthProviderResult result;
|
AuthProviderResult result;
|
||||||
AuthProvider provider = server.config.authProvider[auth_id];
|
AuthProvider provider = server.config.authProvider[auth_id];
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
clientData.type = Client.Type.USER;
|
clientData.type = Client.Type.USER;
|
||||||
AuthContext context = new AuthContext(session, login, password.length(), customText, client, hwid_str, false);
|
AuthContext context = new AuthContext(session, login, password.length(), customText, client, hwid_str, false);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,8 +28,8 @@ private static String echo(int length) {
|
||||||
return new String(chars);
|
return new String(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public AuthServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,6 @@ public void reply() throws Exception {
|
||||||
debug("ServerLogin: '%s', Password: '%s'", login, echo(password.length()));
|
debug("ServerLogin: '%s', Password: '%s'", login, echo(password.length()));
|
||||||
AuthProviderResult result;
|
AuthProviderResult result;
|
||||||
AuthProvider provider = server.config.authProvider[auth_id];
|
AuthProvider provider = server.config.authProvider[auth_id];
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
try {
|
try {
|
||||||
if (server.limiter.isLimit(ip)) {
|
if (server.limiter.isLimit(ip)) {
|
||||||
AuthProvider.authError(server.config.authRejectString);
|
AuthProvider.authError(server.config.authRejectString);
|
||||||
|
|
|
@ -4,14 +4,15 @@
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
public class ChangeServerResponse extends Response {
|
public class ChangeServerResponse extends Response {
|
||||||
public static boolean needChange = false;
|
public static boolean needChange = false;
|
||||||
public static String address;
|
public static String address;
|
||||||
public static int port;
|
public static int port;
|
||||||
|
|
||||||
public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
public final class CheckServerResponse extends Response {
|
public final class CheckServerResponse extends Response {
|
||||||
|
|
||||||
public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,6 @@ public void reply() throws IOException {
|
||||||
String serverID = VerifyHelper.verifyServerID(input.readASCII(41)); // With minus sign
|
String serverID = VerifyHelper.verifyServerID(input.readASCII(41)); // With minus sign
|
||||||
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
||||||
debug("Username: %s, Server ID: %s", username, serverID);
|
debug("Username: %s, Server ID: %s", username, serverID);
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
if (!clientData.isAuth || clientData.type != Client.Type.SERVER) {
|
if (!clientData.isAuth || clientData.type != Client.Type.SERVER) {
|
||||||
requestError("Access denied");
|
requestError("Access denied");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
public final class JoinServerResponse extends Response {
|
public final class JoinServerResponse extends Response {
|
||||||
|
|
||||||
public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,6 @@ public void reply() throws IOException {
|
||||||
String username = VerifyHelper.verifyUsername(input.readString(SerializeLimits.MAX_LOGIN));
|
String username = VerifyHelper.verifyUsername(input.readString(SerializeLimits.MAX_LOGIN));
|
||||||
String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH));
|
String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH));
|
||||||
String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign
|
String serverID = VerifyHelper.verifyServerID(input.readASCII(SerializeLimits.MAX_SERVERID)); // With minus sign
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
if (!clientData.isAuth || clientData.type != Client.Type.USER) {
|
if (!clientData.isAuth || clientData.type != Client.Type.USER) {
|
||||||
requestError("Access denied");
|
requestError("Access denied");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,14 +11,13 @@
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class SetProfileResponse extends Response {
|
public class SetProfileResponse extends Response {
|
||||||
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply() throws Exception {
|
public void reply() throws Exception {
|
||||||
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
if (!clientData.isAuth) requestError("You not auth");
|
if (!clientData.isAuth) requestError("You not auth");
|
||||||
Collection<ClientProfile> profiles = server.getProfiles();
|
Collection<ClientProfile> profiles = server.getProfiles();
|
||||||
for (ClientProfile p : profiles) {
|
for (ClientProfile p : profiles) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -12,8 +13,8 @@
|
||||||
|
|
||||||
public final class BatchProfileByUsernameResponse extends Response {
|
public final class BatchProfileByUsernameResponse extends Response {
|
||||||
|
|
||||||
public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -37,8 +38,8 @@ public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String us
|
||||||
return new PlayerProfile(uuid, username, skin, cloak);
|
return new PlayerProfile(uuid, username, skin, cloak);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileByUUIDResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public ProfileByUUIDResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import ru.gravit.launcher.serialize.SerializeLimits;
|
import ru.gravit.launcher.serialize.SerializeLimits;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.VerifyHelper;
|
import ru.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -24,8 +25,8 @@ public static void writeProfile(LaunchServer server, HOutput output, String user
|
||||||
ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output);
|
ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
public final class LauncherResponse extends Response {
|
public final class LauncherResponse extends Response {
|
||||||
|
|
||||||
public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,17 +25,16 @@ public void reply() throws IOException {
|
||||||
requestError("Missing launcher binary");
|
requestError("Missing launcher binary");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client client = server.sessionManager.getOrNewClient(session);
|
|
||||||
byte[] digest = input.readByteArray(SerializeLimits.MAX_DIGEST);
|
byte[] digest = input.readByteArray(SerializeLimits.MAX_DIGEST);
|
||||||
if (!Arrays.equals(bytes.getDigest(), digest)) {
|
if (!Arrays.equals(bytes.getDigest(), digest)) {
|
||||||
writeNoError(output);
|
writeNoError(output);
|
||||||
output.writeBoolean(true);
|
output.writeBoolean(true);
|
||||||
output.writeByteArray(bytes.getBytes(), 0);
|
output.writeByteArray(bytes.getBytes(), 0);
|
||||||
client.checkSign = false;
|
clientData.checkSign = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
writeNoError(output);
|
writeNoError(output);
|
||||||
output.writeBoolean(false);
|
output.writeBoolean(false);
|
||||||
client.checkSign = true;
|
clientData.checkSign = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,15 @@
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.binary.LauncherBinary;
|
import ru.gravit.launchserver.binary.LauncherBinary;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.SecurityHelper;
|
import ru.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class LegacyLauncherResponse extends Response {
|
public final class LegacyLauncherResponse extends Response {
|
||||||
|
|
||||||
public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,16 +14,15 @@
|
||||||
|
|
||||||
public final class ProfilesResponse extends Response {
|
public final class ProfilesResponse extends Response {
|
||||||
|
|
||||||
public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reply() throws IOException {
|
public void reply() throws IOException {
|
||||||
// Resolve launcher binary
|
// Resolve launcher binary
|
||||||
Client client = server.sessionManager.getClient(session);
|
|
||||||
input.readBoolean();
|
input.readBoolean();
|
||||||
if (client.type == Client.Type.USER && !client.checkSign) {
|
if (clientData.type == Client.Type.USER && !clientData.checkSign) {
|
||||||
LogHelper.warning("User session: %d ip %s try get profiles", session, ip);
|
LogHelper.warning("User session: %d ip %s try get profiles", session, ip);
|
||||||
requestError("Access denied");
|
requestError("Access denied");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,14 +6,15 @@
|
||||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public final class UpdateListResponse extends Response {
|
public final class UpdateListResponse extends Response {
|
||||||
|
|
||||||
public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
public final class UpdateResponse extends Response {
|
public final class UpdateResponse extends Response {
|
||||||
|
|
||||||
public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) {
|
public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) {
|
||||||
super(server, session, input, output, ip);
|
super(server, session, input, output, ip, clientData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +37,6 @@ public void reply() throws IOException {
|
||||||
requestError(String.format("Unknown update dir: %s", updateDirName));
|
requestError(String.format("Unknown update dir: %s", updateDirName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client clientData = server.sessionManager.getClient(session);
|
|
||||||
if (!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) {
|
if (!clientData.isAuth || clientData.type != Client.Type.USER || clientData.profile == null) {
|
||||||
requestError("Access denied");
|
requestError("Access denied");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -82,12 +82,12 @@ private Handshake readHandshake(HInput input, HOutput output) throws IOException
|
||||||
return new Handshake(type, session);
|
return new Handshake(type, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void respond(Integer type, HInput input, HOutput output, long session, String ip) throws Exception {
|
private void respond(Integer type, HInput input, HOutput output, long session, String ip, Client clientData) throws Exception {
|
||||||
if (server.serverSocketHandler.logConnections)
|
if (server.serverSocketHandler.logConnections)
|
||||||
LogHelper.info("Connection #%d from %s", session, ip);
|
LogHelper.info("Connection #%d from %s", session, ip);
|
||||||
|
|
||||||
// Choose response based on type
|
// Choose response based on type
|
||||||
Response response = Response.getResponse(type, server, session, input, output, ip);
|
Response response = Response.getResponse(type, server, session, input, output, ip, clientData);
|
||||||
|
|
||||||
// Reply
|
// Reply
|
||||||
response.reply();
|
response.reply();
|
||||||
|
@ -115,11 +115,13 @@ public void run() {
|
||||||
context.ip = IOHelper.getIP(socket.getRemoteSocketAddress());
|
context.ip = IOHelper.getIP(socket.getRemoteSocketAddress());
|
||||||
context.session = handshake.session;
|
context.session = handshake.session;
|
||||||
context.type = handshake.type;
|
context.type = handshake.type;
|
||||||
|
Client clientData = server.sessionManager.getOrNewClient(context.session);
|
||||||
|
context.client = clientData;
|
||||||
|
|
||||||
// Start response
|
// Start response
|
||||||
if (socketHookManager.preHook(context)) {
|
if (socketHookManager.preHook(context)) {
|
||||||
try {
|
try {
|
||||||
respond(handshake.type, input, output, handshake.session, context.ip);
|
respond(handshake.type, input, output, handshake.session, context.ip, clientData);
|
||||||
socketHookManager.postHook(context);
|
socketHookManager.postHook(context);
|
||||||
} catch (RequestException e) {
|
} catch (RequestException e) {
|
||||||
if (server.socketHookManager.errorHook(context, e)) {
|
if (server.socketHookManager.errorHook(context, e)) {
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
|
||||||
public class SocketContext {
|
public class SocketContext {
|
||||||
HInput input;
|
public HInput input;
|
||||||
HOutput output;
|
public HOutput output;
|
||||||
long session;
|
public long session;
|
||||||
String ip;
|
public String ip;
|
||||||
Integer type;
|
public Integer type;
|
||||||
|
public Client client;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue