Skip to content

Commit 9b163ce

Browse files
committed
Initial commit
1 parent b5c7045 commit 9b163ce

16 files changed

+568
-1
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
* text=auto
2+
/.github export-ignore
3+
/tests export-ignore
4+
/.editorconfig export-ignore
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/.styleci.yml export-ignore
9+
/.sensiolabs.yml export-ignore
10+
/.coveralls.yml export-ignore
11+
/phpunit.xml export-ignore
12+
/CHANGELOG-* export-ignore
13+
/CONTRIBUTING.md export-ignore
14+
/CODE_OF_CONDUCT.md export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/composer.lock

.scrunitizer.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true

README.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,137 @@
11
# laravel-game-essentials
2-
The essentials and basic data for a gaming backend server.
2+
3+
[![Packagist](https://img.shields.io/packagist/v/furic/game-essentials)](https://packagist.org/packages/furic/game-essentials)
4+
[![Packagist](https://img.shields.io/packagist/dt/furic/game-essentials)](https://packagist.org/packages/furic/game-essentials)
5+
[![License](https://img.shields.io/github/license/furic/laravel-game-essentials)](https://packagist.org/packages/furic/game-essentials)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/furic/laravel-game-essentials/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/furic/laravel-game-essentials/?branch=main)
7+
[![Build Status](https://scrutinizer-ci.com/g/furic/laravel-game-essentials/badges/build.png?b=main)](https://scrutinizer-ci.com/g/furic/laravel-game-essentials/build-status/main)
8+
9+
> Game Essentials for [Laravel 5.*](https://laravel.com/). This package is required and used by few packages in [Sweaty Chair Studio](https://www.sweatychair.com) creating the basic data and essential functions for a gaming server backend. This provides functions such as registering players and assign the players in a game. After that the data can be used for analytics purpose.
10+
11+
> If you are using other packages that requires this package, this will be added automatically and you do not need to install it manually. However, you can still use this package alone without using other packages.
12+
13+
## Table of Contents
14+
- [Installation](#installation)
15+
- [Configuration](#configuration)
16+
- [Usage](#usage)
17+
- [Web Console](#web-console)
18+
- [Redeem Code Parameters](#redeem-code-parameters)
19+
- [Redeem Validator API](#redeem-validator-api)
20+
- [Unity Client Repo](#unity-client-repo)
21+
- [TODO](#todo)
22+
- [License](#license)
23+
24+
## Installation
25+
26+
Install this package via Composer:
27+
```bash
28+
$ composer require furic/game-essentials
29+
```
30+
31+
> If you are using Laravel 5.5 or later, then installation is done. Otherwise follow the next steps.
32+
33+
#### Open `config/app.php` and follow steps below:
34+
35+
Find the `providers` array and add our service provider.
36+
37+
```php
38+
'providers' => [
39+
// ...
40+
Furic\GameEssentials\GameEssentialsServiceProvider::class
41+
],
42+
```
43+
44+
## Configuration
45+
46+
Publish config & migration file using Artisan command:
47+
```bash
48+
$ php artisan vendor:publish
49+
```
50+
51+
To create table for redeem codes in database run:
52+
```bash
53+
$ php artisan migrate
54+
```
55+
56+
## Usage
57+
58+
### Game Parameters
59+
60+
A game has following parameters:
61+
```
62+
$table->string('name', 128);
63+
$table->smallInteger('version_ios')->unsigned();
64+
$table->smallInteger('version_android')->unsigned();
65+
$table->smallInteger('version_tvos')->unsigned();
66+
```
67+
- Name: The name of the game/app.
68+
- iOS Version: The latest version number in iOS, used for force update in client.
69+
- Android Version: The latest version number in Android, used for force update in client.
70+
- tvOS Version: The latest version number in tvOS, used for force update in client.
71+
72+
### Player Parameters
73+
74+
A game has following parameters:
75+
```
76+
$table->string('facebook_id', 128)->nullable();
77+
$table->string('gamecenter_id', 128)->nullable();
78+
$table->string('playgames_id', 128)->nullable();
79+
$table->string('udid', 128);
80+
$table->string('name', 128)->nullable;
81+
$table->string('ip', 15);
82+
```
83+
- Facebook ID: The Facebook ID of a player. (Optional)
84+
- Game Center ID: The Game Center ID of a player in iOS. (Optional)
85+
- Google Play Games ID: The Google Play Games ID of a player in Android. (Optional)
86+
- UDID: The unique device UDID of a player. If the player is using multiple devices, only the first device UDID is used here.
87+
- Name: The name of the player input in game/app. (Optional)
88+
- IP: The IP of the player when being first seen.
89+
90+
### Player Parameters
91+
92+
Finally, a player-game has following parameters:
93+
```
94+
$table->integer('player_id')->unsigned();
95+
$table->integer('game_id')->unsigned();
96+
$table->tinyInteger('channel')->unsigned();
97+
$table->smallInteger('version')->unsigned();
98+
$table->boolean('is_hack')->default(false);
99+
```
100+
- Player ID: The ID of a player.
101+
- Game ID: The ID of a the game that player launched.
102+
- Channel: The channel of the player getting into the game. Mostly used for Android players, e.g. Sumsung Store, Huawei App Gallery, etc. (Optional)
103+
- Version: The current game version that the player device running.
104+
- Is Hacked: A boolean to mark if the player ever performed any hack in game, for analytics and limiting functions in client.
105+
106+
### API
107+
108+
GET `<server url>/games/{game-id}`
109+
Returns a JSON data from a given game ID, for debug usage only.
110+
111+
GET `<server url>/games/{game-id}/versions`
112+
Returns a JSON data containing the versions from a given game ID, for client checking the latest game version and perform force-update.
113+
114+
GET `<server url>/players/{player-id}`
115+
Returns a JSON data from a given player ID, for debug usage only.
116+
117+
GET `<server url>/players/name/{player-name}`
118+
Returns a JSON data from a given player name, for debug usage only.
119+
120+
POST `<server url>/players`
121+
Creates a player with given POST data.
122+
123+
POST `<server url>/players/{player-id}`
124+
Updates a player with a given player id and POST data.
125+
126+
GET `<server url>/games/{game-id}/players`
127+
Returns a JSON array of all players from a given game ID, for debug usage only.
128+
129+
## TODO
130+
131+
- Create the web console to add/edit games.
132+
- Add admin login for web console.
133+
- Add tests.
134+
135+
## License
136+
137+
laravel-redeem-codes is licensed under a [MIT License](https://github.com/furic/laravel-game-essentials/blob/main/LICENSE).

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "furic/game-essentials",
3+
"description": "The essentials and basic data for a gaming backend server. ",
4+
"keywords": [
5+
"game",
6+
"gaming server",
7+
"player",
8+
"laravel",
9+
"php"
10+
],
11+
"homepage": "https://github.com/furic/laravel-game-essentials",
12+
"license": "MIT",
13+
"type": "library",
14+
"authors": [
15+
{
16+
"name": "Richard Fu",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"require": {
21+
"php" : "^7.2",
22+
"laravel/framework": "~5.8||~6.0||~7.0||8.0",
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"Furic\\GameEssentials\\": "src/"
27+
}
28+
},
29+
"extra": {
30+
"laravel": {
31+
"providers": [
32+
"furic\\gameessentials\\GameEssentialsServiceProvider"
33+
]
34+
}
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreateGamesTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('games', function (Blueprint $table) {
16+
$table->increments('id');
17+
18+
$table->string('name', 128);
19+
$table->smallInteger('version_ios')->unsigned();
20+
$table->smallInteger('version_android')->unsigned();
21+
$table->smallInteger('version_tvos')->unsigned();
22+
23+
$table->timestamps();
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::drop('games');
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreatePlayersTable extends Migration
7+
{
8+
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('players', function (Blueprint $table) {
17+
$table->increments('id');
18+
19+
$table->string('facebook_id', 128)->nullable();
20+
$table->string('gamecenter_id', 128)->nullable();
21+
$table->string('playgames_id', 128)->nullable();
22+
$table->string('udid', 128);
23+
$table->string('name', 128)->nullable;
24+
$table->string('ip', 15);
25+
26+
$table->timestamps();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*
33+
* @return void
34+
*/
35+
public function down()
36+
{
37+
Schema::drop('players');
38+
}
39+
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreatePlayerGamesTable extends Migration
7+
{
8+
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('player_games', function (Blueprint $table) {
17+
$table->increments('id');
18+
19+
$table->integer('player_id')->unsigned();
20+
$table->integer('game_id')->unsigned();
21+
$table->tinyInteger('channel')->unsigned();
22+
$table->smallInteger('version')->unsigned();
23+
$table->boolean('is_hack')->default(false);
24+
25+
$table->timestamps();
26+
27+
$table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
28+
$table->foreign('game_id')->references('id')->on('games')->onDelete('cascade');
29+
});
30+
}
31+
32+
/**
33+
* Reverse the migrations.
34+
*
35+
* @return void
36+
*/
37+
public function down()
38+
{
39+
Schema::drop('player_games');
40+
}
41+
42+
}

src/Game.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Furic\GameEssentials;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Game extends Model
8+
{
9+
10+
protected $fillable = ['name', 'version_ios', 'version_android', 'version_tvos'];
11+
12+
}

src/GameController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Furic\GameEssentials;
4+
5+
use Game;
6+
use App\Http\Controllers\Controller;
7+
use Illuminate\Http\Request;
8+
9+
class GameController extends Controller
10+
{
11+
12+
public function show($id)
13+
{
14+
return Game::findOrFail($id);
15+
}
16+
17+
public function showVersions($id) // Depricated
18+
{
19+
$game = Game::findOrFail($id);
20+
return ['ios' => $game->version_ios, 'android' => $game->version_android, 'tvos' => $game->version_tvos];
21+
}
22+
}

0 commit comments

Comments
 (0)