[O] DIVA java > kt

This commit is contained in:
Azalea 2025-10-25 06:54:03 +08:00
parent 38b8831efd
commit 664365b09b
80 changed files with 2743 additions and 2855 deletions

View File

@ -1,201 +0,0 @@
package icu.samnyan.aqua.sega.diva.controller;
import icu.samnyan.aqua.sega.diva.handler.boot.AttendHandler;
import icu.samnyan.aqua.sega.diva.handler.boot.GameInitHandler;
import icu.samnyan.aqua.sega.diva.handler.card.*;
import icu.samnyan.aqua.sega.diva.handler.databank.*;
import icu.samnyan.aqua.sega.diva.handler.ingame.*;
import icu.samnyan.aqua.sega.diva.handler.operation.PingHandler;
import icu.samnyan.aqua.sega.diva.handler.user.*;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.request.boot.GameInitRequest;
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest;
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest;
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest;
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest;
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest;
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest;
import icu.samnyan.aqua.sega.diva.model.request.ingame.*;
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest;
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest;
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest;
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest;
import icu.samnyan.aqua.sega.diva.util.DivaMapper;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("/g/diva")
@AllArgsConstructor
public class DivaController {
private static final Logger logger = LoggerFactory.getLogger(DivaController.class);
private final GameInitHandler gameInitHandler;
private final AttendHandler attendHandler;
private final CardProcedureHandler cardProcedureHandler;
private final ChangeNameHandler changeNameHandler;
private final ChangePasswdHandler changePasswdHandler;
private final InitPasswdHandler initPasswdHandler;
private final RegistrationHandler registrationHandler;
/**
* Databank
*/
private final BannerInfoHandler bannerInfoHandler;
private final BannerDataHandler bannerDataHandler;
private final CmPlyInfoHandler cmPlyInfoHandler;
private final ContestInfoHandler contestInfoHandler;
private final CstmzItmCtlgHandler cstmzItmCtlgHandler;
private final CstmzItmNgMdlListHandler cstmzItmNgMdlListHandler;
private final FestaInfoHandler festaInfoHandler;
private final NgWordHandler ngWordHandler;
private final NvRankingHandler nvRankingHandler;
private final PsRankingHandler psRankingHandler;
private final PstdHCtrlHandler pstdHCtrlHandler;
private final PstdItemNgLstHandler pstdItemNgLstHandler;
private final PvDefChrLstHandler pvDefChrLstHandler;
private final PvListHandler pvListHandler;
private final PvNgMdlLstHandler pvNgMdlLstHandler;
private final QstInfHandler qstInfHandler;
private final RmtWpLstHandler rmtWpLstHandler;
private final ShopCatalogHandler shopCatalogHandler;
private final BuyCstmzItmHandler buyCstmzItmHandler;
private final BuyModuleHandler buyModuleHandler;
private final GetPvPdHandler getPvPdHandler;
private final ShopExitHandler shopExitHandler;
private final StageResultHandler stageResultHandler;
private final StageStartHandler stageStartHandler;
private final StoreSsHandler storeSsHandler;
private final PingHandler pingHandler;
private final EndHandler endHandler;
private final PdUnlockHandler pdUnlockHandler;
private final PreStartHandler preStartHandler;
private final SpendCreditHandler spendCreditHandler;
private final StartHandler startHandler;
private final DivaMapper mapper;
@PostMapping(value = "/", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String formRequest(HttpServletRequest request) throws IOException {
String bodyStr = new String(request.getInputStream().readAllBytes());
Map<String, Object> body = parse(bodyStr);
String command = (String) body.getOrDefault("cmd", "");
logger.info("{}: {}", command, body);
return switch (command) {
// Boot
case "game_init" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
case "attend" -> attendHandler.handle(mapper.convert(body, GameInitRequest.class));
//
case "test" -> gameInitHandler.handle(mapper.convert(body, BaseRequest.class));
// Databank
case "nv_ranking" -> nvRankingHandler.handle(mapper.convert(body, BaseRequest.class));
case "ps_ranking" -> psRankingHandler.handle(mapper.convert(body, PsRankingRequest.class));
case "pv_list" -> pvListHandler.handle(mapper.convert(body, BaseRequest.class));
case "ng_word" -> ngWordHandler.handle(mapper.convert(body, BaseRequest.class));
case "rmt_wp_list" -> rmtWpLstHandler.handle(mapper.convert(body, BaseRequest.class));
case "festa_info" -> festaInfoHandler.handle(mapper.convert(body, BaseRequest.class));
case "contest_info" -> contestInfoHandler.handle(mapper.convert(body, BaseRequest.class));
case "pv_def_chr_list" -> pvDefChrLstHandler.handle(mapper.convert(body, BaseRequest.class));
case "pv_ng_mdl_list" -> pvNgMdlLstHandler.handle(mapper.convert(body, BaseRequest.class));
case "cstmz_itm_ng_mdl_list" -> cstmzItmNgMdlListHandler.handle(mapper.convert(body, BaseRequest.class));
case "banner_info" -> bannerInfoHandler.handle(mapper.convert(body, BaseRequest.class));
case "banner_data" -> bannerDataHandler.handle(mapper.convert(body, BannerDataRequest.class));
case "cm_ply_info" -> cmPlyInfoHandler.handle(mapper.convert(body, BaseRequest.class));
case "qst_inf" -> qstInfHandler.handle(mapper.convert(body, BaseRequest.class));
case "pstd_h_ctrl" -> pstdHCtrlHandler.handle(mapper.convert(body, BaseRequest.class));
case "pstd_item_ng_lst" -> pstdItemNgLstHandler.handle(mapper.convert(body, BaseRequest.class));
case "shop_catalog" -> shopCatalogHandler.handle(mapper.convert(body, BaseRequest.class));
case "cstmz_itm_ctlg" -> cstmzItmCtlgHandler.handle(mapper.convert(body, BaseRequest.class));
case "card_procedure" -> cardProcedureHandler.handle(mapper.convert(body, CardProcedureRequest.class));
case "registration" -> registrationHandler.handle(mapper.convert(body, RegistrationRequest.class));
case "init_passwd" -> initPasswdHandler.handle(mapper.convert(body, GameInitRequest.class));
case "change_passwd" -> changePasswdHandler.handle(mapper.convert(body, ChangePasswdRequest.class));
case "change_name" -> changeNameHandler.handle(mapper.convert(body, ChangeNameRequest.class));
case "pre_start" -> preStartHandler.handle(mapper.convert(body, PreStartRequest.class));
case "start" -> startHandler.handle(mapper.convert(body, StartRequest.class));
case "pd_unlock" -> pdUnlockHandler.handle(mapper.convert(body, PdUnlockRequest.class));
case "spend_credit" -> spendCreditHandler.handle(mapper.convert(body, SpendCreditRequest.class));
case "no_card_end" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
case "end" -> endHandler.handle(mapper.convert(body, StageResultRequest.class));
case "get_pv_pd" -> getPvPdHandler.handle(mapper.convert(body, GetPvPdRequest.class));
case "buy_module" -> buyModuleHandler.handle(mapper.convert(body, BuyModuleRequest.class));
case "buy_cstmz_itm" -> buyCstmzItmHandler.handle(mapper.convert(body, BuyCstmzItmRequest.class));
case "shop_exit" -> shopExitHandler.handle(mapper.convert(body, ShopExitRequest.class));
case "stage_start" -> stageStartHandler.handle(mapper.convert(body, StageStartRequest.class));
case "stage_result" -> stageResultHandler.handle(mapper.convert(body, StageResultRequest.class));
case "store_ss" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest.class));
default -> "stat=0";
};
}
@PostMapping(value = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String fileRequest(@RequestParam String query, @RequestParam(required = false) MultipartFile bin) {
Map<String, Object> body = parse(query);
String command = (String) body.getOrDefault("cmd", "");
logger.info("{}: {}", command, body);
return switch (command) {
case "ping" -> pingHandler.handle(mapper.convert(body, BaseRequest.class));
case "investigate" -> gameInitHandler.handle(mapper.convert(body, BaseRequest.class));
case "store_ss" -> storeSsHandler.handle(mapper.convert(body, StoreSsRequest.class), bin);
default -> "stat=1";
};
}
private Map<String, Object> parse(String form) {
String[] kvps = form.split("&");
Map<String, Object> body = new LinkedHashMap<>();
for (String kvp :
kvps) {
String[] k = kvp.split("=");
k[1] = URLDecoder.decode(k[1], StandardCharsets.UTF_8);
Object value;
if (k[1].contains(",")) {
value = deArray(k[1]);
} else {
value = k[1];
}
body.put(k[0], value);
}
return body;
}
private Object deArray(String input) {
if (!input.contains(",")) return input;
return Arrays.stream(input.split(",")).map(x -> URLDecoder.decode(x, StandardCharsets.UTF_8))
.map(this::deArray).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,191 @@
package icu.samnyan.aqua.sega.diva.controller
import ext.MutJDict
import ext.logger
import icu.samnyan.aqua.sega.diva.handler.AttendHandler
import icu.samnyan.aqua.sega.diva.handler.GameInitHandler
import icu.samnyan.aqua.sega.diva.handler.buildResultMap
import icu.samnyan.aqua.sega.diva.handler.card.*
import icu.samnyan.aqua.sega.diva.handler.databank.*
import icu.samnyan.aqua.sega.diva.handler.ingame.*
import icu.samnyan.aqua.sega.diva.handler.PingHandler
import icu.samnyan.aqua.sega.diva.handler.user.*
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.request.boot.GameInitRequest
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest
import icu.samnyan.aqua.sega.diva.model.request.ingame.*
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest
import icu.samnyan.aqua.sega.diva.util.DivaMapper
import jakarta.servlet.http.HttpServletRequest
import lombok.AllArgsConstructor
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@RestController
@RequestMapping("/g/diva")
@AllArgsConstructor
class DivaController(
val gameInitHandler: GameInitHandler,
val attendHandler: AttendHandler,
val cardProcedureHandler: CardProcedureHandler,
val changeNameHandler: ChangeNameHandler,
val changePasswdHandler: ChangePasswdHandler,
val initPasswdHandler: InitPasswdHandler,
val registrationHandler: RegistrationHandler,
val bannerInfoHandler: BannerInfoHandler,
val bannerDataHandler: BannerDataHandler,
val cmPlyInfoHandler: CmPlyInfoHandler,
val contestInfoHandler: ContestInfoHandler,
val cstmzItmCtlgHandler: CstmzItmCtlgHandler,
val cstmzItmNgMdlListHandler: CstmzItmNgMdlListHandler,
val festaInfoHandler: FestaInfoHandler,
val ngWordHandler: NgWordHandler,
val nvRankingHandler: NvRankingHandler,
val psRankingHandler: PsRankingHandler,
val pstdHCtrlHandler: PstdHCtrlHandler,
val pstdItemNgLstHandler: PstdItemNgLstHandler,
val pvDefChrLstHandler: PvDefChrLstHandler,
val pvListHandler: PvListHandler,
val pvNgMdlLstHandler: PvNgMdlLstHandler,
val qstInfHandler: QstInfHandler,
val rmtWpLstHandler: RmtWpLstHandler,
val shopCatalogHandler: ShopCatalogHandler,
val buyCstmzItmHandler: BuyCstmzItmHandler,
val buyModuleHandler: BuyModuleHandler,
val getPvPdHandler: GetPvPdHandler,
val shopExitHandler: ShopExitHandler,
val stageResultHandler: StageResultHandler,
val stageStartHandler: StageStartHandler,
val storeSsHandler: StoreSsHandler,
val pingHandler: PingHandler,
val endHandler: EndHandler,
val pdUnlockHandler: PdUnlockHandler,
val preStartHandler: PreStartHandler,
val spendCreditHandler: SpendCreditHandler,
val startHandler: StartHandler,
) {
val logger = logger()
val mapper = DivaMapper()
@PostMapping(value = ["/"], consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
fun formRequest(request: HttpServletRequest): String? {
val bodyStr = String(request.inputStream.readAllBytes())
val body = parse(bodyStr)
val command = body.getOrDefault("cmd", "") as String?
logger.info("{}: {}", command, body)
val respObj = when (command) {
"game_init" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest::class.java))
"attend" -> attendHandler.handle(mapper.convert(body, GameInitRequest::class.java))
"test" -> gameInitHandler.handle(mapper.convert(body, BaseRequest::class.java))
"nv_ranking" -> nvRankingHandler.handle(mapper.convert(body, BaseRequest::class.java))
"ps_ranking" -> psRankingHandler.handle(mapper.convert(body, PsRankingRequest::class.java))
"pv_list" -> pvListHandler.handle(mapper.convert(body, BaseRequest::class.java))
"ng_word" -> ngWordHandler.handle(mapper.convert(body, BaseRequest::class.java))
"rmt_wp_list" -> rmtWpLstHandler.handle(mapper.convert(body, BaseRequest::class.java))
"festa_info" -> festaInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
"contest_info" -> contestInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
"pv_def_chr_list" -> pvDefChrLstHandler.handle(mapper.convert(body, BaseRequest::class.java))
"pv_ng_mdl_list" -> pvNgMdlLstHandler.handle(mapper.convert(body, BaseRequest::class.java))
"cstmz_itm_ng_mdl_list" -> cstmzItmNgMdlListHandler.handle(mapper.convert(body, BaseRequest::class.java))
"banner_info" -> bannerInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
"banner_data" -> bannerDataHandler.handle(mapper.convert(body, BannerDataRequest::class.java))
"cm_ply_info" -> cmPlyInfoHandler.handle(mapper.convert(body, BaseRequest::class.java))
"qst_inf" -> qstInfHandler.handle(mapper.convert(body, BaseRequest::class.java))
"pstd_h_ctrl" -> pstdHCtrlHandler.handle(mapper.convert(body, BaseRequest::class.java))
"pstd_item_ng_lst" -> pstdItemNgLstHandler.handle(mapper.convert(body, BaseRequest::class.java))
"shop_catalog" -> shopCatalogHandler.handle(mapper.convert(body, BaseRequest::class.java))
"cstmz_itm_ctlg" -> cstmzItmCtlgHandler.handle(mapper.convert(body, BaseRequest::class.java))
"card_procedure" -> cardProcedureHandler.handle(mapper.convert(body, CardProcedureRequest::class.java))
"registration" -> registrationHandler.handle(mapper.convert(body, RegistrationRequest::class.java))
"init_passwd" -> initPasswdHandler.handle(mapper.convert(body, GameInitRequest::class.java))
"change_passwd" -> changePasswdHandler.handle(mapper.convert(body, ChangePasswdRequest::class.java))
"change_name" -> changeNameHandler.handle(mapper.convert(body, ChangeNameRequest::class.java))
"pre_start" -> preStartHandler.handle(mapper.convert(body, PreStartRequest::class.java))
"start" -> startHandler.handle(mapper.convert(body, StartRequest::class.java))
"pd_unlock" -> pdUnlockHandler.handle(mapper.convert(body, PdUnlockRequest::class.java))
"spend_credit" -> spendCreditHandler.handle(mapper.convert(body, SpendCreditRequest::class.java))
"no_card_end" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest::class.java))
"end" -> endHandler.handle(mapper.convert(body, StageResultRequest::class.java))
"get_pv_pd" -> getPvPdHandler.handle(mapper.convert(body, GetPvPdRequest::class.java))
"buy_module" -> buyModuleHandler.handle(mapper.convert(body, BuyModuleRequest::class.java))
"buy_cstmz_itm" -> buyCstmzItmHandler.handle(mapper.convert(body, BuyCstmzItmRequest::class.java))
"shop_exit" -> shopExitHandler.handle(mapper.convert(body, ShopExitRequest::class.java))
"stage_start" -> stageStartHandler.handle(mapper.convert(body, StageStartRequest::class.java))
"stage_result" -> stageResultHandler.handle(mapper.convert(body, StageResultRequest::class.java))
"store_ss" -> gameInitHandler.handle(mapper.convert(body, GameInitRequest::class.java))
else -> "stat=0"
}
val resp = respObj as? String ?: buildResultMap(mapper.toMap(respObj))
logger.info("Response: {}", resp)
return resp
}
@PostMapping(value = ["/"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
fun fileRequest(@RequestParam query: String, @RequestParam(required = false) bin: MultipartFile): String? {
val body = parse(query)
val command = body.getOrDefault("cmd", "") as String?
logger.info("{}: {}", command, body)
val respObj = when (command) {
"ping" -> pingHandler.handle(mapper.convert(body, BaseRequest::class.java))
"investigate" -> gameInitHandler.handle(mapper.convert(body, BaseRequest::class.java))
"store_ss" -> storeSsHandler.handle(mapper.convert(body, StoreSsRequest::class.java), bin)
else -> "stat=1"
}
val resp = respObj as? String ?: buildResultMap(mapper.toMap(respObj))
logger.info("Response: {}", resp)
return resp
}
fun parse(form: String): MutJDict {
val kvps = form.split('&').dropLastWhile { it.isEmpty() }
val body: MutJDict = LinkedHashMap()
for (kvp in kvps) {
var (k, v) = kvp.split('=').dropLastWhile { it.isEmpty() }
v = URLDecoder.decode(v, StandardCharsets.UTF_8)
body[k] = if (v.contains(",")) { v.deArray() } else { v }
}
return body
}
fun String.deArray(): Any {
if (!contains(',')) return this
return split(',').dropLastWhile { it.isEmpty() }
.map { URLDecoder.decode(it, StandardCharsets.UTF_8) }
.map { it.deArray() }
}
}

View File

@ -0,0 +1,31 @@
package icu.samnyan.aqua.sega.diva.dao
import icu.samnyan.aqua.sega.diva.dao.gamedata.*
import icu.samnyan.aqua.sega.diva.dao.userdata.*
import org.springframework.stereotype.Component
@Component
class DivaGameRepos(
val contest: ContestRepository,
val customize: DivaCustomizeRepository,
val module: DivaModuleRepository,
val pv: DivaPvRepository,
val festa: FestaRepository,
val ngWords: NgWordsRepository,
val pvEntry: PvEntryRepository
)
@Component
class DivaRepos(
val g: DivaGameRepos,
val gameSession: GameSessionRepository,
val playLog: PlayLogRepository,
val contest: PlayerContestRepository,
val customize: PlayerCustomizeRepository,
val inventory: PlayerInventoryRepository,
val module: PlayerModuleRepository,
val profile: PlayerProfileRepository,
val pvCustomize: PlayerPvCustomizeRepository,
val pvRecord: PlayerPvRecordRepository,
val screenShot: PlayerScreenShotRepository
)

View File

@ -1,15 +0,0 @@
package icu.samnyan.aqua.sega.diva.exception;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
public class SessionNotExistException extends RuntimeException {
public SessionNotExistException(String message) {
super(message);
}
public SessionNotExistException() {
super();
}
}

View File

@ -1,36 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler;
import icu.samnyan.aqua.sega.diva.util.DivaMapper;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class BaseHandler {
static protected DivaMapper mapper = new DivaMapper();
protected String build(Map<String, Object> map) {
StringBuilder sb = new StringBuilder();
map.forEach((key, val) -> {
if (val != null) {
if (val instanceof String) {
if (!val.equals("")) {
sb.append(key).append("=");
sb.append(val);
sb.append("&");
}
} else {
sb.append(key).append("=");
// sb.append(URLEncoder.encode(String.valueOf(val), StandardCharsets.UTF_8));
sb.append(val);
sb.append("&");
}
}
});
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
}

View File

@ -0,0 +1,23 @@
package icu.samnyan.aqua.sega.diva.handler
import icu.samnyan.aqua.sega.diva.util.DivaMapper
import org.springframework.stereotype.Component
operator fun StringBuilder.plusAssign(other: String) {
this.append(other)
}
fun buildResultMap(map: MutableMap<String, Any?>) =
map.filterValues { it != null && !(it is String && it == "") }
.map { (k, v) -> "$k=$v" }.joinToString("&")
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BaseHandler {
@JvmField
final var mapper = DivaMapper()
fun build(map: MutableMap<String, Any?>) = buildResultMap(map)
}

View File

@ -0,0 +1,59 @@
package icu.samnyan.aqua.sega.diva.handler
import ext.logger
import icu.samnyan.aqua.sega.diva.model.common.attend.DispersalParameter
import icu.samnyan.aqua.sega.diva.model.common.attend.EtcParameter
import icu.samnyan.aqua.sega.diva.model.common.attend.GameBalanceParameter
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.boot.AttendResponse
import icu.samnyan.aqua.sega.diva.model.response.boot.GameInitResponse
import icu.samnyan.aqua.sega.diva.model.response.operation.PingResponse
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository
import icu.samnyan.aqua.sega.general.model.PropertyEntry
import org.springframework.stereotype.Component
import java.time.LocalDateTime
@Component
class GameInitHandler {
fun handle(request: BaseRequest) = GameInitResponse(
request.cmd,
request.req_id,
"ok",
"0,0",
"FFFF"
)
}
@Component
class AttendHandler {
fun handle(request: BaseRequest) = AttendResponse(
request.cmd,
request.req_id,
"ok",
EtcParameter().toInternal(),
DispersalParameter().toInternal(),
GameBalanceParameter().toInternal(),
LocalDateTime.now()
)
}
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PingHandler(val rp: PropertyEntryRepository) : BaseHandler() {
val logger = logger()
fun handle(request: BaseRequest): Any {
val news: PropertyEntry = rp.findByPropertyKey("diva_news") ?: PropertyEntry("diva_news", "xxx")
val warning: PropertyEntry = rp.findByPropertyKey("diva_warning") ?: PropertyEntry("diva_warning", "xxx")
return PingResponse(
request.cmd,
request.req_id,
"ok",
news.propertyValue,
warning.propertyValue
)
}
}

View File

@ -1,38 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.boot;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.attend.DispersalParameter;
import icu.samnyan.aqua.sega.diva.model.common.attend.EtcParameter;
import icu.samnyan.aqua.sega.diva.model.common.attend.GameBalanceParameter;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.boot.AttendResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class AttendHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(AttendHandler.class);
public String handle(BaseRequest request) {
AttendResponse response = new AttendResponse(
request.getCmd(),
request.getReq_id(),
"ok",
new EtcParameter().toInternal(),
new DispersalParameter().toInternal(),
new GameBalanceParameter().toInternal(),
LocalDateTime.now()
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -1,31 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.boot;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.boot.GameInitResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class GameInitHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GameInitHandler.class);
public String handle(BaseRequest request) {
GameInitResponse response = new GameInitResponse(
request.getCmd(),
request.getReq_id(),
"ok",
"0,0",
"FFFF"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -1,100 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.card;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.common.StartMode;
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest;
import icu.samnyan.aqua.sega.diva.model.response.card.CardProcedureResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class CardProcedureHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CardProcedureHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(CardProcedureRequest request) {
Optional<PlayerProfile> profileOptional = playerProfileService.findByPdId(request.getAime_id());
CardProcedureResponse response;
if (profileOptional.isEmpty()) {
response = new CardProcedureResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
PlayerProfile profile = profileOptional.get();
Optional<GameSession> sessionOptional = gameSessionRepository.findByPdId(profile);
if (sessionOptional.isPresent()) {
GameSession session = sessionOptional.get();
if (session.getLastUpdateTime().isBefore(LocalDateTime.now().minusMinutes(5))) {
gameSessionRepository.delete(session);
}
response = new CardProcedureResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
GameSession session = new GameSession(
ThreadLocalRandom.current().nextInt(100, 99999),
profile,
StartMode.CARD_PROCEDURE,
LocalDateTime.now(),
LocalDateTime.now(),
-1,
-1,
-1,
profile.getLevel(),
profile.getLevelExp(),
profile.getLevel(),
profile.getLevelExp(),
profile.getVocaloidPoints()
);
gameSessionRepository.save(session);
response = new CardProcedureResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
100,
session.getAcceptId(),
profile.getPdId(),
profile.getPlayerName(),
profile.getLevel(),
profile.getLevelExp(),
profile.getLevelTitle(),
profile.getPlateEffectId(),
profile.getPlateId(),
profile.getVocaloidPoints(),
profile.getPasswordStatus()
);
}
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,80 @@
package icu.samnyan.aqua.sega.diva.handler.card
import icu.samnyan.aqua.sega.diva.dao.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.common.StartMode
import icu.samnyan.aqua.sega.diva.model.request.card.CardProcedureRequest
import icu.samnyan.aqua.sega.diva.model.response.card.CardProcedureResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.concurrent.ThreadLocalRandom
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CardProcedureHandler(val db: DivaRepos) {
fun handle(request: CardProcedureRequest): Any {
val profileOptional = db.profile.findByPdId(request.aime_id)
if (profileOptional.isEmpty) {
return CardProcedureResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
val profile = profileOptional.get()
val sessionOptional = db.gameSession.findByPdId(profile)
if (sessionOptional.isPresent) {
val session = sessionOptional.get()
if (session.lastUpdateTime.isBefore(LocalDateTime.now().minusMinutes(5))) {
db.gameSession.delete(session)
}
return CardProcedureResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
val session = GameSession(
ThreadLocalRandom.current().nextInt(100, 99999),
profile,
StartMode.CARD_PROCEDURE,
LocalDateTime.now(),
LocalDateTime.now(),
-1,
-1,
-1,
profile.level,
profile.levelExp,
profile.level,
profile.levelExp,
profile.vocaloidPoints
)
db.gameSession.save<GameSession?>(session)
return CardProcedureResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
100,
session.acceptId,
profile.pdId,
profile.playerName,
profile.level,
profile.levelExp,
profile.levelTitle,
profile.plateEffectId,
profile.plateId,
profile.vocaloidPoints,
profile.passwordStatus
)
}
}
}
}

View File

@ -1,54 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.card;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest;
import icu.samnyan.aqua.sega.diva.model.response.card.ChangeNameResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class ChangeNameHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(ChangeNameHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(ChangeNameRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
profile.setPlayerName(request.getPlayer_name());
ChangeNameResponse response = new ChangeNameResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
session.getAcceptId(),
profile.getPdId(),
profile.getPlayerName()
);
playerProfileService.save(profile);
gameSessionRepository.delete(session);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,37 @@
package icu.samnyan.aqua.sega.diva.handler.card
import ext.invoke
import icu.samnyan.aqua.sega.diva.dao.DivaRepos
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.card.ChangeNameRequest
import icu.samnyan.aqua.sega.diva.model.response.card.ChangeNameResponse
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ChangeNameHandler(val db: DivaRepos) {
fun handle(request: ChangeNameRequest): Any {
val profile = db.profile.findByPdId(request.pd_id)() ?: throw ProfileNotFoundException()
val session = db.gameSession.findByPdId(profile)() ?: throw SessionNotFoundException()
profile.playerName = request.player_name
db.profile.save(profile)
db.gameSession.delete(session)
return ChangeNameResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
session.acceptId,
profile.pdId,
profile.playerName
)
}
}

View File

@ -1,53 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.card;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.PassStat;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest;
import icu.samnyan.aqua.sega.diva.model.response.card.ChangePasswdResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class ChangePasswdHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(ChangePasswdHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(ChangePasswdRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
profile.setPasswordStatus(PassStat.SET);
profile.setPassword(request.getNew_passwd());
ChangePasswdResponse response = new ChangePasswdResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
session.getAcceptId(),
profile.getPdId()
);
playerProfileService.save(profile);
gameSessionRepository.delete(session);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,38 @@
package icu.samnyan.aqua.sega.diva.handler.card
import icu.samnyan.aqua.sega.diva.dao.DivaRepos
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.model.common.PassStat
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.card.ChangePasswdRequest
import icu.samnyan.aqua.sega.diva.model.response.card.ChangePasswdResponse
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ChangePasswdHandler(val db: DivaRepos) {
fun handle(request: ChangePasswdRequest): Any {
val profile = db.profile.findByPdId(request.pd_id)
.orElseThrow(Supplier { ProfileNotFoundException() })
val session = db.gameSession.findByPdId(profile)
.orElseThrow(Supplier { SessionNotFoundException() })
profile.passwordStatus = PassStat.SET
profile.password = request.new_passwd
db.profile.save(profile)
db.gameSession.delete(session)
return ChangePasswdResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
session.acceptId,
profile.pdId
)
}
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.card;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class InitPasswdHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(InitPasswdHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(BaseRequest request) {
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"0");
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,17 @@
package icu.samnyan.aqua.sega.diva.handler.card
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class InitPasswdHandler {
fun handle(request: BaseRequest) = BaseResponse(
request.cmd,
request.req_id,
"0"
)
}

View File

@ -1,47 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.card;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest;
import icu.samnyan.aqua.sega.diva.model.response.card.RegistrationResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class RegistrationHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(RegistrationHandler.class);
private final PlayerProfileService playerProfileService;
public String handle(RegistrationRequest request) {
RegistrationResponse response;
if (playerProfileService.findByPdId(request.getAime_id()).isPresent()) {
response = new RegistrationResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED,
-1);
} else {
PlayerProfile profile = playerProfileService.register(request);
response = new RegistrationResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
profile.getPdId());
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,33 @@
package icu.samnyan.aqua.sega.diva.handler.card
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest
import icu.samnyan.aqua.sega.diva.model.response.card.RegistrationResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class RegistrationHandler(val service: PlayerProfileService) {
fun handle(request: RegistrationRequest) =
if (service.findByPdId(request.aime_id).isPresent) {
RegistrationResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED,
-1
)
} else {
val profile = service.register(request)
RegistrationResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
profile.pdId
)
}
}

View File

@ -1,35 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerDataResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class BannerDataHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(BannerDataHandler.class);
public String handle(BannerDataRequest request) {
BannerDataResponse response = new BannerDataResponse(
request.getCmd(),
request.getReq_id(),
"ok",
LocalDateTime.now(),
"***",
"***",
request.getBd_id()
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,23 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.databank.BannerDataRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerDataResponse
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BannerDataHandler : BaseHandler() {
fun handle(request: BannerDataRequest) = BannerDataResponse(
request.cmd,
request.req_id,
"ok",
LocalDateTime.now(),
"***",
"***",
request.bd_id
)
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerInfoResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class BannerInfoHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(BannerInfoHandler.class);
public String handle(BaseRequest request) {
BannerInfoResponse response = new BannerInfoResponse(
request.getCmd(),
request.getReq_id(),
"ok",
null,
null,
null,
null,
null
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,23 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.BannerInfoResponse
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BannerInfoHandler : BaseHandler() {
fun handle(request: BaseRequest) = BannerInfoResponse(
request.cmd,
request.req_id,
"ok",
null,
null,
null,
null,
null
)
}

View File

@ -1,28 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class CmPlyInfoHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CmPlyInfoHandler.class);
public String handle(BaseRequest request) {
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok");
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,18 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CmPlyInfoHandler : BaseHandler() {
fun handle(request: BaseRequest) = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
}

View File

@ -1,49 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.ContestInfoResponse;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class ContestInfoHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CmPlyInfoHandler.class);
private final ContestRepository contestRepository;
public String handle(BaseRequest request) {
List<Contest> contestList = contestRepository.findTop8ByEnable(true);
String ci_str = "***";
if (!contestList.isEmpty()) {
StringBuilder sb = new StringBuilder();
contestList.forEach(x -> sb.append(URIEncoder.encode(x.getString())).append(","));
sb.append("%2A%2A%2A,".repeat(Math.max(0, 8 - contestList.size())));
sb.deleteCharAt(sb.length() - 1);
ci_str = sb.toString();
}
ContestInfoResponse response = new ContestInfoResponse(
request.getCmd(),
request.getReq_id(),
"ok",
LocalDateTime.now(),
ci_str
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,43 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.ContestInfoResponse
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.function.Consumer
import kotlin.math.max
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ContestInfoHandler(private val contestRepository: ContestRepository) : BaseHandler() {
fun handle(request: BaseRequest): Any {
val contestList = contestRepository.findTop8ByEnable(true)
var ci_str = "***"
if (!contestList.isEmpty()) {
val sb = StringBuilder()
contestList.forEach(Consumer { x: Contest? -> sb.append(encode(x!!.getString())).append(",") })
sb.append("%2A%2A%2A,".repeat(max(0, 8 - contestList.size)))
sb.deleteCharAt(sb.length - 1)
ci_str = sb.toString()
}
return ContestInfoResponse(
request.cmd,
request.req_id,
"ok",
LocalDateTime.now(),
ci_str
)
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(CmPlyInfoHandler::class.java)
}
}

View File

@ -1,46 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaCustomize;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmCtlgResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class CstmzItmCtlgHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CstmzItmCtlgHandler.class);
private final DivaCustomizeRepository customizeRepository;
public String handle(BaseRequest request) {
List<DivaCustomize> customizeList = customizeRepository.findAll();
CstmzItmCtlgResponse response = new CstmzItmCtlgResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
URIEncoder.encode(customizeList.stream().map(DivaCustomize::toInternal).map(URIEncoder::encode)
.collect(Collectors.joining(",")))
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,39 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmCtlgResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CstmzItmCtlgHandler(private val customizeRepository: DivaCustomizeRepository) : BaseHandler() {
fun handle(request: BaseRequest): Any {
val customizeList = customizeRepository.findAll()
val response = CstmzItmCtlgResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
encode(customizeList.map { it.toInternal() }.joinToString(",") { encode(it) })
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(CstmzItmCtlgHandler::class.java)
}
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmNgMdlListResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class CstmzItmNgMdlListHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(CstmzItmCtlgHandler.class);
public String handle(BaseRequest request) {
CstmzItmNgMdlListResponse response = new CstmzItmNgMdlListResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.CstmzItmNgMdlListResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CstmzItmNgMdlListHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = CstmzItmNgMdlListResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(CstmzItmCtlgHandler::class.java)
}
}

View File

@ -1,51 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.gamedata.FestaRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.collection.FestaCollection;
import icu.samnyan.aqua.sega.diva.model.gamedata.Festa;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.FestaInfoResponse;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class FestaInfoHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(FestaInfoHandler.class);
private final FestaRepository festaRepository;
public String handle(BaseRequest request) {
List<Festa> festaList = festaRepository.findTop2ByEnableOrderByCreateDateDesc(true);
FestaCollection collection = new FestaCollection(festaList);
FestaInfoResponse response = new FestaInfoResponse(
request.getCmd(),
request.getReq_id(),
"ok",
collection.getIds(),
collection.getNames(),
collection.getKinds(),
collection.getDiffs(),
collection.getPvIds(),
collection.getAttr(),
collection.getAddVps(),
collection.getVpMultipliers(),
collection.getStarts(),
collection.getEnds(),
collection.getLastUpdateTime()
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,47 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.gamedata.FestaRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.collection.FestaCollection
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.FestaInfoResponse
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class FestaInfoHandler(private val festaRepository: FestaRepository) : BaseHandler() {
fun handle(request: BaseRequest): Any {
val festaList = festaRepository.findTop2ByEnableOrderByCreateDateDesc(true)
val collection = FestaCollection(festaList)
val response = FestaInfoResponse(
request.cmd,
request.req_id,
"ok",
collection.ids,
collection.names,
collection.kinds,
collection.diffs,
collection.pvIds,
collection.attr,
collection.addVps,
collection.vpMultipliers,
collection.starts,
collection.ends,
collection.lastUpdateTime
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(FestaInfoHandler::class.java)
}
}

View File

@ -1,28 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class NgWordHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(NgWordHandler.class);
public String handle(BaseRequest request) {
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok");
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,31 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class NgWordHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(NgWordHandler::class.java)
}
}

View File

@ -1,33 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.NvRankingResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class NvRankingHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(NvRankingHandler.class);
public String handle(BaseRequest request) {
NvRankingResponse response = new NvRankingResponse(
request.getCmd(),
request.getReq_id(),
"ok",
null,
null,
null,
null
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.NvRankingResponse
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class NvRankingHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = NvRankingResponse(
request.cmd,
request.req_id,
"ok",
null,
null,
null,
null
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(NvRankingHandler::class.java)
}
}

View File

@ -1,108 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
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.common.collection.PsRankingCollection;
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PsRankingResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class PsRankingHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PsRankingHandler.class);
private final PlayerPvRecordRepository playerPvRecordRepository;
public String handle(PsRankingRequest request) {
Edition edition = Edition.ORIGINAL;
Difficulty difficulty = Difficulty.HARD;
switch (request.getRnk_ps_idx()) {
case 0:
difficulty = Difficulty.HARD;
break;
case 1:
difficulty = Difficulty.EXTREME;
break;
case 2: {
difficulty = Difficulty.EXTREME;
edition = Edition.EXTRA;
break;
}
}
int[] list = request.getRnk_ps_pv_id_lst();
Map<Integer, PsRankingCollection> resultCollections = new LinkedHashMap<>();
for (int i :
list) {
List<PlayerPvRecord> records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(i, edition, difficulty);
resultCollections.put(i, new PsRankingCollection(i, edition, records));
}
List<Integer> pvIds = new LinkedList<>();
List<Integer> edition1 = new LinkedList<>();
List<Integer> edition2 = new LinkedList<>();
List<Integer> edition3 = new LinkedList<>();
List<Integer> score1 = new LinkedList<>();
List<Integer> score2 = new LinkedList<>();
List<Integer> score3 = new LinkedList<>();
List<String> name1 = new LinkedList<>();
List<String> name2 = new LinkedList<>();
List<String> name3 = new LinkedList<>();
resultCollections.forEach((key, obj) -> {
pvIds.add(key);
edition1.add(obj.getFirst().getEdition().getValue());
edition2.add(obj.getSecond().getEdition().getValue());
edition3.add(obj.getThird().getEdition().getValue());
score1.add(obj.getFirst().getMaxScore());
score2.add(obj.getSecond().getMaxScore());
score3.add(obj.getThird().getMaxScore());
name1.add(URIEncoder.encode(obj.getFirst().getPdId() != null ? obj.getFirst().getPdId().getPlayerName() : "xxx"));
name2.add(URIEncoder.encode(obj.getSecond().getPdId() != null ? obj.getSecond().getPdId().getPlayerName() : "xxx"));
name3.add(URIEncoder.encode(obj.getThird().getPdId() != null ? obj.getThird().getPdId().getPlayerName() : "xxx"));
});
PsRankingResponse response = new PsRankingResponse(
request.getCmd(),
request.getReq_id(),
"ok",
LocalDateTime.now(),
LocalDateTime.now(),
request.getRnk_ps_idx(),
pvIds.stream().map(Object::toString).collect(Collectors.joining(",")),
edition1.stream().map(Object::toString).collect(Collectors.joining(",")),
edition2.stream().map(Object::toString).collect(Collectors.joining(",")),
edition3.stream().map(Object::toString).collect(Collectors.joining(",")),
score1.stream().map(Object::toString).collect(Collectors.joining(",")),
score2.stream().map(Object::toString).collect(Collectors.joining(",")),
score3.stream().map(Object::toString).collect(Collectors.joining(",")),
name1.stream().map(Object::toString).collect(Collectors.joining(",")),
name2.stream().map(Object::toString).collect(Collectors.joining(",")),
name3.stream().map(Object::toString).collect(Collectors.joining(","))
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,111 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
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.common.collection.PsRankingCollection
import icu.samnyan.aqua.sega.diva.model.request.databank.PsRankingRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PsRankingResponse
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.*
import java.util.stream.Collectors
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepository) : BaseHandler() {
fun handle(request: PsRankingRequest): Any {
var edition = Edition.ORIGINAL
var difficulty = Difficulty.HARD
when (request.rnk_ps_idx) {
0 -> difficulty = Difficulty.HARD
1 -> difficulty = Difficulty.EXTREME
2 -> {
difficulty = Difficulty.EXTREME
edition = Edition.EXTRA
}
}
val list = request.rnk_ps_pv_id_lst
val resultCollections: MutableMap<Int?, PsRankingCollection?> = LinkedHashMap<Int?, PsRankingCollection?>()
for (i in list) {
val records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(
i,
edition,
difficulty
)
resultCollections.put(i, PsRankingCollection(i, edition, records))
}
val pvIds: MutableList<Int?> = LinkedList<Int?>()
val edition1: MutableList<Int?> = LinkedList<Int?>()
val edition2: MutableList<Int?> = LinkedList<Int?>()
val edition3: MutableList<Int?> = LinkedList<Int?>()
val score1: MutableList<Int?> = LinkedList<Int?>()
val score2: MutableList<Int?> = LinkedList<Int?>()
val score3: MutableList<Int?> = LinkedList<Int?>()
val name1: MutableList<String?> = LinkedList<String?>()
val name2: MutableList<String?> = LinkedList<String?>()
val name3: MutableList<String?> = LinkedList<String?>()
resultCollections.forEach { (key: Int?, obj: PsRankingCollection?) ->
pvIds.add(key)
edition1.add(obj!!.first.edition.value)
edition2.add(obj.second.edition.value)
edition3.add(obj.third.edition.value)
score1.add(obj.first.maxScore)
score2.add(obj.second.maxScore)
score3.add(obj.third.maxScore)
name1.add(
encode(
if (obj.first.pdId != null) obj.first.pdId.playerName else "xxx"
)
)
name2.add(
encode(
if (obj.second.pdId != null) obj.second.pdId.playerName else "xxx"
)
)
name3.add(
encode(
if (obj.third.pdId != null) obj.third.pdId.playerName else "xxx"
)
)
}
val response = PsRankingResponse(
request.cmd,
request.req_id,
"ok",
LocalDateTime.now(),
LocalDateTime.now(),
request.rnk_ps_idx,
pvIds.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition1.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition2.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition3.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score1.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score2.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score3.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
name1.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(",")),
name2.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(",")),
name3.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(","))
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PsRankingHandler::class.java)
}
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdHCtrlResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class PstdHCtrlHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PstdHCtrlHandler.class);
public String handle(BaseRequest request) {
PstdHCtrlResponse response = new PstdHCtrlResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***,***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdHCtrlResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PstdHCtrlHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = PstdHCtrlResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***,***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PstdHCtrlHandler::class.java)
}
}

View File

@ -1,35 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdItemNgLstResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class PstdItemNgLstHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PstdItemNgLstHandler.class);
public String handle(BaseRequest request) {
PstdItemNgLstResponse response = new PstdItemNgLstResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***",
"***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,36 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PstdItemNgLstResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PstdItemNgLstHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = PstdItemNgLstResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***",
"***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PstdItemNgLstHandler::class.java)
}
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PvDefChrLstResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class PvDefChrLstHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PvDefChrLstHandler.class);
public String handle(BaseRequest request) {
PvDefChrLstResponse response = new PvDefChrLstResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PvDefChrLstResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvDefChrLstHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = PvDefChrLstResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PvDefChrLstHandler::class.java)
}
}

View File

@ -1,72 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.gamedata.PvEntryRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
import icu.samnyan.aqua.sega.diva.model.gamedata.PvEntry;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PvListResponse;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class PvListHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(BannerDataHandler.class);
private final PvEntryRepository pvEntryRepository;
private final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public String handle(BaseRequest request) {
StringBuilder sb = new StringBuilder();
List<PvEntry> easyList = pvEntryRepository.findByDifficulty(Difficulty.EASY);
List<PvEntry> normalList = pvEntryRepository.findByDifficulty(Difficulty.NORMAL);
List<PvEntry> hardList = pvEntryRepository.findByDifficulty(Difficulty.HARD);
List<PvEntry> extremeList = pvEntryRepository.findByDifficulty(Difficulty.EXTREME);
sb.append(URIEncoder.encode(difficultyString(easyList))).append(",");
sb.append(URIEncoder.encode(difficultyString(normalList))).append(",");
sb.append(URIEncoder.encode(difficultyString(hardList))).append(",");
sb.append(URIEncoder.encode(difficultyString(extremeList))).append(",");
sb.append("%2A%2A%2A");
PvListResponse response = new PvListResponse(
request.getCmd(),
request.getReq_id(),
"ok",
LocalDateTime.now(),
sb.toString());
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
private String entryString(PvEntry entry) {
return "" + entry.getPvId() + "," +
entry.getVersion() + "," +
entry.getEdition().getValue() + "," +
df.format(entry.getDemoStart()) + "," +
df.format(entry.getDemoEnd()) + "," +
df.format(entry.getPlayableStart()) + "," +
df.format(entry.getPlayableEnd());
}
private String difficultyString(List<PvEntry> list) {
StringBuilder sb = new StringBuilder();
list.forEach(x -> sb.append(URIEncoder.encode(entryString(x))).append(","));
if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
}

View File

@ -0,0 +1,72 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.gamedata.PvEntryRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
import icu.samnyan.aqua.sega.diva.model.gamedata.PvEntry
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PvListResponse
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.function.Consumer
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvListHandler(private val pvEntryRepository: PvEntryRepository) : BaseHandler() {
private val df: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
fun handle(request: BaseRequest): Any {
val sb = StringBuilder()
val easyList = pvEntryRepository.findByDifficulty(Difficulty.EASY)
val normalList = pvEntryRepository.findByDifficulty(Difficulty.NORMAL)
val hardList = pvEntryRepository.findByDifficulty(Difficulty.HARD)
val extremeList = pvEntryRepository.findByDifficulty(Difficulty.EXTREME)
sb.append(encode(difficultyString(easyList))).append(",")
sb.append(encode(difficultyString(normalList))).append(",")
sb.append(encode(difficultyString(hardList))).append(",")
sb.append(encode(difficultyString(extremeList))).append(",")
sb.append("%2A%2A%2A")
val response = PvListResponse(
request.cmd,
request.req_id,
"ok",
LocalDateTime.now(),
sb.toString()
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
private fun entryString(entry: PvEntry): String {
return "" + entry.pvId + "," +
entry.version + "," +
entry.edition.value + "," +
df.format(entry.demoStart) + "," +
df.format(entry.demoEnd) + "," +
df.format(entry.playableStart) + "," +
df.format(entry.playableEnd)
}
private fun difficultyString(list: MutableList<PvEntry?>): String {
val sb = StringBuilder()
list.forEach(Consumer { x: PvEntry? -> sb.append(encode(entryString(x!!))).append(",") })
if (sb.length > 0) sb.deleteCharAt(sb.length - 1)
return sb.toString()
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(BannerDataHandler::class.java)
}
}

View File

@ -1,35 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.PvNgMdlLstResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class PvNgMdlLstHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PvNgMdlLstHandler.class);
public String handle(BaseRequest request) {
PvNgMdlLstResponse response = new PvNgMdlLstResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.PvNgMdlLstResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvNgMdlLstHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = PvNgMdlLstResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PvNgMdlLstHandler::class.java)
}
}

View File

@ -1,36 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.QstInfResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class QstInfHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(QstInfHandler.class);
public String handle(BaseRequest request) {
QstInfResponse response = new QstInfResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
null,
null
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,36 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.QstInfResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class QstInfHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = QstInfResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
null,
null
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(QstInfHandler::class.java)
}
}

View File

@ -1,34 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.RmtWpLstResponse;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
public class RmtWpLstHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(QstInfHandler.class);
public String handle(BaseRequest request) {
RmtWpLstResponse response = new RmtWpLstResponse(
request.getCmd(),
request.getReq_id(),
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,35 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.RmtWpLstResponse
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class RmtWpLstHandler : BaseHandler() {
fun handle(request: BaseRequest): Any {
val response = RmtWpLstResponse(
request.cmd,
request.req_id,
"ok",
DivaDateTimeUtil.getString(LocalDateTime.now()),
"***"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(QstInfHandler::class.java)
}
}

View File

@ -1,44 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.databank;
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaModule;
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest;
import icu.samnyan.aqua.sega.diva.model.response.databank.ShopCatalogResponse;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class ShopCatalogHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(ShopCatalogHandler.class);
private final DivaModuleRepository moduleRepository;
public String handle(BaseRequest request) {
List<DivaModule> moduleList = moduleRepository.findAll();
ShopCatalogResponse response = new ShopCatalogResponse(
request.getCmd(),
request.getReq_id(),
"ok",
LocalDateTime.now(),
URIEncoder.encode(moduleList.stream().map(DivaModule::toInternal).map(URIEncoder::encode)
.collect(Collectors.joining(",")))
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,38 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.ShopCatalogResponse
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ShopCatalogHandler(private val moduleRepository: DivaModuleRepository) : BaseHandler() {
fun handle(request: BaseRequest): Any {
val moduleList = moduleRepository.findAll()
val response = ShopCatalogResponse(
request.cmd,
request.req_id,
"ok",
LocalDateTime.now(),
encode(moduleList.map { it.toInternal() }.joinToString(",") { encode(it) })
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(ShopCatalogHandler::class.java)
}
}

View File

@ -1,84 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaCustomize;
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyCstmzItmRequest;
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyCstmzItmResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class BuyCstmzItmHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(BuyCstmzItmHandler.class);
private final DivaCustomizeRepository divaCustomizeRepository;
private final PlayerProfileService playerProfileService;
private final PlayerCustomizeService playerCustomizeService;
private final GameSessionRepository gameSessionRepository;
public String handle(BuyCstmzItmRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
Optional<DivaCustomize> customizeOptional = divaCustomizeRepository.findById(request.getCstmz_itm_id());
BuyCstmzItmResponse response;
if (customizeOptional.isEmpty()) {
response = new BuyCstmzItmResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
if (session.getVp() < customizeOptional.get().getPrice()) {
response = new BuyCstmzItmResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
playerCustomizeService.buy(profile, request.getCstmz_itm_id());
session.setVp(session.getVp() - customizeOptional.get().getPrice());
gameSessionRepository.save(session);
response = new BuyCstmzItmResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
request.getCstmz_itm_id(),
playerCustomizeService.getModuleHaveString(profile),
session.getVp()
);
}
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,80 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaCustomizeRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyCstmzItmRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyCstmzItmResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BuyCstmzItmHandler(
private val divaCustomizeRepository: DivaCustomizeRepository,
private val playerProfileService: PlayerProfileService,
private val playerCustomizeService: PlayerCustomizeService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
fun handle(request: BuyCstmzItmRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
val customizeOptional = divaCustomizeRepository.findById(request.cstmz_itm_id)
val response: BuyCstmzItmResponse?
if (customizeOptional.isEmpty) {
response = BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
if (session.vp < customizeOptional.get().price) {
response = BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
playerCustomizeService.buy(profile, request.cstmz_itm_id)
session.vp = session.vp - customizeOptional.get().price
gameSessionRepository.save<GameSession?>(session)
response = BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.cstmz_itm_id,
playerCustomizeService.getModuleHaveString(profile),
session.vp
)
}
}
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(BuyCstmzItmHandler::class.java)
}
}

View File

@ -1,85 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.gamedata.DivaModule;
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyModuleRequest;
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyModuleResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class BuyModuleHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(BuyModuleHandler.class);
private final DivaModuleRepository divaModuleRepository;
private final PlayerProfileService playerProfileService;
private final PlayerModuleService playerModuleService;
private final GameSessionRepository gameSessionRepository;
public String handle(BuyModuleRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
Optional<DivaModule> moduleOptional = divaModuleRepository.findById(request.getMdl_id());
BuyModuleResponse response;
if (moduleOptional.isEmpty()) {
response = new BuyModuleResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
if (session.getVp() < moduleOptional.get().getPrice()) {
response = new BuyModuleResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.FAILED
);
} else {
playerModuleService.buy(profile, request.getMdl_id());
session.setVp(session.getVp() - moduleOptional.get().getPrice());
gameSessionRepository.save(session);
response = new BuyModuleResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS,
request.getMdl_id(),
playerModuleService.getModuleHaveString(profile),
session.getVp()
);
}
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,80 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.gamedata.DivaModuleRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyModuleRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyModuleResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BuyModuleHandler(
private val divaModuleRepository: DivaModuleRepository,
private val playerProfileService: PlayerProfileService,
private val playerModuleService: PlayerModuleService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
fun handle(request: BuyModuleRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
val moduleOptional = divaModuleRepository.findById(request.mdl_id)
val response: BuyModuleResponse?
if (moduleOptional.isEmpty) {
response = BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
if (session.vp < moduleOptional.get().price) {
response = BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
playerModuleService.buy(profile, request.mdl_id)
session.vp = session.vp - moduleOptional.get().price
gameSessionRepository.save<GameSession?>(session)
response = BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.mdl_id,
playerModuleService.getModuleHaveString(profile),
session.vp
)
}
}
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(BuyModuleHandler::class.java)
}
}

View File

@ -1,125 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
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.request.ingame.GetPvPdRequest;
import icu.samnyan.aqua.sega.diva.model.response.ingame.GetPvPdResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil;
import icu.samnyan.aqua.sega.diva.util.URIEncoder;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Optional;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class GetPvPdHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(GetPvPdHandler.class);
private final PlayerPvRecordRepository pvRecordRepository;
private final PlayerPvCustomizeRepository pvCustomizeRepository;
private final PlayerProfileService playerProfileService;
public String handle(GetPvPdRequest request) {
Optional<PlayerProfile> profileO = playerProfileService.findByPdId(request.getPd_id());
StringBuilder pd = new StringBuilder();
for (int pvId :
request.getPd_pv_id_lst()) {
if (pvId == -1) {
pd.append("***").append(",");
} else {
if (profileO.isEmpty()) {
pd.append("***").append(",");
} else {
var profile = profileO.get();
int diff = request.getDifficulty();
Difficulty difficulty = Difficulty.fromValue(diff);
// Myself
PlayerPvRecord edition0 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, pvId, Edition.ORIGINAL, difficulty)
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.ORIGINAL));
PlayerPvRecord edition1 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, pvId, Edition.EXTRA, difficulty)
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.EXTRA));
// Rival
PlayerPvRecord rivalEdition0;
PlayerPvRecord rivalEdition1;
if (profile.getRivalPdId() != -1) {
rivalEdition0 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(profile.getRivalPdId(), pvId, Edition.ORIGINAL, difficulty)
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.ORIGINAL));
rivalEdition1 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(profile.getRivalPdId(), pvId, Edition.EXTRA, difficulty)
.orElseGet(() -> new PlayerPvRecord(pvId, Edition.EXTRA));
} else {
rivalEdition0 = new PlayerPvRecord(pvId, Edition.ORIGINAL);
rivalEdition1 = new PlayerPvRecord(pvId, Edition.EXTRA);
}
PlayerPvCustomize customize = pvCustomizeRepository.findByPdIdAndPvId(profile, pvId).orElseGet(() -> new PlayerPvCustomize(profile, pvId));
String str = getString(edition0, customize, rivalEdition0, profile.getRivalPdId()) + "," + getString(edition1, customize, rivalEdition1, profile.getRivalPdId());
// logger.info(str);
pd.append(URIEncoder.encode(str)).append(",");
}
}
}
pd.deleteCharAt(pd.length() - 1);
GetPvPdResponse response = new GetPvPdResponse(
request.getCmd(),
request.getReq_id(),
"ok",
pd.toString(),
false,
DivaDateTimeUtil.getString(LocalDateTime.now())
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
private String getString(PlayerPvRecord record, PlayerPvCustomize customize, PlayerPvRecord rivalRecord, long rivalId) {
return record.getPvId() + "," +
record.getEdition().getValue() + "," +
record.getResult().getValue() + "," +
record.getMaxScore() + "," +
record.getMaxAttain() + "," +
record.getChallengeKind().getValue() + "," +
customize.getModule() + "," +
customize.getCustomize() + "," +
customize.getCustomizeFlag() + "," +
customize.getSkin() + "," +
customize.getButtonSe() + "," +
customize.getSlideSe() + "," +
customize.getChainSlideSe() + "," +
customize.getSliderTouchSe() + "," +
rivalId + "," +
rivalRecord.getMaxScore() + "," +
rivalRecord.getMaxAttain() + "," +
"-1,-1," +
pvRecordRepository.rankByPvIdAndPdIdAndEditionAndDifficulty(record.getPvId(), record.getPdId(), record.getEdition(), record.getDifficulty()) + "," +
record.getRgoPurchased() + "," +
record.getRgoPlayed();
}
}

View File

@ -0,0 +1,156 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
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.request.ingame.GetPvPdRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.GetPvPdResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class GetPvPdHandler(
private val pvRecordRepository: PlayerPvRecordRepository,
private val pvCustomizeRepository: PlayerPvCustomizeRepository,
private val playerProfileService: PlayerProfileService
) : BaseHandler() {
fun handle(request: GetPvPdRequest): Any {
val profileO = playerProfileService.findByPdId(request.pd_id)
val pd = StringBuilder()
for (pvId in request.pd_pv_id_lst) {
if (pvId == -1) {
pd.append("***").append(",")
} else {
if (profileO.isEmpty) {
pd.append("***").append(",")
} else {
val profile = profileO.get()
val diff = request.difficulty
val difficulty = Difficulty.fromValue(diff)
// Myself
val edition0 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
pvId,
Edition.ORIGINAL,
difficulty
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
val edition1 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
pvId,
Edition.EXTRA,
difficulty
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.EXTRA) })
// Rival
val rivalEdition0: PlayerPvRecord?
val rivalEdition1: PlayerPvRecord?
if (profile.rivalPdId != -1L) {
rivalEdition0 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
profile.rivalPdId,
pvId,
Edition.ORIGINAL,
difficulty
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
rivalEdition1 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
profile.rivalPdId,
pvId,
Edition.EXTRA,
difficulty
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.EXTRA) })
} else {
rivalEdition0 = PlayerPvRecord(pvId, Edition.ORIGINAL)
rivalEdition1 = PlayerPvRecord(pvId, Edition.EXTRA)
}
val customize = pvCustomizeRepository.findByPdIdAndPvId(profile, pvId)
.orElseGet(Supplier { PlayerPvCustomize(profile, pvId) })
val str = getString(
edition0,
customize,
rivalEdition0,
profile.rivalPdId
) + "," + getString(edition1, customize, rivalEdition1, profile.rivalPdId)
// logger.info(str);
pd.append(encode(str)).append(",")
}
}
}
pd.deleteCharAt(pd.length - 1)
val response = GetPvPdResponse(
request.cmd,
request.req_id,
"ok",
pd.toString(),
false,
DivaDateTimeUtil.getString(LocalDateTime.now())
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
private fun getString(
record: PlayerPvRecord,
customize: PlayerPvCustomize,
rivalRecord: PlayerPvRecord,
rivalId: Long
): String {
return record.pvId.toString() + "," +
record.edition.value + "," +
record.result.value + "," +
record.maxScore + "," +
record.maxAttain + "," +
record.challengeKind.value + "," +
customize.module + "," +
customize.customize + "," +
customize.customizeFlag + "," +
customize.skin + "," +
customize.buttonSe + "," +
customize.slideSe + "," +
customize.chainSlideSe + "," +
customize.sliderTouchSe + "," +
rivalId + "," +
rivalRecord.maxScore + "," +
rivalRecord.maxAttain + "," +
"-1,-1," +
pvRecordRepository.rankByPvIdAndPdIdAndEditionAndDifficulty(
record.pvId,
record.pdId,
record.edition,
record.difficulty
) + "," +
record.rgoPurchased + "," +
record.rgoPlayed
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(GetPvPdHandler::class.java)
}
}

View File

@ -1,62 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.request.ingame.ShopExitRequest;
import icu.samnyan.aqua.sega.diva.model.response.ingame.ShopExitResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import static icu.samnyan.aqua.sega.diva.util.DivaStringUtils.arrToCsv;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class ShopExitHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(ShopExitHandler.class);
private final PlayerProfileService playerProfileService;
private final PlayerPvCustomizeRepository pvCustomizeRepository;
public String handle(ShopExitRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
PlayerPvCustomize customize = pvCustomizeRepository.findByPdIdAndPvId(profile, request.getPly_pv_id()).orElseGet(() -> new PlayerPvCustomize(profile, request.getPly_pv_id()));
if (request.getUse_pv_mdl_eqp() == 1) {
customize.setModule(arrToCsv(request.getMdl_eqp_pv_ary()));
customize.setCustomize(arrToCsv(request.getC_itm_eqp_pv_ary()));
customize.setCustomizeFlag(arrToCsv(request.getMs_itm_flg_pv_ary()));
} else {
customize.setModule("-1,-1,-1");
customize.setCustomize("-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
customize.setCustomizeFlag("1,1,1,1,1,1,1,1,1,1,1,1");
}
profile.setCommonModule(arrToCsv(request.getMdl_eqp_cmn_ary()));
profile.setCommonCustomizeItems(arrToCsv(request.getC_itm_eqp_cmn_ary()));
profile.setModuleSelectItemFlag(arrToCsv(request.getMs_itm_flg_cmn_ary()));
playerProfileService.save(profile);
pvCustomizeRepository.save(customize);
ShopExitResponse response = new ShopExitResponse(
request.getCmd(),
request.getReq_id(),
"ok",
Result.SUCCESS
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,63 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvCustomizeRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.ShopExitRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.ShopExitResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaStringUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ShopExitHandler(
private val playerProfileService: PlayerProfileService,
private val pvCustomizeRepository: PlayerPvCustomizeRepository
) : BaseHandler() {
fun handle(request: ShopExitRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val customize = pvCustomizeRepository.findByPdIdAndPvId(profile, request.ply_pv_id)
.orElseGet(Supplier { PlayerPvCustomize(profile, request.ply_pv_id) })
if (request.use_pv_mdl_eqp == 1) {
customize.module = DivaStringUtils.arrToCsv(request.mdl_eqp_pv_ary)
customize.customize = DivaStringUtils.arrToCsv(request.c_itm_eqp_pv_ary)
customize.customizeFlag = DivaStringUtils.arrToCsv(request.ms_itm_flg_pv_ary)
} else {
customize.module = "-1,-1,-1"
customize.customize = "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"
customize.customizeFlag = "1,1,1,1,1,1,1,1,1,1,1,1"
}
profile.commonModule = DivaStringUtils.arrToCsv(request.mdl_eqp_cmn_ary)
profile.commonCustomizeItems = DivaStringUtils.arrToCsv(request.c_itm_eqp_cmn_ary)
profile.moduleSelectItemFlag = DivaStringUtils.arrToCsv(request.ms_itm_flg_cmn_ary)
playerProfileService.save(profile)
pvCustomizeRepository.save<PlayerPvCustomize?>(customize)
val response = ShopExitResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(ShopExitHandler::class.java)
}
}

View File

@ -1,403 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.*;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.*;
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest;
import icu.samnyan.aqua.sega.diva.model.response.ingame.StageResultResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.*;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import icu.samnyan.aqua.sega.diva.util.DivaCalculator;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.*;
import static icu.samnyan.aqua.sega.diva.model.common.Const.NULL_QUEST;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@RequiredArgsConstructor
public class StageResultHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(StageResultHandler.class);
private final GameSessionRepository gameSessionRepository;
private final PlayerPvRecordRepository pvRecordRepository;
private final PlayerProfileService playerProfileService;
private final PlayLogRepository playLogRepository;
private final ContestRepository contestRepository;
private final PlayerContestRepository playerContestRepository;
private final PlayerCustomizeRepository playerCustomizeRepository;
private final PlayerInventoryRepository playerInventoryRepository;
private final DivaCalculator divaCalculator;
private PlayerProfile currentProfile = null;
public String handle(StageResultRequest request) {
StageResultResponse response;
if (request.getPd_id() != -1) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
currentProfile = profile;
// Get the last played index
int[] pvIds = request.getStg_ply_pv_id();
int[] stageArr = request.getStg_ply_pv_id();
int stageIndex = 0;
if (stageArr[0] != -1) {
stageIndex = 0;
}
if (stageArr[1] != -1) {
stageIndex = 1;
}
if (stageArr[2] != -1) {
stageIndex = 2;
}
if (stageArr[3] != -1) {
stageIndex = 3;
}
// Convert to play log object
PlayLog log = getLog(request, profile, stageIndex);
logger.debug("Stage Result Object: {}", log.toString());
PlayerPvRecord record = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(profile, log.getPvId(), log.getEdition(), log.getDifficulty())
.orElseGet(() -> new PlayerPvRecord(profile, log.getPvId(), log.getEdition(), log.getDifficulty()));
// Not save personal record in no fail mode
if (request.getGame_type() != 1) {
// Only update personal record when using rhythm game option
if (log.getRhythmGameOptions().equals("0,0,0")) {
// Update pvRecord field
record.setMaxScore(Math.max(record.getMaxScore(), log.getScore()));
record.setMaxAttain(Math.max(record.getMaxAttain(), log.getAttainPoint()));
if (record.getResult().getValue() < log.getClearResult().getValue()) {
record.setResult(log.getClearResult());
}
}
}
String[] updateRgo = log.getRhythmGameOptions().split(",");
String[] oldRgo = record.getRgoPlayed().split(",");
for (int i = 0; i < updateRgo.length; i++) {
if (updateRgo[i].equals("1")) {
oldRgo[i] = "1";
}
}
record.setRgoPlayed(StringUtils.join(oldRgo, ","));
session.setVp(session.getVp() + log.getVp());
session.setLastPvId(log.getPvId());
session.setLastUpdateTime(LocalDateTime.now());
LevelInfo levelInfo = divaCalculator.getLevelInfo(profile);
session.setOldLevelNumber(session.getLevelNumber());
session.setOldLevelExp(session.getLevelExp());
session.setLevelNumber(levelInfo.getLevelNumber());
session.setLevelExp(levelInfo.getLevelExp());
session.setStageResultIndex(stageIndex);
// Calculate reward
// Contest reward
String contestSpecifier = String.join(",", request.getCr_sp());
String[] contestRewardType = {"-1", "-1", "-1"};
String[] contestRewardValue = {"-1", "-1", "-1"};
String[] contestRewardString1 = {"***", "***", "***"};
String[] contestRewardString2 = {"***", "***", "***"};
int contestEntryRewardType = -1;
int contestEntryRewardValue = -1;
String contestEntryRewardString1 = "***";
String contestEntryRewardString2 = "***";
int contestId = request.getCr_cid();
if (contestId != -1) {
List<ContestProgress> progress = getContestProgress(request.getCr_sp());
contestSpecifier = getContestSpecifier(progress);
// Check if the contest info exist
Optional<Contest> contestOptional = contestRepository.findById(contestId);
if (contestOptional.isPresent()) {
Contest contest = contestOptional.get();
Optional<PlayerContest> playerContestOptional = playerContestRepository.findByPdIdAndContestId(profile, contestId);
// Contest Entry Reward
// Check if this is first stage
if (progress.size() == 1 && playerContestOptional.isEmpty()) {
if (StringUtils.isNotBlank(contest.getContestEntryReward())) {
// Check if this is first time play this contest
String reward = contest.getContestEntryReward();
String[] rewardValue = reward.split(":");
contestEntryRewardType = Integer.parseInt(rewardValue[0]);
contestEntryRewardValue = Integer.parseInt(rewardValue[1]);
contestEntryRewardString1 = rewardValue[2];
contestEntryRewardString2 = rewardValue[3];
}
}
// Only if this is the first time reach this value
int previousValue = progress.stream().limit(progress.size() - 1).mapToInt(ContestProgress::getScores).sum();
int currentValue = progress.stream().mapToInt(ContestProgress::getScores).sum();
// Bronze Reward
Map<String, String> bronze = updateReward(currentValue, previousValue, contest.getBronzeBorders(), contest.getBronzeContestReward());
if (bronze != null) {
contestRewardType[0] = bronze.get("type");
contestRewardValue[0] = bronze.get("value");
contestRewardString1[0] = bronze.get("string1");
contestRewardString2[2] = bronze.get("string2");
}
// Silver Reward
Map<String, String> silver = updateReward(currentValue, previousValue, contest.getSliverBorders(), contest.getSliverContestReward());
if (silver != null) {
contestRewardType[1] = silver.get("type");
contestRewardValue[1] = silver.get("value");
contestRewardString1[1] = silver.get("string1");
contestRewardString2[2] = silver.get("string2");
}
// Gold Reward
Map<String, String> gold = updateReward(currentValue, previousValue, contest.getGoldBorders(), contest.getGoldContestReward());
if (gold != null) {
contestRewardType[2] = gold.get("type");
contestRewardValue[2] = gold.get("value");
contestRewardString1[2] = gold.get("string1");
contestRewardString2[2] = gold.get("string2");
}
}
}
pvRecordRepository.save(record);
playLogRepository.save(log);
gameSessionRepository.save(session);
response = new StageResultResponse(
request.getCmd(),
request.getReq_id(),
"ok",
ChallengeKind.UNDEFINED.getValue(),
session.getOldLevelNumber(),
session.getOldLevelExp(),
session.getLevelNumber(),
session.getLevelExp(),
profile.getLevelTitle(),
profile.getPlateEffectId(),
profile.getPlateId(),
session.getVp(),
0,
request.getCr_cid(),
request.getCr_tv(),
contestSpecifier,
String.join(",", contestRewardType),
String.join(",", contestRewardValue),
String.join(",", contestRewardString1),
String.join(",", contestRewardString2),
contestEntryRewardType,
contestEntryRewardValue,
contestEntryRewardString1,
contestEntryRewardString2,
"xxx,xxx,xxx,xxx,xxx",
"-1,-1,-1,-1,-1",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
0,
LocalDateTime.now(),
-1,
-1,
0,
0,
0,
-1,
NULL_QUEST,
NULL_QUEST,
NULL_QUEST,
NULL_QUEST,
NULL_QUEST,
"-1,-1,-1,-1,-1",
"-1,-1,-1,-1,-1",
"-1,-1,-1,-1,-1"
);
} else {
response = new StageResultResponse(
request.getCmd(),
request.getReq_id(),
"ok"
);
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
private PlayLog getLog(StageResultRequest request, PlayerProfile profile, int i) {
return new PlayLog(
profile,
request.getStg_ply_pv_id()[i],
Difficulty.fromValue(request.getStg_difficulty()[i]),
Edition.fromValue(request.getStg_edtn()[i]),
request.getStg_scrpt_ver()[i],
request.getStg_score()[i],
ChallengeKind.fromValue(request.getStg_chllng_kind()[i]),
request.getStg_chllng_result()[i],
ClearResult.fromValue(request.getStg_clr_kind()[i]),
request.getStg_vcld_pts()[i],
request.getStg_cool_cnt()[i],
request.getStg_cool_pct()[i],
request.getStg_fine_cnt()[i],
request.getStg_fine_pct()[i],
request.getStg_safe_cnt()[i],
request.getStg_safe_pct()[i],
request.getStg_sad_cnt()[i],
request.getStg_sad_pct()[i],
request.getStg_wt_wg_cnt()[i],
request.getStg_wt_wg_pct()[i],
request.getStg_max_cmb()[i],
request.getStg_chance_tm()[i],
request.getStg_sm_hl()[i],
request.getStg_atn_pnt()[i],
request.getStg_skin_id()[i],
request.getStg_btn_se()[i],
request.getStg_btn_se_vol()[i],
request.getStg_sld_se()[i],
request.getStg_chn_sld_se()[i],
request.getStg_sldr_tch_se()[i],
slice(request.getStg_mdl_id(), 3, i),
request.getStg_cpt_rslt()[i],
request.getStg_sld_scr()[i],
request.getStg_vcl_chg()[i],
slice(request.getStg_c_itm_id(), 12, i),
slice(request.getStg_rgo(), 3, i),
request.getStg_ss_num()[i],
request.getTime_stamp().toLocalDateTime()
);
}
public String slice(int[] arr, int length, int offset) {
StringBuilder sb = new StringBuilder();
for (int i = length * offset; i < length * (offset + 1); i++) {
sb.append(arr[i]).append(",");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
private List<ContestProgress> getContestProgress(String[] arr) {
List<ContestProgress> result = new LinkedList<>();
for (int i = 0; i < arr.length; i = i + 6) {
if (!arr[i].equals("-1")) {
result.add(new ContestProgress(
Integer.parseInt(arr[i]),
Integer.parseInt(arr[i + 1]),
Integer.parseInt(arr[i + 2]),
Integer.parseInt(arr[i + 3]),
Integer.parseInt(arr[i + 4]),
Integer.parseInt(arr[i + 5])
));
}
}
return result;
}
private String getContestSpecifier(List<ContestProgress> progresses) {
List<String> result = new LinkedList<>();
for (ContestProgress x : progresses) {
result.add(String.valueOf(x.getHardness()));
result.add(String.valueOf(x.getEdition()));
result.add(String.valueOf(x.getStars()));
result.add(String.valueOf(x.getScores()));
result.add(String.valueOf(x.getVersion()));
}
while (result.size() < 60) {
result.add("-1");
}
return String.join(",", result);
}
private Map<String, String> updateReward(int currentValue, int previousValue, int borders, String reward) {
if (currentValue > borders && previousValue < borders) {
if (StringUtils.isNotBlank(reward)) {
String[] rewardValue = reward.split(":");
Map<String, String> result = new HashMap<>();
switch (rewardValue[0]) {
case "-1":
return null;
case "0": {
result.put("type", rewardValue[0]);
result.put("value", rewardValue[1]);
result.put("string1", "***");
result.put("string2", "***");
break;
}
case "1": {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "SKIN", rewardValue[1]).isPresent()) {
result.put("type", "-1");
result.put("value", "-1");
result.put("string1", "***");
result.put("string2", "***");
} else {
playerInventoryRepository.save(new PlayerInventory(null, currentProfile, rewardValue[1], "SKIN"));
result.put("type", rewardValue[0]);
result.put("value", rewardValue[1]);
result.put("string1", rewardValue[2]);
result.put("string2", rewardValue[3]);
}
break;
}
case "2": {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "PLATE", rewardValue[1]).isPresent()) {
result.put("type", "-1");
result.put("value", "-1");
result.put("string1", "***");
result.put("string2", "***");
} else {
playerInventoryRepository.save(new PlayerInventory(null, currentProfile, rewardValue[1], "PLATE"));
result.put("type", rewardValue[0]);
result.put("value", rewardValue[1]);
result.put("string1", rewardValue[2]);
result.put("string2", rewardValue[3]);
}
break;
}
case "3": {
if (playerCustomizeRepository.findByPdIdAndCustomizeId(currentProfile, Integer.parseInt(rewardValue[1])).isPresent()) {
result.put("type", "-1");
result.put("value", "-1");
result.put("string1", "***");
result.put("string2", "***");
} else {
playerCustomizeRepository.save(new PlayerCustomize(currentProfile, Integer.parseInt(rewardValue[1])));
result.put("type", rewardValue[0]);
result.put("value", rewardValue[1]);
result.put("string1", rewardValue[2]);
result.put("string2", rewardValue[3]);
}
break;
}
}
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,465 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.*
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.*
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.StageResultResponse
import icu.samnyan.aqua.sega.diva.model.userdata.*
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaCalculator
import org.apache.commons.lang3.StringUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.lang.String
import java.time.LocalDateTime
import java.util.*
import java.util.function.Supplier
import kotlin.Any
import kotlin.Array
import kotlin.Int
import kotlin.IntArray
import kotlin.arrayOf
import kotlin.math.max
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StageResultHandler(
private val gameSessionRepository: GameSessionRepository,
private val pvRecordRepository: PlayerPvRecordRepository,
private val playerProfileService: PlayerProfileService,
private val playLogRepository: PlayLogRepository,
private val contestRepository: ContestRepository,
private val playerContestRepository: PlayerContestRepository,
private val playerCustomizeRepository: PlayerCustomizeRepository,
private val playerInventoryRepository: PlayerInventoryRepository,
private val divaCalculator: DivaCalculator
) : BaseHandler() {
private var currentProfile: PlayerProfile? = null
fun handle(request: StageResultRequest): Any {
val response: StageResultResponse?
if (request.getPd_id() != -1L) {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
currentProfile = profile
// Get the last played index
request.getStg_ply_pv_id()
val stageArr = request.getStg_ply_pv_id()
var stageIndex = 0
if (stageArr[0] != -1) {
stageIndex = 0
}
if (stageArr[1] != -1) {
stageIndex = 1
}
if (stageArr[2] != -1) {
stageIndex = 2
}
if (stageArr[3] != -1) {
stageIndex = 3
}
// Convert to play log object
val log = getLog(request, profile, stageIndex)
logger.debug("Stage Result Object: {}", log.toString())
val record = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
log.pvId,
log.edition,
log.difficulty
)
.orElseGet(Supplier { PlayerPvRecord(profile, log.pvId, log.edition, log.difficulty) })
// Not save personal record in no fail mode
if (request.getGame_type() != 1) {
// Only update personal record when using rhythm game option
if (log.rhythmGameOptions == "0,0,0") {
// Update pvRecord field
record.maxScore = max(record.maxScore, log.score)
record.maxAttain = max(record.maxAttain, log.attainPoint)
if (record.result.value < log.clearResult.value) {
record.result = log.clearResult
}
}
}
val updateRgo =
log.rhythmGameOptions.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val oldRgo =
record.rgoPlayed.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in updateRgo.indices) {
if (updateRgo[i] == "1") {
oldRgo[i] = "1"
}
}
record.rgoPlayed = StringUtils.join(oldRgo, ",")
session.vp = session.vp + log.vp
session.lastPvId = log.pvId
session.lastUpdateTime = LocalDateTime.now()
val levelInfo = divaCalculator.getLevelInfo(profile)
session.oldLevelNumber = session.levelNumber
session.oldLevelExp = session.levelExp
session.levelNumber = levelInfo.levelNumber
session.levelExp = levelInfo.levelExp
session.stageResultIndex = stageIndex
// Calculate reward
// Contest reward
var contestSpecifier = String.join(",", *request.getCr_sp())
val contestRewardType = arrayOf<kotlin.String?>("-1", "-1", "-1")
val contestRewardValue = arrayOf<kotlin.String?>("-1", "-1", "-1")
val contestRewardString1 = arrayOf<kotlin.String?>("***", "***", "***")
val contestRewardString2 = arrayOf<kotlin.String?>("***", "***", "***")
var contestEntryRewardType = -1
var contestEntryRewardValue = -1
var contestEntryRewardString1: kotlin.String? = "***"
var contestEntryRewardString2: kotlin.String? = "***"
val contestId = request.getCr_cid()
if (contestId != -1) {
val progress = getContestProgress(request.getCr_sp())
contestSpecifier = getContestSpecifier(progress)
// Check if the contest info exist
val contestOptional = contestRepository.findById(contestId)
if (contestOptional.isPresent) {
val contest = contestOptional.get()
val playerContestOptional = playerContestRepository.findByPdIdAndContestId(profile, contestId)
// Contest Entry Reward
// Check if this is first stage
if (progress.size == 1 && playerContestOptional.isEmpty) {
if (StringUtils.isNotBlank(contest.contestEntryReward)) {
// Check if this is first time play this contest
val reward = contest.contestEntryReward
val rewardValue: Array<kotlin.String?> =
reward.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
contestEntryRewardType = rewardValue[0]!!.toInt()
contestEntryRewardValue = rewardValue[1]!!.toInt()
contestEntryRewardString1 = rewardValue[2]
contestEntryRewardString2 = rewardValue[3]
}
}
// Only if this is the first time reach this value
val previousValue = progress.stream().limit((progress.size - 1).toLong())
.mapToInt { obj: ContestProgress? -> obj!!.getScores() }.sum()
val currentValue = progress.stream().mapToInt { obj: ContestProgress? -> obj!!.getScores() }.sum()
// Bronze Reward
val bronze = updateReward(
currentValue,
previousValue,
contest.bronzeBorders,
contest.bronzeContestReward
)
if (bronze != null) {
contestRewardType[0] = bronze.get("type")
contestRewardValue[0] = bronze.get("value")
contestRewardString1[0] = bronze.get("string1")
contestRewardString2[2] = bronze.get("string2")
}
// Silver Reward
val silver = updateReward(
currentValue,
previousValue,
contest.sliverBorders,
contest.sliverContestReward
)
if (silver != null) {
contestRewardType[1] = silver.get("type")
contestRewardValue[1] = silver.get("value")
contestRewardString1[1] = silver.get("string1")
contestRewardString2[2] = silver.get("string2")
}
// Gold Reward
val gold = updateReward(
currentValue,
previousValue,
contest.goldBorders,
contest.goldContestReward
)
if (gold != null) {
contestRewardType[2] = gold.get("type")
contestRewardValue[2] = gold.get("value")
contestRewardString1[2] = gold.get("string1")
contestRewardString2[2] = gold.get("string2")
}
}
}
pvRecordRepository.save<PlayerPvRecord?>(record)
playLogRepository.save<PlayLog?>(log)
gameSessionRepository.save<GameSession?>(session)
response = StageResultResponse(
request.cmd,
request.req_id,
"ok",
ChallengeKind.UNDEFINED.value,
session.oldLevelNumber,
session.oldLevelExp,
session.levelNumber,
session.levelExp,
profile.levelTitle,
profile.plateEffectId,
profile.plateId,
session.vp,
0,
request.getCr_cid(),
request.getCr_tv(),
contestSpecifier,
String.join(",", *contestRewardType),
String.join(",", *contestRewardValue),
String.join(",", *contestRewardString1),
String.join(",", *contestRewardString2),
contestEntryRewardType,
contestEntryRewardValue,
contestEntryRewardString1,
contestEntryRewardString2,
"xxx,xxx,xxx,xxx,xxx",
"-1,-1,-1,-1,-1",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
"xxx,xxx,xxx,xxx,xxx",
0,
LocalDateTime.now(),
-1,
-1,
0,
0,
0,
-1,
Const.NULL_QUEST,
Const.NULL_QUEST,
Const.NULL_QUEST,
Const.NULL_QUEST,
Const.NULL_QUEST,
"-1,-1,-1,-1,-1",
"-1,-1,-1,-1,-1",
"-1,-1,-1,-1,-1"
)
} else {
response = StageResultResponse(
request.cmd,
request.req_id,
"ok"
)
}
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
private fun getLog(request: StageResultRequest, profile: PlayerProfile?, i: Int): PlayLog {
return PlayLog(
profile,
request.getStg_ply_pv_id()[i],
Difficulty.fromValue(request.getStg_difficulty()[i]),
Edition.fromValue(request.getStg_edtn()[i]),
request.getStg_scrpt_ver()[i],
request.getStg_score()[i],
ChallengeKind.fromValue(request.getStg_chllng_kind()[i]),
request.getStg_chllng_result()[i],
ClearResult.fromValue(request.getStg_clr_kind()[i]),
request.getStg_vcld_pts()[i],
request.getStg_cool_cnt()[i],
request.getStg_cool_pct()[i],
request.getStg_fine_cnt()[i],
request.getStg_fine_pct()[i],
request.getStg_safe_cnt()[i],
request.getStg_safe_pct()[i],
request.getStg_sad_cnt()[i],
request.getStg_sad_pct()[i],
request.getStg_wt_wg_cnt()[i],
request.getStg_wt_wg_pct()[i],
request.getStg_max_cmb()[i],
request.getStg_chance_tm()[i],
request.getStg_sm_hl()[i],
request.getStg_atn_pnt()[i],
request.getStg_skin_id()[i],
request.getStg_btn_se()[i],
request.getStg_btn_se_vol()[i],
request.getStg_sld_se()[i],
request.getStg_chn_sld_se()[i],
request.getStg_sldr_tch_se()[i],
slice(request.getStg_mdl_id(), 3, i),
request.getStg_cpt_rslt()[i],
request.getStg_sld_scr()[i],
request.getStg_vcl_chg()[i],
slice(request.getStg_c_itm_id(), 12, i),
slice(request.getStg_rgo(), 3, i),
request.getStg_ss_num()[i],
request.time_stamp.toLocalDateTime()
)
}
fun slice(arr: IntArray, length: Int, offset: Int): kotlin.String {
val sb = StringBuilder()
for (i in length * offset..<length * (offset + 1)) {
sb.append(arr[i]).append(",")
}
sb.deleteCharAt(sb.length - 1)
return sb.toString()
}
private fun getContestProgress(arr: Array<kotlin.String?>): MutableList<ContestProgress> {
val result: MutableList<ContestProgress> = LinkedList<ContestProgress>()
var i = 0
while (i < arr.size) {
if (arr[i] != "-1") {
result.add(
ContestProgress(
arr[i]!!.toInt(),
arr[i + 1]!!.toInt(),
arr[i + 2]!!.toInt(),
arr[i + 3]!!.toInt(),
arr[i + 4]!!.toInt(),
arr[i + 5]!!.toInt()
)
)
}
i = i + 6
}
return result
}
private fun getContestSpecifier(progresses: MutableList<ContestProgress>): kotlin.String {
val result: MutableList<kotlin.String?> = LinkedList<kotlin.String?>()
for (x in progresses) {
result.add(x.getHardness().toString())
result.add(x.getEdition().toString())
result.add(x.getStars().toString())
result.add(x.getScores().toString())
result.add(x.getVersion().toString())
}
while (result.size < 60) {
result.add("-1")
}
return String.join(",", result)
}
private fun updateReward(
currentValue: Int,
previousValue: Int,
borders: Int,
reward: kotlin.String?
): MutableMap<kotlin.String?, kotlin.String?>? {
if (currentValue > borders && previousValue < borders) {
if (StringUtils.isNotBlank(reward)) {
val rewardValue: Array<kotlin.String?> =
reward!!.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val result: MutableMap<kotlin.String?, kotlin.String?> = HashMap<kotlin.String?, kotlin.String?>()
when (rewardValue[0]) {
"-1" -> return null
"0" -> {
result.put("type", rewardValue[0])
result.put("value", rewardValue[1])
result.put("string1", "***")
result.put("string2", "***")
}
"1" -> {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "SKIN", rewardValue[1])
.isPresent
) {
result.put("type", "-1")
result.put("value", "-1")
result.put("string1", "***")
result.put("string2", "***")
} else {
playerInventoryRepository.save<PlayerInventory?>(
PlayerInventory(
null,
currentProfile,
rewardValue[1],
"SKIN"
)
)
result.put("type", rewardValue[0])
result.put("value", rewardValue[1])
result.put("string1", rewardValue[2])
result.put("string2", rewardValue[3])
}
}
"2" -> {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile, "PLATE", rewardValue[1])
.isPresent
) {
result.put("type", "-1")
result.put("value", "-1")
result.put("string1", "***")
result.put("string2", "***")
} else {
playerInventoryRepository.save<PlayerInventory?>(
PlayerInventory(
null,
currentProfile,
rewardValue[1],
"PLATE"
)
)
result.put("type", rewardValue[0])
result.put("value", rewardValue[1])
result.put("string1", rewardValue[2])
result.put("string2", rewardValue[3])
}
}
"3" -> {
if (playerCustomizeRepository.findByPdIdAndCustomizeId(currentProfile, rewardValue[1]!!.toInt())
.isPresent
) {
result.put("type", "-1")
result.put("value", "-1")
result.put("string1", "***")
result.put("string2", "***")
} else {
playerCustomizeRepository.save<PlayerCustomize?>(
PlayerCustomize(
currentProfile,
rewardValue[1]!!.toInt()
)
)
result.put("type", rewardValue[0])
result.put("value", rewardValue[1])
result.put("string1", rewardValue[2])
result.put("string2", rewardValue[3])
}
}
}
return result
}
}
return null
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(StageResultHandler::class.java)
}
}

View File

@ -1,60 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageStartRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class StageStartHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(StageResultHandler.class);
private final GameSessionRepository gameSessionRepository;
private final PlayerProfileService playerProfileService;
public String handle(StageStartRequest request) {
if (request.getPd_id() != -1) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
int[] stageArr = request.getStg_ply_pv_id();
int stageIndex = 0;
if(stageArr[0] != -1) {
stageIndex = 0;
}
if(stageArr[1] != -1) {
stageIndex = 1;
}
if(stageArr[2] != -1) {
stageIndex = 2;
}
if(stageArr[3] != -1) {
stageIndex = 3;
}
session.setStageIndex(stageIndex);
gameSessionRepository.save(session);
}
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok");
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,64 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageStartRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StageStartHandler(
private val gameSessionRepository: GameSessionRepository,
private val playerProfileService: PlayerProfileService
) : BaseHandler() {
fun handle(request: StageStartRequest): Any {
if (request.getPd_id() != -1L) {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
val stageArr = request.getStg_ply_pv_id()
var stageIndex = 0
if (stageArr[0] != -1) {
stageIndex = 0
}
if (stageArr[1] != -1) {
stageIndex = 1
}
if (stageArr[2] != -1) {
stageIndex = 2
}
if (stageArr[3] != -1) {
stageIndex = 3
}
session.stageIndex = stageIndex
gameSessionRepository.save<GameSession?>(session)
}
val response = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(StageResultHandler::class.java)
}
}

View File

@ -1,73 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.ingame;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerScreenShotRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.ingame.StoreSsRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerScreenShot;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import static icu.samnyan.aqua.sega.diva.util.DivaStringUtils.arrToCsv;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class StoreSsHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(StoreSsHandler.class);
private final PlayerProfileService playerProfileService;
private final PlayerScreenShotRepository screenShotRepository;
public String handle(StoreSsRequest request, MultipartFile file) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
BaseResponse response;
try {
String filename = request.getPd_id() + "-" + LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + ".jpg";
Files.write(Paths.get("data/" + filename), file.getBytes());
PlayerScreenShot ss = new PlayerScreenShot(
profile,
filename,
request.getPd_id(),
arrToCsv(request.getSs_mdl_id()),
arrToCsv(request.getSs_c_itm_id())
);
screenShotRepository.save(ss);
response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok");
} catch (IOException e) {
logger.error("Screenshot save failed", e);
response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"0");
}
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,73 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerScreenShotRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.ingame.StoreSsRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerScreenShot
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaStringUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.web.multipart.MultipartFile
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StoreSsHandler(
private val playerProfileService: PlayerProfileService,
private val screenShotRepository: PlayerScreenShotRepository
) : BaseHandler() {
fun handle(request: StoreSsRequest, file: MultipartFile): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
var response: BaseResponse?
try {
val filename =
request.pd_id.toString() + "-" + LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + ".jpg"
Files.write(Paths.get("data/" + filename), file.bytes)
val ss = PlayerScreenShot(
profile,
filename,
request.pd_id,
DivaStringUtils.arrToCsv(request.ss_mdl_id),
DivaStringUtils.arrToCsv(request.ss_c_itm_id)
)
screenShotRepository.save<PlayerScreenShot?>(ss)
response = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
} catch (e: IOException) {
logger.error("Screenshot save failed", e)
response = BaseResponse(
request.cmd,
request.req_id,
"0"
)
}
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(StoreSsHandler::class.java)
}
}

View File

@ -1,35 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.operation
import ext.logger
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.operation.PingResponse
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository
import icu.samnyan.aqua.sega.general.model.PropertyEntry
import org.springframework.stereotype.Component
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PingHandler(val rp: PropertyEntryRepository) : BaseHandler() {
val logger = logger()
fun handle(request: BaseRequest): String? {
val news: PropertyEntry = rp.findByPropertyKey("diva_news") ?: PropertyEntry("diva_news", "xxx")
val warning: PropertyEntry = rp.findByPropertyKey("diva_warning") ?: PropertyEntry("diva_warning", "xxx")
val response = PingResponse(
request.cmd,
request.req_id,
"ok",
news.propertyValue,
warning.propertyValue
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
}

View File

@ -1,111 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.user;
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerContestRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.ContestBorder;
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.common.SortMode;
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest;
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import static icu.samnyan.aqua.sega.diva.util.DivaStringUtils.getDummyString;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class EndHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(EndHandler.class);
private final ContestRepository contestRepository;
private final PlayerProfileService playerProfileService;
private final PlayerContestRepository playerContestRepository;
private final GameSessionRepository gameSessionRepository;
public String handle(StageResultRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
profile.setHeadphoneVolume(request.getHp_vol());
profile.setButtonSeOn(request.isBtn_se_vol());
profile.setButtonSeVolume(request.getBtn_se_vol2());
profile.setSliderSeVolume(request.getSldr_se_vol2());
profile.setVocaloidPoints(session.getVp());
profile.setLevel(session.getLevelNumber());
profile.setLevelExp(session.getLevelExp());
profile.setNextPvId(request.getNxt_pv_id());
profile.setNextDifficulty(Difficulty.fromValue(request.getNxt_dffclty()));
profile.setNextEdition(Edition.fromValue(request.getNxt_edtn()));
profile.setSortMode(SortMode.fromValue(request.getSort_kind()));
if (request.getCr_cid() != -1) {
Contest contest = contestRepository.findById(request.getCr_cid()).orElseGet(Contest::new);
ContestBorder currentResultRank = getContestRank(contest, request.getCr_tv());
if (request.getCr_if() == 0) {
// Do contest is playing
profile.setContestNowPlayingEnable(true);
profile.setContestNowPlayingId(request.getCr_cid());
profile.setContestNowPlayingResultRank(currentResultRank);
profile.setContestNowPlayingValue(request.getCr_tv());
profile.setContestNowPlayingSpecifier(String.join(",", request.getCr_sp()));
} else {
PlayerContest contestRecord = playerContestRepository.findByPdIdAndContestId(profile, request.getCr_cid()).orElseGet(() -> new PlayerContest(profile, request.getCr_cid()));
contestRecord.setStartCount(contestRecord.getStartCount() + 1);
contestRecord.setBestValue(Math.max(contestRecord.getBestValue(), request.getCr_tv()));
contestRecord.setResultRank(currentResultRank.getValue() > contestRecord.getResultRank().getValue() ? currentResultRank : contestRecord.getResultRank());
contestRecord.setLastUpdateTime(LocalDateTime.now());
playerContestRepository.save(contestRecord);
profile.setContestNowPlayingEnable(false);
profile.setContestNowPlayingId(-1);
profile.setContestNowPlayingResultRank(ContestBorder.NONE);
profile.setContestNowPlayingValue(-1);
profile.setContestNowPlayingSpecifier(getDummyString("-1", 60));
}
}
playerProfileService.save(profile);
gameSessionRepository.delete(session);
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
private ContestBorder getContestRank(Contest contest, int value) {
if (value >= contest.getGoldBorders()) return ContestBorder.GOLD;
if (value >= contest.getSliverBorders()) return ContestBorder.SILVER;
if (value >= contest.getBronzeBorders()) return ContestBorder.BRONZE;
return ContestBorder.NONE;
}
}

View File

@ -0,0 +1,114 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.dao.gamedata.ContestRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.ContestBorder
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.common.SortMode
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaStringUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.lang.String
import java.time.LocalDateTime
import java.util.function.Supplier
import kotlin.Any
import kotlin.Int
import kotlin.math.max
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class EndHandler(
private val contestRepository: ContestRepository,
private val playerProfileService: PlayerProfileService,
private val playerContestRepository: PlayerContestRepository,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
fun handle(request: StageResultRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
profile.headphoneVolume = request.getHp_vol()
profile.isButtonSeOn = request.isBtn_se_vol
profile.buttonSeVolume = request.getBtn_se_vol2()
profile.sliderSeVolume = request.getSldr_se_vol2()
profile.vocaloidPoints = session.vp
profile.level = session.levelNumber
profile.levelExp = session.levelExp
profile.nextPvId = request.getNxt_pv_id()
profile.nextDifficulty = Difficulty.fromValue(request.getNxt_dffclty())
profile.nextEdition = Edition.fromValue(request.getNxt_edtn())
profile.sortMode = SortMode.fromValue(request.getSort_kind())
if (request.getCr_cid() != -1) {
val contest = contestRepository.findById(request.getCr_cid()).orElseGet(Supplier { Contest() })
val currentResultRank = getContestRank(contest, request.getCr_tv())
if (request.getCr_if() == 0) {
// Do contest is playing
profile.isContestNowPlayingEnable = true
profile.contestNowPlayingId = request.getCr_cid()
profile.contestNowPlayingResultRank = currentResultRank
profile.contestNowPlayingValue = request.getCr_tv()
profile.contestNowPlayingSpecifier = String.join(",", *request.getCr_sp())
} else {
val contestRecord =
playerContestRepository.findByPdIdAndContestId(profile, request.getCr_cid()).orElseGet(
Supplier { PlayerContest(profile, request.getCr_cid()) })
contestRecord.startCount = contestRecord.startCount + 1
contestRecord.bestValue = max(contestRecord.bestValue, request.getCr_tv())
contestRecord.resultRank = if (currentResultRank.value > contestRecord.resultRank
.value
) currentResultRank else contestRecord.resultRank
contestRecord.lastUpdateTime = LocalDateTime.now()
playerContestRepository.save<PlayerContest?>(contestRecord)
profile.isContestNowPlayingEnable = false
profile.contestNowPlayingId = -1
profile.contestNowPlayingResultRank = ContestBorder.NONE
profile.contestNowPlayingValue = -1
profile.contestNowPlayingSpecifier = DivaStringUtils.getDummyString("-1", 60)
}
}
playerProfileService.save(profile)
gameSessionRepository.delete(session)
val response = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
private fun getContestRank(contest: Contest, value: Int): ContestBorder {
if (value >= contest.goldBorders) return ContestBorder.GOLD
if (value >= contest.sliverBorders) return ContestBorder.SILVER
if (value >= contest.bronzeBorders) return ContestBorder.BRONZE
return ContestBorder.NONE
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(EndHandler::class.java)
}
}

View File

@ -1,45 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.user;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest;
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class PdUnlockHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PdUnlockHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(PdUnlockRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
gameSessionRepository.delete(session);
BaseResponse response = new BaseResponse(
request.getCmd(),
request.getReq_id(),
"ok"
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,46 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PdUnlockHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
fun handle(request: PdUnlockRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
gameSessionRepository.delete(session)
val response = BaseResponse(
request.cmd,
request.req_id,
"ok"
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PdUnlockHandler::class.java)
}
}

View File

@ -1,119 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.user;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.PreStartResult;
import icu.samnyan.aqua.sega.diva.model.common.StartMode;
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest;
import icu.samnyan.aqua.sega.diva.model.response.user.PreStartResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class PreStartHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(PreStartHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
public String handle(PreStartRequest request) {
Optional<PlayerProfile> profileOptional = playerProfileService.findByPdId(request.getAime_id());
PreStartResponse response;
boolean normalStart = false;
if (profileOptional.isEmpty()) {
response = new PreStartResponse(
request.getCmd(),
request.getReq_id(),
"ok",
PreStartResult.NEW_REGISTRATION);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
} else {
PlayerProfile profile = profileOptional.get();
Optional<GameSession> sessionOptional = gameSessionRepository.findByPdId(profile);
if (sessionOptional.isPresent()) {
GameSession session = sessionOptional.get();
if (!session.getLastUpdateTime().isBefore(LocalDateTime.now().minusMinutes(5)) && session.getStartMode() == StartMode.START) {
response = new PreStartResponse(
request.getCmd(),
request.getReq_id(),
"ok",
PreStartResult.ALREADY_PLAYING
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
} else {
gameSessionRepository.delete(session);
}
}
GameSession session = new GameSession(
ThreadLocalRandom.current().nextInt(100, 99999),
profile,
StartMode.PRE_START,
LocalDateTime.now(),
LocalDateTime.now(),
-1,
-1,
-1,
profile.getLevel(),
profile.getLevelExp(),
profile.getLevel(),
profile.getLevelExp(),
profile.getVocaloidPoints()
);
gameSessionRepository.save(session);
response = new PreStartResponse(
request.getCmd(),
request.getReq_id(),
"ok",
PreStartResult.SUCCESS,
session.getAcceptId(),
profile.getPdId(),
profile.getPlayerName(),
profile.getSortMode(),
profile.getLevel(),
profile.getLevelExp(),
profile.getLevelTitle(),
profile.getPlateEffectId(),
profile.getPlateId(),
profile.getCommonModule(),
profile.getCommonModuleSetTime(),
profile.getCommonSkin(),
profile.getButtonSe(),
profile.getSlideSe(),
profile.getChainSlideSe(),
profile.getSliderTouchSe(),
profile.getVocaloidPoints(),
profile.getPasswordStatus()
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}
}

View File

@ -0,0 +1,118 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.PreStartResult
import icu.samnyan.aqua.sega.diva.model.common.StartMode
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest
import icu.samnyan.aqua.sega.diva.model.response.user.PreStartResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.concurrent.ThreadLocalRandom
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PreStartHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
fun handle(request: PreStartRequest): Any {
val profileOptional = playerProfileService.findByPdId(request.aime_id)
val response: PreStartResponse?
if (profileOptional.isEmpty) {
response = PreStartResponse(
request.cmd,
request.req_id,
"ok",
PreStartResult.NEW_REGISTRATION
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
} else {
val profile = profileOptional.get()
val sessionOptional = gameSessionRepository.findByPdId(profile)
if (sessionOptional.isPresent) {
val session = sessionOptional.get()
if (!session.lastUpdateTime
.isBefore(LocalDateTime.now().minusMinutes(5)) && session.startMode == StartMode.START
) {
response = PreStartResponse(
request.cmd,
request.req_id,
"ok",
PreStartResult.ALREADY_PLAYING
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
} else {
gameSessionRepository.delete(session)
}
}
val session = GameSession(
ThreadLocalRandom.current().nextInt(100, 99999),
profile,
StartMode.PRE_START,
LocalDateTime.now(),
LocalDateTime.now(),
-1,
-1,
-1,
profile.level,
profile.levelExp,
profile.level,
profile.levelExp,
profile.vocaloidPoints
)
gameSessionRepository.save<GameSession?>(session)
response = PreStartResponse(
request.cmd,
request.req_id,
"ok",
PreStartResult.SUCCESS,
session.acceptId,
profile.pdId,
profile.playerName,
profile.sortMode,
profile.level,
profile.levelExp,
profile.levelTitle,
profile.plateEffectId,
profile.plateId,
profile.commonModule,
profile.commonModuleSetTime,
profile.commonSkin,
profile.buttonSe,
profile.slideSe,
profile.chainSlideSe,
profile.sliderTouchSe,
profile.vocaloidPoints,
profile.passwordStatus
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(PreStartHandler::class.java)
}
}

View File

@ -1,44 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.user;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest;
import icu.samnyan.aqua.sega.diva.model.response.user.SpendCreditResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class SpendCreditHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(SpendCreditHandler.class);
private final PlayerProfileService playerProfileService;
public String handle(SpendCreditRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
SpendCreditResponse response = new SpendCreditResponse(
request.getCmd(),
request.getReq_id(),
"ok",
"-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x",
0,
profile.getVocaloidPoints(),
profile.getLevelTitle(),
profile.getPlateEffectId(),
profile.getPlateId()
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
}

View File

@ -0,0 +1,43 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest
import icu.samnyan.aqua.sega.diva.model.response.user.SpendCreditResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class SpendCreditHandler(private val playerProfileService: PlayerProfileService) : BaseHandler() {
fun handle(request: SpendCreditRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val response = SpendCreditResponse(
request.cmd,
request.req_id,
"ok",
"-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x,-1,-1,x,-1,-1,x,x,-1,x",
0,
profile.vocaloidPoints,
profile.levelTitle,
profile.plateEffectId,
profile.plateId
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(SpendCreditHandler::class.java)
}
}

View File

@ -1,230 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler.user;
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerContestRepository;
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository;
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException;
import icu.samnyan.aqua.sega.diva.exception.PvRecordDataException;
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException;
import icu.samnyan.aqua.sega.diva.handler.BaseHandler;
import icu.samnyan.aqua.sega.diva.model.common.Result;
import icu.samnyan.aqua.sega.diva.model.common.StartMode;
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearSet;
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearTally;
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest;
import icu.samnyan.aqua.sega.diva.model.response.user.StartResponse;
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile;
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord;
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService;
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
@AllArgsConstructor
public class StartHandler extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(StartHandler.class);
private final PlayerProfileService playerProfileService;
private final GameSessionRepository gameSessionRepository;
private final PlayerCustomizeService playerCustomizeService;
private final PlayerModuleService playerModuleService;
private final PlayerPvRecordRepository playerPvRecordRepository;
private final PlayerContestRepository playerContestRepository;
public String handle(StartRequest request) {
PlayerProfile profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow(ProfileNotFoundException::new);
GameSession session = gameSessionRepository.findByPdId(profile).orElseThrow(SessionNotFoundException::new);
session.setStartMode(StartMode.START);
gameSessionRepository.save(session);
String module_have = playerModuleService.getModuleHaveString(profile);
String customize_have = playerCustomizeService.getModuleHaveString(profile);
Map<String, String> contestResult = getContestResult(profile);
int border = profile.isShowGreatBorder() ? 1 : 0;
border = border | ((profile.isShowExcellentBorder() ? 1 : 0) << 1);
border = border | ((profile.isShowRivalBorder() ? 1 : 0) << 2);
StartResponse response = new StartResponse(
request.getCmd(),
request.getReq_id(),
"ok",
profile.getPdId(),
Result.SUCCESS,
session.getAcceptId(),
session.getAcceptId(),
profile.getPlayerName(),
profile.getHeadphoneVolume(),
profile.isButtonSeOn(),
profile.getButtonSeVolume(),
profile.getSliderSeVolume(),
profile.getSortMode(),
profile.getLevel(),
profile.getLevelExp(),
profile.getLevelTitle(),
profile.getPlateEffectId(),
profile.getPlateId(),
profile.getCommonModule(),
profile.getCommonCustomizeItems(),
profile.getModuleSelectItemFlag(),
LocalDateTime.now(),
module_have,
customize_have,
profile.isPreferPerPvModule(),
profile.isPreferCommonModule(),
profile.isUsePerPvSkin(),
profile.isUsePerPvButtonSe(),
profile.isUsePerPvSliderSe(),
profile.isUsePerPvChainSliderSe(),
profile.isUsePerPvTouchSliderSe(),
profile.getVocaloidPoints(),
profile.getNextPvId(),
profile.getNextDifficulty(),
profile.getNextEdition(),
contestResult.get("cv_cid"), // contest progress
contestResult.get("cv_sc"),
contestResult.get("cv_rr"),
contestResult.get("cv_bv"),
contestResult.get("cv_bf"),
profile.isContestNowPlayingEnable() ? profile.getContestNowPlayingId() : -1,
profile.getContestNowPlayingValue(),
profile.getContestNowPlayingResultRank(),
profile.getContestNowPlayingSpecifier(),
profile.getMyList0(),
profile.getMyList1(),
profile.getMyList2(),
null,
null,
// getDummyString("-1", 40),
// getDummyString("-1", 40),
String.valueOf(border),
profile.isShowInterimRanking(),
profile.isShowClearStatus(),
countClearStatus(profile),
profile.isShowRgoSetting(),
null, // Currently quest not working
null,
null,
null,
null,
null
);
String resp = this.build(mapper.toMap(response));
logger.info("Response: {}", resp);
return resp;
}
private String countClearStatus(PlayerProfile profile) {
List<PlayerPvRecord> pvRecordList = playerPvRecordRepository.findByPdId(profile);
ClearTally clearTally = new ClearTally();
pvRecordList.forEach(x -> {
switch (x.getEdition()) {
case ORIGINAL: {
switch (x.getResult()) {
case CHEAP:
getDiff(x, clearTally).addClear();
break;
case STANDARD:
getDiff(x, clearTally).addClear();
break;
case GREAT:
getDiff(x, clearTally).addGreat();
break;
case EXCELLENT:
getDiff(x, clearTally).addExcellent();
break;
case PERFECT:
getDiff(x, clearTally).addPerfect();
break;
}
break;
}
case EXTRA: {
switch (x.getResult()) {
case CHEAP:
clearTally.getExtraExtreme().addClear();
break;
case STANDARD:
clearTally.getExtraExtreme().addClear();
break;
case GREAT:
clearTally.getExtraExtreme().addGreat();
break;
case EXCELLENT:
clearTally.getExtraExtreme().addExcellent();
break;
case PERFECT:
clearTally.getExtraExtreme().addPerfect();
break;
}
}
}
});
return clearTally.toInternal();
}
private ClearSet getDiff(PlayerPvRecord record, ClearTally clearTally) {
switch (record.getDifficulty()) {
case EASY:
return clearTally.getEasy();
case NORMAL:
return clearTally.getNormal();
case HARD:
return clearTally.getHard();
case EXTREME:
return clearTally.getExtreme();
default:
throw new PvRecordDataException("Difficulty data not exist, record id:" + record.getId());
}
}
private Map<String, String> getContestResult(PlayerProfile profile) {
List<Integer> cv_cid = new LinkedList<>();
List<Integer> cv_sc = new LinkedList<>();
List<Integer> cv_rr = new LinkedList<>();
List<Integer> cv_bv = new LinkedList<>();
List<Integer> cv_bf = new LinkedList<>();
List<PlayerContest> contestList = playerContestRepository.findTop4ByPdIdOrderByLastUpdateTimeDesc(profile);
contestList.forEach(x -> {
cv_cid.add(x.getContestId());
cv_sc.add(x.getStartCount());
cv_rr.add(x.getResultRank().getValue());
cv_bv.add(x.getBestValue());
cv_bf.add(-1);
});
for (int i = cv_cid.size(); i < 4; i++) {
cv_cid.add(-1);
cv_sc.add(-1);
cv_rr.add(-1);
cv_bv.add(-1);
cv_bf.add(-1);
}
Map<String, String> result = new HashMap<>();
result.put("cv_cid", cv_cid.stream().map(Object::toString).collect(Collectors.joining(",")));
result.put("cv_sc", cv_sc.stream().map(Object::toString).collect(Collectors.joining(",")));
result.put("cv_rr", cv_rr.stream().map(Object::toString).collect(Collectors.joining(",")));
result.put("cv_bv", cv_bv.stream().map(Object::toString).collect(Collectors.joining(",")));
result.put("cv_bf", cv_bf.stream().map(Object::toString).collect(Collectors.joining(",")));
return result;
}
}

View File

@ -0,0 +1,205 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.dao.userdata.GameSessionRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.dao.userdata.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.exception.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.exception.PvRecordDataException
import icu.samnyan.aqua.sega.diva.exception.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.model.common.*
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearSet
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearTally
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest
import icu.samnyan.aqua.sega.diva.model.response.user.StartResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.*
import java.util.function.Consumer
import java.util.function.Supplier
import java.util.stream.Collectors
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StartHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository,
private val playerCustomizeService: PlayerCustomizeService,
private val playerModuleService: PlayerModuleService,
private val playerPvRecordRepository: PlayerPvRecordRepository,
private val playerContestRepository: PlayerContestRepository
) : BaseHandler() {
fun handle(request: StartRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
.orElseThrow(Supplier { SessionNotFoundException() })
session.startMode = StartMode.START
gameSessionRepository.save<GameSession?>(session)
val module_have = playerModuleService.getModuleHaveString(profile)
val customize_have = playerCustomizeService.getModuleHaveString(profile)
val contestResult = getContestResult(profile)
var border = if (profile.isShowGreatBorder) 1 else 0
border = border or ((if (profile.isShowExcellentBorder) 1 else 0) shl 1)
border = border or ((if (profile.isShowRivalBorder) 1 else 0) shl 2)
val response = StartResponse(
request.cmd,
request.req_id,
"ok",
profile.pdId,
Result.SUCCESS,
session.acceptId,
session.acceptId,
profile.playerName,
profile.headphoneVolume,
profile.isButtonSeOn,
profile.buttonSeVolume,
profile.sliderSeVolume,
profile.sortMode,
profile.level,
profile.levelExp,
profile.levelTitle,
profile.plateEffectId,
profile.plateId,
profile.commonModule,
profile.commonCustomizeItems,
profile.moduleSelectItemFlag,
LocalDateTime.now(),
module_have,
customize_have,
profile.isPreferPerPvModule,
profile.isPreferCommonModule,
profile.isUsePerPvSkin,
profile.isUsePerPvButtonSe,
profile.isUsePerPvSliderSe,
profile.isUsePerPvChainSliderSe,
profile.isUsePerPvTouchSliderSe,
profile.vocaloidPoints,
profile.nextPvId,
profile.nextDifficulty,
profile.nextEdition,
contestResult.get("cv_cid"), // contest progress
contestResult.get("cv_sc"),
contestResult.get("cv_rr"),
contestResult.get("cv_bv"),
contestResult.get("cv_bf"),
if (profile.isContestNowPlayingEnable) profile.contestNowPlayingId else -1,
profile.contestNowPlayingValue,
profile.contestNowPlayingResultRank,
profile.contestNowPlayingSpecifier,
profile.myList0,
profile.myList1,
profile.myList2,
null,
null, // getDummyString("-1", 40),
// getDummyString("-1", 40),
border.toString(),
profile.isShowInterimRanking,
profile.isShowClearStatus,
countClearStatus(profile),
profile.isShowRgoSetting,
null, // Currently quest not working
null,
null,
null,
null,
null
)
val resp = this.build(mapper.toMap(response))
logger.info("Response: {}", resp)
return resp
}
private fun countClearStatus(profile: PlayerProfile?): String? {
val pvRecordList = playerPvRecordRepository.findByPdId(profile)
val clearTally = ClearTally()
pvRecordList.forEach(Consumer { x: PlayerPvRecord? ->
when (x!!.edition) {
Edition.ORIGINAL -> {
when (x.result) {
ClearResult.CHEAP -> getDiff(x, clearTally)!!.addClear()
ClearResult.STANDARD -> getDiff(x, clearTally)!!.addClear()
ClearResult.GREAT -> getDiff(x, clearTally)!!.addGreat()
ClearResult.EXCELLENT -> getDiff(x, clearTally)!!.addExcellent()
ClearResult.PERFECT -> getDiff(x, clearTally)!!.addPerfect()
else -> {}
}
}
Edition.EXTRA -> {
when (x.result) {
ClearResult.CHEAP -> clearTally.extraExtreme.addClear()
ClearResult.STANDARD -> clearTally.extraExtreme.addClear()
ClearResult.GREAT -> clearTally.extraExtreme.addGreat()
ClearResult.EXCELLENT -> clearTally.extraExtreme.addExcellent()
ClearResult.PERFECT -> clearTally.extraExtreme.addPerfect()
else -> {}
}
}
}
})
return clearTally.toInternal()
}
private fun getDiff(record: PlayerPvRecord, clearTally: ClearTally): ClearSet? {
when (record.difficulty) {
Difficulty.EASY -> return clearTally.easy
Difficulty.NORMAL -> return clearTally.normal
Difficulty.HARD -> return clearTally.hard
Difficulty.EXTREME -> return clearTally.extreme
else -> throw PvRecordDataException("Difficulty data not exist, record id:" + record.id)
}
}
private fun getContestResult(profile: PlayerProfile?): MutableMap<String?, String?> {
val cv_cid: MutableList<Int?> = LinkedList<Int?>()
val cv_sc: MutableList<Int?> = LinkedList<Int?>()
val cv_rr: MutableList<Int?> = LinkedList<Int?>()
val cv_bv: MutableList<Int?> = LinkedList<Int?>()
val cv_bf: MutableList<Int?> = LinkedList<Int?>()
val contestList = playerContestRepository.findTop4ByPdIdOrderByLastUpdateTimeDesc(profile)
contestList.forEach(Consumer { x: PlayerContest? ->
cv_cid.add(x!!.contestId)
cv_sc.add(x.startCount)
cv_rr.add(x.resultRank.value)
cv_bv.add(x.bestValue)
cv_bf.add(-1)
})
for (i in cv_cid.size..3) {
cv_cid.add(-1)
cv_sc.add(-1)
cv_rr.add(-1)
cv_bv.add(-1)
cv_bf.add(-1)
}
val result: MutableMap<String?, String?> = HashMap<String?, String?>()
result["cv_cid"] = cv_cid.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(","))
result["cv_sc"] = cv_sc.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(","))
result["cv_rr"] = cv_rr.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(","))
result["cv_bv"] = cv_bv.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(","))
result["cv_bf"] = cv_bf.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(","))
return result
}
companion object {
private val logger: Logger = LoggerFactory.getLogger(StartHandler::class.java)
}
}