Skip to content

Commit

Permalink
0.10.0
Browse files Browse the repository at this point in the history
* Clean up logging
* Add more requests to Requests.http
* Upgrade jars
* Upgrade kotlin to 1.4.30
  • Loading branch information
pambrose authored Feb 3, 2021
1 parent 6e1499b commit 5405807
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 133 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ versioncheck:
./gradlew dependencyUpdates

upgrade-wrapper:
./gradlew wrapper --gradle-version=6.8 --distribution-type=bin
./gradlew wrapper --gradle-version=6.8.1 --distribution-type=bin
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'java'
id 'maven'
id 'org.jetbrains.kotlin.jvm' version '1.4.30-M1'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.30-M1'
id 'org.jetbrains.kotlin.jvm' version '1.4.30'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.30'
id "com.github.ben-manes.versions" version "0.36.0"
}

Expand All @@ -18,7 +18,7 @@ sourceCompatibility = 1.8

description = 'battlesnake-quickstart'
group = 'io.battlesnake'
version = '0.9.0'
version = '0.10.0'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
Expand Down
17 changes: 1 addition & 16 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
#
# Copyright © 2021 Paul Ambrose (pambrose@mac.com)
#
# 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
#
# http://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.
#
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env sh

#
# Copyright © 2021 Paul Ambrose (pambrose@mac.com)
# Copyright 2015 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
#
# http://www.apache.org/licenses/LICENSE-2.0
# 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,
Expand Down
178 changes: 89 additions & 89 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,89 +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
@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
20 changes: 19 additions & 1 deletion requests/Requests.http
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
GET http://localhost:8080/

###
GET http://localhost:8080/info

###
POST http://localhost:8080/start
Content-Type: application/json

Expand Down Expand Up @@ -165,4 +171,16 @@ Content-Type: application/json
"length": 3,
"shout": ""
}
}
}

###
GET http://localhost:8080/left

###
GET http://localhost:8080/right

###
GET http://localhost:8080/up

###
GET http://localhost:8080/down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/battlesnake/core/AbstractBattleSnake.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class AbstractBattleSnake<T : SnakeContext> : KLogging() {
snakeContext()
.let { context ->
val startRequest = call.receive<StartRequest>()
logger.info { "Creating new snake context for ${startRequest.gameId}" }
//logger.info { "Creating new snake context for ${startRequest.gameId}" }
context.resetStartTime()
context.assignIds(startRequest.gameId, startRequest.you.id)
context.assignRequestResponse(call)
Expand Down
31 changes: 11 additions & 20 deletions src/main/kotlin/io/battlesnake/core/ktor/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import io.battlesnake.core.right
import io.battlesnake.core.up
import io.ktor.application.*
import io.ktor.html.*
import io.ktor.http.*
import io.ktor.http.ContentType.Application.Json
import io.ktor.response.*
import io.ktor.routing.*
import kotlinx.html.Entities.nbsp
Expand All @@ -47,14 +47,9 @@ import kotlinx.html.id
import kotlinx.html.script
import kotlinx.html.span
import kotlinx.html.unsafe
import mu.KLogging

object Routes : KLogging()

fun Application.routes(snake: AbstractBattleSnake<*>) {

routing {

get(INFO) {
call.respondHtml {
head {}
Expand All @@ -76,53 +71,49 @@ fun Application.routes(snake: AbstractBattleSnake<*>) {
}

get(DESCRIBE) {
// We call response.toJson() to avoid ktor adding the "type" property to the json
val response = snake.process(call) as DescribeResponse
call.respondText(response.toJson(), ContentType.Application.Json)
call.respondText(response.toJson(), Json)
}

post(DESCRIBE) {
val response = snake.process(call) as DescribeResponse
call.respondText(response.toJson(), ContentType.Application.Json)
call.respondText(response.toJson(), Json)
}

post(START) {
call.response.headers.append(HttpHeaders.CacheControl, "no-cache, no-store")
val response = snake.process(call) as StartResponse
call.respondText(response.toJson(), ContentType.Application.Json)
call.respondText(response.toJson(), Json)
}

post(MOVE) {
call.response.headers.append(HttpHeaders.CacheControl, "no-cache, no-store")
val response = snake.process(call) as MoveResponse
val json = response.toJson()
Routes.logger.info { "Return value:\n$json" }
call.respondText(json, ContentType.Application.Json)
call.respondText(response.toJson(), Json)
}

post(END) {
call.response.headers.append(HttpHeaders.CacheControl, "no-cache, no-store")
val response = snake.process(call) as EndResponse
call.respondText(response.toJson(), ContentType.Application.Json)
call.respondText(response.toJson(), Json)
}

get("/left") {
val response = left("Going left")
call.respond(response)
call.respondText(response.toJson(), Json)
}

get("/right") {
val response = right("Going right")
call.respond(response)
call.respondText(response.toJson(), Json)
}

get("/up") {
val response = up("Going up")
call.respond(response)
call.respondText(response.toJson(), Json)
}

get("/down") {
val response = down("Going down")
call.respond(response)
call.respondText(response.toJson(), Json)
}
}
}
Expand Down

0 comments on commit 5405807

Please sign in to comment.