mirror of
https://github.com/skogaby/butterfly.git
synced 2026-04-24 15:37:19 -05:00
Checkpoint commit
This commit is contained in:
parent
66463b0bf6
commit
bca2033db2
|
|
@ -21,6 +21,9 @@ import javax.xml.transform.dom.DOMSource;
|
|||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static com.buttongames.butterfly.util.Constants.COMPRESSION_HEADER;
|
||||
import static com.buttongames.butterfly.util.Constants.CRYPT_KEY_HEADER;
|
||||
|
|
@ -48,7 +51,7 @@ public abstract class BaseRequestHandler {
|
|||
* @param request The original request.
|
||||
* @param response The response object we can use to send the data.
|
||||
* @param respBody The XML document of the response.
|
||||
* @return
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
protected Object sendResponse(final Request request, final Response response, final BaseXMLBuilder respBody) {
|
||||
// get the bytes of the XML document
|
||||
|
|
@ -68,6 +71,39 @@ public abstract class BaseRequestHandler {
|
|||
}
|
||||
|
||||
byte[] respBytes = bos.toByteArray();
|
||||
return this.sendBytesToClient(respBytes, request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the response to the client.
|
||||
* @param request The original request.
|
||||
* @param response The response object we can use to send the data.
|
||||
* @param responsePath The path of the resource file with the XML response to send.
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
protected Object sendStaticResponse(final Request request, final Response response, final String responsePath) {
|
||||
try {
|
||||
// read in the static response file, encrypt it, compress it, and send it
|
||||
final Path path = Paths.get(ClassLoader.getSystemResource(responsePath).toURI());
|
||||
byte[] respBody = Files.readAllBytes(path);
|
||||
|
||||
return this.sendBytesToClient(respBody, request, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the raw, unencrypted and decompressed bytes, transforms them as necessary, and sends
|
||||
* them to the client.
|
||||
* @param respBytes The bytes to send.
|
||||
* @param request The original request.
|
||||
* @param response The response object we can use to send the data.
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
private Object sendBytesToClient(byte[] respBytes, final Request request, final Response response) {
|
||||
response.header("Connection", "keep-alive");
|
||||
|
||||
// convert them to binary XML
|
||||
if (!BinaryXmlUtils.isBinaryXML(respBytes)) {
|
||||
|
|
@ -97,7 +133,6 @@ public abstract class BaseRequestHandler {
|
|||
try {
|
||||
final HttpServletResponse rawResponse = response.raw();
|
||||
response.type(MediaType.OCTET_STREAM.toString());
|
||||
rawResponse.setContentLength(respBytes.length);
|
||||
|
||||
rawResponse.getOutputStream().write(respBytes);
|
||||
rawResponse.getOutputStream().flush();
|
||||
|
|
|
|||
|
|
@ -83,33 +83,31 @@ public class FacilityRequestHandler extends BaseRequestHandler {
|
|||
.str("country", shop.getCountry()).up()
|
||||
.str("region", shop.getRegion()).up()
|
||||
.str("name", shop.getName()).up()
|
||||
.u8("type", 0).up().up()
|
||||
.u8("type", 0).up(2)
|
||||
.e("line")
|
||||
.str("id", "3").up()
|
||||
.u8("class", 8).up()
|
||||
.u8("upclass", 8).up()
|
||||
.u16("rtt", 40).up().up()
|
||||
.str("id", "").up()
|
||||
.u8("class", 0).up(2)
|
||||
.e("portfw")
|
||||
// TODO: Use our real IP here
|
||||
.ip("globalip", "1.0.0.127").up()
|
||||
.u16("globalport", 5700).up()
|
||||
.u16("privateport", 5700).up(2)
|
||||
.e("public")
|
||||
.u8("flag", shop.isPublic() ? 1 : 0).up()
|
||||
.str("name", shop.getName()).up()
|
||||
.str("latitude", "0").up()
|
||||
.str("longitude", "0").up().up()
|
||||
.u8("flag", 0).up()
|
||||
.str("name", "").up()
|
||||
.str("latitude", "").up()
|
||||
.str("longitude", "").up(2)
|
||||
.e("share")
|
||||
.e("eacoin")
|
||||
.s32("notchamount", 0).up()
|
||||
.s32("notchcount", 0).up()
|
||||
.s32("supplylimit", 100000).up().up()
|
||||
.s32("supplylimit", 100000).up(2)
|
||||
.e("url")
|
||||
.str("eapass", "http://eagate.573.jp/").up()
|
||||
.str("arcadefan", "http://eagate.573.jp/").up()
|
||||
.str("konaminetdx", "http://eagate.573.jp/").up()
|
||||
.str("konamiid", "http://eagate.573.jp/").up()
|
||||
.str("eagate", "http://eagate.573.jp/").up().up().up()
|
||||
.e("portfw")
|
||||
// TODO: Use our real IP here
|
||||
.ip("globalip", "1.0.0.127").up()
|
||||
.u16("globalport", machine.getPort()).up()
|
||||
.u16("privateport", machine.getPort());
|
||||
.str("eagate", "http://eagate.573.jp/");
|
||||
|
||||
return this.sendResponse(request, response, respBuilder);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,6 @@ import org.w3c.dom.Element;
|
|||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Handler for any requests that come to the <code>playerdata</code> module.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
|
|
@ -25,21 +20,6 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
|
||||
private final Logger LOG = LogManager.getLogger(PcbEventRequestHandler.class);
|
||||
|
||||
/**
|
||||
* Since this response is static (as far as I know right now...), let's just cache it in memory. It's a little large.
|
||||
*/
|
||||
private static KXmlBuilder EVENTS_RESPONSE_2018042300;
|
||||
|
||||
static {
|
||||
try {
|
||||
final Path events20180423Path = Paths.get(ClassLoader.getSystemResource("static_responses/mdx_2018042300/events.xml").toURI());
|
||||
EVENTS_RESPONSE_2018042300 = KXmlBuilder.parse(new String(Files.readAllBytes(events20180423Path), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an incoming request for the <code>playerdata</code> module.
|
||||
* @param requestBody The XML document of the incoming request.
|
||||
|
|
@ -58,11 +38,15 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
final String dataid = XmlUtils.strValueAtPath(requestBody, "/playerdata/data/dataid");
|
||||
|
||||
if (mode.equals("userload")) {
|
||||
LOG.info("Handling a userload request");
|
||||
|
||||
if (refid.equals("X0000000000000000000000000000000") &&
|
||||
dataid.equals("X0000000000000000000000000000000")) {
|
||||
return handleEventsRequest(request, response);
|
||||
}
|
||||
} else if (mode.equals("rivalload")) {
|
||||
LOG.info("Handling a rivalload request");
|
||||
|
||||
int loadFlag = XmlUtils.intValueAtPath(requestBody, "/playerdata/data/loadflag");
|
||||
|
||||
if (loadFlag == 1) {
|
||||
|
|
@ -88,7 +72,7 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
|
||||
// TODO: This is almost *definitely* not supposed to be a static response...
|
||||
if (this.getSanitizedModel(requestModel).equals("mdx_2018042300")) {
|
||||
return this.sendResponse(request, response, EVENTS_RESPONSE_2018042300);
|
||||
return this.sendStaticResponse(request, response, "static_responses/mdx_2018042300/events.xml");
|
||||
} else {
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user