[FEATURE] IP Forwarding

This commit is contained in:
Gravit 2019-05-09 20:05:53 +07:00
parent a66d7a7164
commit fe57424e2a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 11 additions and 6 deletions

View file

@ -46,9 +46,8 @@ public void channelActive(ChannelHandlerContext ctx) {
@Override
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
// ping and pong frames already handled
if (frame instanceof TextWebSocketFrame) {
service.process(ctx, (TextWebSocketFrame) frame, client);
service.process(ctx, (TextWebSocketFrame) frame, client, context.ip);
} else if ((frame instanceof PingWebSocketFrame)) {
frame.content().retain();
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));

View file

@ -35,6 +35,7 @@
import ru.gravit.launchserver.websocket.json.update.LauncherResponse;
import ru.gravit.launchserver.websocket.json.update.UpdateListResponse;
import ru.gravit.launchserver.websocket.json.update.UpdateResponse;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.lang.reflect.Type;
@ -62,7 +63,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
private final GsonBuilder gsonBuiler;
@SuppressWarnings("unchecked")
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client) {
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
String request = frame.text();
JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class);
if(server.config.netty.proxy.enabled)
@ -77,6 +78,8 @@ void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client)
simpleResponse.server = server;
simpleResponse.service = this;
simpleResponse.ctx = ctx;
if(ip != null) simpleResponse.ip = ip;
else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress());
origRequestUUID = simpleResponse.requestUUID;
}
LogHelper.debug("Proxy %s request", response.getType());
@ -122,11 +125,12 @@ void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client)
}
sendObject(ctx, event);
}
return;
}
}
process(ctx,response, client);
process(ctx,response, client, ip);
}
void process(ChannelHandlerContext ctx, JsonResponseInterface response, Client client)
void process(ChannelHandlerContext ctx, JsonResponseInterface response, Client client, String ip)
{
if(response instanceof SimpleResponse)
{
@ -134,6 +138,8 @@ void process(ChannelHandlerContext ctx, JsonResponseInterface response, Client c
simpleResponse.server = server;
simpleResponse.service = this;
simpleResponse.ctx = ctx;
if(ip != null) simpleResponse.ip = ip;
else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress());
}
try {
response.execute(ctx, client);

View file

@ -14,6 +14,7 @@ public abstract class SimpleResponse implements JsonResponseInterface {
public transient LaunchServer server;
public transient WebSocketService service;
public transient ChannelHandlerContext ctx;
public transient String ip;
public void sendResult(RequestEvent result)
{
result.requestUUID = requestUUID;

View file

@ -61,7 +61,6 @@ public String getType() {
public void execute(ChannelHandlerContext ctx, Client clientData) throws Exception {
try {
AuthRequestEvent result = new AuthRequestEvent();
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
if ((authType == null || authType == ConnectTypes.CLIENT) && ( clientData == null || !clientData.checkSign )) {
AuthProvider.authError("Don't skip Launcher Update");
return;