GithubHelp home page GithubHelp logo

topfreegames / khan Goto Github PK

View Code? Open in Web Editor NEW
30.0 19.0 15.0 88.07 MB

khan will drive all your enemies to the sea (and also take care of your game's clans)!

License: MIT License

Makefile 0.84% Go 98.18% Shell 0.68% Python 0.16% Dockerfile 0.15%
game clan khan player online multiplayer

khan's Introduction

Khan

Khan Coverage Status Code Climate Go Report Card Docs

Khan will drive all your enemies to the sea (and also take care of your game's clans)!

What is Khan? Khan is an HTTP "resty" API for managing clans for games. It could be used to manage groups of people, but our aim is players in a game.

Khan allows your app to focus on the interaction required to creating clans and managing applications, instead of the backend required for actually doing it.

Features

  • Multi-tenant - Khan already works for as many games as you need, just keep adding new games;
  • Clan Management - Create and manage clans, their metadata as well as promote and demote people in their rosters;
  • Player Management - Manage players and their metadata, as well as their applications to clans;
  • Applications - Khan handles the work involved with applying to clans, inviting people to clans, accepting, denying and kicking;
  • Clan Search - Search a list of clans to present your player with relevant options;
  • Top Clans - Choose from a specific dimension to return a list of the top clans in that specific range (SOON);
  • Web Hooks - Need to integrate your clan system with another application? We got your back! Use our web hooks sytem and plug into whatever events you need;
  • Auditing Trail - Track every action coming from your games (SOON);
  • New Relic Support - Natively support new relic with segments in each API route for easy detection of bottlenecks;
  • Easy to deploy - Khan comes with containers already exported to docker hub for every single of our successful builds. Just pick your choice!

Read more about Khan in our comprehensive documentation.

Hacking Khan

Setup

Make sure you have go installed on your machine. If you use homebrew you can install it with brew install go.

Run make setup.

Running the application

Create the development database with make migrate (first time only).

Run the api with make run.

Running with docker

Provided you have docker installed, to build Khan's image run:

$ make build-docker

To run a new khan instance, run:

$ make run-docker

Running with docker-compose

We already provide a docker-compose.yml as well with all dependencies configured for you to run. To run Khan and all its dependencies, run:

    $ docker-compose up

Note If you are running it on MacOS, you will need to update the amount of RAM docker has access to. Docker, by default, can use 2GB of RAM, however, Khan uses an instance of ElasticSearch and it needs at least 2GB of RAM to work properly. So, if you are experiencing problems while connecting to the elastic search, this might be the root cause of the problem.

Tests

Running tests can be done with make test, while creating the test database can be accomplished with make drop-test and make db-test.

Benchmark

Running benchmarks can be done with make ci-perf.

Coverage

Getting coverage data can be achieved with make coverage, while reading the actual results can be done with make coverage-html.

Static Analysis

Khan goes through some static analysis tools for go. To run them just use make static.

Right now, gocyclo can't process the vendor folder, so we just ignore the exit code for it, while maintaining the output for anything not in the vendor folder.

Security

If you have found a security vulnerability, please email [email protected]

khan's People

Contributors

andrehp avatar arthur29 avatar banduk avatar capella avatar cscatolini avatar felipejfc avatar ghostec avatar guilhermef avatar henrod avatar heynemann avatar igorvpcleao avatar infax01 avatar leonardo2204 avatar lftakakura avatar matheuscscp avatar mathnogueira avatar mbanduk avatar traysh avatar vctandrade avatar victor-carvalho 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

Watchers

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

khan's Issues

Inconsisten player memberships

Player membership count can become inconsistent for some reason and this prevents users from joining a clan. Maybe run updateplayermemberships before validating the membership request.

Cleanup Makefile

In the next release (#65) we have changed the way we deploy the app, so a lot of code from the makefile can be cleaned-up.

Remove thread sleep from flaky test

There is a time.Sleep that fixed the problem we had with a flaky test. We already tested our hypothesis and now can address the problem with a more reliable solution.

HTTP StatusCode 500 when a player tries to apply for a clan he's already a member

Wrong HTTP status code but right response body

Request:

url: http://localhost:5050/clans/11111111111111111111111111111113/memberships/application
payload: {
  "level": "member",
  "user_id": "11111111111111111111111111111113",
  "message": "oi, deixa eu entrar?"
}

Response:

statusCode: 500
body: {
  "success": false,
  "reason": "Player 11111111111111111111111111111113 already has a valid membership in clan 11111111111111111111111111111113."
}

Game cooldown is applied on newly created invites

The first invite a player receives from an open clan (allowApplication == true and autoJoin == true) imposes the game cooldown and the player needs to wait to accept it.

The fix would be on the following function:

func validateMembership(db DB, game *Game, membership *Membership, clan *Clan, playerPublicID, requestorPublicID string) (int, bool, error) {

khan depends on packages that no longer exist

When trying to install khan I get the following errors:

package github.com/labstack/echo/engine: cannot find package "github.com/labstack/echo/engine" in any of: /usr/local/opt/go/libexec/src/github.com/labstack/echo/engine (from $GOROOT) /Users/cebukin/go/src/github.com/labstack/echo/engine (from $GOPATH) package github.com/labstack/echo/engine/fasthttp: cannot find package "github.com/labstack/echo/engine/fasthttp" in any of: /usr/local/opt/go/libexec/src/github.com/labstack/echo/engine/fasthttp (from $GOROOT) /Users/cebukin/go/src/github.com/labstack/echo/engine/fasthttp (from $GOPATH) package github.com/labstack/echo/engine/standard: cannot find package "github.com/labstack/echo/engine/standard" in any of: /usr/local/opt/go/libexec/src/github.com/labstack/echo/engine/standard (from $GOROOT) /Users/cebukin/go/src/github.com/labstack/echo/engine/standard (from $GOPATH) package github.com/uber-go/zap: code in directory /Users/cebukin/go/src/github.com/uber-go/zap expects import "go.uber.org/zap"

It seems like it is depending on packages that no longer exist

No way to know the result of membership application

If a player applies for membership in a clan, 2 results are possible:

  1. the clan is configured with autoJoin enabled and the player joins it
  2. the clan is configured with autoJoin disabled and the player will only join if approved by an authorized member

Currently, there is no way to know what happened.

Khan panics on create game without all parameters in JSON

when calling:

curl -H "Content-Type: application/json" -X POST -d '{"name":"game","metadata":{}}' http://localhost:5530/games

docker log:

Created temporary directory /tmp/migrations096685914.
Wrote migration file 20160729184159_CreateCooldownAfterInviteField.sql.
Wrote migration file 20160608174439_CreateClanTable.sql.
Wrote migration file 20160621161411_CreateHooksTable.sql.
Wrote migration file 20160627155249_CreatePlayerMembershipAndOwnershipCount.sql.
Wrote migration file 20160728180524_CreateMaxPendingInvitesField.sql.
Wrote migration file 20160608133902_CreateGameTable.sql.
Wrote migration file 20160713191703_CreateMembershipDenierField.sql.
Wrote migration file 20160728195902_CreateMembershipMessageField.sql.
Wrote migration file 20160713185332_CreateGameCooldownAfterDenyAndDelete.sql.
Wrote migration file 20160819145352_CreateHookTriggerFieldsMetadata.sql.
Wrote migration file 20160608182307_CreateMembershipTable.sql.
Wrote migration file 20160627110742_LoadUUIDModule.sql.
Wrote migration file 20160627153918_CreateRetrieveClanIndexes.sql.
Wrote migration file 20160708161944_CreateMembershipApproverField.sql.
Wrote migration file 20160608150958_CreatePlayerTable.sql.
Wrote migration file 20160628181530_CreateClanMembershipCount.sql.
Wrote migration file 20160708192007_CreateOwnerIndex.sql.

Connecting to postgres:5432 as khan using sslMode=disable to db khan...

goose: no migrations to run. current version: 20160819145352
Migrated database successfully to version 20160819145352.
{"level":"info","ts":1495146882.3548918,"msg":"Loaded config file successfully.","source":"app","operation":"loadConfiguration","configPath":"/go/src/github.com/topfreegames/khan/config/default.yaml"}
{"level":"info","ts":1495146882.3560848,"msg":"Configuring sentry with URL ","source":"app","operation":"configureSentry"}
{"level":"info","ts":1495146882.357123,"msg":"New Relic is not enabled..","source":"app","appName":"khan","operation":"configureNewRelic"}
{"level":"info","ts":1495146882.3575394,"msg":"Initialized New Relic successfully.","source":"app","appName":"khan","operation":"configureNewRelic"}
{"level":"info","ts":1495146882.5288424,"msg":"Connected to database successfully.","source":"app","operation":"connectDatabase","host":"postgres","user":"khan","dbName":"khan","port":5432,"sslMode":"disable"}
{"level":"info","ts":1495146882.5301151,"msg":"Dispatcher initialized successfully","source":"app","operation":"initDispatcher"}
{"level":"info","ts":1495146882.5301428,"msg":"ES Worker initialized successfully","source":"app","operation":"initESWorker"}
{"level":"info","ts":1495146882.5312474,"msg":"Worker configured.","source":"dispatcher","operation":"Configure","workerCount":5,"redisHost":"redis","redisPort":6379,"redisDatabase":0,"redisPool":30}
{"level":"error","ts":1495146910.7659552,"msg":"Loading payload failed.","source":"gameHandler","operation":"updateGame","gameID":":1","error":"EOF"}
{"level":"error","ts":1495146910.7664812,"msg":"Failed to retrieve parameters.","source":"gameHandler","operation":"updateGame","gameID":":1","error":"EOF"}
{"level":"warn","ts":1495146910.7669663,"msg":"Request failed.","source":"request","route":"UpdateGame","endTime":1495146910.7668662,"statusCode":400,"latency":1227368,"ip":"172.20.0.1:60460","method":"PUT","path":"/games/:gameID"}
{"level":"error","ts":1495146917.7026482,"msg":"Panic occurred.","source":"app","panicText":"runtime error: index out of range","stack":"goroutine 19 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
/usr/local/go/src/runtime/debug/stack.go:24 +0x80 github.com/topfreegames/khan/api.(*RecoveryMiddleware).Serve.func1.1(0xc820024300, 0x7f94698e9588, 0xc8201ec120)
/go/src/github.com/topfreegames/khan/api/middleware.go:178 +0x1a0 panic(0xe9f620, 0xc820010060)
/usr/local/go/src/runtime/panic.go:443 +0x4e9 github.com/topfreegames/khan/api.(*UpdateGamePayload).Validate(0xc8201ee380, 0x0, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/payload.go:199 +0x426 github.com/topfreegames/khan/api.LoadJSONPayload(0xee54e0, 0xc8201ee380, 0x7f94698e9588, 0xc8201ec120, 0x7f946996b370, 0xc82020c360, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/helpers.go:89 +0x63e github.com/topfreegames/khan/api.UpdateGameHandler.func1.1(0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/game.go:116 +0x126 github.com/topfreegames/khan/api.WithSegment(0x1023f88, 0x7, 0x7f94698e9588, 0xc8201ec120, 0xc8200c8b48, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/helpers.go:152 +0x14a github.com/topfreegames/khan/api.UpdateGameHandler.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/game.go:113 +0x82e github.com/topfreegames/khan/vendor/github.com/labstack/echo.(*Echo).add.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/vendor/github.com/labstack/echo/echo.go:475 +0xa9 github.com/topfreegames/khan/api.getBodyFromNext(0x7f94698e9588, 0xc8201ec120, 0xc8201bf110, 0x0, 0x0, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:32 +0x1e8 github.com/topfreegames/khan/api.(*BodyExtractionMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:48 +0x4a github.com/topfreegames/khan/api.(*LoggerMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:216 +0x40a github.com/topfreegames/khan/api.(*SentryMiddleware).Serve.func1.1(0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:93 +0x69 github.com/topfreegames/khan/api.WithSegment(0x10e7660, 0x11, 0x7f94698e9588, 0xc8201ec120, 0xc8200c94e8, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/helpers.go:152 +0x14a github.com/topfreegames/khan/api.(*SentryMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:123 +0x8a github.com/topfreegames/khan/api.(*VersionMiddleware).Serve.func1.1(0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:72 +0x372 github.com/topfreegames/khan/api.WithSegment(0x10e7680, 0x12, 0x7f94698e9588, 0xc8201ec120, 0xc8200c96b8, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/helpers.go:152 +0x14a github.com/topfreegames/khan/api.(*VersionMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:73 +0x9a github.com/topfreegames/khan/api.(*RecoveryMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:183 +0x83 github.com/topfreegames/khan/api.(*NewRelicMiddleware).Serve.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/api/middleware.go:286 +0x386 github.com/topfreegames/khan/vendor/github.com/labstack/echo.(*Echo).ServeHTTP.func1(0x7f94698e9588, 0xc8201ec120, 0x0, 0x0)
/go/src/github.com/topfreegames/khan/vendor/github.com/labstack/echo/echo.go:556 +0x1bb github.com/topfreegames/khan/vendor/github.com/labstack/echo.(*Echo).ServeHTTP(0xc8200f1c30, 0x7f94698e93c8, 0xc8201625c0, 0x7f94698e94a0, 0xc82020c060)
/go/src/github.com/topfreegames/khan/vendor/github.com/labstack/echo/echo.go:565 +0x2f9 github.com/topfreegames/khan/vendor/github.com/labstack/echo/engine/standard.(*Server).ServeHTTP(0xc82007b7a0, 0x7f94698e92d0, 0xc820212340, 0xc8202100e0)
/go/src/github.com/topfreegames/khan/vendor/github.com/labstack/echo/engine/standard/server.go:156 +0x636 net/http.serverHandler.ServeHTTP(0xc8201de180, 0x7f94698e92d0, 0xc820212340, 0xc8202100e0)
/usr/local/go/src/net/http/server.go:2081 +0x19e net/http.(*conn).serve(0xc8201e6300)
/usr/local/go/src/net/http/server.go:1472 +0xf2e created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2137 +0x44e "}

Rename variable l to logger

There is a variable l all over the codebase that could be renamed to logger. This would improve the legibility of the code.

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.