mirror of
https://github.com/skogaby/butterfly.git
synced 2026-04-26 01:44:56 -05:00
Implement enough handlers to play a full session! Options save in between sessions, but scores, ghost data, and event progress do not, yet.
This commit is contained in:
parent
9c421f62e0
commit
973d49569a
|
|
@ -247,6 +247,9 @@ public class ButterflyHttpServer {
|
|||
exception(UnsupportedRequestException.class, (((exception, request, response) -> {
|
||||
response.status(400);
|
||||
response.body("This request is probably valid, but currently unsupported.");
|
||||
|
||||
LOG.info(String.format("RECEIVED AN UNSUPPORTED REQUEST: %s.%s",
|
||||
request.attribute("module"), request.attribute("method")));
|
||||
})));
|
||||
exception(CardCipherException.class, (((exception, request, response) -> {
|
||||
response.status(403);
|
||||
|
|
@ -268,7 +271,7 @@ public class ButterflyHttpServer {
|
|||
final String requestUriModule = request.queryParams("module");
|
||||
final String requestUriMethod = request.queryParams("method");
|
||||
|
||||
LOG.info("Request received: '" + requestUriModel + "::" + requestUriModule + "." + requestUriMethod + "'");
|
||||
LOG.info("Request received: " + requestUriModel + " (" + requestUriModule + "." + requestUriMethod + ")");
|
||||
|
||||
// 1) validate the model is supported
|
||||
if (!SUPPORTED_MODELS.contains(com.buttongames.butterfly.util.StringUtils.getSanitizedModel(requestUriModel))) {
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ public abstract class BaseRequestHandler {
|
|||
rawResponse.getOutputStream().flush();
|
||||
rawResponse.getOutputStream().close();
|
||||
|
||||
LOG.info("Response sent: '" + request.queryParams("model") + "::" +
|
||||
request.queryParams("module") + "." + request.queryParams("method") + "'");
|
||||
LOG.info("Response sent: " + request.queryParams("model") + " (" +
|
||||
request.queryParams("module") + "." + request.queryParams("method") + ")");
|
||||
|
||||
return 200;
|
||||
} catch (IOException e) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.buttongames.butterfly.http.handlers.impl;
|
|||
import com.buttongames.butterfly.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestException;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.ButterflyUser;
|
||||
import com.buttongames.butterfly.model.Card;
|
||||
|
|
@ -63,9 +63,9 @@ public class CardManageRequestHandler extends BaseRequestHandler {
|
|||
return this.handleGetRefIdRequest(requestBody, request, response);
|
||||
} else if (requestMethod.equals("authpass")) {
|
||||
return this.handleAuthPassRequest(requestBody, request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestException;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.Card;
|
||||
import com.buttongames.butterfly.xml.XmlUtils;
|
||||
|
|
@ -53,9 +52,11 @@ public class EacoinRequestHandler extends BaseRequestHandler {
|
|||
return this.handleCheckinRequest(requestBody, request, response);
|
||||
} else if (requestMethod.equals("consume")) {
|
||||
return this.handleConsumeRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
} else if (requestMethod.equals("checkout")) {
|
||||
return this.handleCheckoutRequest(request, response);
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -93,6 +94,19 @@ public class EacoinRequestHandler extends BaseRequestHandler {
|
|||
return this.sendResponse(request, response, builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an incoming request for the <code>eacoin.checkout</code> method.
|
||||
* @param request The Spark request
|
||||
* @param response The Spark response
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
private Object handleCheckoutRequest(final Request request, final Response response) {
|
||||
final KXmlBuilder builder = KXmlBuilder.create("response")
|
||||
.e("eacoin");
|
||||
|
||||
return this.sendResponse(request, response, builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an incoming request for the <code>eacoin.consume</code> method.
|
||||
* @param request The Spark request
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.ddr16.GameplayEventLogDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.ddr16.GameplayEventLog;
|
||||
import com.buttongames.butterfly.util.TimeUtils;
|
||||
|
|
@ -50,9 +50,9 @@ public class EventLogRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("write")) {
|
||||
return handleWriteRequest(requestBody, request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.buttongames.butterfly.http.handlers.impl;
|
|||
import com.buttongames.butterfly.hibernate.dao.impl.ddr16.ShopDao;
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.MachineDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.ddr16.Shop;
|
||||
import com.buttongames.butterfly.util.StringUtils;
|
||||
|
|
@ -54,9 +55,9 @@ public class FacilityRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("get")) {
|
||||
return handleGetRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.util.PropertyNames;
|
||||
import com.buttongames.butterfly.xml.kbinxml.KXmlBuilder;
|
||||
|
|
@ -40,9 +40,9 @@ public class MessageRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("get")) {
|
||||
return handleGetRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.xml.kbinxml.KXmlBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -32,9 +32,9 @@ public class PackageRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("list")) {
|
||||
return handleListRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.ddr16.PcbEventLogDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.ddr16.PcbEventLog;
|
||||
import com.buttongames.butterfly.util.TimeUtils;
|
||||
|
|
@ -49,9 +49,9 @@ public class PcbEventRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("put")) {
|
||||
return handlePutRequest(requestBody, request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.util.PropertyNames;
|
||||
import com.buttongames.butterfly.xml.kbinxml.KXmlBuilder;
|
||||
|
|
@ -40,9 +40,9 @@ public class PcbTrackerRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("alive")) {
|
||||
return handleAliveRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -141,13 +141,15 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
public Object handleRequest(final Element requestBody, final Request request, final Response response) {
|
||||
final String requestMethod = request.attribute("method");
|
||||
|
||||
// figure out which kind of usergamedata_advanced request this is
|
||||
// handle usergamedata_advanced requests
|
||||
if (requestMethod.equals("usergamedata_advanced")) {
|
||||
final String mode = XmlUtils.strValueAtPath(requestBody, "/playerdata/data/mode");
|
||||
final String refid = XmlUtils.strValueAtPath(requestBody, "/playerdata/data/refid");
|
||||
|
||||
// handle usergamedata_advanced.userload requests
|
||||
if (mode.equals("userload")) {
|
||||
return this.handleUserLoadRequest(refid, request, response);
|
||||
// handle usergamedata_advanced.rivalload requests
|
||||
} else if (mode.equals("rivalload")) {
|
||||
int loadFlag = XmlUtils.intValueAtPath(requestBody, "/playerdata/data/loadflag");
|
||||
|
||||
|
|
@ -158,13 +160,23 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
} else if (loadFlag == 4) {
|
||||
return this.handleGlobalScoresRequest(request, response);
|
||||
}
|
||||
// handle usergamedata_advanced.usernew requests
|
||||
} else if (mode.equals("usernew")) {
|
||||
return this.handleNewUserRequest(refid, request, response);
|
||||
// handle usergamedata_advanced.inheritance requests
|
||||
} else if (mode.equals("inheritance")) {
|
||||
return this.handleInheritanceRequest(request, response);
|
||||
// handle usergamedata_advanced.ghostload requests
|
||||
} else if (mode.equals("ghostload")) {
|
||||
return this.handleGhostLoadRequest(XmlUtils.intValueAtPath(requestBody, "/playerdata/data/ghostid"), request, response);
|
||||
// handle usergamedata_advanced.usersave requests, for saving scores, ghost data, etc.
|
||||
} else if (mode.equals("usersave")) {
|
||||
return this.handleUserSaveRequest(request, response);
|
||||
}
|
||||
// handle usergamedata_send requests
|
||||
} else if (requestMethod.equals("usergamedata_send")) {
|
||||
return this.handleUserGameDataSendRequest(requestBody, request, response);
|
||||
// handle usergamedata_recv requests
|
||||
} else if (requestMethod.equals("usergamedata_recv")) {
|
||||
return this.handleUserGameDataRecvRequest(requestBody, request, response);
|
||||
}
|
||||
|
|
@ -656,7 +668,6 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
* @return A response object for Spark
|
||||
*/
|
||||
private Object handleInheritanceRequest(final Request request, final Response response) {
|
||||
// TODO: Confirm if this value actually matters...
|
||||
final KXmlBuilder builder = KXmlBuilder.create("response")
|
||||
.e("playerdata")
|
||||
.s32("result", 0).up()
|
||||
|
|
@ -664,4 +675,36 @@ public class PlayerDataRequestHandler extends BaseRequestHandler {
|
|||
|
||||
return this.sendResponse(request, response, builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to load a particular ghost data set.
|
||||
* @param ghostId The ghost ID to load.
|
||||
* @param request The Spark request
|
||||
* @param response The Spark response
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
private Object handleGhostLoadRequest(final int ghostId, final Request request, final Response response) {
|
||||
// TODO: Store and load ghost data correctly
|
||||
final KXmlBuilder builder = KXmlBuilder.create("response")
|
||||
.e("playerdata")
|
||||
.s32("result", 0).up();
|
||||
|
||||
return this.sendResponse(request, response, builder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles a request to save scores, options, etc.
|
||||
* @param request The Spark request
|
||||
* @param response The Spark response
|
||||
* @return A response object for Spark
|
||||
*/
|
||||
private Object handleUserSaveRequest(final Request request, final Response response) {
|
||||
// TODO: actually save the input
|
||||
final KXmlBuilder builder = KXmlBuilder.create("response")
|
||||
.e("playerdata")
|
||||
.s32("result", 0).up();
|
||||
|
||||
return this.sendResponse(request, response, builder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.util.PropertyNames;
|
||||
import com.buttongames.butterfly.xml.kbinxml.KXmlBuilder;
|
||||
|
|
@ -51,9 +51,9 @@ public class ServicesRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("get")) {
|
||||
return handleGetRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.buttongames.butterfly.http.handlers.impl;
|
||||
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.util.CardIdUtils;
|
||||
import com.buttongames.butterfly.xml.XmlUtils;
|
||||
|
|
@ -34,9 +34,9 @@ public class SystemRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("convcardnumber")) {
|
||||
return this.handleConvCardNumberRequest(requestBody, request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.buttongames.butterfly.http.handlers.impl;
|
|||
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.MachineDao;
|
||||
import com.buttongames.butterfly.hibernate.dao.impl.UserPhasesDao;
|
||||
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
|
||||
import com.buttongames.butterfly.http.exception.UnsupportedRequestException;
|
||||
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
|
||||
import com.buttongames.butterfly.model.Machine;
|
||||
import com.buttongames.butterfly.model.UserPhases;
|
||||
|
|
@ -53,9 +53,9 @@ public class TaxRequestHandler extends BaseRequestHandler {
|
|||
|
||||
if (requestMethod.equals("get_phase")) {
|
||||
return handleGetPhaseRequest(request, response);
|
||||
} else {
|
||||
throw new InvalidRequestMethodException();
|
||||
}
|
||||
|
||||
throw new UnsupportedRequestException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user