Skip to content

Commit

Permalink
Merge pull request lightvector#122 from lightvector/misc
Browse files Browse the repository at this point in the history
Readme and license file tweaks, disable debug page in production mode
  • Loading branch information
lightvector committed Jan 23, 2016
2 parents 5841d6a + 1113118 commit 1866cc9
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 28 deletions.
60 changes: 60 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -17,15 +17,17 @@

### 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.

## API
To run the server separately, not within SBT, such as you might do on a production machine rather than one used for development:

* See https://github.com/lightvector/arimaa-server/wiki/Arimaa-Game-Server-JSON-API for the current API.
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.

## SBT memory configuration

Expand All @@ -38,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
Expand Down
27 changes: 13 additions & 14 deletions src/main/scala/org/playarimaa/server/ArimaaServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 )
}
}

}
13 changes: 5 additions & 8 deletions src/main/scala/org/playarimaa/server/DatabaseConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -66,4 +64,3 @@ object DatabaseConfig {
}
}
}

14 changes: 14 additions & 0 deletions src/main/scala/org/playarimaa/server/Mode.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 1866cc9

Please sign in to comment.