lila/README.md

267 lines
8.7 KiB
Markdown
Raw Normal View History

2013-06-08 04:40:31 -06:00
[lichess.org](http://lichess.org)
2013-06-08 05:25:27 -06:00
---------------------------------
2013-06-08 04:40:31 -06:00
It's a free online chess game focused on [realtime](http://lichess.org/games) and simplicity.
It haz a [search engine](http://lichess.org/games/search),
2013-12-27 02:42:50 -07:00
[computer analysis](http://lichess.org/analyse/ief49lif),
[tournaments](http://lichess.org/tournament),
[forums](http://lichess.org/forum),
[teams](http://lichess.org/team),
2013-06-08 04:40:31 -06:00
and a weird [monitoring console](http://lichess.org/monitor).
The UI is available in [72 languages](http://lichess.org/translation/contribute) thanks to the community.
2013-12-27 02:42:50 -07:00
Lichess is written in [Scala 2.10](http://www.scala-lang.org/),
2013-10-06 10:27:28 -06:00
and relies on [Play 2.2](http://www.playframework.com/) for the routing, templating, and JSON.
2013-07-29 02:18:05 -06:00
Pure chess logic is contained in [scalachess](http://github.com/ornicar/scalachess) submodule.
2013-06-08 04:40:31 -06:00
The codebase is fully asynchronous, making heavy use of Scala Futures and [Akka 2 actors](http://akka.io).
2013-10-06 10:27:28 -06:00
Lichess talks to [Stockfish 4](http://stockfishchess.org/) using a [FSM Actor](https://github.com/ornicar/lila/blob/master/modules/ai/src/main/stockfish/ActorFSM.scala) to handle AI moves and analysis.
It uses [MongoDB 2.4](http://mongodb.org) to store about 15 million games, which are indexed by [elasticsearch 0.90](http://elasticsearch.org).
2013-06-08 04:40:31 -06:00
HTTP requests and websocket connections are proxied by [nginx 1.4](http://nginx.org).
2012-04-25 14:15:35 -06:00
2013-06-08 05:25:27 -06:00
Join us on [#lichess IRC channel](http://lichess.org/irc) for more info.
2012-06-18 06:36:49 -06:00
Installation
2013-06-08 05:25:27 -06:00
------------
2012-04-25 14:15:35 -06:00
2013-09-12 09:13:01 -06:00
> I am **not** happy to see lichess clones spreading on the Internet. This project source code is open for other developers to have an example of non-trivial scala/play2/mongodb application. You're welcome to reuse as much code as you want for your projects, and to get inspired by the solutions I propose to many common web development problems. But please don't just create a public lichess clone. Also, if you are building a website based on lichess, please mention it in the footer with `Based on <a href="http://lichess.org">lichess</a>`. Thank you!
2013-09-12 09:10:08 -06:00
> Also note that if I provide the source code, I do **not** offer free support for your lichess instance. I will probably ignore any question about lichess installation and runtime issues.
2013-12-27 02:42:50 -07:00
This is full-stack application, not a library, and it may not
2012-06-18 06:36:49 -06:00
be straightforward to get it fully running.
I assume you run a Unix with nginx, mongodb, elasticsearch and stockfish installed.
2012-06-18 06:36:49 -06:00
```sh
git clone git://github.com/ornicar/lila
cd lila
2013-05-06 03:26:15 -06:00
git submodule update --init
2012-06-18 06:36:49 -06:00
```
2013-06-08 05:25:27 -06:00
### Configuration
2012-06-18 06:36:49 -06:00
```sh
2013-05-06 03:26:15 -06:00
cp conf/application.conf.dist conf/application.conf
2012-06-18 06:36:49 -06:00
```
2013-05-10 08:07:47 -06:00
`application.conf` extends `base.conf` and can override any value.
Note that `application.conf` is excluded from git index.
2012-06-18 06:36:49 -06:00
2013-06-08 05:25:27 -06:00
### Websocket proxying and language subdomains
When accessed from the root domaing (e.g. lichess.org),
the application will redirect to a language specific subdomaing (e.g. en.lichess.org).
Additionally, lichess will open websockets on the `socket.` subdomain (e.g. socket.en.lichess.org).
2013-12-15 09:44:18 -07:00
Here is my local nginx configuration for `l.org`, assuming lila is installed in `/home/thib/lila` and runs on 127.0.0.1:9663
2013-06-08 04:55:45 -06:00
[/etc/nginx/l.org.conf](https://github.com/ornicar/lila/blob/master/doc/nginx/l.org.conf)
2013-06-08 04:55:45 -06:00
And here is my local [/etc/hosts file](https://github.com/ornicar/lila/blob/master/doc/hosts)
2013-06-08 05:25:27 -06:00
### Run it
2012-06-18 06:36:49 -06:00
2013-05-10 08:07:47 -06:00
Launch the play console:
```sh
2013-12-15 09:44:18 -07:00
sbt play -Dhttp.port=9663
2012-06-18 06:36:49 -06:00
```
2013-12-27 02:42:50 -07:00
From here you can now run the application (`run`).
2013-06-08 05:25:27 -06:00
2013-12-30 19:00:56 -07:00
## API
2014-01-08 17:06:20 -07:00
### `GET /api/user/<username>` fetch one user
2013-12-30 19:00:56 -07:00
```
2013-12-31 03:51:27 -07:00
> curl http://en.lichess.org/api/user/thibault
2013-12-31 03:45:37 -07:00
```
```javascript
2013-12-30 19:24:24 -07:00
{
2013-12-31 03:51:27 -07:00
"username": "thibault",
2014-01-07 18:43:20 -07:00
"url": "http://lichess.org/@/thibault", // profile url
2014-01-08 17:06:20 -07:00
"rating": 1503, // global Glicko2 rating
2013-12-31 03:51:27 -07:00
"progress": 36, // rating change over the last ten games
"online": true, // is the player currently using lichess?
"playing": "http://lichess.org/abcdefgh", // game being played, if any
2014-01-08 17:06:20 -07:00
"engine": false // true if the user is known to use a chess engine
2013-12-30 19:24:24 -07:00
}
2013-12-30 19:00:56 -07:00
```
2013-12-31 03:45:37 -07:00
#### JSONP
```javascript
$.ajax({
url:'http://en.l.org/api/user/thibault',
dataType:'jsonp',
jsonp:'callback',
success: function(data) {
// data is a javascript object, do something with it!
console.debug(JSON.stringify(data));
}
});
```
2014-01-08 17:06:20 -07:00
### `GET /api/user` fetch many users
All parameters are optional.
name | type | default | description
--- | --- | --- | ---
2014-01-08 17:15:29 -07:00
**team** | string | - | filter users by team
2014-01-08 17:06:20 -07:00
**nb** | int | 10 | maximum number of users to return
```
> curl http://en.lichess.org/api/user?team=coders&nb=100
```
```javascript
{
"list": [
{
"username": "thibault",
"url": "http://lichess.org/@/thibault", // profile url
"rating": 1503, // global Glicko2 rating
"progress": 36, // rating change over the last ten games
"online": true, // is the player currently using lichess?
"engine": false // true if the user is known to use a chess engine
2014-01-08 17:15:29 -07:00
},
... // other users
2014-01-08 17:06:20 -07:00
]
}
```
#### JSONP
```javascript
$.ajax({
url:'http://en.l.org/api/user',
data: {
team: 'coders',
nb: 100
},
dataType:'jsonp',
jsonp:'callback',
success: function(data) {
// data is a javascript object, do something with it!
console.debug(JSON.stringify(data.list));
}
});
```
### `GET /api/game` fetch many games
2014-01-07 18:43:20 -07:00
2014-01-08 17:06:20 -07:00
Games are returned by descendant chronological order.
All parameters are optional.
2014-01-07 18:43:20 -07:00
name | type | default | description
--- | --- | --- | ---
**username** | string | - | filter games by user
**rated** | 1 or 0 | - | filter rated or casual games
2014-01-08 17:06:20 -07:00
**nb** | int | 10 | maximum number of games to return
2014-01-07 18:43:20 -07:00
**token** | string | - | security token (unlocks secret game data)
```
> curl http://en.lichess.org/api/game?username=thibault&rated=1&nb=10
```
```javascript
{
"list": [
{
"id": "x2kpaixn",
"rated": false,
"status": "mate",
"timestamp": 1389100907239,
"turns": 44,
"url": "http://lichess.org/x2kpaixn",
"winner": "black",
"players": {
"white": {
"userId": "thibault"
"rating": 1642,
"analysis": {
"blunder": 1,
"inaccuracy": 0,
"mistake": 2
},
"moveTimes": [1, 15, 15, 10, 20, 15, 15, 20, 30, 10, 15, 20, 20, 30, 40, 30, 20, 20, 15, 30, 20, 10]
},
"black": ... // other player
}
},
{
... // other game
}
]
}
```
(1) All game statuses: https://github.com/ornicar/scalachess/blob/master/src/main/scala/Status.scala#L16-L25
2013-10-16 14:09:35 -06:00
### Read the move stream
Lichess streams all played moves on http://en.lichess.org/stream using chunked HTTP response and the following format:
2013-10-17 01:53:37 -06:00
```sh
ChunkSize # size of the next chunk, in hexadecimal
GameId UciMove IpAddress # actual chunk of data
```
2013-10-16 14:09:35 -06:00
2013-11-04 16:27:59 -07:00
#### UciMove format
```regex
([a-h][1-8]){2}x?(+|#)?
```
where `x` indicates a capture, `+` a check and `#` a checkmate.
#### Try it with netcat
2013-10-16 14:09:35 -06:00
```sh
> echo "GET /stream HTTP/1.1\nHost: en.lichess.org\n" | netcat en.lichess.org 80
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 16 Oct 2013 20:01:11 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
1a
4om0thb7 d1e1 91.121.7.111
1b
2013-11-02 09:40:06 -06:00
o2eg9xu3 c8c2x 89.77.165.159
18
2013-11-02 09:40:06 -06:00
g3ag6xm6 g7f7+ 83.149.8.9
1b
2013-11-02 09:40:06 -06:00
hl0zbh3g c4c5# 109.237.157.8
2013-10-16 14:09:35 -06:00
1a
2013-11-02 09:40:06 -06:00
g3ag6xm6 c2c3x+ 91.121.7.111
1c
2013-11-02 09:40:06 -06:00
tj2u3hus a7a6x# 117.199.47.140
2013-10-16 14:09:35 -06:00
```
By comparing game IDs, you can guess who plays against who.
2013-12-09 06:58:37 -07:00
> Note that `91.121.7.111` and `198.50.141.73` are AI servers.
2013-06-08 05:25:27 -06:00
Credits
-------
Big thanks go to lichess community for the support, inspiration, bug reports, and [amazing translation efforts](http://lichess.org/translation/contribute).
Special thanks go to:
- [Clarkey](http://en.lichess.org/@/Clarkey) for the [cheat detection engine](https://github.com/clarkerubber/engine-evaluator) and countless contributions to lichess.
2013-06-08 05:25:27 -06:00
- [Mephostophilis](http://lichess.org/@/Mephostophilis) for writing [Lichess Wiki](http://lichess.org/wiki), leading the cheater hunt, moderating the site, reporting countless bugs, and contributing to the codebase
- [Smiling Bishop](http://lichess.org/@/smiling_bishop), [legend](http://lichess.org/@/legend), [mb](http://lichess.org/@/mb) and all the moderators who spent time keeping the site enjoyable
2013-12-27 02:42:50 -07:00
- [Evropi](https://github.com/evropi) for contributing to the wiki, translations and [translation contexts](https://github.com/ornicar/lila/wiki/translation_context)
2013-06-08 06:07:33 -06:00
- [Steibock](https://github.com/Steibock) for board theming
- [Yusuke Kamiyamane](http://p.yusukekamiyamane.com/) for the fugue icons
- [pgn4web](http://pgn4web.casaschi.net/home.html) for the analysis board
2013-07-21 06:12:49 -06:00
- [chessboardjs](https://github.com/oakmac/chessboardjs/) for the board editor
2013-06-08 05:25:27 -06:00
Thanks to all players for feeding the database.