Code Monkey home page Code Monkey logo

gamehub.io's Introduction

About GameHub.io

Gitter

โš ๏ธ 16/12/2018: This project seems to be dead but it is not! Here are a couple of things I am planning to do:

  • 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:

Client side

Server side

Goals

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)

Architecture

architecture

Gaming logic

GameHub.io uses a simple gaming sequence through Socket.io that works for 2+ players. Here is a simplified diagram of most relevant events:

gamehub.io

  1. Each player can create a game by sending a 'create-game' event to the server
  2. The server creates a new game and replies to the player with a randomly generated token for the game
  3. The player sends this token to other players and waits for them to join the game
  4. Others players join the game by sending a 'join-game' event to the server
  5. Once all players joined the game, the server joins players sockets to the same socket.io room
  6. 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.
  7. When the game is over, each player is notified and sockets leave the game room

Use case: ChessHub.io

Introduction

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.

Why Chess?

  • 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!

Credits

Chess logic on the client side uses the excellent Chess.js and Chessboard.js libraries.

Live demo

http://chesshub-benas.rhcloud.com/

Build and Run the application

Prerequisites

  • 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)

Run the application

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

Screen shots

Home page

home

Playing chess in real time

play

Watch live game

tv

Search a game

search

Real time monitoring dashboard

monitor

RESTful API

User details: GET /api/user/:name

Example: /api/user/Foo

{
    "id": "54564692985517c304587d01",
    "name": "Foo",
    "email": "[email protected]",
    "lastConnection": "2014-12-02T23:50:59.218Z"
}
Game details: GET /api/game/:id

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"
}

Contribution

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!

License

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.

gamehub.io's People

Contributors

galal-hussein avatar gitter-badger avatar kiran9k avatar theborakompanioni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gamehub.io's Issues

Save games of registered users

It is possible to play chess on chesshub.io as anonymous. Games played by anonymous players are not saved in the database. In contrast, when a registered user plays a game, the game should be persisted to the database and indexed in elastic search

Create vagrant/docker images to easily run chesshub

Currently, the user should install node + mongo + elasticsearch to run chesshub.
It would be awesome to provide vagrant/docker files to setup all these prerequisites so that the user can just run the pre-built application in a vagrant VM or docker container.

Few questions

  1. How would you scale this in the cloud horizontally?
  2. Is it possible to have Android/Windows/iPhone as a client?
  3. Is it possible to have an SQL db instead of mongoDB?

Update mongoose version?

On trying to run the project, I got the following error:
Error: Cannot find module 'mongodb/node_modules/bson'

This issue is also referenced here: Automattic/mongoose#2718 (Although the fix there did not help me). Updating mongoose to 4.7.4 fixed the issue for me.

Has anybody else seen this error (or is it something to do with my system?) and know any other fixes? I could submit a pull request for updating the mongoose version if that's ok also.

Thanks!

Plz help me :( . How can i fix it ?

$ node initdata
Elasticsearch INFO: 2017-01-11T03:19:19Z
Adding connection to http://localhost:9200/

Elasticsearch DEBUG: 2017-01-11T03:19:19Z
starting request {
"method": "HEAD",
"requestTimeout": 5000,
"castExists": true,
"path": "/",
"query": {}
}

Elasticsearch DEBUG: 2017-01-11T03:19:19Z
starting request {
"method": "PUT",
"path": "/chesshub",
"query": {}
}

(node:7088) DeprecationWarning: Mongoose: mpromise (mongoose's default promise l
ibrary) is deprecated, plug in your own promise library instead: http://mongoose
js.com/docs/promises.html
Elasticsearch TRACE: 2017-01-11T03:19:20Z
-> HEAD http://localhost:9200/

<- 0

Elasticsearch ERROR: 2017-01-11T03:19:20Z
Error: Request error, retrying
HEAD http://localhost:9200/ => connect ECONNREFUSED 127.0.0.1:9200
at Log.error (C:\Users\MyPC\Desktop\gamehub.io-master\node_modules\elastic
search\src\lib\log.js:225:56)
at checkRespForFailure (C:\Users\MyPC\Desktop\gamehub.io-master\node_modul
es\elasticsearch\src\lib\transport.js:240:18)
at HttpConnector. (C:\Users\MyPC\Desktop\gamehub.io-master\node
_modules\elasticsearch\src\lib\connectors\http.js:162:7)
at ClientRequest.wrapper (C:\Users\MyPC\Desktop\gamehub.io-master\node_mod
ules\elasticsearch\node_modules\lodash\lodash.js:4968:19)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:309:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

Elasticsearch TRACE: 2017-01-11T03:19:20Z
-> PUT http://localhost:9200/chesshub

<- 0

Elasticsearch ERROR: 2017-01-11T03:19:20Z
Error: Request error, retrying
PUT http://localhost:9200/chesshub => connect ECONNREFUSED 127.0.0.1:9200
at Log.error (C:\Users\MyPC\Desktop\gamehub.io-master\node_modules\elastic
search\src\lib\log.js:225:56)
at checkRespForFailure (C:\Users\MyPC\Desktop\gamehub.io-master\node_modul
es\elasticsearch\src\lib\transport.js:240:18)
at HttpConnector. (C:\Users\MyPC\Desktop\gamehub.io-master\node
_modules\elasticsearch\src\lib\connectors\http.js:162:7)
at ClientRequest.wrapper (C:\Users\MyPC\Desktop\gamehub.io-master\node_mod
ules\elasticsearch\node_modules\lodash\lodash.js:4968:19)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:309:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

Elasticsearch TRACE: 2017-01-11T03:19:21Z
-> HEAD http://localhost:9200/

<- 0

Elasticsearch WARNING: 2017-01-11T03:19:21Z
Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:21Z
No living connections

elasticsearch is down!
Elasticsearch TRACE: 2017-01-11T03:19:21Z
-> HEAD http://localhost:9200/

<- 0

Elasticsearch WARNING: 2017-01-11T03:19:21Z
Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:21Z
No living connections

Elasticsearch DEBUG: 2017-01-11T03:19:21Z
starting request {
"method": "POST",
"path": "/chesshub/game/1/_create",
"body": {
"white": "Foo",
"black": "Anonymous",
"content": "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"
},
"query": {}
}

Elasticsearch TRACE: 2017-01-11T03:19:22Z
-> HEAD http://localhost:9200/

<- 0

Elasticsearch WARNING: 2017-01-11T03:19:22Z
Unable to revive connection: http://localhost:9200/

Elasticsearch WARNING: 2017-01-11T03:19:22Z
No living connections

Elasticsearch DEBUG: 2017-01-11T03:19:23Z
starting request {
"method": "POST",
"path": "/chesshub/game/2/_create",
"body": {
"white": "Anonymous",
"black": "Bar",
"content": "1. e4 c6 2. e5 d5 3. exd6 exd6 4. Nf3 Bg4 5. d4 Nf6 6. Bg5 Be7
",
"result": "1-0"
},
"query": {}
}

IDE for project

Hello Benas

Thank you for your great work

I am using your game hub, that is perfect, but i don't see any ide for project

Could you please give what ide are you using to development this project ? is that eclipse ?

Thank you so much

Tran

Make host and port configurable

Currently, the host and port configuration is hardcoded (localhost:3000) both on client and server side.

This should be configurable at application startup using process.env.PORT

about translate contribute

Hello, we are Korean university students. This project is an area we are interested in, so we would like to contribute.
We want to contribute through the Korean translation of the project. Is it okay to contribute?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.