<commit_before><?php

namespace App\Http\Controllers;

use App\Facades\SphinxNode;
use App\Realms\Player;
use App\Realms\Realm;
use App\Realms\Invite;
use App\Realms\World;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class RealmController extends Controller
{
    /**
     * Generate a JSON response to be packaged up and sent to the client.
     * NOTE: Does not return encoded JSON. JSON must manually be encoded with json_encode().
     * @param Realm $server
     * @return array
     */
    public static function generateServerJSON($server) {
        // Generate player list.
        $players = array();
        foreach ($server->invited_players as $player) {
            $players[] = array(
                'name' => $player->username,
                'uuid' => $player->uuid,
                'operator' => in_array($player, $server->operators)
            );
        }

        // Generate slots JSON.
        $slots = [];
        $firstSlotId = null;
        foreach ($server->worlds as $world) {
            if ($firstSlotId === null) {
                $firstSlotId = $world->slot_id;
            }

            $slots[] = [
                'slotId' => $world->slot_id,

                'options' => json_encode([
                    'slotName' => $world->name,
                    'minecraftVersion' => '1.9',

                    'pvp' => !!$world->pvp,
                    'spawnAnimals' => !!$world->spawn_animals,
                    'spawnMonsters' => !!$world->spawn_monsters,
                    'spawnNPCs' => !!$world->spawn_npcs,
                    'spawnProtection' => $world->spawn_protection,
                    'commandBlocks' => !!$world->command_blocks,
                    'forceGameMode' => !!$world->force_gamemode,
                    'difficulty' => $world->difficulty,
                    'gameMode' => $world->gamemode
                ])
            ];
        }

        if ($firstSlotId === null) {
            $firstSlotId = 1;
        }

        // Formulate JSON response.
        $json = array(
            'id' => intval($server->id),
            'remoteSubscriptionId' => "$server->id",
            'name' => $server->name,
            'players' => $players,
            'motd' => $server->motd,
            'state' => $server->state,
            'owner' => $server->owner->username,
            'ownerUUID' => $server->owner->uuid,
            'daysLeft' => intval($server->days_left),
            'ip' => $server->address,
            'expired' => !!$server->expired,
            'minigame' => !!$server->minigames_server,
            'activeSlot' => $firstSlotId,
            'slots' => $slots
        );

        return $json;
    }

    /**
     * Return a listing of all Realms available to the player.
     *
     * @return array
     */
    public function listing()
    {
        $servers = Realm::all();
<commit_msg>if there are no more days left, the realm will be expired.<commit_after><?php

namespace App\Http\Controllers;

use App\Facades\SphinxNode;
use App\Realms\Player;
use App\Realms\Realm;
use App\Realms\Invite;
use App\Realms\World;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class RealmController extends Controller
{
    /**
     * Generate a JSON response to be packaged up and sent to the client.
     * NOTE: Does not return encoded JSON. JSON must manually be encoded with json_encode().
     * @param Realm $server
     * @return array
     */
    public static function generateServerJSON($server) {
        // Generate player list.
        $players = array();
        foreach ($server->invited_players as $player) {
            $players[] = array(
                'name' => $player->username,
                'uuid' => $player->uuid,
                'operator' => in_array($player, $server->operators)
            );
        }

        // Generate slots JSON.
        $slots = [];
        $firstSlotId = null;
        foreach ($server->worlds as $world) {
            if ($firstSlotId === null) {
                $firstSlotId = $world->slot_id;
            }

            $slots[] = [
                'slotId' => $world->slot_id,

                'options' => json_encode([
                    'slotName' => $world->name,
                    'minecraftVersion' => '1.9',

                    'pvp' => !!$world->pvp,
                    'spawnAnimals' => !!$world->spawn_animals,
                    'spawnMonsters' => !!$world->spawn_monsters,
                    'spawnNPCs' => !!$world->spawn_npcs,
                    'spawnProtection' => $world->spawn_protection,
                    'commandBlocks' => !!$world->command_blocks,
                    'forceGameMode' => !!$world->force_gamemode,
                    'difficulty' => $world->difficulty,
                    'gameMode' => $world->gamemode
                ])
            ];
        }

        if ($firstSlotId === null) {
            $firstSlotId = 1;
        }
		if ($server->days_left < 1)
        {
			$expired = 1;
		} 
		else 
		{
			$expired = 0;
			
		}
		// Formulate JSON response.
        $json = array(
            'id' => intval($server->id),
            'remoteSubscriptionId' => "$server->id",
            'name' => $server->name,
            'players' => $players,
            'motd' => $server->motd,
            'state' => $server->state,
            'owner' => $server->owner->username,
            'ownerUUID' => $server->owner->uuid,
            'daysLeft' => intval($server->days_left),
            'ip' => $server->address,
            'expired' => !!$expired,
            'minigame' => !!$server->minigames_server,
            'activeSlot' => $firstSlotId,
            'slots' => $slots
        );

        return $json;
    }

    /**
     * Return a listing of all Realms available to the player.
     *
     * @return array
     */
    public function listing()
    {
        $servers = Realm::all();

{'fraction_non_alphanumeric': 0.14442753255538643, 'fraction_numerical': 0.0015220700152207, 'mean_word_length': 1.620292423571112, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672704', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1708, 'n_words': 365}