mirror of
https://github.com/skogaby/butterfly.git
synced 2026-09-11 17:55:09 -05:00
Remove the hardcoded events.xml file and use the database for events. TODO: create a mechanism to generate a full unlock scenario from a musicdb.xml so we can have a full unlock response for any version if the user has it toggled.
This commit is contained in:
@@ -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 <code>EventSaveData</code> objects in the database.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Repository
|
||||
@Transactional
|
||||
public class EventSaveDataDao extends AbstractHibernateDao<EventSaveData> {
|
||||
|
||||
@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<EventSaveData> findByUser(final UserProfile user) {
|
||||
final Query<EventSaveData> 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<EventSaveData> 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();
|
||||
}
|
||||
}
|
||||
@@ -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 <code>GlobalEvent</code> objects in the database.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@Repository
|
||||
@Transactional
|
||||
public class GlobalEventDao extends AbstractHibernateDao<GlobalEvent> {
|
||||
|
||||
@Autowired
|
||||
public GlobalEventDao(final SessionFactory sessionFactory) {
|
||||
super(sessionFactory);
|
||||
setClazz(GlobalEvent.class);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ jdbc.password =
|
||||
|
||||
hibernate.hbm2ddl.auto = update
|
||||
hibernate.dialect = com.buttongames.butterflydao.hibernate.SQLiteDialect
|
||||
hibernate.show_sql = false
|
||||
hibernate.show_sql = false
|
||||
hibernate.connection.pool_size = 1
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EventSaveData> 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<UserSongRecord> 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<UserSongRecord> 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<EventSaveData> 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<GlobalEvent> 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Server properties
|
||||
server.port = 80
|
||||
server.maintenance = false
|
||||
server.paselienable = false
|
||||
server.paselienable = true
|
||||
server.forceextrastage = false
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user