Initial Commit

This commit is contained in:
samnyan
2020-01-16 00:50:52 +09:00
commit 89771b7b51
331 changed files with 32076 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
package icu.samnyan.aqua;
import icu.samnyan.aqua.sega.aimedb.AimeDbServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class AquaServerApplication {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(AquaServerApplication.class, args);
final AimeDbServer aimeDbServer = ctx.getBean(AimeDbServer.class);
aimeDbServer.start();
}
}

View File

@@ -0,0 +1,30 @@
package icu.samnyan.aqua.api.controller;
import icu.samnyan.aqua.sega.general.dao.CardRepository;
import icu.samnyan.aqua.sega.general.model.Card;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("api/sega/aime")
public class ApiAimeController {
private final CardRepository cardRepository;
public ApiAimeController(CardRepository cardRepository) {
this.cardRepository = cardRepository;
}
@PostMapping("getByAccessCode")
public Optional<Card> getByAccessCode(@RequestBody Map<String, String> request) {
return cardRepository.findByLuid(request.get("accessCode"));
}
}

View File

@@ -0,0 +1,19 @@
package icu.samnyan.aqua.api.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.NoSuchElementException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestControllerAdvice(basePackages = "icu.samnyan.aqua.api")
public class ApiControllerAdvice {
@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<Object> noSuchElement() {
return ResponseEntity.notFound().build();
}
}

View File

@@ -0,0 +1,148 @@
package icu.samnyan.aqua.api.controller.sega.chuni.amazon;
import com.fasterxml.jackson.core.type.TypeReference;
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.ProfileResp;
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.RatingItem;
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.RecentResp;
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.ScoreResp;
import icu.samnyan.aqua.api.util.ApiMapper;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.Level;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.Music;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCourse;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMusicDetail;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
import icu.samnyan.aqua.sega.chunithm.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("api/game/chuni/amazon")
public class ApiAmazonController {
private final ApiMapper mapper;
private final UserDataService userDataService;
private final UserPlaylogService userPlaylogService;
private final UserMusicDetailService userMusicDetailService;
private final UserCourseService userCourseService;
private final GameMusicService gameMusicService;
@Autowired
public ApiAmazonController(ApiMapper mapper, UserDataService userDataService, UserPlaylogService userPlaylogService, UserMusicDetailService userMusicDetailService, UserCourseService userCourseService, GameMusicService gameMusicService) {
this.mapper = mapper;
this.userDataService = userDataService;
this.userPlaylogService = userPlaylogService;
this.userMusicDetailService = userMusicDetailService;
this.userCourseService = userCourseService;
this.gameMusicService = gameMusicService;
}
/**
* Get Basic info
*
* @return
*/
@GetMapping("profile")
public ProfileResp getProfile(@RequestParam String aimeId) {
ProfileResp resp = mapper.convert(userDataService.getUserByExtId(aimeId).orElseThrow(), new TypeReference<>() {
});
UserCourse course = userCourseService.getByUser(aimeId)
.stream()
.filter(UserCourse::isClear)
.max(Comparator.comparingInt(UserCourse::getClassId))
.orElseGet(() -> new UserCourse(0));
resp.setCourseClass(course.getClassId());
return resp;
}
@GetMapping("recent")
public List<RecentResp> getRecentPlay(@RequestParam String aimeId) {
return mapper.convert(userPlaylogService.getRecentPlays(aimeId), new TypeReference<>() {
});
}
@GetMapping("rating")
public List<RatingItem> getRating(@RequestParam String aimeId) {
Map<Integer, Music> musicMap = gameMusicService.getIdMap();
List<UserMusicDetail> details = userMusicDetailService.getByUser(aimeId);
List<RatingItem> result = new ArrayList<>();
for (UserMusicDetail detail : details) {
Music music = musicMap.get(detail.getMusicId());
Level level = music.getLevels().get(detail.getLevel());
int levelBase = level.getLevel() * 100 + level.getLevelDecimal();
int score = detail.getScoreMax();
int rating = calculateRating(levelBase, score);
result.add(new RatingItem(music.getMusicId(), music.getName(), music.getArtistName(), level.getDiff(), score, levelBase, rating));
}
return result.stream()
.filter(detail -> detail.getLevel() != 4)
.sorted(Comparator.comparingInt(RatingItem::getRating).reversed())
.limit(30)
.collect(Collectors.toList());
}
@GetMapping("rating/recent")
public List<RatingItem> getRecentRating(@RequestParam String aimeId) {
Map<Integer, Music> musicMap = gameMusicService.getIdMap();
List<UserPlaylog> logList = userPlaylogService.getRecent30Plays(aimeId);
List<RatingItem> result = new ArrayList<>();
for (UserPlaylog log : logList) {
Music music = musicMap.get(log.getMusicId());
Level level = music.getLevels().get(log.getLevel());
int levelBase = level.getLevel() * 100 + level.getLevelDecimal();
int score = log.getScore();
int rating = calculateRating(levelBase, score);
result.add(new RatingItem(music.getMusicId(), music.getName(), music.getArtistName(), level.getDiff(), score, levelBase, rating));
}
List<String> keys = new ArrayList<>();
return result.stream()
.filter(detail -> detail.getLevel() != 4)
.sorted(Comparator.comparingInt(RatingItem::getRating).reversed())
.limit(10)
.collect(Collectors.toList());
}
@GetMapping("score/list")
public List<ScoreResp> getScoreList(@RequestParam String aimeId) {
return mapper.convert(userMusicDetailService.getByUser(aimeId), new TypeReference<>() {
});
}
@GetMapping("music")
public List<Music> getMusicList() {
return gameMusicService.getAll();
}
@PostMapping("music/import")
public List<Music> addMusic(@RequestBody List<Music> musicList) {
musicList.forEach(music -> music.getLevels().forEach((integer, level) -> level.setMusic(music)));
return gameMusicService.saveAll(musicList);
}
private int calculateRating(int levelBase, int score) {
if (score >= 1007500) return levelBase + 200;
if (score >= 1005000) return levelBase + 150 + (score - 1005000) * 10 / 500;
if (score >= 1000000) return levelBase + 100 + (score - 1000000) * 5 / 500;
if (score >= 975000) return levelBase + (score - 975000) * 2 / 500;
if (score >= 950000) return levelBase - 150 + (score - 950000) * 3 / 500;
if (score >= 925000) return levelBase - 300 + (score - 925000) * 3 / 500;
if (score >= 900000) return levelBase - 500 + (score - 900000) * 4 / 500;
return 0;
}
}

View File

@@ -0,0 +1,23 @@
package icu.samnyan.aqua.api.controller.sega.diva;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("api/game/diva/data")
public class ApiDivaGameDataController {
@GetMapping(value = "musicList", produces = MediaType.APPLICATION_JSON_VALUE)
public byte[] musicList() throws IOException {
return Files.readAllBytes(Paths.get("data/diva_musiclist.json"));
}
}

View File

@@ -0,0 +1,113 @@
package icu.samnyan.aqua.api.controller.sega.diva;
import icu.samnyan.aqua.api.model.OkResponse;
import icu.samnyan.aqua.api.model.req.sega.diva.ModuleEntry;
import icu.samnyan.aqua.api.model.req.sega.diva.PvListEntry;
import icu.samnyan.aqua.api.model.req.sega.diva.PvListRequest;
import icu.samnyan.aqua.sega.diva.dao.gamedata.*;
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
import icu.samnyan.aqua.sega.diva.model.common.Edition;
import icu.samnyan.aqua.sega.diva.model.gamedata.*;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("api/game/diva/manage")
public class ApiDivaManageController {
private final PvEntryRepository pvEntryRepository;
private final DivaModuleRepository moduleRepository;
private final DivaCustomizeRepository customizeRepository;
private final FestaRepository festaRepository;
private final ContestRepository contestRepository;
public ApiDivaManageController(PvEntryRepository pvEntryRepository, DivaModuleRepository moduleRepository, DivaCustomizeRepository customizeRepository, FestaRepository festaRepository, ContestRepository contestRepository) {
this.pvEntryRepository = pvEntryRepository;
this.moduleRepository = moduleRepository;
this.customizeRepository = customizeRepository;
this.festaRepository = festaRepository;
this.contestRepository = contestRepository;
}
@PostMapping("pvList")
public List<PvEntry> updatePvList(@RequestBody PvListRequest request) {
request.getEasy().forEach(x -> savePv(x, Difficulty.EASY));
request.getNormal().forEach(x -> savePv(x, Difficulty.NORMAL));
request.getHard().forEach(x -> savePv(x, Difficulty.HARD));
request.getExtreme().forEach(x -> savePv(x, Difficulty.EXTREME));
return pvEntryRepository.findAll();
}
@PostMapping("module")
public List<DivaModule> updateModuleList(@RequestBody List<ModuleEntry> request) {
List<DivaModule> moduleList = new ArrayList<>();
request.forEach(x -> moduleList.add(new DivaModule(x.getID(), x.getName(), x.getPrice(), x.getReleaseDate(), x.getEndDate(), x.getSortOrder())));
return moduleRepository.saveAll(moduleList);
}
@PostMapping("item")
public List<DivaCustomize> updateItemList(@RequestBody List<ModuleEntry> request) {
List<DivaCustomize> itemList = new ArrayList<>();
request.forEach(x -> itemList.add(new DivaCustomize(x.getID(), x.getName(), x.getPrice(), x.getReleaseDate(), x.getEndDate(), x.getSortOrder())));
return customizeRepository.saveAll(itemList);
}
private void savePv(PvListEntry x, Difficulty difficulty) {
pvEntryRepository.save(new PvEntry(x.getPVID(),
difficulty,
x.getVersion(),
Edition.fromValue(x.getEdition()),
x.getAdvDemo().getStart(),
x.getAdvDemo().getEnd(),
x.getPlayable().getStart(),
x.getPlayable().getEnd()
));
}
@GetMapping("festa")
public List<Festa> getFesta() {
return festaRepository.findAll();
}
@PutMapping("festa")
public Festa updateFesta(@RequestBody Festa festa) {
return festaRepository.save(festa);
}
@DeleteMapping("festa/{id}")
public OkResponse getFesta(@PathVariable int id) {
festaRepository.deleteById(id);
return new OkResponse("Deleted " + id);
}
@GetMapping("contest")
public List<Contest> getContest() {
return contestRepository.findAll();
}
@PutMapping("contest")
public Contest updateContest(@RequestBody Contest contest) {
return contestRepository.save(contest);
}
@DeleteMapping("contest/{id}")
public OkResponse deleteContest(@PathVariable int id) {
contestRepository.deleteById(id);
return new OkResponse("Deleted " + id);
}
@GetMapping("module")
public List<DivaModule> getModule() {
return moduleRepository.findAll();
}
@GetMapping("customize")
public List<DivaCustomize> getCustomize() {
return customizeRepository.findAll();
}
}

View File

@@ -0,0 +1,183 @@
package icu.samnyan.aqua.api.controller.sega.diva;
import icu.samnyan.aqua.api.model.ReducedPageResponse;
import icu.samnyan.aqua.sega.diva.dao.userdata.*;
import icu.samnyan.aqua.sega.diva.model.userdata.*;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("api/game/diva")
public class ApiDivaPlayerDataController {
private final PlayerProfileService playerProfileService;
private final PlayLogRepository playLogRepository;
private final PlayerPvRecordRepository playerPvRecordRepository;
private final PlayerPvCustomizeRepository playerPvCustomizeRepository;
private final PlayerModuleRepository playerModuleRepository;
private final PlayerCustomizeRepository playerCustomizeRepository;
public ApiDivaPlayerDataController(PlayerProfileService playerProfileService, PlayLogRepository playLogRepository, PlayerPvRecordRepository playerPvRecordRepository, PlayerPvCustomizeRepository playerPvCustomizeRepository, PlayerModuleRepository playerModuleRepository, PlayerCustomizeRepository playerCustomizeRepository) {
this.playerProfileService = playerProfileService;
this.playLogRepository = playLogRepository;
this.playerPvRecordRepository = playerPvRecordRepository;
this.playerPvCustomizeRepository = playerPvCustomizeRepository;
this.playerModuleRepository = playerModuleRepository;
this.playerCustomizeRepository = playerCustomizeRepository;
}
@GetMapping("playerInfo")
public Optional<PlayerProfile> getPlayerInfo(@RequestParam int pdId) {
return playerProfileService.findByPdId(pdId);
}
@PutMapping("playerInfo/playerName")
public PlayerProfile updateName(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setPlayerName((String) request.get("playerName"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/title")
public PlayerProfile updateTitle(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setLevelTitle((String) request.get("title"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/plate")
public PlayerProfile updatePlate(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setPlateId((Integer) request.get("plateId"));
profile.setPlateEffectId((Integer) request.get("plateEffectId"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/commonModule")
public PlayerProfile updateModule(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setCommonModule((String) request.get("commonModule"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/commonCustomize")
public PlayerProfile updateCustomize(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setCommonCustomizeItems((String) request.get("commonCustomize"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/commonSkin")
public PlayerProfile updateSkin(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setCommonSkin((Integer) request.get("skinId"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/myList")
public PlayerProfile updateMyList(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
switch ((Integer) request.get("myListId")) {
case 0:
profile.setMyList0((String) request.get("myListData"));
break;
case 1:
profile.setMyList1((String) request.get("myListData"));
break;
case 2:
profile.setMyList2((String) request.get("myListData"));
break;
}
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/se")
public PlayerProfile updateSe(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setButtonSe((Integer) request.get("buttonSe"));
profile.setChainSlideSe((Integer) request.get("chainSlideSe"));
profile.setSlideSe((Integer) request.get("slideSe"));
profile.setSliderTouchSe((Integer) request.get("sliderTouchSe"));
return playerProfileService.save(profile);
}
@PutMapping("playerInfo/display")
public PlayerProfile updateDisplay(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
profile.setShowInterimRanking((Boolean) request.get("showInterimRanking"));
profile.setShowClearStatus((Boolean) request.get("showClearStatus"));
profile.setShowClearBorder((Boolean) request.get("showClearBorder"));
profile.setShowRgoSetting((Boolean) request.get("showRgoSetting"));
return playerProfileService.save(profile);
}
@GetMapping("playLog")
public ReducedPageResponse<PlayLog> getPlayLogs(@RequestParam int pdId,
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size) {
Page<PlayLog> playLogs = playLogRepository.findByPdId_PdIdOrderByDateTimeDesc(pdId, PageRequest.of(page, size));
return new ReducedPageResponse<>(playLogs.getContent(), playLogs.getPageable().getPageNumber(), playLogs.getTotalPages(), playLogs.getTotalElements());
}
/**
* PvRecord
*/
@GetMapping("pvRecord")
public ReducedPageResponse<PlayerPvRecord> getPvRecords(@RequestParam int pdId,
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size) {
Page<PlayerPvRecord> pvRecords = playerPvRecordRepository.findByPdId_PdIdOrderByPvId(pdId, PageRequest.of(page, size));
return new ReducedPageResponse<>(pvRecords.getContent(), pvRecords.getPageable().getPageNumber(), pvRecords.getTotalPages(), pvRecords.getTotalElements());
}
@GetMapping("pvRecord/{pvId}")
public Map<String, Object> getPvRecord(@RequestParam int pdId, @PathVariable int pvId) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("records", playerPvRecordRepository.findByPdId_PdIdAndPvId(pdId, pvId));
playerPvCustomizeRepository.findByPdId_PdIdAndPvId(pdId, pvId).ifPresent(x -> resultMap.put("customize", x));
return resultMap;
}
@PutMapping("pvRecord/{pvId}")
public PlayerPvCustomize updatePvCustomize(@RequestBody Map<String, Object> request, @PathVariable int pvId) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
PlayerPvCustomize playerPvCustomize = playerPvCustomizeRepository.findByPdIdAndPvId(profile, pvId)
.orElseGet(() -> new PlayerPvCustomize(profile, pvId));
playerPvCustomize.setModule((String) request.get("module"));
playerPvCustomize.setCustomize((String) request.get("customize"));
playerPvCustomize.setCustomizeFlag((String) request.get("customizeFlag"));
playerPvCustomize.setSkin((Integer) request.get("skin"));
playerPvCustomize.setButtonSe((Integer) request.get("buttonSe"));
playerPvCustomize.setSlideSe((Integer) request.get("slideSe"));
playerPvCustomize.setChainSlideSe((Integer) request.get("chainSlideSe"));
playerPvCustomize.setSliderTouchSe((Integer) request.get("sliderTouchSe"));
return playerPvCustomizeRepository.save(playerPvCustomize);
}
@GetMapping("module")
public ReducedPageResponse<PlayerModule> getModules(@RequestParam int pdId,
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size) {
Page<PlayerModule> modules = playerModuleRepository.findByPdId_PdId(pdId, PageRequest.of(page, size));
return new ReducedPageResponse<>(modules.getContent(), modules.getPageable().getPageNumber(), modules.getTotalPages(), modules.getTotalElements());
}
@GetMapping("customize")
public ReducedPageResponse<PlayerCustomize> getCustomizes(@RequestParam int pdId,
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size) {
Page<PlayerCustomize> customizes = playerCustomizeRepository.findByPdId_PdId(pdId, PageRequest.of(page, size));
return new ReducedPageResponse<>(customizes.getContent(), customizes.getPageable().getPageNumber(), customizes.getTotalPages(), customizes.getTotalElements());
}
}

View File

@@ -0,0 +1,23 @@
package icu.samnyan.aqua.api.model;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class OkResponse {
private String message = "ok";
public OkResponse(String message) {
this.message = message;
}
public OkResponse() {
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@@ -0,0 +1,25 @@
package icu.samnyan.aqua.api.model;
import lombok.Getter;
import lombok.Setter;
import java.util.Collection;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Getter
@Setter
public class ReducedPageResponse<T> {
private Collection<T> content;
private Integer page;
private Integer totalPages;
private Long totalElements;
public ReducedPageResponse(Collection<T> content, Integer page, Integer totalPages, Long totalElements) {
this.content = content;
this.page = page;
this.totalPages = totalPages;
this.totalElements = totalElements;
}
}

View File

@@ -0,0 +1,21 @@
package icu.samnyan.aqua.api.model.req.sega.diva;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DatePair {
@JsonProperty("Start")
private LocalDateTime Start;
@JsonProperty("End")
private LocalDateTime End;
}

View File

@@ -0,0 +1,29 @@
package icu.samnyan.aqua.api.model.req.sega.diva;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ModuleEntry {
@JsonProperty("ID")
private int ID;
@JsonProperty("Name")
private String Name;
@JsonProperty("Price")
private int Price;
@JsonProperty("ReleaseDate")
private LocalDateTime ReleaseDate;
@JsonProperty("EndDate")
private LocalDateTime EndDate;
@JsonProperty("SortOrder")
private int SortOrder;
}

View File

@@ -0,0 +1,25 @@
package icu.samnyan.aqua.api.model.req.sega.diva;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PvListEntry {
@JsonProperty("PVID")
private int PVID;
@JsonProperty("Version")
private int Version;
@JsonProperty("Edition")
private int Edition;
@JsonProperty("AdvDemo")
private DatePair AdvDemo;
@JsonProperty("Playable")
private DatePair Playable;
}

View File

@@ -0,0 +1,28 @@
package icu.samnyan.aqua.api.model.req.sega.diva;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PvListRequest {
@JsonProperty("CreationDate")
private LocalDateTime CreationDate;
@JsonProperty("Easy")
private List<PvListEntry> Easy;
@JsonProperty("Normal")
private List<PvListEntry> Normal;
@JsonProperty("Hard")
private List<PvListEntry> Hard;
@JsonProperty("Extreme")
private List<PvListEntry> Extreme;
}

View File

@@ -0,0 +1,60 @@
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProfileResp {
private String userName;
private int level;
private String exp;
private long point;
private long totalPoint;
private int playCount;
private int playerRating;
private int highestRating;
private int nameplateId;
private int frameId;
private int characterId;
private int trophyId;
private int totalMapNum;
private long totalHiScore;
private long totalBasicHighScore;
private long totalAdvancedHighScore;
private long totalExpertHighScore;
private long totalMasterHighScore;
private int friendCount;
private LocalDateTime firstPlayDate;
private LocalDateTime lastPlayDate;
private int courseClass;
}

View File

@@ -0,0 +1,28 @@
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RatingItem {
private int musicId;
private String musicName;
private String artistName;
private int level;
private int score;
private int ratingBase;
private int rating;
}

View File

@@ -0,0 +1,87 @@
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RecentResp {
private LocalDateTime playDate;
private LocalDateTime userPlayDate;
private int musicId;
private int level;
private int customId;
private int playedCustom1;
private int playedCustom2;
private int playedCustom3;
private int track;
private int score;
private int rank;
private int maxCombo;
private int maxChain;
private int rateTap;
private int rateHold;
private int rateSlide;
private int rateAir;
private int rateFlick;
private int judgeGuilty;
private int judgeAttack;
private int judgeJustice;
private int judgeCritical;
private int playerRating;
@JsonProperty("isNewRecord")
private boolean isNewRecord;
@JsonProperty("isFullCombo")
private boolean isFullCombo;
private int fullChainKind;
@JsonProperty("isAllJustice")
private boolean isAllJustice;
private int characterId;
private int skillId;
private int playKind;
@JsonProperty("isClear")
private boolean isClear;
private int skillLevel;
private int skillEffect;
}

View File

@@ -0,0 +1,48 @@
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ScoreResp {
private int musicId;
private int level;
private int playCount;
private int scoreMax;
private int resRequestCount;
private int resAcceptCount;
private int resSuccessCount;
private int missCount;
private int maxComboCount;
@JsonProperty("isFullCombo")
private boolean isFullCombo;
@JsonProperty("isAllJustice")
private boolean isAllJustice;
@JsonProperty("isSuccess")
private boolean isSuccess;
private int fullChain;
private int maxChain;
private int scoreRank;
}

View File

@@ -0,0 +1,13 @@
package icu.samnyan.aqua.api.model.resp.sega.diva;
import lombok.Data;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
public class PlayerInfo {
private int pdId;
private String playerName;
private int vocaloidPoints;
}

View File

@@ -0,0 +1,35 @@
package icu.samnyan.aqua.api.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class ApiMapper {
private final ObjectMapper mapper;
public ApiMapper() {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule();
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(module);
}
public String write(Object o) throws JsonProcessingException {
return mapper.writeValueAsString(o);
}
public <T> T convert(Object object, TypeReference<T> toClass) {
return mapper.convertValue(object, toClass);
}
}

View File

@@ -0,0 +1,24 @@
package icu.samnyan.aqua.security.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.headers().disable()
.csrf().disable()
.authorizeRequests()
.anyRequest().permitAll();
}
}

View File

@@ -0,0 +1,91 @@
package icu.samnyan.aqua.sega.aimedb;
import icu.samnyan.aqua.sega.aimedb.exception.InvalidRequestException;
import icu.samnyan.aqua.sega.aimedb.util.Encryption;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AimeDbDecoder extends ByteToMessageDecoder {
private static final Logger logger = LoggerFactory.getLogger(AimeDbDecoder.class);
private int length = 0;
/**
* Decrypt the incoming request including frame management
*
* @param ctx
* @param in
* @param out
* @throws Exception
*/
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 16) {
return;
}
if (length == 0) {
length = getLength(in);
}
if (in.readableBytes() < length) {
return;
}
// Create a byte array to store the encrypted data
ByteBuf result = Encryption.decrypt(in.readBytes(length));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", ((Short) result.getShortLE(0x04)).intValue());
resultMap.put("data", result);
logger.debug("Aime Server Request Type: " + resultMap.get("type"));
out.add(resultMap);
}
/**
* Get the length from request
*
* @param in the request
* @return int the length of this request
* @throws InvalidRequestException
* @throws IllegalBlockSizeException
* @throws InvalidKeyException
* @throws BadPaddingException
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
*/
private int getLength(ByteBuf in) throws InvalidRequestException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
int currentPos = in.readerIndex();
ByteBuf result = Encryption.decrypt(in);
// Check the header
if (result.getByte(0) != 0x3e) {
throw new InvalidRequestException();
}
// Read the length from offset 6
return result.getShortLE(currentPos + 6);
}
}

View File

@@ -0,0 +1,32 @@
package icu.samnyan.aqua.sega.aimedb;
import icu.samnyan.aqua.sega.aimedb.util.Encryption;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AimeDbEncoder extends MessageToByteEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
if (msg instanceof ByteBuf) {
ByteBuf resp = ((ByteBuf) msg);
resp.writerIndex(0);
resp.writeShortLE(0xa13e);
resp.writeShortLE(0x3087);
resp.setShortLE(0x0006, resp.capacity());
ByteBuf encryptedResp = Encryption.encrypt(resp);
ctx.writeAndFlush(encryptedResp);
}
}
}

View File

@@ -0,0 +1,96 @@
package icu.samnyan.aqua.sega.aimedb;
import icu.samnyan.aqua.sega.aimedb.handler.Impl.*;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@Scope("prototype")
public class AimeDbRequestHandler extends ChannelInboundHandlerAdapter {
private static final Logger logger = LoggerFactory.getLogger(AimeDbRequestHandler.class);
private final CampaignHandler campaignHandler;
private final FeliCaLookupHandler feliCaLookupHandler;
private final GoodbyeHandler goodbyeHandler;
private final HelloHandler helloHandler;
private final LogHandler logHandler;
private final LookupHandler lookupHandler;
private final Lookup2Handler lookup2Handler;
private final RegisterHandler registerHandler;
@Autowired
public AimeDbRequestHandler(CampaignHandler campaignHandler, FeliCaLookupHandler feliCaLookupHandler, GoodbyeHandler goodbyeHandler, HelloHandler helloHandler, LogHandler logHandler, LookupHandler lookupHandler, Lookup2Handler lookup2Handler, RegisterHandler registerHandler) {
this.campaignHandler = campaignHandler;
this.feliCaLookupHandler = feliCaLookupHandler;
this.goodbyeHandler = goodbyeHandler;
this.helloHandler = helloHandler;
this.logHandler = logHandler;
this.lookupHandler = lookupHandler;
this.lookup2Handler = lookup2Handler;
this.registerHandler = registerHandler;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Map) {
int type = ((int) ((Map) msg).get("type"));
ByteBuf data = (ByteBuf) ((Map) msg).get("data");
switch (type) {
case 0x0001:
feliCaLookupHandler.handle(ctx, data);
break;
case 0x0004:
lookupHandler.handle(ctx, data);
break;
case 0x0005:
registerHandler.handle(ctx, data);
break;
case 0x0009:
logHandler.handle(ctx, data);
break;
case 0x000b:
campaignHandler.handle(ctx, data);
break;
case 0x000d:
registerHandler.handle(ctx, data);
break;
case 0x000f:
lookup2Handler.handle(ctx, data);
break;
case 0x0064:
helloHandler.handle(ctx, data);
break;
case 0x0066:
goodbyeHandler.handle(ctx, data);
break;
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
logger.info("Connection closed");
}
}

View File

@@ -0,0 +1,54 @@
package icu.samnyan.aqua.sega.aimedb;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.net.InetSocketAddress;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class AimeDbServer {
private static final Logger logger = LoggerFactory.getLogger(AimeDbServer.class);
private final AimeDbServerInitializer aimeDbServerInitializer;
private final int port;
private final boolean enableAimeDb;
public AimeDbServer(AimeDbServerInitializer aimeDbServerInitializer,
@Value("${aimedb.server.port}") int port,
@Value("${aimedb.server.enable}") boolean enableAimeDb) {
this.aimeDbServerInitializer = aimeDbServerInitializer;
this.port = port;
this.enableAimeDb = enableAimeDb;
}
public void start() throws Exception {
if (enableAimeDb) {
ServerBootstrap bootstrap = new ServerBootstrap();
EventLoopGroup boss = new NioEventLoopGroup();
EventLoopGroup work = new NioEventLoopGroup();
bootstrap.group(boss, work)
.handler(new LoggingHandler(LogLevel.DEBUG))
.channel(NioServerSocketChannel.class)
.childHandler(aimeDbServerInitializer)
.option(ChannelOption.SO_BACKLOG, 128);
ChannelFuture f = bootstrap.bind(new InetSocketAddress(port)).sync();
logger.info("Aime DB start up on port : " + port);
f.channel().closeFuture();
}
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.aimedb;
import icu.samnyan.aqua.sega.aimedb.handler.Impl.*;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AimeDbServerInitializer extends ChannelInitializer<SocketChannel> {
private final CampaignHandler campaignHandler;
private final FeliCaLookupHandler feliCaLookupHandler;
private final GoodbyeHandler goodbyeHandler;
private final HelloHandler helloHandler;
private final LogHandler logHandler;
private final LookupHandler lookupHandler;
private final Lookup2Handler lookup2Handler;
private final RegisterHandler registerHandler;
@Autowired
public AimeDbServerInitializer(CampaignHandler campaignHandler, FeliCaLookupHandler feliCaLookupHandler, GoodbyeHandler goodbyeHandler, HelloHandler helloHandler, LogHandler logHandler, LookupHandler lookupHandler, Lookup2Handler lookup2Handler, RegisterHandler registerHandler) {
this.campaignHandler = campaignHandler;
this.feliCaLookupHandler = feliCaLookupHandler;
this.goodbyeHandler = goodbyeHandler;
this.helloHandler = helloHandler;
this.logHandler = logHandler;
this.lookupHandler = lookupHandler;
this.lookup2Handler = lookup2Handler;
this.registerHandler = registerHandler;
}
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("encoder", new AimeDbEncoder());
pipeline.addLast("decoder", new AimeDbDecoder());
pipeline.addLast("handler", new AimeDbRequestHandler(campaignHandler, feliCaLookupHandler, goodbyeHandler, helloHandler, logHandler, lookupHandler, lookup2Handler, registerHandler));
}
}

View File

@@ -0,0 +1,7 @@
package icu.samnyan.aqua.sega.aimedb.exception;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class InvalidRequestException extends Exception {
}

View File

@@ -0,0 +1,13 @@
package icu.samnyan.aqua.sega.aimedb.handler;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public interface BaseHandler {
void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException;
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class CampaignHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CampaignHandler.class);
private final LogMapper logMapper;
@Autowired
public CampaignHandler(LogMapper logMapper) {
this.logMapper = logMapper;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "campaign");
logger.info("Request: " + logMapper.write(requestMap));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "campaign");
resultMap.put("status", 1);
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0200]);
respSrc.setShortLE(0x0004, 0x000c);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,66 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class FeliCaLookupHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(FeliCaLookupHandler.class);
private final LogMapper logMapper;
@Autowired
public FeliCaLookupHandler(LogMapper logMapper) {
this.logMapper = logMapper;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "felica_lookup");
requestMap.put("idm", msg.slice(0x0020, 0x0028 - 0x0020));
requestMap.put("pmm", msg.slice(0x0028, 0x0030 - 0x0028));
logger.info("Request: " + logMapper.write(requestMap));
// Get the decimal represent of the hex value, same from minime
StringBuilder accessCode = new StringBuilder(String.valueOf(((ByteBuf) requestMap.get("idm")).getLong(0)));
while (accessCode.length() < 20) {
accessCode.insert(0, "0");
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "felica_lookup");
resultMap.put("status", 1);
resultMap.put("accessCode", accessCode);
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0030]);
respSrc.setShortLE(0x0004, 0x0003);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
respSrc.setBytes(0x0024, ByteBufUtil.decodeHexDump(accessCode));
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,32 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GoodbyeHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GoodbyeHandler.class);
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, String> requestMap = new HashMap<>();
requestMap.put("type", "goodbye");
logger.info("Request: " + new ObjectMapper().writeValueAsString(requestMap));
ctx.flush();
}
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class HelloHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(HelloHandler.class);
private final LogMapper logMapper;
@Autowired
public HelloHandler(LogMapper logMapper) {
this.logMapper = logMapper;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "hello");
logger.info("Request: " + logMapper.write(requestMap));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "hello");
resultMap.put("status", 1);
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0020]);
respSrc.setShortLE(0x0004, 0x0065);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,54 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class LogHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(LogHandler.class);
private final LogMapper logMapper;
@Autowired
public LogHandler(LogMapper logMapper) {
this.logMapper = logMapper;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "log");
logger.info("Request: " + logMapper.write(requestMap));
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "log");
resultMap.put("status", 1);
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0020]);
respSrc.setShortLE(0x0004, 0x000a);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,70 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import icu.samnyan.aqua.sega.general.dao.CardRepository;
import icu.samnyan.aqua.sega.general.model.Card;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class Lookup2Handler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(Lookup2Handler.class);
private final LogMapper logMapper;
private final CardRepository cardRepository;
@Autowired
public Lookup2Handler(LogMapper logMapper, CardRepository cardRepository) {
this.logMapper = logMapper;
this.cardRepository = cardRepository;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "lookup2");
requestMap.put("luid", ByteBufUtil.hexDump(msg.slice(0x0020, 0x002a - 0x0020)));
logger.info("Request: " + logMapper.write(requestMap));
long aimeId = -1;
Optional<Card> card = cardRepository.findByLuid((String) requestMap.get("luid"));
if (card.isPresent()) {
aimeId = card.get().getExtId();
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "lookup2");
resultMap.put("status", 1);
resultMap.put("aimeId", aimeId);
resultMap.put("registerLevel", "none");
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0130]);
respSrc.setShortLE(0x0004, 0x0010);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
respSrc.setLongLE(0x0020, (long) resultMap.get("aimeId"));
respSrc.setByte(0x0024, 0);
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,29 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Mifare Card lookup? idk
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class LookupHandler implements BaseHandler {
private final LogMapper logMapper;
@Autowired
public LookupHandler(LogMapper logMapper) {
this.logMapper = logMapper;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) {
}
}

View File

@@ -0,0 +1,72 @@
package icu.samnyan.aqua.sega.aimedb.handler.Impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.aimedb.handler.BaseHandler;
import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
import icu.samnyan.aqua.sega.general.dao.CardRepository;
import icu.samnyan.aqua.sega.general.model.Card;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class RegisterHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(RegisterHandler.class);
private final LogMapper logMapper;
private final CardRepository cardRepository;
@Autowired
public RegisterHandler(LogMapper logMapper, CardRepository cardRepository) {
this.logMapper = logMapper;
this.cardRepository = cardRepository;
}
@Override
public void handle(ChannelHandlerContext ctx, ByteBuf msg) throws JsonProcessingException {
Map<String, Object> requestMap = AimeDbUtil.getBaseInfo(msg);
requestMap.put("type", "register");
requestMap.put("luid", ByteBufUtil.hexDump(msg.slice(0x0020, 0x002a - 0x0020)));
logger.info("Request: " + logMapper.write(requestMap));
Card card = new Card();
card.setLuid((String) requestMap.get("luid"));
card.setExtId(ThreadLocalRandom.current().nextLong(99999999));
card.setRegisterTime(LocalDateTime.now());
card.setAccessTime(LocalDateTime.now());
cardRepository.save(card);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("type", "register");
resultMap.put("status", 1);
resultMap.put("aimeId", card.getExtId());
logger.info("Response: " + logMapper.write(resultMap));
ByteBuf respSrc = Unpooled.copiedBuffer(new byte[0x0030]);
respSrc.setShortLE(0x0004, 0x0006);
respSrc.setShortLE(0x0008, (int) resultMap.get("status"));
respSrc.setLongLE(0x0020, (long) resultMap.get("aimeId"));
ctx.writeAndFlush(respSrc);
}
}

View File

@@ -0,0 +1,20 @@
package icu.samnyan.aqua.sega.aimedb.util;
import io.netty.buffer.ByteBuf;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class AimeDbUtil {
public static Map<String, Object> getBaseInfo(ByteBuf in) {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("gameId", in.toString(0x000a, 0x000e - 0x000a, StandardCharsets.US_ASCII));
resultMap.put("keychipId", in.toString(0x0014, 0x001f - 0x0014, StandardCharsets.US_ASCII));
return resultMap;
}
}

View File

@@ -0,0 +1,41 @@
package icu.samnyan.aqua.sega.aimedb.util;
import icu.samnyan.aqua.sega.util.ByteBufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class Encryption {
private static final Logger logger = LoggerFactory.getLogger(Encryption.class);
private static SecretKeySpec KEY = new SecretKeySpec("Copyright(C)SEGA".getBytes(StandardCharsets.UTF_8), "AES");
public static ByteBuf decrypt(ByteBuf src) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, KEY);
return Unpooled.copiedBuffer(cipher.doFinal(ByteBufUtil.toBytes(src)));
}
public static ByteBuf encrypt(ByteBuf src) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, KEY);
byte[] bytes = cipher.doFinal(ByteBufUtil.toAllBytes(src));
return Unpooled.copiedBuffer(bytes);
}
}

View File

@@ -0,0 +1,29 @@
package icu.samnyan.aqua.sega.aimedb.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import icu.samnyan.aqua.sega.util.jackson.ByteBufSerializer;
import io.netty.buffer.ByteBuf;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class LogMapper {
private final ObjectMapper mapper;
private final SimpleModule module;
public LogMapper() {
mapper = new ObjectMapper();
module = new SimpleModule();
module.addSerializer(ByteBuf.class, new ByteBufSerializer());
mapper.registerModule(module);
}
public String write(Object o) throws JsonProcessingException {
return mapper.writeValueAsString(o);
}
}

View File

@@ -0,0 +1,78 @@
package icu.samnyan.aqua.sega.allnet;
import com.fasterxml.jackson.databind.ObjectMapper;
import icu.samnyan.aqua.sega.allnet.model.response.PowerOnResponse;
import icu.samnyan.aqua.sega.allnet.util.Decoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.Map;
import java.util.zip.DataFormatException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
public class AllNetController {
private static final Logger logger = LoggerFactory.getLogger(AllNetController.class);
@PostMapping(value = "/sys/servlet/PowerOn", produces = "text/plain")
String powerOn(InputStream dataStream) throws DataFormatException, IOException {
byte[] bytes = dataStream.readAllBytes();
Map<String, String> reqMap = Decoder.decode(bytes);
logger.info("Request: PowerOn, " + new ObjectMapper().writeValueAsString(reqMap));
String gameId = reqMap.getOrDefault("game_id", "");
PowerOnResponse resp = new PowerOnResponse(
1,
switchUri(gameId),
switchHost(gameId),
"123",
"",
"",
"1",
"W",
"X",
"Y",
"Z",
"JPN",
"456",
"+0900",
Instant.now().toString().substring(0, 19).concat("Z"),
"",
"3",
reqMap.get("token")
);
logger.info("Response: " + new ObjectMapper().writeValueAsString(resp));
return resp.toString().concat("\n");
}
private String switchUri(String gameId) {
switch (gameId) {
case "SDBT":
return "http://192.168.123.208:80/";
case "SBZV":
return "http://192.168.123.208:80/diva/";
default:
return "";
}
}
private String switchHost(String gameId) {
switch (gameId) {
case "SDDF":
return "http://127.0.0.1:?/";
default:
return "";
}
}
}

View File

@@ -0,0 +1,25 @@
package icu.samnyan.aqua.sega.allnet.model.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PowerOnRequest {
private String game_id;
private String ver;
private String serial;
private String ip;
private String firm_ver;
private String boot_ver;
private String encode;
private String format_ver;
private String hops;
private String token;
}

View File

@@ -0,0 +1,54 @@
package icu.samnyan.aqua.sega.allnet.model.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PowerOnResponse {
private int stat;
private String uri;
private String host;
private String place_id;
private String name;
private String nickname;
private String region0;
private String region_name0;
private String region_name1;
private String region_name2;
private String region_name3;
private String country;
private String allnet_id;
private String client_timezone;
private String utc_time;
private String setting;
private String res_ver;
private String token;
@Override
public String toString() {
return "stat=" + stat +
"&uri=" + uri +
"&host=" + host +
"&place_id=" + place_id +
"&name=" + name +
"&nickname=" + nickname +
"&region0=" + region0 +
"&region_name0=" + region_name0 +
"&region_name1=" + region_name1 +
"&region_name2=" + region_name2 +
"&region_name3=" + region_name3 +
"&country=" + country +
"&allnet_id=" + allnet_id +
"&client_timezone=" + client_timezone +
"&utc_time=" + utc_time +
"&setting=" + setting +
"&res_ver=" + res_ver +
"&token=" + token;
}
}

View File

@@ -0,0 +1,32 @@
package icu.samnyan.aqua.sega.allnet.util;
import icu.samnyan.aqua.sega.util.Compression;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class Decoder {
public static Map<String, String> decode(byte[] src) {
byte[] bytes = Base64.getMimeDecoder().decode(src);
byte[] output = Compression.decompress(bytes);
String outputString = new String(output, StandardCharsets.UTF_8).trim();
String[] split = outputString.split("&");
Map<String, String> resultMap = new HashMap<>();
for (String s :
split) {
String[] kv = s.split("=");
resultMap.put(kv[0], kv[1]);
}
return resultMap;
}
}

View File

@@ -0,0 +1,249 @@
package icu.samnyan.aqua.sega.chunithm.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("ChuniServlet")
public class ChuniServletController {
private final GameLoginHandler gameLoginHandler;
private final GameLogoutHandler gameLogoutHandler;
private final GetGameChargeHandler getGameChargeHandler;
private final GetGameEventHandler getGameEventHandler;
private final GetGameIdlistHandler getGameIdlistHandler;
private final GetGameMessageHandler getGameMessageHandler;
private final GetGameRankingHandler getGameRankingHandler;
private final GetGameSaleHandler getGameSaleHandler;
private final GetGameSettingHandler getGameSettingHandler;
private final GetUserActivityHandler getUserActivityHandler;
private final GetUserCharacterHandler getUserCharacterHandler;
private final GetUserChargeHandler getUserChargeHandler;
private final GetUserCourseHandler getUserCourseHandler;
private final GetUserDataExHandler getUserDataExHandler;
private final GetUserDataHandler getUserDataHandler;
private final GetUserDuelHandler getUserDuelHandler;
private final GetUserItemHandler getUserItemHandler;
private final GetUserMapHandler getUserMapHandler;
private final GetUserMusicHandler getUserMusicHandler;
private final GetUserOptionExHandler getUserOptionExHandler;
private final GetUserOptionHandler getUserOptionHandler;
private final GetUserPreviewHandler getUserPreviewHandler;
private final GetUserRecentRatingHandler getUserRecentRatingHandler;
private final GetUserRegionHandler getUserRegionHandler;
private final UpsertClientBookkeepingHandler upsertClientBookkeepingHandler;
private final UpsertClientDevelopHandler upsertClientDevelopHandler;
private final UpsertClientErrorHandler upsertClientErrorHandler;
private final UpsertClientSettingHandler upsertClientSettingHandler;
private final UpsertClientTestmodeHandler upsertClientTestmodeHandler;
private final UpsertUserAllHandler upsertUserAllHandler;
private final UpsertUserChargelogHandler upsertUserChargelogHandler;
@Autowired
public ChuniServletController(GameLoginHandler gameLoginHandler, GameLogoutHandler gameLogoutHandler, GetGameChargeHandler getGameChargeHandler, GetGameEventHandler getGameEventHandler, GetGameIdlistHandler getGameIdlistHandler, GetGameMessageHandler getGameMessageHandler, GetGameRankingHandler getGameRankingHandler, GetGameSaleHandler getGameSaleHandler, GetGameSettingHandler getGameSettingHandler, GetUserActivityHandler getUserActivityHandler, GetUserCharacterHandler getUserCharacterHandler, GetUserChargeHandler getUserChargeHandler, GetUserCourseHandler getUserCourseHandler, GetUserDataExHandler getUserDataExHandler, GetUserDataHandler getUserDataHandler, GetUserDuelHandler getUserDuelHandler, GetUserItemHandler getUserItemHandler, GetUserMapHandler getUserMapHandler, GetUserMusicHandler getUserMusicHandler, GetUserOptionExHandler getUserOptionExHandler, GetUserOptionHandler getUserOptionHandler, GetUserPreviewHandler getUserPreviewHandler, GetUserRecentRatingHandler getUserRecentRatingHandler, GetUserRegionHandler getUserRegionHandler, UpsertClientBookkeepingHandler upsertClientBookkeepingHandler, UpsertClientDevelopHandler upsertClientDevelopHandler, UpsertClientErrorHandler upsertClientErrorHandler, UpsertClientSettingHandler upsertClientSettingHandler, UpsertClientTestmodeHandler upsertClientTestmodeHandler, UpsertUserAllHandler upsertUserAllHandler, UpsertUserChargelogHandler upsertUserChargelogHandler) {
this.gameLoginHandler = gameLoginHandler;
this.gameLogoutHandler = gameLogoutHandler;
this.getGameChargeHandler = getGameChargeHandler;
this.getGameEventHandler = getGameEventHandler;
this.getGameIdlistHandler = getGameIdlistHandler;
this.getGameMessageHandler = getGameMessageHandler;
this.getGameRankingHandler = getGameRankingHandler;
this.getGameSaleHandler = getGameSaleHandler;
this.getGameSettingHandler = getGameSettingHandler;
this.getUserActivityHandler = getUserActivityHandler;
this.getUserCharacterHandler = getUserCharacterHandler;
this.getUserChargeHandler = getUserChargeHandler;
this.getUserCourseHandler = getUserCourseHandler;
this.getUserDataExHandler = getUserDataExHandler;
this.getUserDataHandler = getUserDataHandler;
this.getUserDuelHandler = getUserDuelHandler;
this.getUserItemHandler = getUserItemHandler;
this.getUserMapHandler = getUserMapHandler;
this.getUserMusicHandler = getUserMusicHandler;
this.getUserOptionExHandler = getUserOptionExHandler;
this.getUserOptionHandler = getUserOptionHandler;
this.getUserPreviewHandler = getUserPreviewHandler;
this.getUserRecentRatingHandler = getUserRecentRatingHandler;
this.getUserRegionHandler = getUserRegionHandler;
this.upsertClientBookkeepingHandler = upsertClientBookkeepingHandler;
this.upsertClientDevelopHandler = upsertClientDevelopHandler;
this.upsertClientErrorHandler = upsertClientErrorHandler;
this.upsertClientSettingHandler = upsertClientSettingHandler;
this.upsertClientTestmodeHandler = upsertClientTestmodeHandler;
this.upsertUserAllHandler = upsertUserAllHandler;
this.upsertUserChargelogHandler = upsertUserChargelogHandler;
}
@PostMapping("GameLoginApi")
String gameLogin(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return gameLoginHandler.handle(request);
}
@PostMapping("GameLogoutApi")
String gameLogout(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return gameLogoutHandler.handle(request);
}
@PostMapping("GetGameChargeApi")
String getGameCharge(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameChargeHandler.handle(request);
}
@PostMapping("GetGameEventApi")
String getGameEvent(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameEventHandler.handle(request);
}
@PostMapping("GetGameIdlistApi")
String getGameIdList(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameIdlistHandler.handle(request);
}
@PostMapping("GetGameMessageApi")
String getGameMessage(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameMessageHandler.handle(request);
}
@PostMapping("GetGameRankingApi")
String getGameRanking(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameRankingHandler.handle(request);
}
@PostMapping("GetGameSaleApi")
String getGameSale(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameSaleHandler.handle(request);
}
/**
* The game start up request
*
* @return
*/
@PostMapping("GetGameSettingApi")
String getGameSetting(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getGameSettingHandler.handle(request);
}
@PostMapping("GetUserActivityApi")
String getUserActivity(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserActivityHandler.handle(request);
}
@PostMapping("GetUserCharacterApi")
String getUserCharacter(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserCharacterHandler.handle(request);
}
@PostMapping("GetUserChargeApi")
String getUserCharge(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserChargeHandler.handle(request);
}
@PostMapping("GetUserCourseApi")
String getUserCourse(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserCourseHandler.handle(request);
}
@PostMapping("GetUserDataApi")
String getUserData(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserDataHandler.handle(request);
}
@PostMapping("GetUserDataExApi")
String getUserDataEx(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserDataExHandler.handle(request);
}
@PostMapping("GetUserDuelApi")
String getUserDuel(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserDuelHandler.handle(request);
}
@PostMapping("GetUserItemApi")
String getUserItem(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserItemHandler.handle(request);
}
@PostMapping("GetUserMapApi")
String getUserMap(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserMapHandler.handle(request);
}
@PostMapping("GetUserMusicApi")
String getUserMusic(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserMusicHandler.handle(request);
}
@PostMapping("GetUserOptionApi")
String getUserOption(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserOptionHandler.handle(request);
}
@PostMapping("GetUserOptionExApi")
String getUserOptionEx(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserOptionExHandler.handle(request);
}
// Call when login. Return null if no profile exist
@PostMapping("GetUserPreviewApi")
String getUserPreview(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserPreviewHandler.handle(request);
}
@PostMapping("GetUserRecentRatingApi")
String getUserRecentRating(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserRecentRatingHandler.handle(request);
}
@PostMapping("GetUserRegionApi")
String getUserRegion(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return getUserRegionHandler.handle(request);
}
@PostMapping("UpsertClientBookkeepingApi")
String upsertClientBookkeeping(@ModelAttribute Map<String, Object> request) {
return "{\"returnCode\":\"1\"}";
}
@PostMapping("UpsertClientDevelopApi")
String upsertClientDevelop(@ModelAttribute Map<String, Object> request) {
return "{\"returnCode\":\"1\"}";
}
@PostMapping("UpsertClientErrorApi")
String upsertClientError(@ModelAttribute Map<String, Object> request) {
return "{\"returnCode\":\"1\"}";
}
@PostMapping("UpsertClientSettingApi")
String upsertClientSetting(@ModelAttribute Map<String, Object> request) {
return "{\"returnCode\":\"1\"}";
}
@PostMapping("UpsertClientTestmodeApi")
String upsertClientTestmode(@ModelAttribute Map<String, Object> request) {
return "{\"returnCode\":\"1\"}";
}
@PostMapping("UpsertUserAllApi")
String upsertUserAll(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return upsertUserAllHandler.handle(request);
}
@PostMapping("UpsertUserChargelogApi")
String upsertUserChargelog(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
return upsertUserChargelogHandler.handle(request);
}
}

View File

@@ -0,0 +1,39 @@
package icu.samnyan.aqua.sega.chunithm.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestControllerAdvice(basePackages = "icu.samnyan.aqua.sega.chunithm")
public class ChuniServletControllerAdvice {
private static final Logger logger = LoggerFactory.getLogger(ChuniServletControllerAdvice.class);
/**
* Get the map object from json string
*
* @param request HttpServletRequest
*/
@ModelAttribute
public Map<String, Object> preHandle(HttpServletRequest request) throws IOException {
byte[] src = request.getInputStream().readAllBytes();
String outputString = new String(src, StandardCharsets.UTF_8).trim();
logger.info("Request " + request.getRequestURI() + ": " + outputString);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(outputString, new TypeReference<>() {
});
}
}

View File

@@ -0,0 +1,12 @@
package icu.samnyan.aqua.sega.chunithm.dao.gamedata;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameCharge;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface GameChargeRepository extends JpaRepository<GameCharge, Long> {
}

View File

@@ -0,0 +1,12 @@
package icu.samnyan.aqua.sega.chunithm.dao.gamedata;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameEvent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface GameEventRepository extends JpaRepository<GameEvent, Integer> {
}

View File

@@ -0,0 +1,12 @@
package icu.samnyan.aqua.sega.chunithm.dao.gamedata;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface GameMessageRepository extends JpaRepository<GameMessage, Integer> {
}

View File

@@ -0,0 +1,16 @@
package icu.samnyan.aqua.sega.chunithm.dao.gamedata;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.Music;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface GameMusicRepository extends JpaRepository<Music, Long> {
Optional<Music> findByMusicId(int musicId);
}

View File

@@ -0,0 +1,20 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserActivity;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserActivityRepository extends JpaRepository<UserActivity, Long> {
Optional<UserActivity> findTopByUserAndActivityIdAndKindOrderByIdDesc(UserData user, int activityId, int kind);
List<UserActivity> findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(long extId, int kind);
}

View File

@@ -0,0 +1,21 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharacter;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserCharacterRepository extends JpaRepository<UserCharacter, Long> {
Optional<UserCharacter> findTopByUserAndCharacterIdOrderByIdDesc(UserData user, int characterId);
Page<UserCharacter> findByUser_Card_ExtId(long parseLong, Pageable pageable);
}

View File

@@ -0,0 +1,19 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharge;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserChargeRepository extends JpaRepository<UserCharge, Long> {
List<UserCharge> findByUser_Card_ExtId(long userId);
Optional<UserCharge> findByUserAndChargeId(UserData extId, int chargeId);
}

View File

@@ -0,0 +1,23 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCourse;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserCourseRepository extends JpaRepository<UserCourse, Long> {
Optional<UserCourse> findTopByUserAndCourseIdOrderByIdDesc(UserData user, int courseId);
Page<UserCourse> findByUser_Card_ExtId(long aimeId, Pageable page);
List<UserCourse> findByUser_Card_ExtId(long aimeId);
}

View File

@@ -0,0 +1,19 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserDataEx;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserDataExRepository extends JpaRepository<UserDataEx, Long> {
Optional<UserDataEx> findByUser(UserData user);
Optional<UserDataEx> findByUser_Card_ExtId(long userId);
}

View File

@@ -0,0 +1,19 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.general.model.Card;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserDataRepository extends JpaRepository<UserData, Long> {
Optional<UserData> findByCard(Card card);
Optional<UserData> findByCard_ExtId(long extId);
}

View File

@@ -0,0 +1,20 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserDuel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserDuelRepository extends JpaRepository<UserDuel, Long> {
Optional<UserDuel> findTopByUserAndDuelIdOrderByIdDesc(UserData user, int duelId);
List<UserDuel> findByUser_Card_ExtId(long extId);
}

View File

@@ -0,0 +1,18 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserGameOptionEx;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserGameOptionExRepository extends JpaRepository<UserGameOptionEx, Long> {
Optional<UserGameOptionEx> findByUser(UserData user);
Optional<UserGameOptionEx> findByUser_Card_ExtId(long parseLong);
}

View File

@@ -0,0 +1,19 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserGameOption;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserGameOptionRepository extends JpaRepository<UserGameOption, Long> {
Optional<UserGameOption> findByUser(UserData user);
Optional<UserGameOption> findByUser_Card_ExtId(long extId);
}

View File

@@ -0,0 +1,21 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserItemRepository extends JpaRepository<UserItem, Long> {
Optional<UserItem> findTopByUserAndItemIdOrderByIdDesc(UserData user, int itemId);
Page<UserItem> findAllByUser_Card_ExtIdAndItemKind(long extId, int itemKind, Pageable pageable);
}

View File

@@ -0,0 +1,21 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserMapRepository extends JpaRepository<UserMap, Long> {
List<UserMap> findAllByUser(UserData user);
List<UserMap> findAllByUser_Card_ExtId(long extId);
Optional<UserMap> findTopByUserAndMapIdOrderByIdDesc(UserData user, int mapId);
}

View File

@@ -0,0 +1,24 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMusicDetail;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserMusicDetailRepository extends JpaRepository<UserMusicDetail, Long> {
Optional<UserMusicDetail> findTopByUserAndMusicIdAndLevelOrderByIdDesc(UserData user, int musicId, int level);
List<UserMusicDetail> findByUser_Card_ExtId(long parseLong);
Page<UserMusicDetail> findByUser_Card_ExtId(long aimeId, Pageable page);
}

View File

@@ -0,0 +1,18 @@
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Repository
public interface UserPlaylogRepository extends JpaRepository<UserPlaylog, Long> {
List<UserPlaylog> findByUser_Card_ExtIdAndLevelNot(long extId, int levelNot, Pageable page);
List<UserPlaylog> findByUser_Card_ExtId(long parseLong, Pageable page);
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.chunithm.filter;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class ChuniRequestWrapper extends HttpServletRequestWrapper {
private ByteArrayInputStream input;
private ServletInputStream filterInput;
public ChuniRequestWrapper(HttpServletRequest request, byte[] input) {
super(request);
this.input = new ByteArrayInputStream(input);
}
@Override
public ServletInputStream getInputStream() throws IOException {
if (filterInput == null) {
filterInput = new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return input.read();
}
};
}
return filterInput;
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.chunithm.filter;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class ChuniResponseWrapper extends HttpServletResponseWrapper {
private ByteArrayOutputStream output;
private ServletOutputStream filterOutput;
ChuniResponseWrapper(HttpServletResponse response) {
super(response);
output = new ByteArrayOutputStream();
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
if (filterOutput == null) {
filterOutput = new ServletOutputStream() {
@Override
public boolean isReady() {
return false;
}
@Override
public void setWriteListener(WriteListener writeListener) {
}
@Override
public void write(int b) throws IOException {
output.write(b);
}
};
}
return filterOutput;
}
byte[] toByteArray() {
return output.toByteArray();
}
}

View File

@@ -0,0 +1,58 @@
package icu.samnyan.aqua.sega.chunithm.filter;
import icu.samnyan.aqua.sega.util.Compression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class CompressionFilter extends OncePerRequestFilter {
private static final Logger logger = LoggerFactory.getLogger(CompressionFilter.class);
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String encoding = request.getHeader("content-encoding");
byte[] reqSrc = request.getInputStream().readAllBytes();
byte[] reqResult;
if (encoding != null && encoding.equals("deflate")) {
reqResult = Compression.decompress(reqSrc);
} else {
reqResult = reqSrc;
}
ChuniRequestWrapper requestWrapper = new ChuniRequestWrapper(request, reqResult);
ChuniResponseWrapper responseWrapper = new ChuniResponseWrapper(response);
filterChain.doFilter(requestWrapper, responseWrapper);
byte[] respSrc = responseWrapper.toByteArray();
byte[] respResult = Compression.compress(respSrc);
response.setContentLength(respResult.length);
response.setContentType("application/json; charset=utf-8");
response.addHeader("Content-Encoding", "deflate");
response.getOutputStream().write(respResult);
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
String path = request.getServletPath();
return !path.startsWith("/ChuniServlet");
}
}

View File

@@ -0,0 +1,13 @@
package icu.samnyan.aqua.sega.chunithm.handler;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public interface BaseHandler {
String handle(Map<String, Object> request) throws JsonProcessingException;
}

View File

@@ -0,0 +1,43 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.CodeResp;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.service.UserDataService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GameLoginHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GameLoginHandler.class);
private final StringMapper mapper;
private final UserDataService userDataService;
public GameLoginHandler(StringMapper mapper, UserDataService userDataService) {
this.mapper = mapper;
this.userDataService = userDataService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserData> userDataOptional = userDataService.getUserByExtId(userId);
userDataOptional.ifPresent(userDataService::updateLoginTime);
String json = mapper.write(new CodeResp(1));
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,34 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.CodeResp;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GameLogoutHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GameLogoutHandler.class);
private final StringMapper mapper;
public GameLogoutHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String json = mapper.write(new CodeResp(1));
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,46 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.dao.gamedata.GameChargeRepository;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameCharge;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameChargeHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameChargeHandler.class);
private final GameChargeRepository gameChargeRepository;
private final StringMapper mapper;
@Autowired
public GetGameChargeHandler(GameChargeRepository gameChargeRepository, StringMapper mapper) {
this.gameChargeRepository = gameChargeRepository;
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
List<GameCharge> gameChargeList = gameChargeRepository.findAll();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("length", gameChargeList.size());
resultMap.put("gameChargeList", gameChargeList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.dao.gamedata.GameEventRepository;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameEvent;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameEventHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameEventHandler.class);
private final GameEventRepository gameEventRepository;
private final StringMapper mapper;
@Autowired
public GetGameEventHandler(GameEventRepository gameEventRepository, StringMapper mapper) {
this.gameEventRepository = gameEventRepository;
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String type = (String) request.get("type");
List<GameEvent> gameEventList = gameEventRepository.findAll();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("type", type);
resultMap.put("length", 0);
resultMap.put("gameEventList", gameEventList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,47 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameIdlistHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameIdlistHandler.class);
private final StringMapper mapper;
@Autowired
public GetGameIdlistHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String type = (String) request.get("type");
List<Object> gameIdlistList = new ArrayList<>();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("type", type);
resultMap.put("length", 0);
resultMap.put("gameIdlistList", gameIdlistList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.dao.gamedata.GameMessageRepository;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.gamedata.GameMessage;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameMessageHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameMessageHandler.class);
private final GameMessageRepository gameMessageRepository;
private final StringMapper mapper;
@Autowired
public GetGameMessageHandler(GameMessageRepository gameMessageRepository, StringMapper mapper) {
this.gameMessageRepository = gameMessageRepository;
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String type = (String) request.get("type");
List<GameMessage> gameMessageList = gameMessageRepository.findAll();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("type", type);
resultMap.put("length", 0);
resultMap.put("gameMessageList", gameMessageList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,46 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameRankingHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameRankingHandler.class);
private final StringMapper mapper;
@Autowired
public GetGameRankingHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String type = (String) request.get("type");
List<Object> gameRankingList = new ArrayList<>();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("type", type);
resultMap.put("length", 0);
resultMap.put("gameRankingList", gameRankingList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,47 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.data.GameSale;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameSaleHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameSaleHandler.class);
private final StringMapper mapper;
@Autowired
public GetGameSaleHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String type = (String) request.get("type");
List<GameSale> gameSaleList = new ArrayList<>();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("type", type);
resultMap.put("length", 0);
resultMap.put("gameSaleList", gameSaleList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,56 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.GetGameSettingResp;
import icu.samnyan.aqua.sega.chunithm.model.response.data.GameSetting;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetGameSettingHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetGameSettingHandler.class);
private final StringMapper mapper;
@Autowired
public GetGameSettingHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
GameSetting gameSetting = new GameSetting(
1,
false,
10,
0,
0,
false,
999,
999,
999);
GetGameSettingResp resp = new GetGameSettingResp(
gameSetting,
false,
false
);
String json = mapper.write(resp);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserActivity;
import icu.samnyan.aqua.sega.chunithm.service.UserActivityService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserActivityHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserActivityHandler.class);
private final StringMapper mapper;
private final UserActivityService userActivityService;
@Autowired
public GetUserActivityHandler(StringMapper mapper, UserActivityService userActivityService) {
this.mapper = mapper;
this.userActivityService = userActivityService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
String kind = (String) request.get("kind");
List<UserActivity> userActivityList = userActivityService.getAllByUserIdAndKind(userId, kind);
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", userActivityList.size());
resultMap.put("kind", kind);
resultMap.put("userActivityList", userActivityList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,59 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharacter;
import icu.samnyan.aqua.sega.chunithm.service.UserCharacterService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserCharacterHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserCharacterHandler.class);
private final StringMapper mapper;
private final UserCharacterService userCharacterService;
@Autowired
public GetUserCharacterHandler(StringMapper mapper, UserCharacterService userCharacterService) {
this.mapper = mapper;
this.userCharacterService = userCharacterService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
int nextIndex = Integer.parseInt((String) request.get("nextIndex"));
int maxCount = Integer.parseInt((String) request.get("maxCount"));
int pageNum = nextIndex / maxCount;
Page<UserCharacter> dbPage = userCharacterService.getByUser(userId, pageNum, maxCount);
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", dbPage.getNumberOfElements());
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
resultMap.put("userCharacterList", dbPage.getContent());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharge;
import icu.samnyan.aqua.sega.chunithm.service.UserChargeService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserChargeHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserChargeHandler.class);
private final StringMapper mapper;
private final UserChargeService userChargeService;
@Autowired
public GetUserChargeHandler(StringMapper mapper, UserChargeService userChargeService) {
this.mapper = mapper;
this.userChargeService = userChargeService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
List<UserCharge> userChargeList = userChargeService.getByUserId(userId);
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", userChargeList.size());
resultMap.put("userChargeList", userChargeList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,58 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCourse;
import icu.samnyan.aqua.sega.chunithm.service.UserCourseService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserCourseHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserCourseHandler.class);
private final StringMapper mapper;
private final UserCourseService userCourseService;
@Autowired
public GetUserCourseHandler(StringMapper mapper, UserCourseService userCourseService) {
this.mapper = mapper;
this.userCourseService = userCourseService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
int nextIndex = Integer.parseInt((String) request.get("nextIndex"));
int maxCount = Integer.parseInt((String) request.get("maxCount"));
int pageNum = nextIndex / maxCount;
Page<UserCourse> dbPage = userCourseService.getByUser(userId, pageNum, maxCount);
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", dbPage.getNumberOfElements());
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
resultMap.put("userCourseList", dbPage.getContent());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserDataEx;
import icu.samnyan.aqua.sega.chunithm.service.UserDataExService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserDataExHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserDataExHandler.class);
private final StringMapper mapper;
private final UserDataExService userDataExService;
@Autowired
public GetUserDataExHandler(StringMapper mapper, UserDataExService userDataExService) {
this.mapper = mapper;
this.userDataExService = userDataExService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserDataEx> userDataExOptional = userDataExService.getUserByExtId(userId);
if (userDataExOptional.isPresent()) {
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("userDataEx", userDataExOptional.get());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
return null;
}
}

View File

@@ -0,0 +1,51 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.service.UserDataService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserDataHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserDataHandler.class);
private final StringMapper mapper;
private final UserDataService userDataService;
@Autowired
public GetUserDataHandler(StringMapper mapper, UserDataService userDataService) {
this.mapper = mapper;
this.userDataService = userDataService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserData> userDataOptional = userDataService.getUserByExtId(userId);
if (userDataOptional.isPresent()) {
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("userData", userDataOptional.get());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
return null;
}
}

View File

@@ -0,0 +1,54 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserDuel;
import icu.samnyan.aqua.sega.chunithm.service.UserDuelService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserDuelHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserDuelHandler.class);
private final StringMapper mapper;
private final UserDuelService userDuelService;
@Autowired
public GetUserDuelHandler(StringMapper mapper, UserDuelService userDuelService) {
this.mapper = mapper;
this.userDuelService = userDuelService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
String duelId = (String) request.get("duelId");
String isAllDuel = (String) request.get("isAllDuel");
// TODO:
List<UserDuel> userDuelList = userDuelService.getByUser(userId);
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", userDuelList.size());
resultMap.put("userDuelList", userDuelList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,67 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserItem;
import icu.samnyan.aqua.sega.chunithm.service.UserItemService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Handler for getting user item.
* This get call before profile create.
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserItemHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserItemHandler.class);
private final StringMapper mapper;
private final UserItemService userItemService;
public GetUserItemHandler(StringMapper mapper, UserItemService userItemService) {
this.mapper = mapper;
this.userItemService = userItemService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Long nextIndexVal = Long.parseLong((String) request.get("nextIndex"));
int maxCount = Integer.parseInt((String) request.get("maxCount"));
Long mul = 10000000000L;
int kind = (int) (nextIndexVal / mul);
int nextIndex = (int) (nextIndexVal % mul);
int pageNum = nextIndex / maxCount;
Page<UserItem> userItemPage = userItemService.getByUserAndItemKind(userId, kind, pageNum, maxCount);
List<UserItem> userItemList = userItemPage.getContent();
long currentIndex = kind * mul + maxCount * pageNum + userItemPage.getNumberOfElements();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", userItemPage.getNumberOfElements());
resultMap.put("nextIndex", userItemPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
resultMap.put("itemKind", kind);
resultMap.put("userItemList", userItemList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,50 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMap;
import icu.samnyan.aqua.sega.chunithm.service.UserMapService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserMapHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserItemHandler.class);
private final StringMapper mapper;
private final UserMapService userMapService;
@Autowired
public GetUserMapHandler(StringMapper mapper, UserMapService userMapService) {
this.mapper = mapper;
this.userMapService = userMapService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
List<UserMap> userMapList = userMapService.getByUser(userId);
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", userMapList.size());
resultMap.put("userMapList", userMapList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,98 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.data.UserMusicListItem;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserMusicDetail;
import icu.samnyan.aqua.sega.chunithm.service.GameMusicService;
import icu.samnyan.aqua.sega.chunithm.service.UserMusicDetailService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
/**
* Response:
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserMusicHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserMusicHandler.class);
private final StringMapper mapper;
private final UserMusicDetailService userMusicDetailService;
private final GameMusicService gameMusicService;
@Autowired
public GetUserMusicHandler(StringMapper mapper, UserMusicDetailService userMusicDetailService, GameMusicService gameMusicService) {
this.mapper = mapper;
this.userMusicDetailService = userMusicDetailService;
this.gameMusicService = gameMusicService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
int nextIndex = Integer.parseInt((String) request.get("nextIndex"));
int maxCount = Integer.parseInt((String) request.get("maxCount"));
List<UserMusicDetail> userMusicDetailList = userMusicDetailService.getByUser(userId);
Map<Integer, Map<Integer, UserMusicDetail>> allMusicMap = new LinkedHashMap<>();
userMusicDetailList.forEach(userMusicDetail -> {
int musicId = userMusicDetail.getMusicId();
int level = userMusicDetail.getLevel();
if (allMusicMap.containsKey(musicId)) {
allMusicMap.get(musicId).put(level, userMusicDetail);
} else {
Map<Integer, UserMusicDetail> levelMap = new HashMap<>();
levelMap.put(level, userMusicDetail);
allMusicMap.put(musicId, levelMap);
}
});
// Convert to result format
// Result Map
Map<Integer, UserMusicListItem> userMusicMap = new LinkedHashMap<>();
allMusicMap.forEach((mid, lvMap) -> {
UserMusicListItem list;
if (userMusicMap.containsKey(mid)) {
list = userMusicMap.get(mid);
} else {
list = new UserMusicListItem(0, new ArrayList<>());
userMusicMap.put(mid, list);
}
list.getUserMusicDetailList().addAll(lvMap.values());
list.setLength(lvMap.size());
});
List<UserMusicListItem> result = userMusicMap.values().stream().skip(nextIndex).limit(maxCount).collect(Collectors.toList());
long currentIndex = result.size();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", result.size());
resultMap.put("nextIndex", allMusicMap.size() < maxCount ? -1 : currentIndex);
resultMap.put("userMusicList", result);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,53 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserGameOptionEx;
import icu.samnyan.aqua.sega.chunithm.service.UserGameOptionExService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserOptionExHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserOptionExHandler.class);
private final StringMapper mapper;
private final UserGameOptionExService userGameOptionExService;
@Autowired
public GetUserOptionExHandler(StringMapper mapper, UserGameOptionExService userGameOptionExService) {
this.mapper = mapper;
this.userGameOptionExService = userGameOptionExService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserGameOptionEx> userGameOptionEx = userGameOptionExService.getByUserId(userId);
if (userGameOptionEx.isPresent()) {
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("userGameOptionEx", userGameOptionEx.get());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
return null;
}
}

View File

@@ -0,0 +1,52 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserGameOption;
import icu.samnyan.aqua.sega.chunithm.service.UserGameOptionService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserOptionHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserOptionHandler.class);
private final StringMapper mapper;
private final UserGameOptionService userGameOptionService;
@Autowired
public GetUserOptionHandler(StringMapper mapper, UserGameOptionService userGameOptionService) {
this.mapper = mapper;
this.userGameOptionService = userGameOptionService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserGameOption> userGameOption = userGameOptionService.getByUserId(userId);
if (userGameOption.isPresent()) {
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("userGameOption", userGameOption.get());
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
return null;
}
}

View File

@@ -0,0 +1,90 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.GetUserPreviewResp;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharacter;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserGameOption;
import icu.samnyan.aqua.sega.chunithm.service.UserCharacterService;
import icu.samnyan.aqua.sega.chunithm.service.UserDataService;
import icu.samnyan.aqua.sega.chunithm.service.UserGameOptionService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Optional;
/**
* The handler for loading basic profile information.
* <p>
* return null if no profile exist
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserPreviewHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserPreviewHandler.class);
private final StringMapper mapper;
private final UserDataService userDataService;
private final UserCharacterService userCharacterService;
private final UserGameOptionService userGameOptionService;
@Autowired
public GetUserPreviewHandler(StringMapper mapper, UserDataService userDataService, UserCharacterService userCharacterService, UserGameOptionService userGameOptionService) {
this.mapper = mapper;
this.userDataService = userDataService;
this.userCharacterService = userCharacterService;
this.userGameOptionService = userGameOptionService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Optional<UserData> userData = userDataService.getUserByExtId(userId);
if (userData.isEmpty()) {
return null;
}
UserData user = userData.get();
GetUserPreviewResp resp = new GetUserPreviewResp();
resp.setUserId(userId);
resp.setLogin(false);
resp.setLastLoginDate(user.getLastLoginDate());
resp.setUserName(user.getUserName());
resp.setReincarnationNum(user.getReincarnationNum());
resp.setLevel(user.getLevel());
resp.setExp(user.getExp());
resp.setPlayerRating(user.getPlayerRating());
resp.setLastGameId(user.getLastGameId());
resp.setLastRomVersion(user.getLastRomVersion());
resp.setLastDataVersion(user.getLastDataVersion());
resp.setLastPlayDate(user.getLastPlayDate());
resp.setTrophyId(user.getTrophyId());
Optional<UserCharacter> userCharacterOptional = userCharacterService.getByUserAndCharacterId(user, user.getCharacterId());
userCharacterOptional.ifPresent(resp::setUserCharacter);
Optional<UserGameOption> userGameOptionOptional = userGameOptionService.getByUser(user);
userGameOptionOptional.ifPresent(userGameOption -> {
resp.setPlayerLevel(userGameOption.getPlayerLevel());
resp.setRating(userGameOption.getRating());
resp.setHeadphone(userGameOption.getHeadphone());
});
String json = mapper.write(resp);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,56 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.data.UserRecentRating;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
import icu.samnyan.aqua.sega.chunithm.service.UserPlaylogService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Return the recent play to calculate rating. Rating base on top 30 songs plus top 10 in recent 30 plays.
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserRecentRatingHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserRecentRatingHandler.class);
private final StringMapper mapper;
private final UserPlaylogService userPlaylogService;
@Autowired
public GetUserRecentRatingHandler(StringMapper mapper, UserPlaylogService userPlaylogService) {
this.mapper = mapper;
this.userPlaylogService = userPlaylogService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
List<UserPlaylog> top = userPlaylogService.getRecent30Plays(userId);
List<UserRecentRating> rating = top.stream().map(log -> new UserRecentRating(log.getMusicId(), log.getLevel(), "1030000", log.getScore()))
.collect(Collectors.toList());
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", rating.size());
resultMap.put("userRecentRatingList", rating);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,46 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GetUserRegionHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetUserRegionHandler.class);
private final StringMapper mapper;
@Autowired
public GetUserRegionHandler(StringMapper mapper) {
this.mapper = mapper;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
List<Object> userRegionList = new ArrayList<>();
Map<String, Object> resultMap = new LinkedHashMap<>();
resultMap.put("userId", userId);
resultMap.put("length", 0);
resultMap.put("userRegionList", userRegionList);
String json = mapper.write(resultMap);
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,10 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertClientBookkeepingHandler {
}

View File

@@ -0,0 +1,10 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertClientDevelopHandler {
}

View File

@@ -0,0 +1,10 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertClientErrorHandler {
}

View File

@@ -0,0 +1,10 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertClientSettingHandler {
}

View File

@@ -0,0 +1,10 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertClientTestmodeHandler {
}

View File

@@ -0,0 +1,350 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.CodeResp;
import icu.samnyan.aqua.sega.chunithm.model.userdata.*;
import icu.samnyan.aqua.sega.chunithm.service.*;
import icu.samnyan.aqua.sega.general.model.Card;
import icu.samnyan.aqua.sega.general.service.CardService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* The handler for save user data. Only send in the end of the session.
*
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertUserAllHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(UpsertUserAllHandler.class);
private final StringMapper mapper;
private final CardService cardService;
private final UserDataService userDataService;
private final UserCharacterService userCharacterService;
private final UserGameOptionService userGameOptionService;
private final UserGameOptionExService userGameOptionExService;
private final UserMapService userMapService;
private final UserItemService userItemService;
private final UserMusicDetailService userMusicDetailService;
private final UserActivityService userActivityService;
private final UserPlaylogService userPlaylogService;
private final UserChargeService userChargeService;
private final UserDataExService userDataExService;
private final UserCourseService userCourseService;
private final UserDuelService userDuelService;
@Autowired
public UpsertUserAllHandler(StringMapper mapper, CardService cardService, UserDataService userDataService, UserCharacterService userCharacterService, UserGameOptionService userGameOptionService, UserGameOptionExService userGameOptionExService, UserMapService userMapService, UserItemService userItemService, UserMusicDetailService userMusicDetailService, UserActivityService userActivityService, UserPlaylogService userPlaylogService, UserChargeService userChargeService, UserDataExService userDataExService, UserCourseService userCourseService, UserDuelService userDuelService) {
this.mapper = mapper;
this.cardService = cardService;
this.userDataService = userDataService;
this.userCharacterService = userCharacterService;
this.userGameOptionService = userGameOptionService;
this.userGameOptionExService = userGameOptionExService;
this.userMapService = userMapService;
this.userItemService = userItemService;
this.userMusicDetailService = userMusicDetailService;
this.userActivityService = userActivityService;
this.userPlaylogService = userPlaylogService;
this.userChargeService = userChargeService;
this.userDataExService = userDataExService;
this.userCourseService = userCourseService;
this.userDuelService = userDuelService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
Map<String, Object> upsertUserAll = (Map<String, Object>) request.get("upsertUserAll");
// Not all field will be sent. Check if they are exist first.
UserData userData;
UserData newUserData;
// UserData
if (!upsertUserAll.containsKey("userData")) {
return null;
} else {
Map<String, Object> userDataMap = ((List<Map<String, Object>>) upsertUserAll.get("userData")).get(0);
Optional<UserData> userOptional = userDataService.getUserByExtId(userId);
if (userOptional.isPresent()) {
userData = userOptional.get();
} else {
userData = new UserData();
Card card = cardService.getCardByExtId(userId).orElseThrow();
userData.setCard(card);
}
// Map the map to object
newUserData = mapper.convert(userDataMap, UserData.class);
newUserData.setId(userData.getId());
newUserData.setCard(userData.getCard());
// Decode Username
String userName = new String(newUserData.getUserName()
.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
newUserData.setUserName(userName);
userDataService.saveAndFlushUserData(newUserData);
}
// userGameOption
if (upsertUserAll.containsKey("userGameOption")) {
Map<String, Object> userGameOptionMap = ((List<Map<String, Object>>) upsertUserAll.get("userGameOption")).get(0);
Optional<UserGameOption> userGameOptionOptional = userGameOptionService.getByUser(newUserData);
UserGameOption userGameOption = userGameOptionOptional.orElseGet(() -> new UserGameOption(newUserData));
UserGameOption newUserGameOption = mapper.convert(userGameOptionMap, UserGameOption.class);
newUserGameOption.setId(userGameOption.getId());
newUserGameOption.setUser(userGameOption.getUser());
userGameOptionService.save(newUserGameOption);
}
// userGameOptionEx
if (upsertUserAll.containsKey("userGameOptionEx")) {
Map<String, Object> userGameOptionExMap = ((List<Map<String, Object>>) upsertUserAll.get("userGameOptionEx")).get(0);
Optional<UserGameOptionEx> userGameOptionExOptional = userGameOptionExService.getByUser(newUserData);
UserGameOptionEx userGameOptionEx = userGameOptionExOptional.orElseGet(() -> new UserGameOptionEx(newUserData));
UserGameOptionEx newUserGameOptionEx = mapper.convert(userGameOptionExMap, UserGameOptionEx.class);
newUserGameOptionEx.setId(userGameOptionEx.getId());
newUserGameOptionEx.setUser(userGameOptionEx.getUser());
userGameOptionExService.save(newUserGameOptionEx);
}
// userMapList
if (upsertUserAll.containsKey("userMapList")) {
int mapPos = 0;
List<Map<String, Object>> userMapList = (List<Map<String, Object>>) upsertUserAll.get("userMapList");
Map<String, UserMap> newUserMapMap = new HashMap<>();
userMapList.forEach(userMapListMap -> {
String mapId = (String) userMapListMap.get("mapId");
UserMap userMap;
Optional<UserMap> userMapOptional = userMapService.getByUserAndMapId(newUserData, mapId);
userMap = userMapOptional.orElseGet(() -> new UserMap(newUserData));
UserMap newUserMap = mapper.convert(userMapListMap, UserMap.class);
newUserMap.setId(userMap.getId());
newUserMap.setUser(userMap.getUser());
newUserMapMap.put(mapId, newUserMap);
});
userMapService.saveAll(newUserMapMap.values());
}
// userCharacterList
if (upsertUserAll.containsKey("userCharacterList")) {
List<Map<String, Object>> userCharacterList = (List<Map<String, Object>>) upsertUserAll.get("userCharacterList");
Map<String, UserCharacter> newCharacterMap = new HashMap<>();
userCharacterList.forEach(userCharacterMap -> {
String characterId = (String) userCharacterMap.get("characterId");
Optional<UserCharacter> userCharacterOptional = userCharacterService.getByUserAndCharacterId(newUserData, characterId);
UserCharacter userCharacter = userCharacterOptional.orElseGet(() -> new UserCharacter(newUserData));
UserCharacter newUserCharacter = mapper.convert(userCharacterMap, UserCharacter.class);
newUserCharacter.setId(userCharacter.getId());
newUserCharacter.setUser(userCharacter.getUser());
newCharacterMap.put(characterId, newUserCharacter);
});
userCharacterService.saveAll(newCharacterMap.values());
}
// userItemList
if (upsertUserAll.containsKey("userItemList")) {
List<Map<String, Object>> userItemList = (List<Map<String, Object>>) upsertUserAll.get("userItemList");
Map<String, UserItem> newUserItemMap = new HashMap<>();
userItemList.forEach(userItemMap -> {
String itemId = (String) userItemMap.get("itemId");
Optional<UserItem> userItemOptional = userItemService.getByUserAndItemId(newUserData, itemId);
UserItem userItem = userItemOptional.orElseGet(() -> new UserItem(newUserData));
UserItem newUserItem = mapper.convert(userItemMap, UserItem.class);
newUserItem.setId(userItem.getId());
newUserItem.setUser(userItem.getUser());
newUserItemMap.put(itemId, newUserItem);
});
userItemService.saveAll(newUserItemMap.values());
}
// userMusicDetailList
if (upsertUserAll.containsKey("userMusicDetailList")) {
List<Map<String, Object>> userMusicDetailList = (List<Map<String, Object>>) upsertUserAll.get("userMusicDetailList");
Map<String, UserMusicDetail> newUserMusicDetailMap = new HashMap<>();
userMusicDetailList.forEach(userMusicDetailMap -> {
String musicId = (String) userMusicDetailMap.get("musicId");
String level = (String) userMusicDetailMap.get("level");
Optional<UserMusicDetail> userMusicDetailOptional = userMusicDetailService.getByUserAndMusicIdAndLevel(newUserData, musicId, level);
UserMusicDetail userMusicDetail = userMusicDetailOptional.orElseGet(() -> new UserMusicDetail(newUserData));
UserMusicDetail newUserMusicDetail = mapper.convert(userMusicDetailMap, UserMusicDetail.class);
newUserMusicDetail.setId(userMusicDetail.getId());
newUserMusicDetail.setUser(userMusicDetail.getUser());
newUserMusicDetailMap.put(musicId + "," + level, newUserMusicDetail);
});
userMusicDetailService.saveAll(newUserMusicDetailMap.values());
}
// userActivityList
if (upsertUserAll.containsKey("userActivityList")) {
List<Map<String, Object>> userActivityList = (List<Map<String, Object>>) upsertUserAll.get("userActivityList");
userActivityList.forEach(userActivityMap -> {
// No need to rename to activityId. jackson auto handle that
String activityId = (String) userActivityMap.get("id");
String kind = (String) userActivityMap.get("kind");
Optional<UserActivity> userActivityOptional = userActivityService.getByUserAndActivityIdAndKind(newUserData, activityId, kind);
UserActivity userActivity = userActivityOptional.orElseGet(() -> new UserActivity(newUserData));
UserActivity newUserActivity = mapper.convert(userActivityMap, UserActivity.class);
newUserActivity.setId(userActivity.getId());
newUserActivity.setUser(userActivity.getUser());
userActivityService.save(newUserActivity);
});
}
// userRecentRatingList
// userChargeList
if (upsertUserAll.containsKey("userChargeList")) {
List<Map<String, Object>> userChargeList = (List<Map<String, Object>>) upsertUserAll.get("userChargeList");
List<UserCharge> newUserChargeList = new ArrayList<>();
userChargeList.forEach(userChargeMap -> {
String chargeId = (String) userChargeMap.get("chargeId");
Optional<UserCharge> userChargeOptional = userChargeService.getByUserAndChargeId(newUserData, chargeId);
UserCharge userCharge = userChargeOptional.orElseGet(() -> new UserCharge(newUserData));
UserCharge newUserCharge = mapper.convert(userChargeMap, UserCharge.class);
newUserCharge.setId(userCharge.getId());
newUserCharge.setUser(userCharge.getUser());
newUserChargeList.add(newUserCharge);
});
userChargeService.saveAll(newUserChargeList);
}
// userPlaylogList
if (upsertUserAll.containsKey("userPlaylogList")) {
List<Map<String, Object>> userPlaylogList = (List<Map<String, Object>>) upsertUserAll.get("userPlaylogList");
List<UserPlaylog> newUserPlaylogList = new ArrayList<>();
userPlaylogList.forEach(userPlayLogMap -> {
UserPlaylog newUserPlaylog = mapper.convert(userPlayLogMap, UserPlaylog.class);
newUserPlaylog.setUser(newUserData);
newUserPlaylogList.add(newUserPlaylog);
});
if (newUserPlaylogList.size() > 0) userPlaylogService.saveAll(newUserPlaylogList);
}
// userCourseList
if (upsertUserAll.containsKey("userCourseList")) {
List<Map<String, Object>> userCourseList = (List<Map<String, Object>>) upsertUserAll.get("userCourseList");
userCourseList.forEach(userCourseMap -> {
String courseId = (String) userCourseMap.get("courseId");
Optional<UserCourse> userCourseOptional = userCourseService.getByUserAndCourseId(newUserData, courseId);
UserCourse userCourse = userCourseOptional.orElseGet(() -> new UserCourse(newUserData));
UserCourse newUserCourse = mapper.convert(userCourseMap, UserCourse.class);
newUserCourse.setId(userCourse.getId());
newUserCourse.setUser(userCourse.getUser());
userCourseService.save(newUserCourse);
});
}
// userDataEx
if (upsertUserAll.containsKey("userDataEx")) {
Map<String, Object> userDataExMap = ((List<Map<String, Object>>) upsertUserAll.get("userDataEx")).get(0);
Optional<UserDataEx> userDataExOptional = userDataExService.getByUser(newUserData);
UserDataEx userDataEx = userDataExOptional.orElseGet(() -> new UserDataEx(newUserData));
UserDataEx newUserDataEx = mapper.convert(userDataExMap, UserDataEx.class);
newUserDataEx.setId(userDataEx.getId());
newUserDataEx.setUser(userDataEx.getUser());
userDataExService.save(newUserDataEx);
}
// userDuelList
if (upsertUserAll.containsKey("userDuelList")) {
List<Map<String, Object>> userDuelList = (List<Map<String, Object>>) upsertUserAll.get("userDuelList");
Map<String, UserDuel> newUserDuelMap = new HashMap<>();
userDuelList.forEach(userDuelMap -> {
String duelId = (String) userDuelMap.get("duelId");
Optional<UserDuel> userDuelOptional = userDuelService.getByUserAndDuelId(newUserData, duelId);
UserDuel userDuel = userDuelOptional.orElseGet(() -> new UserDuel(newUserData));
UserDuel newUserDuel = mapper.convert(userDuelMap, UserDuel.class);
newUserDuel.setId(userDuel.getId());
newUserDuel.setUser(userDuel.getUser());
newUserDuelMap.put(duelId, newUserDuel);
});
userDuelService.saveAll(newUserDuelMap.values());
}
String json = mapper.write(new CodeResp(1));
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,60 @@
package icu.samnyan.aqua.sega.chunithm.handler.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.CodeResp;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserCharge;
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
import icu.samnyan.aqua.sega.chunithm.service.UserChargeService;
import icu.samnyan.aqua.sega.chunithm.service.UserDataService;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class UpsertUserChargelogHandler implements BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(UpsertUserChargelogHandler.class);
private final StringMapper mapper;
private final UserDataService userDataService;
private final UserChargeService userChargeService;
public UpsertUserChargelogHandler(StringMapper mapper, UserDataService userDataService, UserChargeService userChargeService) {
this.mapper = mapper;
this.userDataService = userDataService;
this.userChargeService = userChargeService;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
String userId = (String) request.get("userId");
UserData user = userDataService.getUserByExtId(userId).orElseThrow();
Map<String, Object> userChargeMap = (Map<String, Object>) request.get("userCharge");
String chargeId = (String) userChargeMap.get("chargeId");
UserCharge charge = mapper.convert(userChargeMap, UserCharge.class);
UserCharge userCharge = userChargeService.getByUserAndChargeId(user, chargeId).orElseGet(() -> new UserCharge(user));
userCharge.setChargeId(charge.getChargeId());
userCharge.setStock(charge.getStock());
userCharge.setPurchaseDate(charge.getPurchaseDate());
userCharge.setValidDate(charge.getValidDate());
userCharge.setParam1(charge.getParam1());
userCharge.setParam2(charge.getParam2());
userCharge.setParamDate(charge.getParamDate());
userChargeService.save(userCharge);
String json = mapper.write(new CodeResp(1));
logger.info("Response: " + json);
return json;
}
}

View File

@@ -0,0 +1,28 @@
package icu.samnyan.aqua.sega.chunithm.model.gamedata;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public enum Diff {
BASIC("BASIC"),
ADVANCED("ADVANCED"),
EXPERT("EXPERT"),
MASTER("MASTER"),
WE("WORLD'S END");
private String displayName;
Diff(String displayName) {
this.displayName = displayName;
}
public String displayName() {
return displayName;
}
@Override
public String toString() {
return displayName;
}
}

View File

@@ -0,0 +1,46 @@
package icu.samnyan.aqua.sega.chunithm.model.gamedata;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Entity(name = "ChuniGameCharge")
@Table(name = "chuni_game_charge")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GameCharge implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private long id;
private int orderId;
@Column(unique = true)
private int chargeId;
private int price;
private LocalDateTime startDate;
private LocalDateTime endDate;
private int salePrice;
private LocalDateTime saleStartDate;
private LocalDateTime saleEndDate;
}

View File

@@ -0,0 +1,33 @@
package icu.samnyan.aqua.sega.chunithm.model.gamedata;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Entity(name = "ChuniGameEvent")
@Table(name = "chuni_game_event")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GameEvent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private int type;
private LocalDateTime startDate;
private LocalDateTime endDate;
}

View File

@@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.chunithm.model.gamedata;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Entity(name = "ChuniGameMessage")
@Table(name = "chuni_game_message")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GameMessage implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private int type;
private String message;
private LocalDateTime startDate;
private LocalDateTime endDate;
}

Some files were not shown because too many files have changed in this diff Show More