Codenjoy is a framework for developers. Its goal is to organize fun teambuilding activities and/or train how to code. Already now you have some games on board. And you can write one that will be your own.
All you need to develop a game is jdk11, maven3, git client and IDE Idea. All you need to develop a game is jdk11, maven3, git client and IDE Idea.
- install a git client locally, for example, tortoise git
- create an account on github or bitbucket
- make a fork (or copy the sample project) from the current repository
- pull the project to your computer
- install maven3 (download the archive and unzip it to
c:\java)- If any problems with build, please use version 3.6.3
- add the
M2_HOMEenvironment variable that points to the root ofc:\java\apache-maven-3.x.x - add the
;%M2_HOME%\binstring at the end of thePathvariable - install jdk, if necessary (also to the folder
c:\java) - add the
JAVA_HOMEenvironment variable that points to the root ofc:\java\jdk1.x.x_xx - add the
;%JAVA_HOME%\binstring at the end of the Path variable - check by running cmd.exe with the
mvn -versioncommand. If installation is successful, you will see the command output the version of maven and java, rather than "command not found"
C:\Users\user>mvn -version
Apache Maven 3.x.x
Maven home: C:\java\apache-maven-3.x.x
Java version: 1.x.x_x, vendor: Oracle Corporation
Java home: C:\java\jdk1.x.x_xx\jre
Default locale: xxxxx, platform encoding: xxxxxxx
OS name: "xxxxxxxxxx", version: "xxx", arch: "xxxxx", family: "xxxxxxx"
C:\Users\user>- download and install IntelliJ IDEA Community version
- install Lombok plugin for idea
- [Optional] clone and install our changes of maven plugins
- in
masterbranch markdown-page-generator-plugin - in
masterbranch minify-maven-plugin - otherwise you will get it from codenjoy maven repository located on GitHub
<snapshotRepository> <id>codenjoy-snapshots</id> <url>https://github.com/codenjoyme/codenjoy-repo/raw/master/snapshots</url> </snapshotRepository>
- in
To run a project with your game, do the following:
- clone the project from the codenjoy main repository
with submodules
git clone --recursive https://github.com/codenjoyme/codenjoy.git
- configure Codenjoy server by modifying the settings in files:
- \CodingDojo\server\src\main\resources\application.yml
- you can change any of these properties in runtime by using parameters
mvn ... -Dkey1=value1 -Dkey2=value2java -jar ... --key1=value1 --key2=value2
- you can change any of these properties in runtime by using parameters
- \CodingDojo\server\src\main\webapp\resources\js\init.js
- \CodingDojo\server\src\main\resources\application.yml
- build one game
- run
mvn clean install -N -DskipTests=truein the\CodingDojo\gamesproject to install only games parent project - run
mvn clean install -DskipTests=truein the\CodingDojo\clients\javaproject to install java client dependency - run
mvn clean install -DskipTests=truein the\CodingDojo\games\engineproject to install games engine dependency - run
mvn clean install -DskipTests=truein the\CodingDojo\games\yourgameproject to install your game - run
mvn clean spring-boot:run -DMAVEN_OPTS=-Xmx1024m -Dmaven.test.skip=true -Dspring.profiles.active=sqlite,yourgame,debug -Dcontext=/codenjoy-contest -Dserver.port=8080 -Pyourgamein the\CodingDojo\serverproject to launch the game (where 'yourgame') is a name of profile that you have set recently in\CodingDojo\server\pom.xml. There may be several games listed separated by commas.
- run
- build all games
- run
mvn clean install -DskipTests=truein the\CodingDojo\gamesproject to install all games - If you want to run all games just run
mvn clean spring-boot:run -DMAVEN_OPTS=-Xmx1024m -Dmaven.test.skip=true -Dspring.profiles.active=sqlite,debug -Dcontext=/codenjoy-contest -Dserver.port=8080 -DallGames
- run
- if maven is not installed on you machine, try
mvnwinstead ofmvn - a simpler way of launching Codenjoy with all games is by running a script in the root
\CodingDojo\build-server.batthen\CodingDojo\start-server.bat- please change
set GAMES_TO_RUN=tetris,knibert,mollymagebefore run\CodingDojo\build-server.bat - also you can change properties
--spring.profiles.active=sqlite,debug --context=/codenjoy-contest --server.port=8080inside\CodingDojo\start-server.batcontextchanges link to the application http://127.0.0.1:8080/codenjoy-contestserver.portthe port on which the application startsspring.profiles.activesqlitefor the lightweight database (<50 participants)postgresfor the postgres database (>50 participants)database.hostdatabase server host,localhostby defaultdatabase.portdatabase server port,5432by defaultdatabase.namedatabase name,codenjoyby defaultdatabase.userusername to connect,codenjoyby defaultdatabase.passwordpassword to connect,securePostgresDBPasswordby default
tracefor enable log.debugdebugif you want to debug js files (otherwise it will compress and obfuscate)yourgameif you added your custom configuration to the game insideCodingDojo\games\yourgame\src\main\resources\application-yourgame.yml
- please change
- another way to run game from war
- build war file
mvn clean package -DskipTests=true -DallGamesin the\CodingDojo\serverproject to build server with all games - build war file
mvn clean package -DskipTests=true -Pyourgamein the\CodingDojo\serverproject to build server with (one or) several gamesyourgamecan be a CSV listyourgame1,yourgame2
- run war like jar file
java -jar codenjoy-contest.war --spring.profiles.active=sqlite,debug,yourgamein the\CodingDojo\server\target
- build war file
- after that in the browser access http://127.0.0.1:8080/codenjoy-contest and register the player
- you can read a description of any game on the help page http://127.0.0.1:8080/codenjoy-contest/help
- in case of any problems, please email [email protected] or chat to Skype Oleksandr Baglai
There are three scripts to run Codenjoy on Ubuntu and Windows:
- How to run the server on Ubuntu
- How to run the server on Windows
- How to run the server on Linux (simple version)
By default, the run goal runs your application in a forked process. If you need to debug it, you should add the necessary JVM arguments to enable remote debugging
mvn clean spring-boot:run "-Dspring-boot.run.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -DMAVEN_OPTS=-Xmx1024m -Dmaven.test.skip=true -Dspring.profiles.active=sqlite,yourgame,debug -Dcontext=/codenjoy-contest -Dserver.port=8080" -Pyourgame
You should have such a log message that ensures the server can process a remote debug connection
[INFO] --- spring-boot-maven-plugin:2.1.18.RELEASE:run (default-cli) @ codenjoy-contest ---
[INFO] Attaching agents: []
Listening for transport dt_socket at address: 5005
Then you can launch Remote JVM Debug with the following command line arguments
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
To find out more on how to create a game, read here
Game server has support of two RDBMS solutions: PostgreSQL and SQLite. Choice of exact solution is implemented by means of Spring profile and is mandatory (e.i. server will fail to start if none of database-profiles are chosen).
To choose DB implementation, add one of profiles below into either --spring.profiles.active CLI argument or
SPRING_PROFILES_ACTIVE environment variables:
| Spring profile | Purpose |
|---|---|
postgresql |
Aims game server to PostgreSQL database. Setting up application-postgresql.yml properties properly is mandatory |
sqlite |
Aims game server to SQLite database. Set up application-sqlite.yml properties to change SQLite files location |
Server supports for several authorization and authentication approaches depending on Spring profiles that must be set
either by --spring.profiles.active CLI argument or SPRING_PROFILES_ACTIVE environment variable:
| spring profile | purpose |
|---|---|
| default profile | If none of authorization specific profiles are set server will run with form-based authorization. User data along with email, password and roles are being stored in USERS table in underlying DBSee [Choosing database](## Choosing database) |
oauth2 |
Profile sets up the server to use Authorization Grant Type OAuth2 flow according to provided authorization settings in application-oauth2.yml.Any non-authenticated user is redirected to Authorization Server login form. (see authorization settings below) |
sso |
Profile sets up the server to use Authorization Grant Type OAuth2 flow according to provided authorization settings in application-sso.yml.This profile in opposite to oauth2 one does not support for SA's form-based redirects. It checks Authorization http header instead to authorize incoming requests. Server running in this profile is meant to be deployed behind authorization aware reverse-proxy |
oauth2 and sso profiled server instance must be provided with proper OAuth2 specific settings in application context via CLI arguments or env. vars according to spring framework specification.
Those mandatory settings are:
| application property | env. variable (if supported) |
Purpose |
|---|---|---|
auth-server.location |
OAUTH2_AUTH_SERVER_URL |
Authorization Server URL |
spring.security.oauth2.client.registration.dojo.client-id |
OAUTH2_CLIENT_ID |
OAuth2 client_id. Client with specified ID must be registered on AS |
spring.security.oauth2.client.registration.dojo.client-secret |
OAUTH2_CLIENT_SECRET |
OAuth2 client_secret. Client secret for client_id |
spring.security.oauth2.client.registration.dojo.scopeDefault value is: openid profile email |
OAUTH2_SCOPES |
OAuth2 scopes used for Resource Server resources restriction. Few standard scopes: • profile - includes user name information into userinfo endpoint response and/or into Identity Tokens• email - includes email address into userinfo endpoint response and/or into Identity token• id_token - OpenID Connect specific scopes. Requests AS to enroll Identity Token along with access_token |
spring.security.oauth2.client.provider.dojo.authorization-uri |
OAUTH2_AUTH_URI |
AS Authorization URI (part after auth-server.location)Provides user with AS authentication form. For more details see OAuth2 RFC |
spring.security.oauth2.client.provider.dojo. token-uri |
OAUTH2_TOKEN_URI |
AS Token URI (part after auth-server.location)Provides an access_token (and id_token if AS supports OpenID Connect).For more details see OAuth2 RFC |
spring.security.oauth2.client.provider.dojo.jwk-set-uri |
OAUTH2_JWKS_URI |
AS JWKS URI (part after auth-server.location)Provides information about AS signature algorithms and Public Keys. Only for OpenID Connect compatible AS For more details see OIDC RFC |
spring.security.oauth2.client.provider.dojo.user-info-uri |
OAUTH2_USERINFO_URI |
AS Userinfo URI (part after auth-server.location)Provides information about user depending on requested scopes and in response to properly authorized request For more details see OAuth2 RFC |
spring.security.oauth2.client.provider.dojo.user-name-attribute |
OAUTH2_USERNAME_ATTR |
Key for the user name attribute in AS response to Userinfo endpoint request For more details see OAuth2 RFC |
For oauth2 try run clean install spring-boot:run -DMAVEN_OPTS=-Xmx1024m -Dmaven.test.skip=true -Dspring.profiles.active=sqlite,debug,oauth2 -Dcontext=/codenjoy-contest -DallGames -DOAUTH2_AUTH_SERVER_URL=https://authorization-server.com/core -DOAUTH2_AUTH_URI=/connect/authorize -DOAUTH2_CLIENT_ID=dojo -DOAUTH2_CLIENT_SECRET=secret -DOAUTH2_TOKEN_URI=/connect/token -DOAUTH2_USERINFO_URI=/connect/userinfo -DCLIENT_NAME=dojo
Then try go to /codenjoy-contest from browser, follow authorize steps and play the game.
For sso try run clean install spring-boot:run -DMAVEN_OPTS=-Xmx1024m -Dmaven.test.skip=true -Dspring.profiles.active=sqlite,debug,sso -Dcontext=/codenjoy-contest -DallGames -DOAUTH2_AUTH_SERVER_URL=https://authorization-server.com/core -DOAUTH2_AUTH_URI=/connect/authorize -DOAUTH2_CLIENT_ID=dojo -DOAUTH2_CLIENT_SECRET=secret -DOAUTH2_TOKEN_URI=/connect/token -DOAUTH2_USERINFO_URI=/connect/userinfo -DCLIENT_NAME=dojo
Then try go to /codenjoy-contest from browser, follow authorize steps and play the game.
<oauth>
<error_description>
Full authentication is required to access this resource
</error_description>
<error>unauthorized</error>
</oauth>
Don't worry about it. Just download postman and create GET request:
http://127.0.0.1/codenjoy-contest/board/rejoining/mollymage/room/<ROOM_NAME>- or
http://127.0.0.1/codenjoy-contest/board/rejoining/mollymage - with
Authorization->Bearer Token=USER_JWT_TOKEN_FROM_AUTHORIZATION_SERVERAfter submit you can see html page with board, try find inside:
<body style="display:none;">
<div id="settings" page="board" contextPath="/codenjoy-contest" gameName="mollymage"
playerId="t8o7ty34t9h43fpgf9b8" readableName="Stiven Pupkin" code="3465239452394852393"
allPlayersScreen="false"></div>
Another way to add Authroization: Bearer USER_JWT_TOKEN_FROM_AUTHORIZATION_SERVER header parameter.
Also you can use https://jwt.io/ to parse USER_JWT_TOKEN_FROM_AUTHORIZATION_SERVER and get additional data.