forked from openrs2/openrs2
Required by the most recent versions of the Java plugin (before it was killed). Signed-off-by: Graham <gpe@openrs2.org>
parent
2a6b97480c
commit
92a01b6262
@ -0,0 +1,46 @@ |
|||||||
|
package org.openrs2.game.net.crossdomain |
||||||
|
|
||||||
|
import io.netty.buffer.Unpooled |
||||||
|
import io.netty.channel.ChannelFutureListener |
||||||
|
import io.netty.channel.ChannelHandler |
||||||
|
import io.netty.channel.ChannelHandlerContext |
||||||
|
import io.netty.channel.SimpleChannelInboundHandler |
||||||
|
import io.netty.handler.codec.http.HttpHeaderNames |
||||||
|
import io.netty.handler.codec.http.HttpMethod |
||||||
|
import io.netty.handler.codec.http.HttpRequest |
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus |
||||||
|
import org.openrs2.game.net.http.Http |
||||||
|
|
||||||
|
@ChannelHandler.Sharable |
||||||
|
public object CrossDomainChannelHandler : SimpleChannelInboundHandler<HttpRequest>() { |
||||||
|
private const val ENDPOINT = "/crossdomain.xml" |
||||||
|
private val POLICY = """ |
||||||
|
<?xml version="1.0"?> |
||||||
|
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> |
||||||
|
<cross-domain-policy> |
||||||
|
<site-control permitted-cross-domain-policies="master-only" /> |
||||||
|
<allow-access-from domain="*" /> |
||||||
|
</cross-domain-policy> |
||||||
|
""".trimIndent().plus("\n").toByteArray(Charsets.UTF_8) |
||||||
|
|
||||||
|
override fun handlerAdded(ctx: ChannelHandlerContext) { |
||||||
|
ctx.read() |
||||||
|
} |
||||||
|
|
||||||
|
override fun channelRead0(ctx: ChannelHandlerContext, msg: HttpRequest) { |
||||||
|
if (msg.method() != HttpMethod.GET || msg.uri() != ENDPOINT) { |
||||||
|
ctx.write(Http.createResponse(HttpResponseStatus.BAD_REQUEST)).addListener(ChannelFutureListener.CLOSE) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
val response = Http.createResponse(HttpResponseStatus.OK) |
||||||
|
response.headers().add(HttpHeaderNames.CONTENT_TYPE, Http.TEXT_X_CROSS_DOMAIN_POLICY) |
||||||
|
response.headers().add(HttpHeaderNames.CONTENT_LENGTH, POLICY.size) |
||||||
|
ctx.write(response, ctx.voidPromise()) |
||||||
|
ctx.write(Unpooled.wrappedBuffer(POLICY)).addListener(ChannelFutureListener.CLOSE) |
||||||
|
} |
||||||
|
|
||||||
|
override fun channelReadComplete(ctx: ChannelHandlerContext) { |
||||||
|
ctx.flush() |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package org.openrs2.game.net.http |
||||||
|
|
||||||
|
import io.netty.handler.codec.http.DefaultHttpResponse |
||||||
|
import io.netty.handler.codec.http.HttpHeaderNames |
||||||
|
import io.netty.handler.codec.http.HttpHeaderValues |
||||||
|
import io.netty.handler.codec.http.HttpResponse |
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus |
||||||
|
import io.netty.handler.codec.http.HttpVersion |
||||||
|
|
||||||
|
public object Http { |
||||||
|
public const val MAX_CONTENT_LENGTH: Int = 65536 |
||||||
|
public const val TEXT_X_CROSS_DOMAIN_POLICY: String = "text/x-cross-domain-policy" |
||||||
|
|
||||||
|
public fun createResponse(status: HttpResponseStatus): HttpResponse { |
||||||
|
val response = DefaultHttpResponse(HttpVersion.HTTP_1_1, status) |
||||||
|
response.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE) |
||||||
|
response.headers().add(HttpHeaderNames.SERVER, "OpenRS2") |
||||||
|
return response |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
package org.openrs2.protocol.login |
||||||
|
|
||||||
|
import org.openrs2.protocol.EmptyPacketCodec |
||||||
|
|
||||||
|
public object InitCrossDomainConnectionCodec : EmptyPacketCodec<LoginRequest.InitCrossDomainConnection>( |
||||||
|
opcode = 'G'.code, |
||||||
|
packet = LoginRequest.InitCrossDomainConnection |
||||||
|
) |
Loading…
Reference in new issue