Initial Commit

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

31
.gitignore vendored 100644
View File

@ -0,0 +1,31 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/

View File

@ -0,0 +1,118 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}

BIN
.mvn/wrapper/maven-wrapper.jar vendored 100644

Binary file not shown.

View File

@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

42
README.md 100644
View File

@ -0,0 +1,42 @@
# Aqua Server
An multipurpose game server power by Spring Boot.
### Supported Game:
* CHUNITHM Amazon
* Project DIVA Arcade Future Tone
### Usage:
Requirements:
* Java 11 or above
* MySQL (Optional)
Just run `java -jar aqua.jar`
or use the `start.bat` if you are using windows.
User data will be save in data/db.sqlite.
If you switch to MySQL, it will auto create the table and import some initial data.
Auto creation won't work with Sqlite, so if you want to recreate the database please use the file come with the release
### Configuration:
Configuration is save in `application.properties`
If you are going to deploy on other machine, you must change the `allnet.server.host` and `allnet.server.port` to the IP or Hostname of the hosting machine.
This will be send to the game at booting and being used by following request.
And you can switch to MySQL(MariaDB) database by commenting the Sqlite part.
### Other Information:
This server provide a simple API for changing some DIVA's setting.
A Web App can be found on https://github.com/samnyan/aqua-viewer
Live Version: http://aqua.samnyan.icu/
And DIVA screenshot will be save in data folder.
### Credit:
* **samnyan**
* **Akasaka Ryuunosuke** : providing all the DIVA protocol information
* All devs who contribute to the MiniMe server

BIN
data/db.sqlite 100644

Binary file not shown.

File diff suppressed because it is too large Load Diff

310
mvnw vendored 100644
View File

@ -0,0 +1,310 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=`cygpath --path --windows "$javaClass"`
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

182
mvnw.cmd vendored 100644
View File

@ -0,0 +1,182 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%

120
pom.xml 100644
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>icu.samnya</groupId>
<artifactId>aqua</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Aqua Server</name>
<description>A multipurpose game server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.43.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.30.1</version>
</dependency>
<dependency>
<groupId>com.github.gwenn</groupId>
<artifactId>sqlite-dialect</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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