- Add a docker compose file to start the entire stack with a single command
- Update dependencies to the latest version
- Replace the current ad-hoc monitoring feature with something like influxdb + grafana.
GameHub.io is an attempt to make a real-time multi player gaming server using the following technologies:
- HTML5, CSS3, Twitter bootstrap and Font awesome to make a nice looking UI
- JQuery combined with the inevitable Javascript utilities (Lodash, Moment.js, Messenger.js and Highcharts) for client side logic
- Socket.io client to make real time gaming possible
- Node JS as web server
- Express JS as web framework
- Passport JS as authentication middleware
- Socket.io server to make real time gaming possible
- Handlebars.js to easily render HTML templates
- Mongo DB along with Mongoose
- ElasticSearch server for (near) real time game indexing and lookup
The main goal of GameHub.io is to provide a non trivial web application serving as an example of gaming server using the aforementioned technologies.
Here is a list of core features:
- Application structure and setup
- User authentication and registration process (/login & /register)
- Real time multi player gaming logic (See gaming logic section)
- RESTful API (/api)
- Real time monitoring dashboard (/monitor)
- "TV" page to broadcast any real time content (/tv)
- Real time game indexing and searching using ElasticSearch (/search)
GameHub.io uses a simple gaming sequence through Socket.io that works for 2+ players. Here is a simplified diagram of most relevant events:
- Each player can create a game by sending a 'create-game' event to the server
- The server creates a new game and replies to the player with a randomly generated token for the game
- The player sends this token to other players and waits for them to join the game
- Others players join the game by sending a 'join-game' event to the server
- Once all players joined the game, the server joins players sockets to the same socket.io room
- At this point, the game starts: depending on the game nature, each player can send a random number of events that will be broadcast to other players.
- When the game is over, each player is notified and sockets leave the game room
ChessHub.io is a real time multi player chess server that serves as a sample of how to reuse GameHub.io core features.
The goal of ChessHub.io is not to provide a fully featured web application to play chess online.
Even though the application is related to chess, it is easy to change the domain model along with application logic and keep/adapt the application structure.
- Because it is a good use case for real time multi player gaming
- Because every time you look for a real time application example on the web, you end up on chat applications, so I decided to change the landscape :-)
- Because I am a chess junkie!
Chess logic on the client side uses the excellent Chess.js and Chessboard.js libraries.
http://chesshub-benas.rhcloud.com/
- Node JS
- Mongo DB up and running on the default port (27017) and using the default database (test)
- ElasticSearch server up and running on the default port (9200)
$> npm install
$> bower install
$> node initData.js
$> node .
Browse the following address: http://localhost:3000
You can register a new account or sign in with the following credentials: [email protected] / foobar
Note: The initData.js
script will populate Mongo DB and ElasticSearch with some data so you can use the application.
Example: /api/user/Foo
{
"id": "54564692985517c304587d01",
"name": "Foo",
"email": "[email protected]",
"lastConnection": "2014-12-02T23:50:59.218Z"
}
Example: /api/game/5456476066be11c704942161
{
"id":"5456476066be11c704942161",
"user":"54564692985517c304587d01",
"white":"Foo",
"black":"Anonymous",
"pgn":"1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. O-O Bc5 5. c3 O-O 6. d4 exd4 7. cxd4 Bb4",
"result":"1-0"
}
There are probably some points of improvement in the application design, structure or code.
If you believe there is a best practice I have not followed, please let me know by opening an issue on the issue tracker. Pull requests are welcome!
GameHub.io is released under the MIT license:
The MIT License (MIT)
Copyright (c) 2014 Mahmoud Ben Hassine
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.