diff --git a/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/EventSaveDataDao.java b/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/EventSaveDataDao.java new file mode 100644 index 0000000..5cfbaef --- /dev/null +++ b/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/EventSaveDataDao.java @@ -0,0 +1,58 @@ +package com.buttongames.butterflydao.hibernate.dao.impl.ddr16; + +import com.buttongames.butterflydao.hibernate.dao.AbstractHibernateDao; +import com.buttongames.butterflymodel.model.ddr16.EventSaveData; +import com.buttongames.butterflymodel.model.ddr16.UserProfile; +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * DAO for interacting with EventSaveData objects in the database. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +@Repository +@Transactional +public class EventSaveDataDao extends AbstractHibernateDao { + + @Autowired + public EventSaveDataDao(final SessionFactory sessionFactory) { + super(sessionFactory); + setClazz(EventSaveData.class); + } + + /** + * Finds all event progress for a user. + * @param user The user for the events + * @return A list of matching records + */ + public List findByUser(final UserProfile user) { + final Query query = this.getCurrentSession().createQuery("from EventSaveData where user = :user"); + query.setParameter("user", user); + + return query.getResultList(); + } + + /** + * Finds an entry for an event for a user based on its event id. + * @param user The user for the events + * @param eventId The id of the event + * @return The matching records + */ + public EventSaveData findByUserAndEventId(final UserProfile user, final int eventId) { + final Query query = this.getCurrentSession().createQuery( + "from EventSaveData where user = :user and eventId = :eventId") + .setMaxResults(1); + query.setParameter("user", user); + query.setParameter("eventId", eventId); + + return query.getSingleResult(); + } +} diff --git a/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/GlobalEventDao.java b/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/GlobalEventDao.java new file mode 100644 index 0000000..866a20f --- /dev/null +++ b/butterflydao/src/main/java/com/buttongames/butterflydao/hibernate/dao/impl/ddr16/GlobalEventDao.java @@ -0,0 +1,26 @@ +package com.buttongames.butterflydao.hibernate.dao.impl.ddr16; + +import com.buttongames.butterflydao.hibernate.dao.AbstractHibernateDao; +import com.buttongames.butterflymodel.model.ddr16.GlobalEvent; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +/** + * DAO for interacting with GlobalEvent objects in the database. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +@Repository +@Transactional +public class GlobalEventDao extends AbstractHibernateDao { + + @Autowired + public GlobalEventDao(final SessionFactory sessionFactory) { + super(sessionFactory); + setClazz(GlobalEvent.class); + } +} diff --git a/butterflydao/src/main/java/com/buttongames/butterflydao/spring/configuration/HibernateConfiguration.java b/butterflydao/src/main/java/com/buttongames/butterflydao/spring/configuration/HibernateConfiguration.java index 415e57c..4ccf1bd 100644 --- a/butterflydao/src/main/java/com/buttongames/butterflydao/spring/configuration/HibernateConfiguration.java +++ b/butterflydao/src/main/java/com/buttongames/butterflydao/spring/configuration/HibernateConfiguration.java @@ -3,7 +3,9 @@ package com.buttongames.butterflydao.spring.configuration; import com.buttongames.butterflydao.hibernate.dao.impl.CardDao; import com.buttongames.butterflydao.hibernate.dao.impl.MachineDao; import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.EventSaveDataDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GhostDataDao; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GlobalEventDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.ProfileDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.ShopDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GameplayEventLogDao; @@ -54,12 +56,16 @@ public class HibernateConfiguration { @Value("${hibernate.show_sql}") private String showSql; + @Value("${hibernate.connection.pool_size}") + private String connectionLimit; + @Bean public LocalSessionFactoryBean sessionFactory(final DriverManagerDataSource dataSource) { final Properties hibernateProperties = new Properties(); hibernateProperties.setProperty("hibernate.hbm2ddl.auto", this.hbm2ddl); hibernateProperties.setProperty("hibernate.dialect", this.dialect); hibernateProperties.setProperty("hibernate.show_sql", this.showSql); + hibernateProperties.setProperty("hibernate.connection.pool_size", this.connectionLimit); final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource); @@ -138,4 +144,14 @@ public class HibernateConfiguration { public GhostDataDao ghostDataDao(final SessionFactory sessionFactory) { return new GhostDataDao(sessionFactory); } + + @Bean + public EventSaveDataDao eventSaveDataDao(final SessionFactory sessionFactory) { + return new EventSaveDataDao(sessionFactory); + } + + @Bean + public GlobalEventDao globalEventDao(final SessionFactory sessionFactory) { + return new GlobalEventDao(sessionFactory); + } } diff --git a/butterflydao/src/main/resources/hibernate.properties b/butterflydao/src/main/resources/hibernate.properties index cd90b81..21127fa 100644 --- a/butterflydao/src/main/resources/hibernate.properties +++ b/butterflydao/src/main/resources/hibernate.properties @@ -4,4 +4,5 @@ jdbc.password = hibernate.hbm2ddl.auto = update hibernate.dialect = com.buttongames.butterflydao.hibernate.SQLiteDialect -hibernate.show_sql = false \ No newline at end of file +hibernate.show_sql = false +hibernate.connection.pool_size = 1 \ No newline at end of file diff --git a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/EventSaveData.java b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/EventSaveData.java new file mode 100644 index 0000000..fb13d86 --- /dev/null +++ b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/EventSaveData.java @@ -0,0 +1,184 @@ +package com.buttongames.butterflymodel.model.ddr16; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * Model class that represents a user gameplay event. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Entity +@Table(name = "ddr_16_event_save_data") +public class EventSaveData implements Externalizable { + + private static final long serialVersionUID = 1L; + + /** ID of the event, primary key */ + @Id + @GeneratedValue + @Column(name = "id") + private long id; + + /** The user this data belongs to */ + @ManyToOne + @JoinColumn(name = "user_id") + private UserProfile user; + + /** The id for the event */ + @Column(name = "event_id") + private int eventId; + + /** The type of the event */ + @Column(name = "event_type") + private int eventType; + + /** The number for the event */ + @Column(name = "event_no") + private int eventNo; + + /** Comp time? Not sure what this is. */ + @Column(name = "comp_time") + private long compTime; + + /** Not sure what this is either. */ + @Column(name = "save_data") + private long saveData; + + /** Condition of the event */ + @Column(name = "condition") + private long condition; + + /** Reward for the event */ + @Column(name = "reward") + private int reward; + + public EventSaveData() { } + + public EventSaveData(UserProfile user, int eventId, int eventType, int eventNo, long compTime, long saveData, + long condition, int reward) { + this.user = user; + this.eventId = eventId; + this.eventType = eventType; + this.eventNo = eventNo; + this.compTime = compTime; + this.saveData = saveData; + this.condition = condition; + this.reward = reward; + } + + public EventSaveData(EventSaveData other) { + this.user = other.user; + this.eventId = other.eventId; + this.eventType = other.eventType; + this.eventNo = other.eventNo; + this.compTime = other.compTime; + this.saveData = other.saveData; + this.condition = other.condition; + this.reward = other.reward; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(this.user); + out.writeInt(this.eventId); + out.writeInt(this.eventType); + out.writeInt(this.eventNo); + out.writeLong(this.compTime); + out.writeLong(this.saveData); + out.writeLong(this.condition); + out.writeInt(this.reward); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + this.setUser((UserProfile) in.readObject()); + this.setEventId(in.readInt()); + this.setEventType(in.readInt()); + this.setEventNo(in.readInt()); + this.setCompTime(in.readLong()); + this.setSaveData(in.readLong()); + this.setCondition(in.readLong()); + this.setReward(in.readInt()); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public UserProfile getUser() { + return user; + } + + public void setUser(UserProfile user) { + this.user = user; + } + + public int getEventId() { + return eventId; + } + + public void setEventId(int eventId) { + this.eventId = eventId; + } + + public int getEventType() { + return eventType; + } + + public void setEventType(int eventType) { + this.eventType = eventType; + } + + public int getEventNo() { + return eventNo; + } + + public void setEventNo(int eventNo) { + this.eventNo = eventNo; + } + + public long getCompTime() { + return compTime; + } + + public void setCompTime(long compTime) { + this.compTime = compTime; + } + + public long getSaveData() { + return saveData; + } + + public void setSaveData(long saveData) { + this.saveData = saveData; + } + + public long getCondition() { + return condition; + } + + public void setCondition(long condition) { + this.condition = condition; + } + + public int getReward() { + return reward; + } + + public void setReward(int reward) { + this.reward = reward; + } +} diff --git a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/GlobalEvent.java b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/GlobalEvent.java new file mode 100644 index 0000000..8287dea --- /dev/null +++ b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/GlobalEvent.java @@ -0,0 +1,110 @@ +package com.buttongames.butterflymodel.model.ddr16; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * Model class to represent a global event entry. + * @author skogaby (skogabyskogaby@gmail.com) + */ +@Entity +@Table(name = "ddr_16_global_events") +public class GlobalEvent implements Externalizable { + + private static final long serialVersionUID = 1L; + + /** ID of the event, primary key */ + @Id + @Column(name = "event_id") + private int eventId; + + /** Type of the event */ + @Column(name = "event_type") + private int eventType; + + /** Number of the event */ + @Column(name = "event_no") + private int eventNo; + + /** Condition of the event */ + @Column(name = "condition") + private long condition; + + /** Reward for the event */ + @Column(name = "reward") + private int reward; + + public GlobalEvent() { } + + public GlobalEvent(int eventId, int eventType, int eventNo, long condition, int reward) { + this.eventId = eventId; + this.eventType = eventType; + this.eventNo = eventNo; + this.condition = condition; + this.reward = reward; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeInt(this.eventId); + out.writeInt(this.eventType); + out.writeInt(this.eventNo); + out.writeLong(this.condition); + out.writeInt(this.reward); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + this.setEventId(in.readInt()); + this.setEventType(in.readInt()); + this.setEventNo(in.readInt()); + this.setCondition(in.readLong()); + this.setReward(in.readInt()); + } + + public int getEventId() { + return eventId; + } + + public void setEventId(int eventId) { + this.eventId = eventId; + } + + public int getEventType() { + return eventType; + } + + public void setEventType(int eventType) { + this.eventType = eventType; + } + + public int getEventNo() { + return eventNo; + } + + public void setEventNo(int eventNo) { + this.eventNo = eventNo; + } + + public long getCondition() { + return condition; + } + + public void setCondition(long condition) { + this.condition = condition; + } + + public int getReward() { + return reward; + } + + public void setReward(int reward) { + this.reward = reward; + } +} diff --git a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/Song.java b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/Song.java deleted file mode 100644 index 301d9d2..0000000 --- a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/Song.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.buttongames.butterflymodel.model.ddr16; - -/** - * This doesn't get persisted to the database, but it represents a song in the musicdb. - * @author skogaby (skogabyskogaby@gmail.com) - */ -public class Song { - - private int mcode; - private String baseName; - private String title; - private String artist; - - public Song(final int mcode, final String baseName, final String title, final String artist) { - this.mcode = mcode; - this.baseName = baseName; - this.title = title; - this.artist = artist; - } - - public int getMcode() { - return mcode; - } - - public void setMcode(int mcode) { - this.mcode = mcode; - } - - public String getBaseName() { - return baseName; - } - - public void setBaseName(String baseName) { - this.baseName = baseName; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getArtist() { - return artist; - } - - public void setArtist(String artist) { - this.artist = artist; - } -} diff --git a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/UserProfile.java b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/UserProfile.java index 84aeca9..731fc7d 100644 --- a/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/UserProfile.java +++ b/butterflymodel/src/main/java/com/buttongames/butterflymodel/model/ddr16/UserProfile.java @@ -197,6 +197,14 @@ public class UserProfile implements Externalizable { @Column(name = "unk_last", columnDefinition = "TEXT") private String unkLast; + /** The user's Dan ranking for singles */ + @Column(name = "single_class") + private Integer singleClass; + + /** The user's Dan ranking for doubles */ + @Column(name = "double_class") + private Integer doubleClass; + public UserProfile() { } public UserProfile(ButterflyUser user, String name, int dancerCode, int area, boolean displayWeight, int extraCharge, @@ -207,7 +215,7 @@ public class UserProfile implements Externalizable { JumpsOption jumpsOption, ArrowSkinOption arrowSkinOption, ScreenFilterOption screenFilterOption, GuideLinesOption guideLinesOption, LifeGaugeOption lifeGaugeOption, JudgementLayerOption judgementLayerOption, boolean showFastSlow, int lastCalories, UserProfile rival1, UserProfile rival2, UserProfile rival3, - String unkLast) { + String unkLast, int singleClass, int doubleClass) { this.user = user; this.name = name; this.dancerCode = dancerCode; @@ -240,6 +248,8 @@ public class UserProfile implements Externalizable { this.rival2 = rival2; this.rival3 = rival3; this.unkLast = unkLast; + this.singleClass = singleClass; + this.doubleClass = doubleClass; } @Override @@ -277,6 +287,8 @@ public class UserProfile implements Externalizable { out.writeObject(this.rival2); out.writeObject(this.rival3); out.writeUTF(this.unkLast); + out.writeInt(this.singleClass); + out.writeInt(this.doubleClass); } @Override @@ -314,6 +326,8 @@ public class UserProfile implements Externalizable { this.setRival2((UserProfile) in.readObject()); this.setRival3((UserProfile) in.readObject()); this.setUnkLast(in.readUTF()); + this.setSingleClass(in.readInt()); + this.setDoubleClass(in.readInt()); } public long getId() { @@ -579,4 +593,20 @@ public class UserProfile implements Externalizable { public void setUnkLast(String unkLast) { this.unkLast = unkLast; } + + public int getSingleClass() { + return (this.singleClass == null) ? 0 : singleClass; + } + + public void setSingleClass(int singleClass) { + this.singleClass = singleClass; + } + + public int getDoubleClass() { + return (this.doubleClass == null) ? 0 : doubleClass; + } + + public void setDoubleClass(int doubleClass) { + this.doubleClass = doubleClass; + } } diff --git a/butterflyserver/src/main/java/com/buttongames/butterflyserver/http/handlers/impl/PlayerDataRequestHandler.java b/butterflyserver/src/main/java/com/buttongames/butterflyserver/http/handlers/impl/PlayerDataRequestHandler.java index 0b806dd..ed75fd4 100644 --- a/butterflyserver/src/main/java/com/buttongames/butterflyserver/http/handlers/impl/PlayerDataRequestHandler.java +++ b/butterflyserver/src/main/java/com/buttongames/butterflyserver/http/handlers/impl/PlayerDataRequestHandler.java @@ -1,6 +1,9 @@ package com.buttongames.butterflyserver.http.handlers.impl; -import com.buttongames.butterflyserver.Main; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.EventSaveDataDao; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GlobalEventDao; +import com.buttongames.butterflymodel.model.ddr16.EventSaveData; +import com.buttongames.butterflymodel.model.ddr16.GlobalEvent; import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao; import com.buttongames.butterflydao.hibernate.dao.impl.CardDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GhostDataDao; @@ -33,21 +36,23 @@ import com.buttongames.butterflycore.util.TimeUtils; import com.buttongames.butterflycore.xml.kbinxml.KXmlBuilder; import com.buttongames.butterflycore.xml.XmlUtils; import com.buttongames.butterflyserver.util.PropertyNames; -import com.google.common.io.ByteStreams; +import com.google.common.collect.ImmutableList; 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.Document; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; import spark.Request; import spark.Response; +import java.time.Instant; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -127,6 +132,16 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { */ private final UserSongRecordDao songRecordDao; + /** + * The DAO for managing global events. + */ + private final GlobalEventDao globalEventDao; + + /** + * The DAO for managing user events progress. + */ + private final EventSaveDataDao eventSaveDataDao; + /** * Says whether or not we force every session to have extra stage. */ @@ -134,36 +149,25 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { private String isForceExtraStage; /** - * Static list of events for the server. + * This is a set of base user-level events we create for users when + * they have no event progress saved, yet. */ - private static NodeList EVENTS; - - static { - loadEvents(); - } + private final List baseUserEvents; public PlayerDataRequestHandler(final ButterflyUserDao userDao, final CardDao cardDao, final ProfileDao profileDao, - final GhostDataDao ghostDataDao, final UserSongRecordDao songRecordDao) { + final GhostDataDao ghostDataDao, final UserSongRecordDao songRecordDao, + final GlobalEventDao globalEventDao, final EventSaveDataDao eventSaveDataDao) { this.userDao = userDao; this.cardDao = cardDao; this.profileDao = profileDao; this.ghostDataDao = ghostDataDao; this.songRecordDao = songRecordDao; - } - - /** - * Load the events data into memory. - */ - private static void loadEvents() { - try { - final byte[] respBody = ByteStreams.toByteArray( - Main.class.getResourceAsStream("/static_responses/mdx/events.xml")); - final Element doc = XmlUtils.byteArrayToXmlFile(respBody); - EVENTS = XmlUtils.nodesAtPath(doc, "/response/playerdata/eventdata"); - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } + this.globalEventDao = globalEventDao; + this.eventSaveDataDao = eventSaveDataDao; + this.baseUserEvents = ImmutableList.of( + // Baby-Lon's Adventure + new EventSaveData(null, 999, 30, 0, 0, 0, 0, 5) + ); } /** @@ -337,7 +341,7 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { } /** - * Handles a request for the user scores. + * Handles a request for the user scores and event data. * @param refId The refId for the calling card * @param request The Spark request * @param response The Spark response @@ -353,10 +357,9 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { if (!refId.equals("X0000000000000000000000000000000")) { // get the user's scores and sort them out so we can get the top scores // for each song/difficulty - final List userRecords = - this.songRecordDao.findByUser( - this.profileDao.findByUser( - this.cardDao.findByRefId(refId).getUser())); + final UserProfile user = this.profileDao.findByUser( + this.cardDao.findByRefId(refId).getUser()); + final List userRecords = this.songRecordDao.findByUser(user); // sort them by song and difficulty, then insert them into the response // key for top map is the song ID @@ -404,15 +407,50 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { respBuilder = respBuilder.up(); } + + // set the user's dan ranking + respBuilder.e("grade") + .u32("single_grade", user.getSingleClass()).up() + .u32("double_grade", user.getDoubleClass()).up().up(); + + // set the user's user-level event progress + final List userEvents = this.eventSaveDataDao.findByUser(user); + + if (userEvents.isEmpty()) { + // if the user has no event progress, create their base event progress + for (EventSaveData event : this.baseUserEvents) { + EventSaveData newEvent = new EventSaveData(event); + newEvent.setUser(user); + + this.eventSaveDataDao.create(newEvent); + userEvents.add(newEvent); + } + } + + for (EventSaveData event : userEvents) { + respBuilder.e("eventdata") + .u32("eventid", event.getEventId()).up() + .s32("eventtype", event.getEventType()).up() + .u32("eventno", event.getEventNo()).up() + .s64("condition", event.getCondition()).up() + .u32("reward", event.getReward()).up() + .s32("comptime", (int) event.getCompTime()).up() + .s64("savedata", event.getSaveData()).up().up(); + } } - // TODO: Events isn't supposed to be a static response - final Document document = respBuilder.getDocument(); - final Element elem = respBuilder.getElement(); + // set the global events on the response + final List globalEvents = this.globalEventDao.findAll(); - for (int i = 0; i < EVENTS.getLength(); i++) { - Node tmp = document.importNode(EVENTS.item(i), true); - elem.appendChild(tmp); + for (GlobalEvent event : globalEvents) { + respBuilder.e("eventdata") + .u32("eventid", event.getEventId()).up() + .s32("eventtype", event.getEventType()).up() + .u32("eventno", event.getEventNo()).up() + .s64("condition", event.getCondition()).up() + .u32("reward", event.getReward()).up() + .s32("comptime", 1).up() + .s64("savedata", 0).up().up(); } return this.sendResponse(request, response, respBuilder); @@ -453,7 +491,7 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { SpeedOption.X_1_00, BoostOption.NORMAL, AppearanceOption.VISIBLE, TurnOption.OFF, StepZoneOption.ON, ScrollOption.NORMAL, ArrowColorOption.RAINBOW, CutOption.OFF, FreezeArrowOption.ON, JumpsOption.ON, ArrowSkinOption.NORMAL, ScreenFilterOption.DARK, GuideLinesOption.OFF, LifeGaugeOption.NORMAL, - JudgementLayerOption.BACKGROUND, true, 0, null, null, null, defaultLastCsv); + JudgementLayerOption.BACKGROUND, true, 0, null, null, null, defaultLastCsv, 0, 0); this.profileDao.create(profile); // send the response @@ -989,6 +1027,55 @@ public class PlayerDataRequestHandler extends BaseRequestHandler { this.songRecordDao.create(newRecord); } + // parse out the event progress saving and save them individually + final NodeList eventNodes = XmlUtils.nodesAtPath(dataNode, "/data/event"); + + for (int i = 0; i < eventNodes.getLength(); i++) { + Element eventNode = (Element) eventNodes.item(i); + int eventId = XmlUtils.intAtChild(eventNode, "eventid"); + + if (eventId == 0) { + continue; + } + + int eventType = XmlUtils.intAtChild(eventNode, "eventtype"); + int eventNo = XmlUtils.intAtChild(eventNode, "eventno"); + long compTime = XmlUtils.longAtChild(eventNode, "comptime"); + long saveData = XmlUtils.longAtChild(eventNode, "savedata"); + + // see if there's an entry for this event ID already. if there is, update its progress + EventSaveData eventSaveData = this.eventSaveDataDao.findByUserAndEventId(user, eventId); + + // construct and save + if (eventSaveData != null) { + eventSaveData.setEventType(eventType); + eventSaveData.setEventNo(eventNo); + eventSaveData.setCompTime(compTime); + eventSaveData.setSaveData(saveData); + this.eventSaveDataDao.update(eventSaveData); + } else { + eventSaveData = new EventSaveData(user, eventId, eventType, eventNo, compTime, saveData, 0, 0); + this.eventSaveDataDao.create(eventSaveData); + } + } + + // parse out the user's grade and also save that + final Element gradeNode = (Element) XmlUtils.nodeAtPath(dataNode, "/data/grade"); + + if (gradeNode != null) { + int singleGrade = XmlUtils.intAtChild(gradeNode, "single_grade"); + int doubleGrade = XmlUtils.intAtChild(gradeNode, "double_grade"); + + if (user.getSingleClass() != singleGrade || + user.getDoubleClass() != doubleGrade) { + user.setSingleClass(singleGrade); + user.setDoubleClass(doubleGrade); + + this.profileDao.update(user); + } + } + + // send the response final KXmlBuilder builder = KXmlBuilder.create("response") .e("playerdata") .s32("result", 0).up(); diff --git a/butterflyserver/src/main/java/com/buttongames/butterflyserver/spring/configuration/HttpConfiguration.java b/butterflyserver/src/main/java/com/buttongames/butterflyserver/spring/configuration/HttpConfiguration.java index d3a7382..d6edea3 100644 --- a/butterflyserver/src/main/java/com/buttongames/butterflyserver/spring/configuration/HttpConfiguration.java +++ b/butterflyserver/src/main/java/com/buttongames/butterflyserver/spring/configuration/HttpConfiguration.java @@ -2,8 +2,10 @@ package com.buttongames.butterflyserver.spring.configuration; import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao; import com.buttongames.butterflydao.hibernate.dao.impl.CardDao; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.EventSaveDataDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GameplayEventLogDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GhostDataDao; +import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.GlobalEventDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.PcbEventLogDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.ProfileDao; import com.buttongames.butterflydao.hibernate.dao.impl.ddr16.ShopDao; @@ -103,8 +105,9 @@ public class HttpConfiguration { @Bean public PlayerDataRequestHandler playerDataRequestHandler(final ButterflyUserDao userDao, final CardDao cardDao, final ProfileDao profileDao, final GhostDataDao ghostDataDao, - final UserSongRecordDao songRecordDao) { - return new PlayerDataRequestHandler(userDao, cardDao, profileDao, ghostDataDao, songRecordDao); + final UserSongRecordDao songRecordDao, final GlobalEventDao globalEventDao, + final EventSaveDataDao eventSaveDataDao) { + return new PlayerDataRequestHandler(userDao, cardDao, profileDao, ghostDataDao, songRecordDao, globalEventDao, eventSaveDataDao); } @Bean diff --git a/butterflyserver/src/main/resources/butterflyserver.properties b/butterflyserver/src/main/resources/butterflyserver.properties index 61cdb8e..706dca1 100644 --- a/butterflyserver/src/main/resources/butterflyserver.properties +++ b/butterflyserver/src/main/resources/butterflyserver.properties @@ -1,5 +1,5 @@ # Server properties server.port = 80 server.maintenance = false -server.paselienable = false +server.paselienable = true server.forceextrastage = false \ No newline at end of file diff --git a/butterflyserver/src/main/resources/static_responses/mdx/events.xml b/butterflyserver/src/main/resources/static_responses/mdx/events.xml deleted file mode 100644 index 66d3b47..0000000 --- a/butterflyserver/src/main/resources/static_responses/mdx/events.xml +++ /dev/null @@ -1,1519 +0,0 @@ - - - - 0 - 0 - - 1 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 2 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 3 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 4 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 5 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 6 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 7 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 8 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 9 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 10 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 11 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 12 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 13 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 14 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 15 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 16 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 17 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 18 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 19 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 20 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 21 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 22 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 23 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 24 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 25 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 26 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 27 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 28 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 29 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 30 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 31 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 32 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 33 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 34 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 35 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 36 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 37 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 38 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 39 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 40 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 41 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 42 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 43 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 44 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 45 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 46 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 47 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 48 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 49 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 50 - 9999 - 0 - 0 - 0 - 1 - 0 - - - 816 - 31 - 1 - 10000 - 16 - 1 - 0 - - - 817 - 31 - 2 - 10000 - 17 - 1 - 0 - - - 818 - 31 - 3 - 10000 - 18 - 1 - 0 - - - 819 - 31 - 0 - 10000 - 19 - 1 - 0 - - - 2000 - 31 - 0 - 10000 - 16 - 1 - 0 - - - 2001 - 31 - 0 - 10000 - 17 - 1 - 0 - - - 2002 - 31 - 0 - 10000 - 18 - 1 - 0 - - - 2003 - 31 - 0 - 10000 - 19 - 1 - 0 - - - 2100 - 10 - 0 - 0 - 38145 - 1 - 0 - - - 2101 - 10 - 0 - 0 - 38177 - 1 - 0 - - - 2102 - 10 - 0 - 0 - 37993 - 1 - 0 - - - 2103 - 10 - 0 - 0 - 37994 - 1 - 0 - - - 2104 - 10 - 0 - 0 - 37995 - 1 - 0 - - - 3000 - 10 - 0 - 0 - 41 - 1 - 0 - - - 3001 - 10 - 0 - 0 - 38124 - 1 - 0 - - - 3002 - 10 - 0 - 0 - 38121 - 1 - 0 - - - 3003 - 10 - 0 - 0 - 38127 - 1 - 0 - - - 3004 - 10 - 0 - 0 - 38081 - 1 - 0 - - - 3005 - 10 - 0 - 0 - 38091 - 1 - 0 - - - 3006 - 10 - 0 - 0 - 38072 - 1 - 0 - - - 3007 - 10 - 0 - 0 - 38088 - 1 - 0 - - - 3008 - 10 - 0 - 0 - 38098 - 1 - 0 - - - 3009 - 10 - 0 - 0 - 38120 - 1 - 0 - - - 3010 - 10 - 0 - 0 - 38130 - 1 - 0 - - - 3011 - 10 - 0 - 0 - 38137 - 1 - 0 - - - 3012 - 10 - 0 - 0 - 38139 - 1 - 0 - - - 3013 - 10 - 0 - 0 - 38140 - 1 - 0 - - - 3014 - 10 - 0 - 0 - 38144 - 1 - 0 - - - 3015 - 10 - 0 - 0 - 38146 - 1 - 0 - - - 3016 - 10 - 0 - 0 - 38197 - 1 - 0 - - - 3017 - 10 - 0 - 0 - 38182 - 1 - 0 - - - 3018 - 10 - 0 - 0 - 38147 - 1 - 0 - - - 3019 - 10 - 0 - 0 - 38198 - 1 - 0 - - - 3020 - 10 - 0 - 0 - 38149 - 1 - 0 - - - 3021 - 10 - 0 - 0 - 38156 - 1 - 0 - - - 3100 - 10 - 0 - 10000 - 38054 - 1 - 0 - - - 3101 - 10 - 0 - 10000 - 38057 - 1 - 0 - - - 3102 - 10 - 0 - 10000 - 38052 - 1 - 0 - - - 3103 - 10 - 0 - 10000 - 38055 - 1 - 0 - - - 3104 - 10 - 0 - 10000 - 38053 - 1 - 0 - - - 3105 - 10 - 0 - 10000 - 38059 - 1 - 0 - - - 3106 - 10 - 0 - 10000 - 38050 - 1 - 0 - - - 3107 - 10 - 0 - 10000 - 38051 - 1 - 0 - - - 3108 - 10 - 0 - 10000 - 38049 - 1 - 0 - - - 3109 - 10 - 0 - 10000 - 38048 - 1 - 0 - - - 3110 - 10 - 0 - 10000 - 38025 - 1 - 0 - - - 3111 - 10 - 0 - 10000 - 37997 - 1 - 0 - - - 3112 - 10 - 0 - 10000 - 38004 - 1 - 0 - - - 3113 - 10 - 0 - 10000 - 38001 - 1 - 0 - - - 3114 - 10 - 0 - 10000 - 37996 - 1 - 0 - - - 3115 - 10 - 0 - 10000 - 37999 - 1 - 0 - - - 3116 - 10 - 0 - 10000 - 38000 - 1 - 0 - - - 3117 - 10 - 0 - 10000 - 38003 - 1 - 0 - - - 3118 - 10 - 0 - 10000 - 37998 - 1 - 0 - - - 3119 - 10 - 0 - 10000 - 38002 - 1 - 0 - - - 3120 - 10 - 0 - 10000 - 37950 - 1 - 0 - - - 3121 - 10 - 0 - 10000 - 37954 - 1 - 0 - - - 3122 - 10 - 0 - 10000 - 37957 - 1 - 0 - - - 3123 - 10 - 0 - 10000 - 37947 - 1 - 0 - - - 3124 - 10 - 0 - 10000 - 37956 - 1 - 0 - - - 3125 - 10 - 0 - 10000 - 37952 - 1 - 0 - - - 3126 - 10 - 0 - 10000 - 37961 - 1 - 0 - - - 3127 - 10 - 0 - 10000 - 37949 - 1 - 0 - - - 3128 - 10 - 0 - 10000 - 37948 - 1 - 0 - - - 3129 - 10 - 0 - 10000 - 37955 - 1 - 0 - - - 3130 - 10 - 0 - 10000 - 37946 - 1 - 0 - - - 3131 - 10 - 0 - 10000 - 37951 - 1 - 0 - - - 3132 - 10 - 0 - 10000 - 37953 - 1 - 0 - - - 3133 - 10 - 0 - 10000 - 37958 - 1 - 0 - - - 3134 - 10 - 0 - 10000 - 38076 - 1 - 0 - - - 3135 - 10 - 0 - 10000 - 38095 - 1 - 0 - - - 3136 - 10 - 4 - 10000 - 38094 - 1 - 0 - - - 3137 - 10 - 8 - 10000 - 38094 - 1 - 0 - - - 3138 - 10 - 4 - 10000 - 38099 - 1 - 0 - - - 3139 - 10 - 8 - 10000 - 38099 - 1 - 0 - - - 3140 - 10 - 0 - 10000 - 38067 - 1 - 0 - - - 3141 - 10 - 0 - 10000 - 38083 - 1 - 0 - - - 3142 - 10 - 0 - 10000 - 38097 - 1 - 0 - - - 3143 - 10 - 0 - 10000 - 38128 - 1 - 0 - - - 3144 - 10 - 0 - 10000 - 38082 - 1 - 0 - - - 3145 - 10 - 0 - 10000 - 38129 - 1 - 0 - - - 3146 - 10 - 0 - 10000 - 38070 - 1 - 0 - - - 3147 - 10 - 0 - 10000 - 38071 - 1 - 0 - - - 3148 - 10 - 0 - 10000 - 38085 - 1 - 0 - - - 3149 - 10 - 0 - 10000 - 38086 - 1 - 0 - - - 3150 - 10 - 0 - 10000 - 38131 - 1 - 0 - - - 3151 - 10 - 0 - 10000 - 38132 - 1 - 0 - - - 3152 - 10 - 0 - 10000 - 38133 - 1 - 0 - - - 3153 - 10 - 0 - 10000 - 38134 - 1 - 0 - - - 3154 - 10 - 0 - 10000 - 38135 - 1 - 0 - - - 3155 - 10 - 0 - 10000 - 38136 - 1 - 0 - - - 3156 - 10 - 0 - 10000 - 38142 - 1 - 0 - - - 3157 - 10 - 0 - 10000 - 38143 - 1 - 0 - - - 3158 - 10 - 0 - 10000 - 38183 - 1 - 0 - - - 3159 - 10 - 0 - 10000 - 38184 - 1 - 0 - - - 3160 - 10 - 0 - 10000 - 38190 - 1 - 0 - - - 3161 - 10 - 0 - 10000 - 38191 - 1 - 0 - - - 3162 - 10 - 0 - 10000 - 38192 - 1 - 0 - - - 3163 - 10 - 0 - 10000 - 38194 - 1 - 0 - - - 3164 - 10 - 0 - 10000 - 38195 - 1 - 0 - - - 3165 - 10 - 0 - 10000 - 38196 - 1 - 0 - - - 3166 - 10 - 0 - 10000 - 38150 - 1 - 0 - - - 3167 - 10 - 0 - 10000 - 38151 - 1 - 0 - - - 3168 - 10 - 0 - 10000 - 38193 - 1 - 0 - - - 3169 - 10 - 0 - 10000 - 38200 - 1 - 0 - - - 3170 - 10 - 0 - 10000 - 38201 - 1 - 0 - - - 3171 - 10 - 0 - 10000 - 38202 - 1 - 0 - - - 3172 - 10 - 0 - 10000 - 38203 - 1 - 0 - - - 3173 - 10 - 0 - 10000 - 38204 - 1 - 0 - - - 3174 - 10 - 0 - 10000 - 38205 - 1 - 0 - - - 3175 - 10 - 0 - 10000 - 38206 - 1 - 0 - - - 3176 - 10 - 0 - 10000 - 38215 - 1 - 0 - - - 3177 - 10 - 0 - 10000 - 38216 - 1 - 0 - - - 3178 - 10 - 0 - 10000 - 38217 - 1 - 0 - - - 3179 - 10 - 0 - 10000 - 38218 - 1 - 0 - - - 3180 - 10 - 0 - 10000 - 38220 - 1 - 0 - - - 3181 - 10 - 0 - 10000 - 38221 - 1 - 0 - - - 3182 - 10 - 0 - 10000 - 38222 - 1 - 0 - - - \ No newline at end of file