|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* rmarchiv.tk |
|
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
|
9
|
|
|
|
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use App\Models\GamesSavegame; |
|
12
|
|
|
|
|
13
|
|
|
class SavegameController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
public function index($gamefileid) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function show($gamefileid, $slotid) |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function api_load($gamefileid) |
|
24
|
|
|
{ |
|
25
|
|
|
//Load Savegame Data from Database |
|
26
|
|
|
$savegames = GamesSavegame::whereGamefileId($gamefileid) |
|
27
|
|
|
->where('user_id', '=', \Auth::id()) |
|
28
|
|
|
->get(); |
|
29
|
|
|
|
|
30
|
|
|
$ret = []; |
|
31
|
|
|
|
|
32
|
|
|
foreach ($savegames as $s) { |
|
33
|
|
|
$ret[$s->slot_id] = $s->save_data; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return response()->json($ret); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function api_save(Request $request, $gamefileid) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$payLoad = json_decode(request()->getContent(), true); |
|
42
|
|
|
|
|
43
|
|
|
\Log::info('savegamecount: '.count($payLoad)); |
|
44
|
|
|
|
|
45
|
|
|
foreach ($payLoad as $key=>$value) { |
|
46
|
|
|
\Log::info('slot: '.$key); |
|
47
|
|
|
\Log::info('data: '.$value); |
|
48
|
|
|
$save = GamesSavegame::where([ |
|
|
|
|
|
|
49
|
|
|
'user_id' => $user = \Auth::id(), |
|
50
|
|
|
'gamefile_id' => $gamefileid, |
|
51
|
|
|
'slot_id' => $key, |
|
52
|
|
|
]) |
|
53
|
|
|
->first(); |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
if (! $save) { |
|
|
|
|
|
|
56
|
|
|
$s = new GamesSavegame(); |
|
|
|
|
|
|
57
|
|
|
$s->save_data = $value; |
|
|
|
|
|
|
58
|
|
|
$s->slot_id = $key; |
|
|
|
|
|
|
59
|
|
|
$s->gamefile_id = $gamefileid; |
|
60
|
|
|
$s->user_id = \Auth::id(); |
|
|
|
|
|
|
61
|
|
|
$s->save(); |
|
62
|
|
|
\Log::info('created'); |
|
63
|
|
|
} else { |
|
64
|
|
|
$save->save_data = $value; |
|
65
|
|
|
$save->save(); |
|
66
|
|
|
\Log::info('updated'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function api_save_slot(Request $request, $gamefileid, $slot) |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
$value = request()->getContent(); |
|
74
|
|
|
$key = $slot; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
\Log::info('slot: '.$key); |
|
77
|
|
|
\Log::info('data: '.$value); |
|
78
|
|
|
$save = GamesSavegame::where([ |
|
|
|
|
|
|
79
|
|
|
'user_id' => $user = \Auth::id(), |
|
80
|
|
|
'gamefile_id' => $gamefileid, |
|
81
|
|
|
'slot_id' => $key, |
|
82
|
|
|
]) |
|
83
|
|
|
->first(); |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
if (! $save) { |
|
|
|
|
|
|
86
|
|
|
$s = new GamesSavegame(); |
|
|
|
|
|
|
87
|
|
|
$s->save_data = $value; |
|
|
|
|
|
|
88
|
|
|
$s->slot_id = $key; |
|
|
|
|
|
|
89
|
|
|
$s->gamefile_id = $gamefileid; |
|
90
|
|
|
$s->user_id = \Auth::id(); |
|
|
|
|
|
|
91
|
|
|
$s->save(); |
|
92
|
|
|
\Log::info('created'); |
|
93
|
|
|
} else { |
|
94
|
|
|
$save->save_data = $value; |
|
95
|
|
|
$save->save(); |
|
96
|
|
|
\Log::info('updated'); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.