You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Game\Player\UserCurrency;
|
||||
use App\Models\User;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
public function created(User $user): void
|
||||
{
|
||||
$user->settings()->create([
|
||||
'last_hc_payday' => (setting('give_hc_on_register') ?: '0') == '1' ? now()->addYears(10)->unix() : 0,
|
||||
]);
|
||||
|
||||
if ((setting('give_hc_on_register') ?: '0') == '1') {
|
||||
$user->hcSubscription()->insert([
|
||||
'user_id' => $user->id,
|
||||
'subscription_type' => 'HABBO_CLUB',
|
||||
'timestamp_start' => now()->unix(),
|
||||
'duration' => (int) (setting('hc_on_register_duration') ?: 0),
|
||||
'active' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
UserCurrency::upsert([
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'type' => 0,
|
||||
'amount' => $user->username === 'Admin' ? 0 : (setting('start_duckets') ?: 0),
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'type' => 5,
|
||||
'amount' => $user->username === 'Admin' ? 0 : (setting('start_diamonds') ?: 0),
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'type' => 101,
|
||||
'amount' => $user->username === 'Admin' ? 0 : (setting('start_points') ?: 0),
|
||||
],
|
||||
], ['user_id', 'type'], ['amount']);
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\WebsiteDrawBadge;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class WebsiteDrawBadgeObserver
|
||||
{
|
||||
public function updated(WebsiteDrawBadge $websiteDrawBadge): void
|
||||
{
|
||||
if (! $websiteDrawBadge->wasChanged() || ! $websiteDrawBadge->badge_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
$badgeCode = pathinfo($websiteDrawBadge->badge_path, PATHINFO_FILENAME);
|
||||
|
||||
if (! $websiteDrawBadge->published) {
|
||||
DB::table('users_badges')
|
||||
->where('user_id', $websiteDrawBadge->user_id)
|
||||
->where('badge_code', $badgeCode)
|
||||
->delete();
|
||||
|
||||
// Remove from JSON
|
||||
$this->updateExternalTexts(false, $badgeCode);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$exists = DB::table('users_badges')
|
||||
->where('user_id', $websiteDrawBadge->user_id)
|
||||
->where('badge_code', $badgeCode)
|
||||
->exists();
|
||||
|
||||
if (! $exists) {
|
||||
DB::table('users_badges')->insert([
|
||||
'user_id' => $websiteDrawBadge->user_id,
|
||||
'slot_id' => 0,
|
||||
'badge_code' => $badgeCode,
|
||||
]);
|
||||
}
|
||||
|
||||
// Add to JSON
|
||||
$this->updateExternalTexts(true, $badgeCode, $websiteDrawBadge->badge_name, $websiteDrawBadge->badge_desc);
|
||||
}
|
||||
|
||||
protected function updateExternalTexts(bool $add, string $badgeCode, ?string $name = null, ?string $desc = null): void
|
||||
{
|
||||
$filePath = DB::table('website_settings')->where('key', 'nitro_external_texts_file')->value('value');
|
||||
|
||||
if (! $filePath || ! file_exists($filePath) || ! is_writable($filePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$json = json_decode(file_get_contents($filePath), true);
|
||||
|
||||
if ($add) {
|
||||
$json = array_merge($json, [
|
||||
"badge_name_{$badgeCode}" => $name,
|
||||
"badge_desc_{$badgeCode}" => $desc,
|
||||
]);
|
||||
} else {
|
||||
unset($json["badge_name_{$badgeCode}"]);
|
||||
unset($json["badge_desc_{$badgeCode}"]);
|
||||
}
|
||||
|
||||
file_put_contents($filePath, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user