diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..c92a1c7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'org.springframework.boot' version '2.6.7' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' + id 'war' +} + +group = 'com.ntlab' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-jersey' + implementation 'org.springframework.boot:spring-boot-starter-web' + providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.jar Binary files differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..00e33ed --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +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 + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem 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, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e3b400e --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'iris-server' diff --git a/src/main/java/com/ntlab/irisserver/IrisServerApplication.java b/src/main/java/com/ntlab/irisserver/IrisServerApplication.java new file mode 100644 index 0000000..fd81885 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/IrisServerApplication.java @@ -0,0 +1,30 @@ +package com.ntlab.irisserver; + +import com.ntlab.irisserver.entities.Member; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.KeywordManager; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +@SpringBootApplication +public class IrisServerApplication { + + public static void main(String[] args) { + ApplicationContext applicationContext = SpringApplication.run(IrisServerApplication.class, args); + String path; + try { + path = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/keywords.txt"; + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/com/ntlab/irisserver/JerseyConfig.java b/src/main/java/com/ntlab/irisserver/JerseyConfig.java new file mode 100644 index 0000000..cc87b2d --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/JerseyConfig.java @@ -0,0 +1,15 @@ +package com.ntlab.irisserver; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +import javax.ws.rs.ApplicationPath; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + packages("com.ntlab.irisserver.resources"); + } + +} diff --git a/src/main/java/com/ntlab/irisserver/ServletInitializer.java b/src/main/java/com/ntlab/irisserver/ServletInitializer.java new file mode 100644 index 0000000..c59a7a0 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/ServletInitializer.java @@ -0,0 +1,13 @@ +package com.ntlab.irisserver; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(IrisServerApplication.class); + } + +} diff --git a/src/main/java/com/ntlab/irisserver/datas/keywords.txt b/src/main/java/com/ntlab/irisserver/datas/keywords.txt new file mode 100644 index 0000000..21cea2f --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/keywords.txt @@ -0,0 +1,179 @@ +あんぱん +いくら +ウインナー +うどん +うなぎ +うに +梅干し +あさり +イカ +いちご +枝豆 +海老 +おでん +柿 +牡蠣 +カステラ +かに +かぼちゃ +カレー +からあげ +キャラメル +キムチ +きゅうり +クロワッサン +栗 +ケーキ +ケチャップ +米 +コロッケ +餃子 +さくらんぼ +さつまいも +サラダ +サンドイッチ +ざるそば +じゃがいも +牛丼 +シュウマイ +生姜 +すいか +すき焼き +寿司 +ステーキ +スパゲティ +ソフトクリーム +たけのこ +たこ +たこ焼き +たまご +大根 +ちくわ +チーズ +ツナ +豆腐 +とうもろこし +トマト +どら焼き +ドーナッツ +ナス +納豆 +にんにく +ねぎ +のり +白菜 +はちみつ +ハンバーガー +バナナ +パイナップル +ピザ +ピーマン +フライドポテト +フランクフルト +ぶどう +ブロッコリー +ポテトサラダ +ポップコーン +ほうれん草 +ホタテ +マシュマロ +みかん +味噌汁 +メロン +明太子 +もやし +焼きそば +焼肉 +ヨーグルト +ラーメン +りんご +レモン +わかめ +わさび +プリン +パフェ +アイスクリーム +カステラ +ナポリタン +犬 +牛 +馬 +カバ +さる +ゾウ +猫 +豚 +ヤギ +リス +イルカ +ウサギ +狐 +キリン +ゴリラ +ネズミ +パンダ +羊 +狼 +ライオン +トナカイ +ラクダ +ペンギン +ワニ +スライム +ひまわり +バラ +タンポポ +ハエトリグサ +サボテン +車 +救急車 +パトカー +ヘリコプター +飛行機 +バス +ヨット +めがね +リモコン +ドライヤー +スマートフォン +ホイッスル +鏡 +エアコン +扇風機 +掃除機 +キーボード +マウス +イヤホン +ボールペン +風船 +地球 +傘 +弁当 +ティッシュ +目薬 +リップクリーム +コンタクト +綿棒 +ガムテープ +体温計 +消毒液 +ペットボトル +歯ブラシ +筆箱 +そろばん +トランペット +リコーダー +ギター +マイク +タオル +時計 +服 +マスク +ゲーム機 +財宝 +本 +ぬいぐるみ +椅子 +机 +テレビ +パソコン \ No newline at end of file diff --git a/src/main/java/com/ntlab/irisserver/datas/test01.jpg b/src/main/java/com/ntlab/irisserver/datas/test01.jpg new file mode 100644 index 0000000..ba20055 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test01.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test02.jpg b/src/main/java/com/ntlab/irisserver/datas/test02.jpg new file mode 100644 index 0000000..c695fec --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test02.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test03.jpg b/src/main/java/com/ntlab/irisserver/datas/test03.jpg new file mode 100644 index 0000000..8fb3b32 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test03.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test04.jpg b/src/main/java/com/ntlab/irisserver/datas/test04.jpg new file mode 100644 index 0000000..8fb3b32 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test04.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test05.jpg b/src/main/java/com/ntlab/irisserver/datas/test05.jpg new file mode 100644 index 0000000..4dcb3e7 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test05.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test06.jpg b/src/main/java/com/ntlab/irisserver/datas/test06.jpg new file mode 100644 index 0000000..df620dd --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test06.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test07.jpg b/src/main/java/com/ntlab/irisserver/datas/test07.jpg new file mode 100644 index 0000000..fcce73a --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test07.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test08.jpg b/src/main/java/com/ntlab/irisserver/datas/test08.jpg new file mode 100644 index 0000000..d2522fe --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test08.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test09.jpg b/src/main/java/com/ntlab/irisserver/datas/test09.jpg new file mode 100644 index 0000000..ec4708a --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test09.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test10.jpg b/src/main/java/com/ntlab/irisserver/datas/test10.jpg new file mode 100644 index 0000000..1d67f38 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test10.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test11.jpg b/src/main/java/com/ntlab/irisserver/datas/test11.jpg new file mode 100644 index 0000000..bfa19f0 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test11.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test12.jpg b/src/main/java/com/ntlab/irisserver/datas/test12.jpg new file mode 100644 index 0000000..935a0aa --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test12.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test13.jpg b/src/main/java/com/ntlab/irisserver/datas/test13.jpg new file mode 100644 index 0000000..6173c75 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test13.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test14.jpg b/src/main/java/com/ntlab/irisserver/datas/test14.jpg new file mode 100644 index 0000000..a0b9270 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test14.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test15.jpg b/src/main/java/com/ntlab/irisserver/datas/test15.jpg new file mode 100644 index 0000000..24f41f8 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test15.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/datas/test16.jpg b/src/main/java/com/ntlab/irisserver/datas/test16.jpg new file mode 100644 index 0000000..4e2f3da --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/datas/test16.jpg Binary files differ diff --git a/src/main/java/com/ntlab/irisserver/entities/Cell.java b/src/main/java/com/ntlab/irisserver/entities/Cell.java new file mode 100644 index 0000000..1217fb0 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Cell.java @@ -0,0 +1,41 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Cell { + + @JsonProperty("isOpen") + private boolean isOpen; //trueが空いてる、falseは空いてない + + @JsonProperty("color") + public String color; + + @JsonProperty("dno") + public int dno; + + @JsonProperty("cno") + public int cno; + + //コンストラクタ + public Cell(){ + isOpen = false; + } + + //setter + public void setIsOpen(boolean isOpen) {this.isOpen = isOpen;} + + public void setColor(String color) {this.color = color;} + + public void setDno(int dno) {this.dno = dno;} + + public void setCno(int cno) {this.cno = cno;} + + //getter + public boolean getIsOpen() {return this.isOpen;} + + public String getColor() {return this.color;} + + public int getDno() {return this.dno;} + + public int getCno() {return this.cno;} +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Drawing.java b/src/main/java/com/ntlab/irisserver/entities/Drawing.java new file mode 100644 index 0000000..10926ab --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Drawing.java @@ -0,0 +1,21 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Drawing { + + @JsonProperty("drawing") + private String drawingPath; + + // getter + public String getDrawing() {return this.drawingPath;} + + // setter + public void setDrawing(String drawing) {this.drawingPath = drawing;} + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/DrawingController.java b/src/main/java/com/ntlab/irisserver/entities/DrawingController.java new file mode 100644 index 0000000..f629466 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/DrawingController.java @@ -0,0 +1,121 @@ +package com.ntlab.irisserver.entities; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DrawingController { + + private int stage = 0; + private int maxstage; + + private IStateListener stateListener; + private List members; + private Game game; + private Map> assignments; + + //ニックネームからメンバーを特定するマップ + private Map membersMap= new HashMap<>(); + + private long startTime; //ステージの開始時刻 + private long nowTime; //現在の時刻 + private int drawingTime; //お絵描きのタイムリミット + private int countdown; //あと何秒でタイムリミットになるか + private boolean isDrawingTimer; //タイマーを使うかどうか + + //描いている最中にタイムリミット(countdown==0)がくれば、描いている途中のものをputさせる。既に描き終わっている人は何もしない + //時間が0になったときに、描き終わっていない人は「描いている最中の絵をput」する。(クライアントサイド) デバッグがしにくい assingmentのgetで見れるようにする + //getdnoの番号が変わっていたら、「新しい絵を描く」 + + public DrawingController(IStateListener stateListener, List members, Game game) { + + this.stateListener = stateListener; + this.members = members; + this.game = game; + assignments = game.getAssignments(); + + //16枚の絵をそろえるために必要なステージ数を計算 16/人数 端数切り上げ + maxstage = (16 + members.size() - 1)/members.size(); + + for(Member mem :members) { + String nick = mem.getNickname(); + membersMap.put(nick,mem); + } + + //お絵描きのタイムリミットを記録 + Settings setting = game.getSettings(); + startTime = System.currentTimeMillis(); + this.drawingTime = setting.getDrawingTimerTimes(); + this.isDrawingTimer = setting.isDrawingTimer(); + + + } + + //絵がアップロードされたときに、ステージを進めるか確認する + public void update(){ + + boolean canUpdate = true; + + //参加者全員が絵を書き終わっているかを確認 + for(Member mem :members) { + int dno = getDno(mem.getNickname()); + Drawing drawing = game.getDrawing(dno); + + //まだ描けていない絵があればステージ変更しない + if(drawing == null){ + canUpdate = false; + } + } + + //全員描き終わていれば、ステージを進める + if(canUpdate) { + stage += 1; + + //タイマーをリセット + startTime = System.currentTimeMillis(); + countdown = drawingTime; + + //ゲームに必要な枚数がそろうと、roomのstateを「お絵描き中2」から「ゲーム中3」に変更 + if(stage == maxstage){ + stateListener.changeState(); + } + } + } + + //お絵描き中のタイマーを更新 + private void updateTimer(){ + //経過した時間を計算(秒) + nowTime = System.currentTimeMillis(); + int count = ((int)nowTime - (int)startTime)/1000; + + if(drawingTime - count > 0){ + countdown = drawingTime - count; + }else { + countdown = 0; + } + } + + //pathパラメーターを引数にするので、memberではなくてString + //nicknameから書いてほしいdnoを返す + public Integer getDno(String nickname) { + Member mem = membersMap.get(nickname); + if(mem == null){ + return null; + } + List dnoList = assignments.get(mem); + int dno = dnoList.get(stage); + return dno; + } + + //現在のステージでお絵描きができる残り時間を返す + public Integer getCountdown(){ + if(isDrawingTimer){ + updateTimer(); + return countdown; + }else{ + return null; + } + + } + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Game.java b/src/main/java/com/ntlab/irisserver/entities/Game.java new file mode 100644 index 0000000..f7903ef --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Game.java @@ -0,0 +1,186 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.*; + +public class Game { + + @JsonProperty("assignments") + private Map> assignments = new HashMap<>();//> + @JsonProperty("drawingList") + private Map drawingList = new HashMap<>();// + @JsonProperty("keywordList") + private Map keywordList = new HashMap<>();// + @JsonProperty("cellList") + private Map cellList = new HashMap<>();// + + @JsonProperty("map") + private List map = new ArrayList<>();//cno順にdnoを管理 + @JsonProperty("colorList") + private List colorList = new ArrayList<>();//cno順にr:赤,g:灰,b:青,d:黒を管理 + @JsonProperty("turnList") + private List turnList = new ArrayList<>(); + + @JsonProperty("nowTurn") + private Turn nowTurn = null;//現在のターン + @JsonProperty("drawingController") + private DrawingController drawingController = null; + @JsonProperty("settings") + private Settings settings = null; + + + public Game(Room room, String[] keywords) { + + room.setGame(this); + this.settings = room.getSettings(); + drawingController = new DrawingController(room, room.getMembers(), this); + + List memberList = room.getMembers(); + int num = 16/memberList.size();//一人あたりが確実に採用されるイラスト枚数 + int cnt = 0; + for(int i=0; i dnoList = new ArrayList<>();//一人が描くイラストのdnoリスト + for(int j=0; j dnoList = assignments.get(memberList.get(i)); + dnoList.add(cnt); + cnt++; + assignments.put(memberList.get(i), dnoList); + } + + for(int i=0; i<16; i++) map.add(i); + Collections.shuffle(map);//0~15のdnoをランダムにマップに割り振る + System.out.println(map); + //r:6 b:5 g:4 d:1 + for(int i=0; i<6; i++) colorList.add("r"); + for(int i=0; i<5; i++) colorList.add("b"); + for(int i=0; i<4; i++) colorList.add("g"); + colorList.add("d"); + Collections.shuffle(colorList);//r,b,g,dをランダムにマップに割り振る + + List randKeys = Arrays.asList(keywords);//コンストラクタの引数で受け取ったキーワードをリストに変換 + Collections.shuffle(randKeys);//キーワードをシャッフル + + //Cellのインスタンス作成 + for(int i=0; i<16; i++){ + Cell c = new Cell(); + cellList.put(i, c); + c.setCno(i); + c.setColor(colorList.get(i)); + c.setDno(map.get(i)); + + //今回のゲームで使用するキーワードを追加 + //keywordList.put(i, randKeys.get(i));//(dno, キーワード) + } + int drawNum = 16; + if(16%memberList.size()!=0) drawNum = (num+1)*memberList.size(); + + for(int i=0; i getDrawings(){ + return drawingList; + } + + public Drawing putDrawing(int dno, Drawing drawing) { + Drawing d = drawingList.put(dno, drawing); + drawingController.update(); + return d; + } + + public String getKeyword(int dno) { + String keyword = keywordList.get(dno); + return keyword; + } + +// public List getKeywords() { +// List keywords = new ArrayList<>(); +// for(int i=0; i<16; i++){ +// keywords.add(keywordList.get(map.get(i))); +// } +// return keywords; +// } + + public List getKeywords() { + List keywords = new ArrayList<>(); + for(List dnoList: assignments.values()){ + for(int i=0; i getOpens(){ + List opens= new ArrayList<>(); + for(int i=0; i<16; i++){ + Cell cell = cellList.get(i); + boolean isOpen = cell.getIsOpen(); + opens.add(isOpen); + } + return opens; + } + + public Map> getAssignments(){ + return assignments; + } + + public List getMap(){ + return map; + } + public List getColorList(){ + return colorList; + } + + public Settings getSettings(){ + return this.settings; + } + + public void createTurn(){ + nowTurn = new Turn(); + if(turnList.size()%2==0){//偶数ターンなら青色,奇数ターンは赤色 + nowTurn.setTeam("r"); + }else{ + nowTurn.setTeam("b"); + } + this.turnList.add(nowTurn); + } + + public Turn getTurn(Integer num){ + return turnList.get(num); + } + + public Integer getNowTurn(){//現在何ターン目か取得 + return turnList.size()-1; + } + + public Cell getCell(Integer cno){ + return cellList.get(cno); + } + + public Map getDrawingList() {return drawingList;} +} diff --git a/src/main/java/com/ntlab/irisserver/entities/GameJson.java b/src/main/java/com/ntlab/irisserver/entities/GameJson.java new file mode 100644 index 0000000..5e7fa31 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/GameJson.java @@ -0,0 +1,35 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GameJson { + @JsonProperty("drawingList") + private Map drawingList; // + @JsonProperty("map") + private List map ; //cno順にdnoを管理 + @JsonProperty("colorList") + private List colorList ; //cno順にr,g,b,dを管理 + + //コンストラクタ + public GameJson(Game g){ + this.drawingList = g.getDrawingList(); + this.map = g.getMap(); + this.colorList = g.getColorList(); + } + + //ゲッター + public Map getDrawingList() {return drawingList;} + public List getMap() {return map;} + public List getColorList() {return colorList;} + + //セッター + public void setDrawingList(Map dlist) {drawingList = dlist;} + public void setMap(List map) {this.map = map;} + public void setColorList(List color) {this.colorList = color;} + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/IStateListener.java b/src/main/java/com/ntlab/irisserver/entities/IStateListener.java new file mode 100644 index 0000000..74195f5 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/IStateListener.java @@ -0,0 +1,10 @@ +package com.ntlab.irisserver.entities; + +interface IStateListener { + + //stateに1を加算する + void changeState(); + + //stateを0に戻す + void resetState(); +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Member.java b/src/main/java/com/ntlab/irisserver/entities/Member.java new file mode 100644 index 0000000..82fe79c --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Member.java @@ -0,0 +1,40 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Member { + + @JsonProperty("nickname") + private String nickname; + + //r:赤チーム b:青チーム n:無所属 + @JsonProperty("belongs") + private String belongs; + + @JsonProperty("master") + private boolean master; + + //----------------------------------------------------------------- + //コンストラクト + public Member(String nickname) { + this.nickname = nickname; + this.belongs = "n"; + this.master = false; + } + + //----------------------------------------------------------------- + // setter + public void setNickname(String nickname) {this.nickname = nickname;} + + public void setBelongs(String belongs) {this.belongs = belongs;} + + public void setMaster(boolean master) {this.master = master;} + + //----------------------------------------------------------------- + // getter + public String getNickname() {return this.nickname;} + + public String getBelongs() {return this.belongs;} + + public boolean isMaster() {return this.master;} +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Room.java b/src/main/java/com/ntlab/irisserver/entities/Room.java new file mode 100644 index 0000000..ca7bf3c --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Room.java @@ -0,0 +1,182 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.*; + + +public class Room implements IStateListener { + @JsonProperty("rid") + public String rid; + //String rid = null; + + @JsonProperty("state") + private int state; + //int state; + + @JsonProperty("ownerName") + public String ownerName; + //String ownerName = null; + + @JsonProperty("members") + Map members= new HashMap<>(); + + @JsonProperty("settings") + Settings settings = new Settings(); + + @JsonProperty("game") + Game game = null; + + private Member redMaster; + private Member blueMaster; + + + + + public Room(String rid, String owner) { + this.rid=rid; + ownerName=owner; + } + + public String getOwnerName() { + return ownerName; + } + + public Settings getSettings() { + return settings; + } + + public List getMembers() { + + + List memberslist = new ArrayList(members.values()) ; + return memberslist; + + } + + public void setRedMaster(Member redMaster) { + this.redMaster = redMaster; + } + + public void setBlueMaster(Member blueMaster) { + this.blueMaster = blueMaster; + } + + //プレイヤーの情報を変更する + public void changeTeamAndMaster(String nick, String belongs, boolean isMaster) { + + + //変更対象の情報を取得 + Member m = members.get(nick); + + //変更先のチームに既に所属している場合はチームに変更なし + if(!(m.getBelongs().equals(belongs))) { + + //1チームの最大人数は8人 + //変更先のチームの人数を数える + int memberscount = 0; + List membersList = new ArrayList(members.values()) ; + + for(Member mem :membersList) { + if(mem.getBelongs().equals(belongs)) { + memberscount++; + } + } + + //変更先のチームが満員であれば変更不可 + if(memberscount >= 8) { + return; + }else{ + m.setBelongs(belongs); + } + + } + + //変更対象がマスターであればマスター不在に修正 + if(m.isMaster()){ + + m.setMaster(false); + + if(redMaster == m){ + redMaster = null; + } + if(blueMaster == m){ + blueMaster = null; + } + } + + //マスターに変更する処理 + if(isMaster){ + //マスターを変更 + if(belongs.equals("r")) { + + //赤チームのマスターをメンバーに変更 + if(redMaster != null) { + redMaster.setMaster(false); + } + + //変更対象を赤チームのマスターに変更 + m.setMaster(true); + redMaster = m; + } + + if(belongs.equals("b")) { + + //青チームのマスターをメンバーに変更 + if(blueMaster != null) { + blueMaster.setMaster(false); + } + + //変更対象を赤チームのマスターに変更 + m.setMaster(true); + blueMaster = m; + } + } + + } + + public void setGame(Game game) { + this.game = game; + } + + public Game getGame() { + return game; + } + + public Member getMember(String nick) { + Member m = members.get(nick); + return m; + } + + public void addMember(String nick) { + Member m=new Member(nick); + m.setNickname(nick); + members.put(nick,m); + } + + public void deleteMember(String nick) { + members.remove(nick); + } + + + public int getState() { + return state; + } + + public void setState(int state){ + this.state=state; + } + + public void changeState(){ + state += 1; + } + + public void resetState(){ + state = 0; + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/ntlab/irisserver/entities/RoomJson.java b/src/main/java/com/ntlab/irisserver/entities/RoomJson.java new file mode 100644 index 0000000..535db8e --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/RoomJson.java @@ -0,0 +1,47 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RoomJson { + @JsonProperty("rid") + private String rid; + + @JsonProperty("state") + private int state; + + @JsonProperty("ownerName") + private String ownerName; + +// @JsonProperty("members") +// List members = new ArrayList<>(); + + //コンストラクタ + public RoomJson(Room r){ + this.rid = r.rid; + this.ownerName = r.ownerName; + this.state = r.getState(); +// this.members = r.getMembers(); + } + + //getter + public String getRid() {return this.rid;} + + public int getState() {return this.state;} + + public String getOwnerName() {return this.ownerName;} + +// public List getMembers() {return this.members;} + + //setter + public void setRid(String rid) {this.rid = rid;} + + public void setState(Integer state) {this.state = state;} + + public void setOwnerName(String ownerName) {this.ownerName = ownerName;} + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Settings.java b/src/main/java/com/ntlab/irisserver/entities/Settings.java new file mode 100644 index 0000000..7227136 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Settings.java @@ -0,0 +1,74 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + + +public class Settings { + @JsonProperty("drawingTimer") + private boolean drawingTimer; + + @JsonProperty("drawingTimerTimes") + private int drawingTimerTimes; + + @JsonProperty("gameTimer") + private boolean gameTimer; + + @JsonProperty("gameTimerTimes") + private int gameTimerTimes; + + @JsonProperty("gameTimerFirstThinkingTimes") + private int gameTimerFirstThinkingTimes; + + //-------------------------------------------------------------------- + //コンストラクタで初期値設定 + public Settings(){ + drawingTimer = true; + drawingTimerTimes = 40; + gameTimer = true; + gameTimerTimes = 90; + gameTimerFirstThinkingTimes = 10; + } + + //-------------------------------------------------------------------- + //setter & getter + public boolean isDrawingTimer() { + return drawingTimer; + } + + public void setDrawingTimer(boolean drawingTimer) { + this.drawingTimer = drawingTimer; + } + + public int getDrawingTimerTimes() { + return drawingTimerTimes; + } + + public void setDrawingTimerTimes(int drawingTimerTimes) { + this.drawingTimerTimes = drawingTimerTimes; + } + + public boolean isGameTimer() { + return gameTimer; + } + + public void setGameTimer(boolean gameTimer) { + this.gameTimer = gameTimer; + } + + public int getGameTimerTimes() { + return gameTimerTimes; + } + + public void setGameTimerTimes(int gameTimerTimes) { + this.gameTimerTimes = gameTimerTimes; + } + + public int getGameTimerFirstThinkingTimes() { + return gameTimerFirstThinkingTimes; + } + + public void setGameTimerFirstThinkingTimes(int gameTimerFirstThinkingTimes) { + this.gameTimerFirstThinkingTimes = gameTimerFirstThinkingTimes; + } + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/Turn.java b/src/main/java/com/ntlab/irisserver/entities/Turn.java new file mode 100644 index 0000000..f91c3cd --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/Turn.java @@ -0,0 +1,103 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; + +public class Turn { + + @JsonProperty("hint") + private String hint; + + @JsonProperty("team") + private String team; + + @JsonProperty("max") + private Integer max; + + @JsonProperty("turnstate") + private int turnstate; //0:スパイマスターのターン 1:諜報員のターン + + @JsonProperty("endstate") + private int endstate;//0:game継続, 1:game終了 + + private Boolean[] questions = new Boolean[16] ;//> + + private List openlist = new ArrayList<>(); + + //コンストラクタ + + public Turn(){ + turnstate = 0; + endstate = 0; + int i; + for(i = 0; i < 16; i++)questions[i] = false; + } + + //--------------------------------------------------------- + //セッター + + public void setHint(String hint) {this.hint = hint;} + + public void setTeam(String team) {this.team = team;} + + public void setMax(int max) {this.max = max;} + + public void setTurnstate(int turnstate) {this.turnstate = turnstate;} + + public void setEndstate(int endstate) {this.endstate = endstate;} + + //--------------------------------------------------------- + //ゲッター + + public String getHint() {return hint;} + + public String getTeam() {return team;} + + public int getMax() {return max;} + + public List getOpenListAll() {return openlist;} //リストそのものを返す。 + + public Boolean[] getQuestionsList() {return questions;} + + public int getTurnstate() {return turnstate;} + + public int getEndstate() {return endstate;} + + //--------------------------------------------------------- + //questions操作 + + public boolean getQuestions(int cno){return questions[cno];} + + public void setQuestions(int cno){questions[cno] = !questions[cno];} + + /* + public void delieteQuestions(int cno, Member m){ + List list = questions[cno]; + for(Iterator it = list.iterator(); it.hasNext();){ + Member member = (Member) it.next(); + if(member.getNickname() == m.getNickname()){ + it.remove(); + break; + } + } + + } + + public int sizeQuestions(int cno){return questions[cno].size();} + */ + + //openlist操作 + + public Integer getOpenListSolo(int num){return openlist.get(num);} + + public void addOpenList(Integer cno){openlist.add(cno);} + + public void delieteOpenList(int num){openlist.remove(num);} + + public int sizeOpenList(){return openlist.size();} + + +} diff --git a/src/main/java/com/ntlab/irisserver/entities/TurnJson.java b/src/main/java/com/ntlab/irisserver/entities/TurnJson.java new file mode 100644 index 0000000..7c0d843 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/entities/TurnJson.java @@ -0,0 +1,38 @@ +package com.ntlab.irisserver.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.List; + +public class TurnJson { + + @JsonProperty("hint") + private String hint; + + @JsonProperty("team") + private String team; + + @JsonProperty("max") + private int max; + + @JsonProperty("turnstate") + private int turnstate; //0:スパイマスターのターン 1:諜報員のターン + + @JsonProperty("gamestate") + private int endstate; //0:game継続, 1:game終了 + + private List openlist = new ArrayList<>(); + + //コンストラクタ + + public TurnJson(Turn t){ + hint = t.getHint(); + team = t.getTeam(); + max = t.getMax(); + openlist = t.getOpenListAll(); + turnstate = t.getTurnstate(); + endstate = t.getEndstate(); + } + +} diff --git a/src/main/java/com/ntlab/irisserver/models/KeywordManager.java b/src/main/java/com/ntlab/irisserver/models/KeywordManager.java new file mode 100644 index 0000000..c175210 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/models/KeywordManager.java @@ -0,0 +1,66 @@ +package com.ntlab.irisserver.models; + +import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + + +@Component +public class KeywordManager { + + private static KeywordManager theInstance = null; + String[] keywords = {"0"}; + + //シングルトンパターンでインスタンス作成 + public static KeywordManager getInstance() { + if(theInstance == null) { + theInstance = new KeywordManager(); + } + return theInstance; + } + + //------------------------------------------------------------------------------ + //読み込んだファイルのキーワードをStringの配列で返す + public String[] getKeywords(String path){ + var response = Response.status(Response.Status.NO_CONTENT); + + if(path == null){ + response.status(400).entity("パスがありません"); + throw new WebApplicationException(response.build()); + } else if(FileRead(path).size() == 0){ + response.status(404).entity(path+"に対応したファイルがありません"); + throw new WebApplicationException(response.build()); + } else { + keywords = FileRead(path).toArray(new String[FileRead(path).size()]); + } + + return keywords; + } + + //----------------------------------------------------------------------------- + //pathのファイルを読み込み + private List FileRead(String path) { + List ss = new ArrayList(); + + try { + BufferedReader buffReader = new BufferedReader(new FileReader(path)); + String s; + while ((s = buffReader.readLine()) != null) { + ss.add(s); + } + + buffReader.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + + return ss; + } + +} diff --git a/src/main/java/com/ntlab/irisserver/models/RoomManager.java b/src/main/java/com/ntlab/irisserver/models/RoomManager.java new file mode 100644 index 0000000..f5f7928 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/models/RoomManager.java @@ -0,0 +1,61 @@ +package com.ntlab.irisserver.models; +import com.ntlab.irisserver.entities.Room; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import java.util.*; + +@Component +public class RoomManager { + private static RoomManager theInstance = null; + private Map rooms = new HashMap(); + + public static RoomManager getInstance() { + if(theInstance == null) { + theInstance = new RoomManager(); + } + return theInstance; + } + + + + public Room createRoom(String owner) { + UUID uuid = UUID.randomUUID(); + String rid = uuid.toString(); //uuid型からstring型に変換 + Room r = new Room(rid, owner); + rooms.put(rid, r); + return r; + } + + public Room getRoom(String rid) { + Room r = rooms.get(rid); + return r; + } + + public List getRooms() { + List roomlist = new ArrayList<>(rooms.values()); + return roomlist; + } + + public void deleteRoom(String rid) { + rooms.remove(rid); + } + + //--------------------------------テスト用-------------------------------------- + + public void createTestRoom() { + + //お絵描きテスト用 + Room dr = new Room("drawtest", "owner"); + rooms.put("drawtest", dr); + dr.addMember("owner"); + + //ゲームテスト用 + Room gr = new Room("gametest", "RedSpy(owner)"); + rooms.put("gametest", gr); + gr.addMember("RedSpy(owner)"); + + } + + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java b/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java new file mode 100644 index 0000000..080c417 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java @@ -0,0 +1,79 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.DrawingController; +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@Component +@Path("/rooms") +public class AssignmentRest { + //GETでニックネームを貰うと、いま書いてほしいdnoを返す + @GET + @Path("/{rid}/game/drawings/assignment/{nickname}") + @Produces(MediaType.APPLICATION_JSON) + public int getDno(@PathParam("rid") String rid,@PathParam("nickname") String nickname ) { + + Integer dno = null; + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + if(room != null) { + + Game game = room.getGame(); + DrawingController drawingController = game.getDrawingController(); + dno = drawingController.getDno(nickname); // dno = new Integer(drawingController.getDno(nickname)); + + if(dno == null ){ + + //プレイヤーがいなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("プレイヤーが存在しません"); + throw new WebApplicationException(response.build()); + } + + }else{ + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + + return dno; + } + + @GET + @Path("/{rid}/game/drawings/assignment/timer") + @Produces(MediaType.APPLICATION_JSON) + public Integer getTime(@PathParam("rid") String rid){ + + Integer countdown = null; + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + if(room != null) { + Game game = room.getGame(); + DrawingController drawingController = game.getDrawingController(); + + //絵を描ける時間を取得 + countdown = drawingController.getCountdown(); + }else{ + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + + return countdown; + + + } +} diff --git a/src/main/java/com/ntlab/irisserver/resources/DrawingsRest.java b/src/main/java/com/ntlab/irisserver/resources/DrawingsRest.java new file mode 100644 index 0000000..928a6e8 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/DrawingsRest.java @@ -0,0 +1,86 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Drawing; +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; +import com.ntlab.irisserver.utils.Base64Decode; +import org.springframework.context.ApplicationContextAware; +import org.springframework.beans.BeansException; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +@Component +@Path("/rooms") + +public class DrawingsRest implements ApplicationContextAware { + + private org.springframework.context.ApplicationContext applicationContext; + + public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + // お絵描きの終了判定 + @GET + @Path("/{rid}/game/drawings") + public String getDrawings(@PathParam("rid") String rid) { + // 絵のデータ取得 + // 一旦必要のない方向性で行く + return null; + } + + // 絵のデータ取得(パスを渡せば良い) + @GET + @Path("/{rid}/game/drawings/{dno}") + @Produces(MediaType.APPLICATION_JSON) + public Drawing getDrawing(@PathParam("rid") String rid, @PathParam("dno") int dno ) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Drawing drawing = game.getDrawing(dno); + + return drawing; + } + + // 描いた絵を送る + @PUT + @Path("/{rid}/game/drawings/{dno}") + @Produces(MediaType.APPLICATION_JSON) + public String putDrawing(@PathParam("rid") String rid, @PathParam("dno") int dno, @FormParam("drawing") String drawingStr ) { + String pathDirectory = ""; + String drawingPath = ""; + + try { + pathDirectory = applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image"; + // utilsのBase64Decodeにデコードしてもらって、そのついでに保存してもらう + drawingPath = Base64Decode.saveAsFile(rid, dno, pathDirectory, drawingStr); + + System.out.println("kota0210/base64Decodeは成功。drawingPath完成→"+ drawingPath.toString()); + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + + // 絵の情報を上書き + Drawing drawing = game.getDrawing(dno); + + if (drawing == null) { + drawing = new Drawing(); + System.out.println("kota0210/nullだったからdrawingをnewした"); + } + drawing.setDrawing(drawingPath); + game.putDrawing(dno, drawing); + + } catch (IOException e) { + e.printStackTrace(); + throw new WebApplicationException(500); + } + + return "画像保存完了"; + } + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/GameRest.java b/src/main/java/com/ntlab/irisserver/resources/GameRest.java new file mode 100644 index 0000000..c0a7873 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/GameRest.java @@ -0,0 +1,64 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.GameJson; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.stereotype.Component; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.List; + +@Component +@Path("/rooms") +public class GameRest { + + @GET + @Path("/{rid}/game") + @Produces(MediaType.APPLICATION_JSON) + public GameJson getGame(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + GameJson gj = new GameJson(game); + return gj; + } + + @GET + @Path("/{rid}/game/map") + @Produces(MediaType.APPLICATION_JSON) + public List getMap(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + List map = game.getMap(); + return map; + } + + @GET + @Path("/{rid}/game/color") + @Produces(MediaType.APPLICATION_JSON) + public List getColorList(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + List color = game.getColorList(); + return color; + } + + @GET + @Path("/{rid}/game/keywords") + @Produces(MediaType.APPLICATION_JSON) + public List getKeywords(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + List keywords = game.getKeywords(); + return keywords; + } + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/GameStateRest.java b/src/main/java/com/ntlab/irisserver/resources/GameStateRest.java new file mode 100644 index 0000000..698ea4a --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/GameStateRest.java @@ -0,0 +1,41 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Cell; +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.entities.Turn; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; +import java.util.List; + +@Component +@Path("/rooms") + +public class GameStateRest { + @Path("/{rid}/game/opens") + @GET + @Produces(MediaType.APPLICATION_JSON) + public List getOpens(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + List opens = game.getOpens(); + return opens; + } + + @Path("/{rid}/game/turn") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getTeam(@PathParam("rid") String rid) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn turn = game.getTurn(game.getNowTurn()); + String team = turn.getTeam(); + return team; + } +} diff --git a/src/main/java/com/ntlab/irisserver/resources/HelloWorld.java b/src/main/java/com/ntlab/irisserver/resources/HelloWorld.java new file mode 100644 index 0000000..338c57a --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/HelloWorld.java @@ -0,0 +1,17 @@ +package com.ntlab.irisserver.resources; + +import org.springframework.stereotype.Component; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Component +@Path("/hello") +public class HelloWorld { + @GET + public String getHello() { + return "Hello World"; + } +} diff --git a/src/main/java/com/ntlab/irisserver/resources/KeywordsRest.java b/src/main/java/com/ntlab/irisserver/resources/KeywordsRest.java new file mode 100644 index 0000000..d34045c --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/KeywordsRest.java @@ -0,0 +1,38 @@ +package com.ntlab.irisserver.resources; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.models.KeywordManager; + + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + + +@Component +@Path("/keywords") + +public class KeywordsRest implements ApplicationContextAware { + + private ApplicationContext applicationContext; + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public String[] getKeywords() throws IOException { + + String path; + path = applicationContext.getResource("file:").getFile().getAbsolutePath()+"/apache-tomcat-9.0.10/webapps/irisdata/keywords.txt"; + KeywordManager km = KeywordManager.getInstance(); + + return km.getKeywords(path); + } + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/MemberRest.java b/src/main/java/com/ntlab/irisserver/resources/MemberRest.java new file mode 100644 index 0000000..730dd04 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/MemberRest.java @@ -0,0 +1,54 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + +@Component +@Path("/rooms") +public class MemberRest { + // チーム変更・役職変更のメソッド + @Path("/{rid}/members/{nickname}") + @PUT + public String putMember(@PathParam("rid") String rid, @PathParam("nickname") String nickname, + @FormParam("belongs") String belongs, @FormParam("is-master") boolean isMaster) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + //部屋の確認 + if (room != null) { + //ニックネームの確認 + if (room.getMember(nickname) != null) { + room.changeTeamAndMaster(nickname, belongs, isMaster); + } else { + //ニックネームがなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("ニックネームが存在しません"); + throw new WebApplicationException(response.build()); + } + } else { + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return "変更しました"; + } + + // プレイヤーを退出させるメソッド + @Path("/{rid}/members/{nickname}") + @DELETE + public String deleteMember(@PathParam("rid") String rid, @PathParam("nickname") String nickname) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + if (room != null && room.getMember(nickname) != null) { + room.deleteMember(nickname); + } + + return "退出しました"; + } +} \ No newline at end of file diff --git a/src/main/java/com/ntlab/irisserver/resources/MembersRest.java b/src/main/java/com/ntlab/irisserver/resources/MembersRest.java new file mode 100644 index 0000000..3d88054 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/MembersRest.java @@ -0,0 +1,106 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.RoomJson; +import com.ntlab.irisserver.models.RoomManager; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.entities.Member; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Collections; +import javax.ws.rs.*; +import java.util.List; +import java.util.Random; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Component +@Path("/rooms") +public class MembersRest { + + public static void membershuffle(String rid, List m) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + //List<Member>をshuffleする + Collections.shuffle(m); + + for(int i=0; i < 10; i++){ + + //ListのMember人数以上になればbreakする + if(i >= m.size())break; + + //各Memberの情報取ってくる + Member info = m.get(i); + + //Listの0番目と1番目をチームマスターにする + if(i==0){ + info.setMaster(true); + room.changeTeamAndMaster(info.getNickname(), "r", true); + }else if(i==1){ + info.setMaster(true); + room.changeTeamAndMaster(info.getNickname(), "b", true); + }else{ + info.setMaster(false); + } + + //Listの偶数番目を"r"(赤)に、奇数番目を"b"(青)にする + if(i % 2 == 0){ + info.setBelongs("r"); + }else{ + info.setBelongs("b"); + } + + } + + } + + //ランダムにチーム編成を送り、全員の役職を変更する + @PUT + @Path("/{rid}/members") + @Produces(MediaType.APPLICATION_JSON) + public void putMembers(@PathParam("rid") String rid, @FormParam("nickname") String nickname) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + List gm = room.getMembers(); + + //引数で取ってきたnicknameがownerかどうか確認 + String owner = room.getOwnerName(); + if(nickname.equals(owner)) { + //全員の役職を変更 + membershuffle(rid, gm); + }else{ + var response = Response.status(401).entity("あなたはオーナーではありません"); + throw new WebApplicationException(response.build()); + } + + + } + + //自分のnicknameを送り、Roomに追加 + @POST + @Path("/{rid}/members") + @Produces(MediaType.APPLICATION_JSON) + public RoomJson postMembers(@PathParam("rid") String rid, @FormParam("nickname") String nickname) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + List gm = room.getMembers(); + RoomJson rj = new RoomJson(room); + + //引数で取ってきたnicknameがListに存在しているか確認 + if(room.getMember(nickname)==null && gm.size() < 10 ){ + room.addMember(nickname); + } else { + var response = Response.status(401).entity("満席です"); + throw new WebApplicationException(response.build()); + } + + return rj; + + } + + + + + +} \ No newline at end of file diff --git a/src/main/java/com/ntlab/irisserver/resources/RoomsRest.java b/src/main/java/com/ntlab/irisserver/resources/RoomsRest.java new file mode 100644 index 0000000..51f7f5f --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/RoomsRest.java @@ -0,0 +1,70 @@ +package com.ntlab.irisserver.resources; +import com.ntlab.irisserver.entities.Member; +import com.ntlab.irisserver.entities.RoomJson; +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@Component +@Path("/rooms") + + +public class RoomsRest { + + @POST //部屋の作成,オーナーを設定 + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public RoomJson makeRooms(@FormParam("nickname") String owner){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.createRoom(owner); + room.addMember(owner); + RoomJson rj = new RoomJson(room); + + return rj; + } + + @GET//部屋の情報を表示 + @Path("/{rid}") + @Produces(MediaType.APPLICATION_JSON) + public List getRoomMember(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + if(room == null){ + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return room.getMembers(); + } + + @DELETE//部屋の削除 + @Path("/{rid}") + public void deleteRooms(@PathParam("rid") String rid){ + RoomManager rm = RoomManager.getInstance(); + rm.deleteRoom(rid); + } + +//--------------------------------------テスト用------------------------------------------- + + @GET //すべての部屋の情報を表示 + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public List getRoomsInfo() { + RoomManager rm = RoomManager.getInstance(); + rm.getRooms(); + List rms = rm.getRooms(); + + return rms; + } + + +} + diff --git a/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java b/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java new file mode 100644 index 0000000..622a98b --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/SettingsRest.java @@ -0,0 +1,71 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.entities.Settings; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Component +@Path("rooms") +public class SettingsRest { + + RoomManager rm = RoomManager.getInstance(); + +//------------------------------------------------------------------------------------ + //GET:設定情報の入手 + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/{rid}/settings") + public Settings getSettings(@PathParam("rid") String rid) { + + Room r = rm.getRoom(rid); + + //部屋がある時、JsonでSettingsの情報を返す + if (r != null) { + return r.getSettings(); + + } else { + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + } + +//---------------------------------------------------------------------------------------------------- + //PUT:設定値の変更 + @PUT + @Path("/{rid}/settings") + public void putSettings(@PathParam("rid") String rid, + @FormParam("drawingTimer") boolean dTimer, + @FormParam("drawingTimerTimes") int dTimerTimes, + @FormParam("gameTimer") boolean gTimer, + @FormParam("gameTimerTimes") int gTimerTimes, + @FormParam("gameTimerFirstThinkingTimes") int gTimerFTTimes) { + + Room r = rm.getRoom(rid); + var response = Response.status(Response.Status.NO_CONTENT); + + //部屋がある時、値を変更 + if (r != null) { + Settings settings = r.getSettings(); + + settings.setDrawingTimer(dTimer); + settings.setDrawingTimerTimes(dTimerTimes); + settings.setGameTimer(gTimer); + settings.setGameTimerTimes(gTimerTimes); + settings.setGameTimerFirstThinkingTimes(gTimerFTTimes); + + response.status(200).entity("値変更完了"); + throw new WebApplicationException(response.build()); + } else { + //部屋がなければエラー + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + } +} diff --git a/src/main/java/com/ntlab/irisserver/resources/StateRest.java b/src/main/java/com/ntlab/irisserver/resources/StateRest.java new file mode 100644 index 0000000..59fdf0d --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/StateRest.java @@ -0,0 +1,69 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.models.KeywordManager; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.RoomManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + + +@Component +@Path("/rooms") + +public class StateRest implements ApplicationContextAware { + private ApplicationContext applicationContext; + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + @GET//部屋の情報を入手 + + @Path("/{rid}/state") + + public int getState(@PathParam("rid") String rid) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + if(room==null){ + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return room.getState(); //部屋の情報を送る + } +//---------------------------------------------------------------------------------------------------------------------------------- + @PUT//部屋の情報を変更する + + @Path("/{rid}/state") + + //rid,nickname,stateを引数として持ってくる + public void putState(@PathParam("rid") String rid,@FormParam("nickname") String nickname,@FormParam("state") Integer state) throws IOException { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + + + if(nickname.equals(room.ownerName)){ //nicknameがownerだった場合 + room.setState(state); //部屋の情報を変更 + if (state == 2) { + String path; + path = applicationContext.getResource("file:").getFile().getAbsolutePath()+"/apache-tomcat-9.0.10/webapps/irisdata/keywords.txt"; + //path = "C:\\Users\\student\\IdeaProjects\\IrisServer\\src\\main\\java\\com\\ntlab\\irisserver\\tmp\\keywords.txt"; + KeywordManager km = KeywordManager.getInstance(); + String[] keywords = km.getKeywords(path); + Game game = new Game(room, keywords); + } + } + } + + +} diff --git a/src/main/java/com/ntlab/irisserver/resources/TestRest.java b/src/main/java/com/ntlab/irisserver/resources/TestRest.java new file mode 100644 index 0000000..fdcbcb9 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/TestRest.java @@ -0,0 +1,136 @@ +package com.ntlab.irisserver.resources; + +import com.ntlab.irisserver.entities.Drawing; +import com.ntlab.irisserver.entities.Game; +import com.ntlab.irisserver.entities.Member; +import com.ntlab.irisserver.entities.Room; +import com.ntlab.irisserver.models.KeywordManager; +import com.ntlab.irisserver.models.RoomManager; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +@Component +@Path("/rooms") + +public class TestRest implements ApplicationContextAware { + + private org.springframework.context.ApplicationContext applicationContext; + + public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @PUT + @Path("/test") + public void putTestRoom() throws IOException { + KeywordManager km = KeywordManager.getInstance(); + RoomManager rm = RoomManager.getInstance(); + rm.deleteRoom("drawtest"); + rm.deleteRoom("gametest"); + rm.createTestRoom(); + + Room dr = rm.getRoom("drawtest"); + Room gr = rm.getRoom("gametest"); + + //メンバー設定() + dr.addMember("member"); + gr.addMember("RedAgent"); + gr.addMember("BlueSpy"); + gr.addMember("BlueAgent"); + gr.changeTeamAndMaster("RedSpy(owner)", "r", true); + gr.changeTeamAndMaster("RedAgent", "r", false); + gr.changeTeamAndMaster("BlueSpy", "b", true); + gr.changeTeamAndMaster("BlueAgent", "b", false); + + //両部屋:gameインスタンス作成,stateの初期化 + String path = null; + dr.setState(2); + gr.setState(3); + + try { + path = applicationContext.getResource("file:").getFile().getAbsolutePath()+"/apache-tomcat-9.0.10/webapps/irisdata/keywords.txt"; + } catch (IOException e) { + e.printStackTrace(); + } + String[] keywords = km.getKeywords(path); + Game dgame = new Game(dr, keywords); + Game game = new Game(gr, keywords); + + //gametest部屋:絵の格納 + for(int i = 0; i < 16; i++){ + Drawing draw = new Drawing(); + switch (i) { + case 0: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test01.jpg"; + break; + case 1: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test02.jpg"; + break; + case 2: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test03.jpg"; + break; + case 3: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test04.jpg"; + break; + case 4: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test05.jpg"; + break; + case 5: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test06.jpg"; + break; + case 6: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test07.jpg"; + break; + case 7: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test08.jpg"; + break; + case 8: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test09.jpg"; + break; + case 9: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test10.jpg"; + break; + case 10: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test11.jpg"; + break; + case 11: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test12.jpg"; + break; + case 12: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test13.jpg"; + break; + case 13: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test14.jpg"; + break; + case 14: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test15.jpg"; + break; + case 15: + path = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test16.jpg"; + break; + default: + break; + } + draw.setDrawing(path); + if(i<8){ + game.putDrawing(i*2, draw); + }else{ + game.putDrawing(i*2-15, draw); + } + + } + + + } + + +} +//applicationContext.getResource("file:").getFile().getAbsolutePath() + "/apache-tomcat-9.0.10/webapps/irisdata/image/test16.jpg"; diff --git a/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java b/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java new file mode 100644 index 0000000..2861983 --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/resources/TurnsRest.java @@ -0,0 +1,261 @@ +package com.ntlab.irisserver.resources; +import com.ntlab.irisserver.entities.*; +import org.springframework.stereotype.Component; +import com.ntlab.irisserver.models.RoomManager; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; +import java.util.Iterator; + +@Component +@Path("/rooms") + + +public class TurnsRest { + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns: + + @GET //現在のターンの取得 + @Path("/{rid}/game/turns") + @Produces(MediaType.APPLICATION_JSON) + public Integer getTurnNumber(@PathParam("rid") String rid) { + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Integer tn = game.getNowTurn(); + + return tn; + } + + @POST //新しいターンの作成 + @Path("/{rid}/game/turns") + @Produces(MediaType.APPLICATION_JSON) + public void addTurns(@PathParam("rid") String rid) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + game.createTurn(); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}: + + @GET //Turnインスタンスの取得 + @Path("/{rid}/game/turns/{tno}") + @Produces(MediaType.APPLICATION_JSON) + public TurnJson getTurns(@PathParam("rid") String rid, @PathParam("tno") int tno) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + TurnJson tj = new TurnJson(t); + + if (t == null) { + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + return tj; + } + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/hint: + + @GET //ヒントを取得 + @Path("/{rid}/game/turns/{tno}/hint") + @Produces(MediaType.TEXT_PLAIN) + public String getHint(@PathParam("rid") String rid, @PathParam("tno") int tno){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getHint(); + } + + @PUT //ヒントと最大数を入力することで諜報員のターンに遷移する + @Path("/{rid}/game/turns/{tno}/hint") + public void putHint(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("hint") String hint, @FormParam("max") Integer max){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setHint(hint); + t.setMax(max); + t.setTurnstate(1); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/max: + @GET //Maxを取得 + @Path("/{rid}/game/turns/{tno}/max") + public Integer getMax(@PathParam("rid") String rid, @PathParam("tno") int tno){ + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getMax(); + } + +/* + @PUT //putHintに吸収合併 + @Path("/{rid}/game/turns/{tno}/max") + public void putMax(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("max") int max){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setMax(max); + + } +*/ + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/questions: + + @GET //カードごとの疑っている人のリストを取得...は動いてんのかな? + @Path("/{rid}/game/turns/{tno}//questions") + @Produces(MediaType.APPLICATION_JSON) + public Boolean[] getQ(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getQuestionsList(); + } + + @POST //怪しいの切り替え + @Path("/{rid}/game/turns/{tno}/questions") + public void changeQ(@PathParam("rid") String rid, @PathParam("tno") int tno, @FormParam("cno") int cno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + t.setQuestions(cno); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/openlist: + + @GET + @Path("/{rid}/game/turns/{tno}/openlist") + @Produces(MediaType.APPLICATION_JSON) + public List getOpenList(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getOpenListAll(); + } + + @PUT //オープンリストの追加 カードをめくったときの色ごとの処理() + @Path("/{rid}/game/turns/{tno}/openlist") + public void setOpenList(@PathParam("rid") String rid, @PathParam("tno") Integer tno, @FormParam("cno")Integer cno) { + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + Cell card = game.getCell(cno); + + t.addOpenList(cno); + card.setIsOpen(true); + + //turnが続くかの判定 + /* + int i; + int r = 0; + int b = 0; + for(i = 0; i < 16; i++){ + Cell cell = game.getCell(i); + boolean isOpen = cell.getIsOpen(); + if(isOpen == true){ + if(cell.getColor() == "r")r++; + if(cell.getColor() == "b")b++; + } + } + if(card.color == "d"){ + t.setEndstate(1); + }else if(r >= 6||(b >= 5)){ + t.setEndstate(1); + }else if(t.getMax() <= t.getOpenListAll().size()){ + game.createTurn(); + }else if(card.color == "g"||(card.color != t.getTeam())){ + game.createTurn(); + } + */ + + } + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/turnstate: + + @GET + @Path("/{rid}/game/turns/{tno}/turnstate") + @Produces(MediaType.APPLICATION_JSON) + public Integer getTurnstate(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getTurnstate(); + } + + @PUT //Turnstateを1に変更 + @Path("/{rid}/game/turns/{tno}/turnstate") + public void setTurnstate(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setTurnstate(1); + + } + + //------------------------------------------------------------------------ + // rooms/{rid}/game/turns/{tno}/endstate: + + @GET + @Path("/{rid}/game/turns/{tno}/endstate") + @Produces(MediaType.APPLICATION_JSON) + public Integer getEndstate(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + + return t.getEndstate(); + } + + @PUT //Endstateを1に変更 + @Path("/{rid}/game/turns/{tno}/endstate") + public void setEndstate(@PathParam("rid") String rid, @PathParam("tno") int tno){ + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + Game game = room.getGame(); + Turn t = game.getTurn(tno); + t.setEndstate(1); + + } + +} diff --git a/src/main/java/com/ntlab/irisserver/utils/Base64Decode.java b/src/main/java/com/ntlab/irisserver/utils/Base64Decode.java new file mode 100644 index 0000000..edec65c --- /dev/null +++ b/src/main/java/com/ntlab/irisserver/utils/Base64Decode.java @@ -0,0 +1,38 @@ +package com.ntlab.irisserver.utils; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Base64; + +public class Base64Decode { + public static String saveAsFile(String rid ,Integer dno ,String path1 ,String enimage) throws IOException { + + //デコードを行う + byte[] dedata = Base64.getDecoder().decode(enimage); + + //ファイルを作成する + String fileName = rid + "-" + dno.toString() + ".png"; + String path = path1 + "/" + fileName; + + + File file = new File(path); + file.getParentFile().mkdirs(); + file.createNewFile(); + + //ファイルに画像データを書き込む + FileOutputStream file1 = new FileOutputStream(file, false); + BufferedOutputStream bf = new BufferedOutputStream(file1); + bf.write(dedata, 0, dedata.length); + + //ファイルを閉じる + bf.close(); + + // 保存先のURLリンクを返す + String drawingUrlPath = "http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/" + rid + "-" + dno + ".png"; + + //セーブしたファイルの相対パスを文字列として返す + return drawingUrlPath; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..70533cf --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +server.servlet.context-path=/iris \ No newline at end of file diff --git a/src/test/java/com/ntlab/irisserver/IrisServerApplicationTests.java b/src/test/java/com/ntlab/irisserver/IrisServerApplicationTests.java new file mode 100644 index 0000000..40ea36b --- /dev/null +++ b/src/test/java/com/ntlab/irisserver/IrisServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.ntlab.irisserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class IrisServerApplicationTests { + + @Test + void contextLoads() { + } + +}