From d15bf8329aa59e24b49ef701b99490f2536d3631 Mon Sep 17 00:00:00 2001 From: lightvector Date: Sat, 23 Jan 2016 14:46:28 -0500 Subject: [PATCH 1/4] Update readme --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b201c1..f56047f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # arimaa-server -[playArimaa](http://playarimaa.org) +This site is currently live in alpha at: [playArimaa.org](http://playarimaa.org/) ## Getting started @@ -17,15 +17,20 @@ ### Further Setup If you want to run the server in a production mode with persistent state (as opposed to an in-memory db that is erased when the server is restarted) and also have the email features of the site working properly: -1. Set up an empty postgres database and/or an email server, editing `src/main/resources/application.conf` appropriately. + +1. Set up an empty postgres database, (Google for how to do this), editing `src/main/resources/application.conf` with the values necessary to connect to the database. 2. Run the command `sbt -DisProd=true 'run-main org.playarimaa.server.CreateTables'` from the command line to create the necessary tables in the empty database. -3. Set up an smtp server or register for an online service (such as via gmail) so that the server can send email, editing `src/main/resources/application.conf` appropriately. -4. Run `gulp build` as necessary for any other changes you might have made to the frontend. +3. Set up an email/smtp server, or register for an online service for smtp (such as Amazon SES if you're using Amazon Web Services), again editing `src/main/resources/application.conf` as needed so that the server can send email. +4. Run `gulp build` as necessary if you make any changes to the frontend in the process. 5. Within sbt, run `startServerProd` to start up the webserver in production mode. +To run the server separately, not within SBT, such as you might do on a production machine rather than one used for development: +6. Download an appropriate Java servlet engine such as Jetty: http://www.eclipse.org/jetty/. For a quick lightweight start, consider Jetty Runner: http://www.eclipse.org/jetty/documentation/9.2.3.v20140905/runner.html +7. Within sbt, run `clean` and then `package` to build a ".war" file in target/scala-2.11/. This is the packaged servlet that can then be run using Jetty or the servlet engine. Note that `clean` is often necessary here because if there are stale unused build files left over from development, they can sometimes actually get packaged in with the .war file and cause issues. + ## API -* See https://github.com/lightvector/arimaa-server/wiki/Arimaa-Game-Server-JSON-API for the current API. +* See https://github.com/lightvector/arimaa-server/wiki/Arimaa-Game-Server-JSON-API for the current API. As the site is new and major features are still being worked out, the API is subject to change, although most of the basic queries, such as those directly involved in joining and playing games are unlikely to change much more at this point (except for possibly the addition of new fields to the return values of the queries). ## SBT memory configuration From 077ba57bbdb367149643491ae38cac98c5c48f40 Mon Sep 17 00:00:00 2001 From: lightvector Date: Sat, 23 Jan 2016 15:00:28 -0500 Subject: [PATCH 2/4] Disable the debug page in production mode --- .../org/playarimaa/server/ArimaaServlet.scala | 27 +++++++++---------- .../playarimaa/server/DatabaseConfig.scala | 13 ++++----- .../scala/org/playarimaa/server/Mode.scala | 14 ++++++++++ 3 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 src/main/scala/org/playarimaa/server/Mode.scala diff --git a/src/main/scala/org/playarimaa/server/ArimaaServlet.scala b/src/main/scala/org/playarimaa/server/ArimaaServlet.scala index 5b5d7b6..c32a50d 100644 --- a/src/main/scala/org/playarimaa/server/ArimaaServlet.scala +++ b/src/main/scala/org/playarimaa/server/ArimaaServlet.scala @@ -4,17 +4,13 @@ import org.scalatra.scalate.ScalateSupport import org.json4s.{DefaultFormats, Formats} import org.scalatra.json.JacksonJsonSupport +import org.json4s.jackson.Serialization -case class Response(message: String, message2: Option[String], timestamp: Long) -object Response { - def create(message: String): Response = { - val timestamp = System.currentTimeMillis() - Response(message,None,timestamp) - } - def create(message: String, message2: String): Response = { - val timestamp = System.currentTimeMillis() - Response(message,Some(message2),timestamp) - } +import org.playarimaa.server.CommonTypes._ +import org.playarimaa.server.Utils._ + +object IOTypes { + case class SimpleError(error: String) } class ArimaaServlet(val siteLogin: SiteLogin) @@ -108,9 +104,12 @@ class ArimaaServlet(val siteLogin: SiteLogin) } get("/debug/?") { - contentType="text/html" - val path = "/board.html" - new java.io.File( getServletContext().getResource(path).getFile ) + if(Mode.isProd) + Json.write(IOTypes.SimpleError("Debug page not available in production mode")) + else { + contentType="text/html" + val path = "/board.html" + new java.io.File( getServletContext().getResource(path).getFile ) + } } - } diff --git a/src/main/scala/org/playarimaa/server/DatabaseConfig.scala b/src/main/scala/org/playarimaa/server/DatabaseConfig.scala index 4c7eb4a..ea0a49e 100644 --- a/src/main/scala/org/playarimaa/server/DatabaseConfig.scala +++ b/src/main/scala/org/playarimaa/server/DatabaseConfig.scala @@ -20,15 +20,13 @@ object DatabaseConfig { //Switch which db we load based on whether we are in prod or test. See /project/Build.scala for the run configurations //that take advantage of this lazy val whichDB: WhichDB = { - System.getProperty("isProd") match { - case "true" => - logger.info("Using PostgresDB") + Mode.isProd match { + case true => + logger.info("Server in production mode - using PostgresDB") PostgresDB - case "false" => - logger.info("Using H2DB") + case false => + logger.info("Server in testing mode - using H2DB") H2DB - case null => throw new Exception("isProd system property undefined, expected \"true\" or \"false\"") - case x => throw new Exception("Unexpected value for isProd system property, expected \"true\" or \"false\": " + x) } } @@ -66,4 +64,3 @@ object DatabaseConfig { } } } - diff --git a/src/main/scala/org/playarimaa/server/Mode.scala b/src/main/scala/org/playarimaa/server/Mode.scala new file mode 100644 index 0000000..0060780 --- /dev/null +++ b/src/main/scala/org/playarimaa/server/Mode.scala @@ -0,0 +1,14 @@ +package org.playarimaa.server + +object Mode { + + //Is the server running in production mode? + def isProd: Boolean = { + System.getProperty("isProd") match { + case "true" => true + case "false" => false + case null => throw new Exception("isProd system property undefined, expected \"true\" or \"false\"") + case x => throw new Exception("Unexpected value for isProd system property, expected \"true\" or \"false\": " + x) + } + } +} From 1b89563983782b09fc49bab4a0b42be65f36082e Mon Sep 17 00:00:00 2001 From: lightvector Date: Sat, 23 Jan 2016 15:23:25 -0500 Subject: [PATCH 3/4] Add license file and slightly rearrange readme. --- LICENSE.txt | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++++++---- 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..169bef3 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,60 @@ +The source code, files, and other resources in this repository are +freely provided for distribution, modification, and use under a +BSD-style license, the text of which is below. + +HOWEVER, the rights granted under this license DO NOT extend to the +Arimaa game itself, and any commercial or non-commercial usage +involving the Arimaa game (such as running a public copy of this +website) may require additional authorization, as the owner of Arimaa +has retained all rights to the game itself. + +In particular, any user of the contents of this repository or of any +derivative work based on it, if such usage involves the Arimaa game or +the Arimaa name in any way, is responsible for ensuring that the usage +complies with the Arimaa Public License +(http://arimaa.com/arimaa/license/current.txt) and is responsible for +obtaining any necessary authorization or license by contacting +Arimaa.com. The Arimaa name is a trademark of Arimaa.com. The Arimaa +game is patented. The Arimaa game rules are copyright protected. + +---------------------------------------------------------------------- + +The following license covers all the contents of this repository and +their distribution, modification, and usage for any non-Arimaa-related +purposes, as well as their distribution, modification, and usage for +any Arimaa-related purposes subject to compliance with the Arimaa +Public License linked above. + +Copyright (c) 2016, playarimaa.org +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index f56047f..68119d1 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,10 @@ If you want to run the server in a production mode with persistent state (as opp 5. Within sbt, run `startServerProd` to start up the webserver in production mode. To run the server separately, not within SBT, such as you might do on a production machine rather than one used for development: + 6. Download an appropriate Java servlet engine such as Jetty: http://www.eclipse.org/jetty/. For a quick lightweight start, consider Jetty Runner: http://www.eclipse.org/jetty/documentation/9.2.3.v20140905/runner.html 7. Within sbt, run `clean` and then `package` to build a ".war" file in target/scala-2.11/. This is the packaged servlet that can then be run using Jetty or the servlet engine. Note that `clean` is often necessary here because if there are stale unused build files left over from development, they can sometimes actually get packaged in with the .war file and cause issues. -## API - -* See https://github.com/lightvector/arimaa-server/wiki/Arimaa-Game-Server-JSON-API for the current API. As the site is new and major features are still being worked out, the API is subject to change, although most of the basic queries, such as those directly involved in joining and playing games are unlikely to change much more at this point (except for possibly the addition of new fields to the return values of the queries). - ## SBT memory configuration Note that to avoid memory leaks via Java's permanent generation in a long-running sbt process, @@ -43,6 +40,20 @@ to call Java with the following flags: -XX:+UseConcMarkSweepGC -XX:MaxPermSize=1G +## API + +See https://github.com/lightvector/arimaa-server/wiki/Arimaa-Game-Server-JSON-API for the current API. + +As the site is new and major features are still being worked out, the API is subject to change, although most of the basic queries, such as those directly involved in joining and playing games are unlikely to change much more at this point (except for possibly the addition of new fields to the return values of the queries). + + +## License + +The contents of this repository are available under a BSD-style license. However, please note that this license alone does not grant usage for purposes related to the Arimaa game or any rights the Arimaa game itself - for that, please contact the creator of Arimaa at http://arimaa.com/. + +See the included LICENSE.txt file for more details: https://github.com/lightvector/arimaa-server/blob/master/LICENSE.txt + + ## Contributors * lightvector From 1113118b956d63b3829fcefc8b1500340b2bf1b7 Mon Sep 17 00:00:00 2001 From: lightvector Date: Sat, 23 Jan 2016 16:04:45 -0500 Subject: [PATCH 4/4] Tiny tweak to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68119d1..418f129 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # arimaa-server -This site is currently live in alpha at: [playArimaa.org](http://playarimaa.org/) +This site is currently live in alpha at: [playarimaa.org](http://playarimaa.org/) ## Getting started