mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
Reset invalid player textures automatically
This commit is contained in:
parent
f07cc0f76f
commit
b7df1b362c
@ -38,8 +38,11 @@ class PlayerController extends Controller
|
||||
{
|
||||
$this->user = $users->get(session('uid'));
|
||||
|
||||
if ($request->has('pid'))
|
||||
$this->player = Player::find($request->pid);
|
||||
if ($request->has('pid')) {
|
||||
if ($this->player = Player::find($request->pid)) {
|
||||
$this->player->checkForInvalidTextures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
|
@ -205,33 +205,46 @@ class SkinlibController extends Controller
|
||||
{
|
||||
$result = Texture::find($request->tid);
|
||||
|
||||
if (!$result)
|
||||
if (!$result) {
|
||||
return json(trans('skinlib.non-existent'), 1);
|
||||
}
|
||||
|
||||
if ($result->uploader != $this->user->uid && !$this->user->isAdmin())
|
||||
if ($result->uploader != $this->user->uid && !$this->user->isAdmin()) {
|
||||
return json(trans('skinlib.no-permission'), 1);
|
||||
}
|
||||
|
||||
// check if file occupied
|
||||
if (Texture::where('hash', $result['hash'])->count() == 1)
|
||||
if (Texture::where('hash', $result['hash'])->count() == 1) {
|
||||
Storage::delete($result['hash']);
|
||||
}
|
||||
|
||||
if (option('return_score')) {
|
||||
// remove the public texture from all users' closet
|
||||
if ($result->public == 1) {
|
||||
$users->get($result->uploader)->setScore($result->size * Option::get('score_per_storage'), 'plus');
|
||||
$users->get($result->uploader)->setScore(
|
||||
$result->size * option('score_per_storage'), 'plus'
|
||||
);
|
||||
|
||||
foreach (Closet::all() as $closet) {
|
||||
if ($closet->has($result->tid)) {
|
||||
$closet->remove($result->tid);
|
||||
$users->get($closet->uid)->setScore(option('score_per_closet_item'), 'plus');
|
||||
|
||||
$users->get($closet->uid)->setScore(
|
||||
option('score_per_closet_item'), 'plus'
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$users->get($result->uploader)->setScore(
|
||||
$result->size * option('private_score_per_storage'), 'plus'
|
||||
);
|
||||
}
|
||||
else
|
||||
$users->get($result->uploader)->setScore($result->size * Option::get('private_score_per_storage'), 'plus');
|
||||
}
|
||||
|
||||
if ($result->delete())
|
||||
if ($result->delete()) {
|
||||
return json(trans('skinlib.delete.success'), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function privacy(Request $request, UserRepository $users)
|
||||
{
|
||||
|
@ -94,6 +94,25 @@ class Player extends Model
|
||||
return Event::fire(new PlayerProfileUpdated($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and delete invalid textures from player profile.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkForInvalidTextures()
|
||||
{
|
||||
foreach (self::$models as $model) {
|
||||
$property = "tid_$model";
|
||||
|
||||
if (!Texture::find($this->$property)) {
|
||||
// reset texture
|
||||
$this->$property = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the textures of player.
|
||||
*
|
||||
|
2
plugins
2
plugins
@ -1 +1 @@
|
||||
Subproject commit 1125d0876374343c1e4885d670f693d98618cf6e
|
||||
Subproject commit c7ac80b11bac6fd0bd9037acfb65b1c9902bc071
|
Loading…
Reference in New Issue
Block a user