Rename facilities to shops. Check if PCBs are banned / disabled. Make the port and maint flags configurable

This commit is contained in:
skogaby 2019-01-12 02:49:52 -06:00
parent b94e4d44ce
commit 22ca376c7d
10 changed files with 65 additions and 25 deletions

View File

@ -1,7 +1,7 @@
package com.buttongames.butterfly.hibernate.dao.impl;
import com.buttongames.butterfly.hibernate.dao.AbstractHibernateDao;
import com.buttongames.butterfly.model.Ddr16Facility;
import com.buttongames.butterfly.model.Ddr16Shop;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
@ -9,16 +9,16 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
/**
* DAO for interacting with <code>Ddr16Facility</code> objects in the database.
* DAO for interacting with <code>Ddr16Shop</code> objects in the database.
* @author skogaby (skogabyskogaby@gmail.com)
*/
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Repository
public class Ddr16FacilityDao extends AbstractHibernateDao<Ddr16Facility> {
public class Ddr16ShopDao extends AbstractHibernateDao<Ddr16Shop> {
@Autowired
public Ddr16FacilityDao(final SessionFactory sessionFactory) {
public Ddr16ShopDao(final SessionFactory sessionFactory) {
super(sessionFactory);
setClazz(Ddr16Facility.class);
setClazz(Ddr16Shop.class);
}
}

View File

@ -17,12 +17,15 @@ import com.buttongames.butterfly.http.handlers.impl.PcbEventRequestHandler;
import com.buttongames.butterfly.http.handlers.impl.PcbTrackerRequestHandler;
import com.buttongames.butterfly.http.handlers.impl.ServicesRequestHandler;
import com.buttongames.butterfly.http.handlers.impl.TaxRequestHandler;
import com.buttongames.butterfly.model.Machine;
import com.buttongames.butterfly.util.PropertyNames;
import com.buttongames.butterfly.xml.BinaryXmlUtils;
import com.buttongames.butterfly.xml.XmlUtils;
import com.google.common.collect.ImmutableSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@ -69,6 +72,10 @@ public class ButterflyHttpServer {
"package", "eventlog", "tax");
}
/** The port the server listens on */
@Value(PropertyNames.PORT)
private String port;
/** Handler for requests for the <code>services</code> module. */
private final ServicesRequestHandler servicesRequestHandler;
@ -131,7 +138,7 @@ public class ButterflyHttpServer {
// once routes are configured, the server automatically begins
threadPool(maxThreads, minThreads, timeOutMillis);
port(80);
port(Integer.parseInt(this.port));
this.configureRoutesAndExceptions();
}
@ -260,8 +267,13 @@ public class ButterflyHttpServer {
final String requestBodyModule = moduleNode.getNodeName();
final String requestBodyMethod = moduleNode.getAttribute("method");
// check if the PCB exists in the database
if (this.machineDao.findByPcbId(requestBodyPcbId) == null) {
// check if the PCB exists and is unbanned in the database
final Machine machine = this.machineDao.findByPcbId(requestBodyPcbId);
machine.setEnabled(true);
machineDao.update(machine);
if (machine == null ||
!machine.isEnabled()) {
throw new InvalidPcbIdException();
}

View File

@ -2,9 +2,11 @@ package com.buttongames.butterfly.http.handlers.impl;
import com.buttongames.butterfly.http.exception.InvalidRequestMethodException;
import com.buttongames.butterfly.http.handlers.BaseRequestHandler;
import com.buttongames.butterfly.util.PropertyNames;
import com.buttongames.butterfly.xml.KXmlBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.w3c.dom.Element;
import spark.Request;
@ -19,6 +21,12 @@ public class MessageRequestHandler extends BaseRequestHandler {
private final Logger LOG = LogManager.getLogger(MessageRequestHandler.class);
/**
* Says whether or not this server is running in maintenance mode.
*/
@Value(PropertyNames.MAINT_MODE)
private String isMaintenance;
/**
* Handles an incoming request for the <code>message</code> module.
* @param requestBody The XML document of the incoming request.
@ -44,11 +52,16 @@ public class MessageRequestHandler extends BaseRequestHandler {
* @return A response object for Spark
*/
private Object handleGetRequest(final Request request, final Response response) {
// TODO: Remove all the hardcoded stuff and actually do something with the input
KXmlBuilder respBuilder = KXmlBuilder.create("response")
.e("message").a("expire", "1800").a("status", "0")
final boolean isMaint = Boolean.parseBoolean(this.isMaintenance);
KXmlBuilder respBuilder = KXmlBuilder.create("response");
if (isMaint) {
respBuilder = respBuilder.e("message").a("expire", "1800").a("status", "0")
.e("item").a("end", "604800").a("name", "sys.mainte").a("start", "0").up()
.e("item").a("end", "604800").a("name", "sys.eacoin.mainte").a("start", "0");
} else {
respBuilder = respBuilder.e("message");
}
return this.sendResponse(request, response, respBuilder);
}

View File

@ -44,7 +44,6 @@ public class PcbTrackerRequestHandler extends BaseRequestHandler {
* @return A response object for Spark
*/
private Object handleAliveRequest(final Request request, final Response response) {
// TODO: Remove all the hardcoded stuff and actually do something with the input
KXmlBuilder respBuilder = KXmlBuilder.create("response")
.e("pcbtracker").a("ecenable", "1").a("eclimit", "0").a("expire", "0").a("limit", "0").a("status", "0");

View File

@ -11,12 +11,12 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Model class that represents a facility housing a DDR 16 machine.
* Model class that represents a shop housing a DDR 16 machine.
* @author skogaby (skogabyskogaby@gmail.com)
*/
@Entity
@Table(name = "ddr_16_facilities")
public class Ddr16Facility implements Externalizable {
@Table(name = "ddr_16_shops")
public class Ddr16Shop implements Externalizable {
private static final long serialVersionUID = 1L;
@ -70,11 +70,11 @@ public class Ddr16Facility implements Externalizable {
@Column(name = "supply_limit")
private int supplyLimit;
public Ddr16Facility() { }
public Ddr16Shop() { }
public Ddr16Facility(final String pcbId, final String locationId, final String name,
final String country, final String region, final boolean isPublic, final String latitude, final String longitude,
final int notchAmount, final int notchCount, final int supplyLimit) {
public Ddr16Shop(final String pcbId, final String locationId, final String name,
final String country, final String region, final boolean isPublic, final String latitude, final String longitude,
final int notchAmount, final int notchCount, final int supplyLimit) {
this.pcbId = pcbId;
this.locationId = locationId;
this.name = name;
@ -105,7 +105,7 @@ public class Ddr16Facility implements Externalizable {
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
public void readExternal(ObjectInput in) throws IOException {
this.setId(in.readLong());
this.setPcbId(in.readUTF());
this.setLocationId(in.readUTF());

View File

@ -41,7 +41,7 @@ public class UserPhases implements Externalizable {
/**
* The user's phase for DDR Ace.
*/
@Column
@Column(name = "ddr_16_phase")
private int ddr16Phase;
public UserPhases() { }

View File

@ -2,7 +2,7 @@ package com.buttongames.butterfly.spring.configuration;
import com.buttongames.butterfly.hibernate.dao.impl.MachineDao;
import com.buttongames.butterfly.hibernate.dao.impl.ButterflyUserDao;
import com.buttongames.butterfly.hibernate.dao.impl.Ddr16FacilityDao;
import com.buttongames.butterfly.hibernate.dao.impl.Ddr16ShopDao;
import com.buttongames.butterfly.hibernate.dao.impl.Ddr16GameplayEventLogDao;
import com.buttongames.butterfly.hibernate.dao.impl.Ddr16PcbEventLogDao;
import com.buttongames.butterfly.hibernate.dao.impl.UserPhasesDao;
@ -87,7 +87,7 @@ public class HibernateConfiguration {
}
@Bean
public MachineDao butterflyPcbDao(final SessionFactory sessionFactory) {
public MachineDao machineDao(final SessionFactory sessionFactory) {
return new MachineDao(sessionFactory);
}
@ -107,7 +107,7 @@ public class HibernateConfiguration {
}
@Bean
public Ddr16FacilityDao ddr16FacilityDao(final SessionFactory sessionFactory) {
return new Ddr16FacilityDao(sessionFactory);
public Ddr16ShopDao ddr16ShopDao(final SessionFactory sessionFactory) {
return new Ddr16ShopDao(sessionFactory);
}
}

View File

@ -15,6 +15,7 @@ import com.buttongames.butterfly.http.handlers.impl.TaxRequestHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* Bean config class for <code>com.buttongames.butterfly.http</code> package.
@ -22,6 +23,7 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
@ComponentScan({"com.buttongames.butterfly.spring.configuration"})
@PropertySource("classpath:butterfly.properties")
public class HttpConfiguration {
@Bean

View File

@ -0,0 +1,11 @@
package com.buttongames.butterfly.util;
/**
* Simple class to hold our config / property keys for reading properties files.
* @author skogaby (skogabyskogaby@gmail.com)
*/
public class PropertyNames {
public static final String PORT = "${server.port}";
public static final String MAINT_MODE = "${server.maintenance}";
}

View File

@ -0,0 +1,3 @@
# Server properties
server.port = 80
server.maintenance = true