mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
[FEATURE] IP Forwarding
This commit is contained in:
parent
a66d7a7164
commit
fe57424e2a
4 changed files with 11 additions and 6 deletions
|
@ -46,9 +46,8 @@ public void channelActive(ChannelHandlerContext ctx) {
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
|
||||||
// ping and pong frames already handled
|
// ping and pong frames already handled
|
||||||
|
|
||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
service.process(ctx, (TextWebSocketFrame) frame, client);
|
service.process(ctx, (TextWebSocketFrame) frame, client, context.ip);
|
||||||
} else if ((frame instanceof PingWebSocketFrame)) {
|
} else if ((frame instanceof PingWebSocketFrame)) {
|
||||||
frame.content().retain();
|
frame.content().retain();
|
||||||
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));
|
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
import ru.gravit.launchserver.websocket.json.update.LauncherResponse;
|
import ru.gravit.launchserver.websocket.json.update.LauncherResponse;
|
||||||
import ru.gravit.launchserver.websocket.json.update.UpdateListResponse;
|
import ru.gravit.launchserver.websocket.json.update.UpdateListResponse;
|
||||||
import ru.gravit.launchserver.websocket.json.update.UpdateResponse;
|
import ru.gravit.launchserver.websocket.json.update.UpdateResponse;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -62,7 +63,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
|
||||||
private final GsonBuilder gsonBuiler;
|
private final GsonBuilder gsonBuiler;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client) {
|
void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
|
||||||
String request = frame.text();
|
String request = frame.text();
|
||||||
JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class);
|
JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class);
|
||||||
if(server.config.netty.proxy.enabled)
|
if(server.config.netty.proxy.enabled)
|
||||||
|
@ -77,6 +78,8 @@ void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client)
|
||||||
simpleResponse.server = server;
|
simpleResponse.server = server;
|
||||||
simpleResponse.service = this;
|
simpleResponse.service = this;
|
||||||
simpleResponse.ctx = ctx;
|
simpleResponse.ctx = ctx;
|
||||||
|
if(ip != null) simpleResponse.ip = ip;
|
||||||
|
else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
||||||
origRequestUUID = simpleResponse.requestUUID;
|
origRequestUUID = simpleResponse.requestUUID;
|
||||||
}
|
}
|
||||||
LogHelper.debug("Proxy %s request", response.getType());
|
LogHelper.debug("Proxy %s request", response.getType());
|
||||||
|
@ -122,11 +125,12 @@ void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client)
|
||||||
}
|
}
|
||||||
sendObject(ctx, event);
|
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)
|
if(response instanceof SimpleResponse)
|
||||||
{
|
{
|
||||||
|
@ -134,6 +138,8 @@ void process(ChannelHandlerContext ctx, JsonResponseInterface response, Client c
|
||||||
simpleResponse.server = server;
|
simpleResponse.server = server;
|
||||||
simpleResponse.service = this;
|
simpleResponse.service = this;
|
||||||
simpleResponse.ctx = ctx;
|
simpleResponse.ctx = ctx;
|
||||||
|
if(ip != null) simpleResponse.ip = ip;
|
||||||
|
else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
response.execute(ctx, client);
|
response.execute(ctx, client);
|
||||||
|
|
|
@ -14,6 +14,7 @@ public abstract class SimpleResponse implements JsonResponseInterface {
|
||||||
public transient LaunchServer server;
|
public transient LaunchServer server;
|
||||||
public transient WebSocketService service;
|
public transient WebSocketService service;
|
||||||
public transient ChannelHandlerContext ctx;
|
public transient ChannelHandlerContext ctx;
|
||||||
|
public transient String ip;
|
||||||
public void sendResult(RequestEvent result)
|
public void sendResult(RequestEvent result)
|
||||||
{
|
{
|
||||||
result.requestUUID = requestUUID;
|
result.requestUUID = requestUUID;
|
||||||
|
|
|
@ -61,7 +61,6 @@ public String getType() {
|
||||||
public void execute(ChannelHandlerContext ctx, Client clientData) throws Exception {
|
public void execute(ChannelHandlerContext ctx, Client clientData) throws Exception {
|
||||||
try {
|
try {
|
||||||
AuthRequestEvent result = new AuthRequestEvent();
|
AuthRequestEvent result = new AuthRequestEvent();
|
||||||
String ip = IOHelper.getIP(ctx.channel().remoteAddress());
|
|
||||||
if ((authType == null || authType == ConnectTypes.CLIENT) && ( clientData == null || !clientData.checkSign )) {
|
if ((authType == null || authType == ConnectTypes.CLIENT) && ( clientData == null || !clientData.checkSign )) {
|
||||||
AuthProvider.authError("Don't skip Launcher Update");
|
AuthProvider.authError("Don't skip Launcher Update");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue