/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Starting import from MCF Modlist...'); $this->info(''); $versions = MinecraftVersion::all(); foreach ($versions as $version) { $this->info('Starting import of ' . $version->name . ' mods...'); $mods = $this->getModJson($version->name); foreach ($mods as $mod) { $this->info('Processing ' . $mod->name); $database_mod = ImportMCFModlist::where('name', '=', $mod->name)->first(); if (!$database_mod) { $database_mod = new ImportMCFModlist(); } $database_mod->name = $mod->name; $database_mod->description = $mod->desc; $database_mod->raw_authors = serialize($mod->author); if (isset($mod->source)) { $database_mod->source = $mod->source; } $database_mod->url = $mod->link; $database_mod->raw_type = serialize($mod->type); $database_mod->raw_dependencies = serialize($mod->dependencies); $database_mod->raw_minecraft_versions = serialize($mod->versions); $database_mod->save(); } } }
public function __construct() { $this->sitemap = App::make("sitemap"); $this->minecraft_version_array = []; $minecraft_versions = MinecraftVersion::all(); foreach ($minecraft_versions as $version) { $version_id = $version->id; $this->minecraft_version_array[$version_id] = preg_replace('/\\./', '-', $version->name); } }
public function fire($job) { $versions = MinecraftVersion::all(); foreach ($versions as $version) { $url_version = preg_replace('/\\./', '-', $version->name); $this->getPage('api/table/mods/' . $url_version . '.json'); $this->getPage('api/table/modpacks/' . $url_version . '.json'); } $this->getPage('api/table/mods/all.json'); $this->getPage('api/table/modpacks/all.json'); $job->delete(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Starting import from Not Enough Mods...'); $this->info(''); $versions = MinecraftVersion::all(); foreach ($versions as $version) { $this->info('Starting import of ' . $version->name . ' mods...'); $mods = $this->getModJson($version->name); foreach ($mods as $mod) { $versions_array = []; $authors_array = []; $this->info('Processing ' . $mod->name); $database_mod = ImportNEM::where('name', '=', $mod->name)->first(); if (!$database_mod) { $database_mod = new ImportNEM(); $versions_array[] = $version->name; } else { $versions_array = unserialize($database_mod->raw_minecraft_versions); if (!in_array($version->name, $versions_array)) { $versions_array[] = $version->name; } } $exploded_authors = explode(',', $mod->author); foreach ($exploded_authors as $author) { $authors_array[] = ltrim($author); } $database_mod->name = $mod->name; $database_mod->raw_authors = serialize($authors_array); $database_mod->url = $mod->longurl; $database_mod->raw_dependencies = serialize($mod->dependencies); $database_mod->raw_minecraft_versions = serialize($versions_array); $database_mod->repo = $mod->repo; $database_mod->mod_version = $mod->version; $database_mod->nem_lastupdated = $mod->lastupdated; $database_mod->save(); } } }
public function postEdit($id) { $selected_versions = []; $selected_authors = []; $selected_maintainers = []; $minecraft_versions = MinecraftVersion::all(); $title = 'Edit A Mod - ' . $this->site_name; $can_edit_maintainers = false; $mod = Mod::find($id); if (Auth::check()) { $maintainer = $mod->maintainers()->where('user_id', Auth::id())->first(); if (!$maintainer) { if ($this->checkRoute()) { $can_edit_maintainers = true; } else { return Redirect::route('index'); } } } else { return Redirect::route('index'); } $authors = $mod->authors; $versions = $mod->versions; $maintainers = $mod->maintainers; $input = Input::only('name', 'selected_versions', 'selected_authors', 'selected_maintainers', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'mod_list_hide'); $messages = ['unique' => 'This mod already exists in the database. If it requires an update let us know!', 'url' => 'The :attribute field is not a valid URL.']; $validator = Validator::make($input, ['name' => 'required|unique:mods,name,' . $mod->id, 'selected_authors' => 'required', 'selected_versions' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('ModController@getEdit', [$mod->id])->withErrors($validator)->withInput(); } $mod->name = $input['name']; $mod->deck = $input['deck']; $mod->website = $input['website']; $mod->download_link = $input['download_link']; $mod->donate_link = $input['donate_link']; $mod->wiki_link = $input['wiki_link']; $mod->description = $input['description']; if ($can_edit_maintainers) { if ($input['slug'] == '' || $input['slug'] == $mod->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $mod->slug = $slug; if ($input['mod_list_hide'] == 1) { $mod->mod_list_hide = 1; } else { $mod->mod_list_hide = 0; } } $mod->last_ip = Request::getClientIp(); $success = $mod->save(); if ($success) { foreach ($authors as $a) { $mod->authors()->detach($a->id); } $mod->authors()->attach($input['selected_authors']); foreach ($versions as $v) { $mod->versions()->detach($v->id); } $mod->versions()->attach($input['selected_versions']); if ($can_edit_maintainers) { foreach ($maintainers as $m) { $mod->maintainers()->detach($m->id); } if ($input['selected_maintainers']) { $mod->maintainers()->attach($input['selected_maintainers']); } } $updated_mod = Mod::find($mod->id); foreach ($updated_mod->versions as $v) { $selected_versions[] = $v->name; } foreach ($updated_mod->authors as $a) { $selected_authors[] = $a->id; } foreach ($updated_mod->maintainers as $m) { $selected_maintainers[] = $m->id; } Cache::tags('mods')->flush(); Queue::push('BuildCache'); return View::make('mods.edit', ['title' => $title, 'mod' => $mod, 'chosen' => true, 'success' => true, 'selected_versions' => $selected_versions, 'selected_authors' => $selected_authors, 'selected_maintainers' => $selected_maintainers, 'versions' => $minecraft_versions, 'can_edit_maintainers' => $can_edit_maintainers]); } return Redirect::action('ModController@getEdit', [$mod->id])->withErrors(['message' => 'Unable to edit mod.'])->withInput(); }
public function getServers() { $servers_array = []; $versions = []; $input = Input::only('modpack', 'tags', 'country', 'permission'); $query = Server::where('active', 1); if ($input['modpack']) { $input_modpacks_array = explode(',', $input['modpack']); $query->where(function ($query) use($input_modpacks_array) { foreach ($input_modpacks_array as $modpack_id) { $query->orWhere('modpack_id', $modpack_id); } }); } if ($input['tags']) { $input_tags_array = explode(',', $input['tags']); foreach ($input_tags_array as $tag) { $query->whereHas('tags', function ($q) use($tag) { $q->where('server_tags.id', '=', $tag); }); } } if ($input['country']) { $query->where('country', $input['country']); } if ($input['permission']) { $query->where('permissions', $input['permission']); } $servers = $query->with('modpack')->with('status')->get(); $countries = Server::countryList(); $raw_versions = MinecraftVersion::all(); foreach ($raw_versions as $v) { $versions[$v->id] = $v->name; } foreach ($servers as $server) { $server_status = $server->status; $modpack = $server->modpack; if ($server->server_address_hide == 1) { $server_address = 'Hidden / Private'; } else { $server_address = $server->ip_host . ':' . $server->port; } $version_slug = $this->getVersion($versions[$modpack->minecraft_version_id]); $options = ''; //1 = Whitelist //2 = Greylist //3 = Open switch ($server->permissions) { case 1: $options = '<i class="fa fa-lock" title="Whitelist"></i>'; break; case 2: $options = '<i class="fa fa-lock" title="Greylist"></i>'; break; case 3: $options = '<i class="fa fa-unlock-alt" title="Open"></i>'; break; } $country_name = $countries[$server->country]; $options .= '<span class="flag-icon flag-icon-' . strtolower($server->country) . '" title="' . $country_name . '"></span> '; $server_name = link_to_action('ServerController@getServer', $server->name, [$server->id, $server->slug]); $modpack = link_to_action('ModpackController@getModpack', $modpack->name, [$version_slug, $modpack->slug]); $players = $server_status->current_players . ' / ' . $server_status->max_players; $servers_array[] = ['id' => $server->id, 'name' => $server_name, 'modpack' => $modpack, 'options' => $options, 'server_address' => $server_address, 'players' => $players, 'deck' => $server->deck]; } shuffle($servers_array); return $this->buildDTServerOutput($servers_array); }
public function postImportMod($import_id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $import_mod = Import::find($import_id); $versions = MinecraftVersion::all(); $title = 'Import A Mod - ' . $this->site_name; $input = Input::only('name', 'selected_versions', 'selected_authors', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'mod_list_hide'); $messages = ['unique' => 'This mod already exists in the database. If it requires an update let us know!', 'url' => 'The :attribute field is not a valid URL.']; $validator = Validator::make($input, ['name' => 'required|unique:mods,name', 'selected_authors' => 'required', 'versions' => 'selected_versions', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('ImportController@getImportMod', [$import_mod->id])->withErrors($validator)->withInput(); } $mod = new Mod(); $mod->name = $input['name']; $mod->deck = $input['deck']; $mod->website = $input['website']; $mod->download_link = $input['download_link']; $mod->donate_link = $input['donate_link']; $mod->wiki_link = $input['wiki_link']; $mod->description = $input['description']; if ($input['slug'] == '') { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } if ($input['mod_list_hide'] == 1) { $mod->mod_list_hide = 1; } $mod->slug = $slug; $mod->last_ip = Request::getClientIp(); $success = $mod->save(); if ($success) { foreach ($input['selected_authors'] as $author) { $mod->authors()->attach($author); } foreach ($input['selected_versions'] as $version) { $mod->versions()->attach($version); } Cache::tags('mods')->flush(); Queue::push('BuildCache'); $import_mod->status = 1; $import_mod->save(); $raw_mcf_mods = ImportMCFModlist::orderBy('name', 'asc')->get(); $raw_nem_mods = ImportNEM::orderBy('name', 'asc')->get(); $mcf_mods_array[0] = 'None'; $nem_mods_array[0] = 'None'; foreach ($raw_mcf_mods as $mcf_mod) { $mcf_mod_id = $mcf_mod->id; $mcf_mods_array[$mcf_mod_id] = $mcf_mod->name; } foreach ($raw_nem_mods as $nem_mod) { $nem_mod_id = $nem_mod->id; $nem_mods_array[$nem_mod_id] = $nem_mod->name; } return View::make('imports.import', ['title' => $title, 'chosen' => true, 'success' => true, 'mcf_mods_array' => $mcf_mods_array, 'nem_mods_array' => $nem_mods_array, 'versions' => $versions]); } return Redirect::action('ImportController@getImportMod', [$import_mod->id])->withErrors(['message' => 'Unable to import mod.'])->withInput(); }
public function postEdit($id, $password = null) { $logged_in = false; $server_user = false; if (Auth::check()) { $logged_in = true; } $server = Server::find($id); if (!$server) { return Redirect::action('ServerController@getServers'); } if ($server->user_id == 0) { $server_user = $server->serverUser; if (!Hash::check($password, $server_user->edit_password)) { return Redirect::route('index'); } } else { if (!Auth::check()) { return Redirect::to(action('UserController@getLogin') . '?return=server/edit/' . $id); } if (Auth::id() != $server->user_id && !$this->checkRoute()) { return Redirect::route('index'); } } $versions = MinecraftVersion::all(); $title = 'Edit Server - ' . $this->site_name; $countries = Server::countryList(); $permissions = [1 => 'Whitelist', 2 => 'Greylist', 3 => 'Open']; $input = Input::only('name', 'modpack', 'email', 'deck', 'website', 'application_url', 'description', 'slug', 'server_address_hide', 'player_list_hide', 'motd_hide', 'server_address', 'selected_tags', 'country', 'permissions', 'last_world_reset', 'next_world_reset', 'active', 'email_alerts'); $modpack = Modpack::find($input['modpack']); $modpack_version = $modpack->version->name; if (preg_match('/:/', $input['server_address'])) { $exploded_hostname = explode(':', $input['server_address']); $server_host = $exploded_hostname[0]; $server_port = $exploded_hostname[1]; } else { $server_host = $input['server_address']; $server_port = 25565; } $input['server_host'] = $server_host; $server_info = Server::check($server_host, $server_port, $modpack_version); $validator_messages = ['name.unique' => 'A server with this name already exists in the database.', 'server_host.unique' => 'A server with this address already exists in the database.', 'country.not_in' => 'The country field is required.', 'deck.required' => 'The short description field is required.', 'deck.max' => 'The short description may not be greater than 255 characters.', 'url' => 'The :attribute field is not a valid URL.']; $validator_rules = ['name' => 'required|unique:servers,name,' . $server->id, 'server_host' => 'required|unique:servers,ip_host,' . $server->id . ',id,port,' . $server_port, 'deck' => 'required|max:255', 'website' => 'url', 'application_url' => 'url', 'selected_tags' => 'required', 'country' => 'required|not_in:choose,separator1,separator2', 'permissions' => 'required', 'last_world_reset' => 'date_format:Y-m-d', 'next_world_reset' => 'date_format:Y-m-d']; if (!$logged_in) { $validator_rules['email'] = 'required|email'; } $validator = Validator::make($input, $validator_rules, $validator_messages); if (!$server_info) { $validator->fails(); //manually fail the validator since we can't reach the server $validator->getMessageBag()->add('server_address', 'Unable to reach server.'); if (!$logged_in) { return Redirect::action('ServerController@getEdit', [$id, $password])->withErrors($validator)->withInput(); } return Redirect::action('ServerController@getEdit', [$id])->withErrors($validator)->withInput(); } elseif ($validator->fails()) { if (!$logged_in) { return Redirect::action('ServerController@getEdit', [$id, $password])->withErrors($validator)->withInput(); } return Redirect::action('ServerController@getEdit', [$id])->withErrors($validator)->withInput(); } $server->modpack_id = $modpack->id; $server->user_id = Auth::id(); $server->minecraft_version_id = $modpack->minecraft_version_id; $server->name = $input['name']; $server->ip_host = $server_host; $server->port = $server_port; $server->deck = $input['deck']; $server->country = $input['country']; $server->permissions = $input['permissions']; $server->website = $input['website']; $server->application_url = $input['application_url']; $server->description = $input['description']; $server->last_world_reset = $input['last_world_reset']; $server->next_world_reset = $input['next_world_reset']; $server->last_check = Carbon\Carbon::now()->toDateTimeString(); $server->active = 0; if ($input['active'] == 1) { $server->active = 1; } $server->email_alerts = 0; if ($input['email_alerts'] == 1) { $server->email_alerts = 1; } $server->server_address_hide = 0; if ($input['server_address_hide'] == 1) { $server->server_address_hide = 1; } $server->player_list_hide = 0; if ($input['player_list_hide'] == 1) { $server->player_list_hide = 1; } $server->motd_hide = 0; if ($input['motd_hide'] == 1) { $server->motd_hide = 1; } if ($input['slug'] == '') { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $server->slug = $slug; $server->last_ip = Request::getClientIp(); $success = $server->save(); if ($success) { foreach ($server->tags as $t) { $server->tags()->detach($t->id); } $server->tags()->attach($input['selected_tags']); $server_status = ServerStatus::where('server_id', $server->id)->first(); $server_status->server_id = $server->id; if (isset($server_info['players']['online'])) { $server_status->current_players = $server_info['players']['online']; } elseif (isset($server_info['Players'])) { $server_status->current_players = $server_info['Players']; } if (isset($server_info['players']['max'])) { $server_status->max_players = $server_info['players']['max']; } elseif (isset($server_info['MaxPlayers'])) { $server_status->max_players = $server_info['MaxPlayers']; } $server_status->last_success = Carbon\Carbon::now()->toDateTimeString(); if (isset($server_info['modinfo'])) { $server_status->mods = json_encode($server_info['modinfo']); } if (isset($server_info['players']['sample'])) { $server_status->players = json_encode($server_info['players']['sample']); } $success = $server_status->save(); if ($success) { if (!$logged_in) { $server_user = ServerUser::where('server_id', $server->id)->first(); $server_user->email = $input['email']; $server_user->last_ip = Request::getClientIp(); } $updated_server = Server::find($id); foreach ($updated_server->tags as $t) { $selected_tags[] = $t->id; } if ($updated_server->last_world_reset == '0000-00-00') { $updated_server->last_world_reset = null; } if ($updated_server->next_world_reset == '0000-00-00') { $updated_server->next_world_reset = null; } return View::make('servers.edit', ['chosen' => true, 'versions' => $versions, 'countries' => $countries, 'permissions' => $permissions, 'title' => $title, 'server' => $updated_server, 'server_user' => $server_user, 'password' => $password, 'selected_tags' => $selected_tags, 'success' => true, 'datepicker' => true]); } if (!$logged_in) { return Redirect::action('ServerController@getEdit', [$id, $password])->withErrors(['message' => 'Unable to edit server.'])->withInput(); } return Redirect::action('ServerController@getEdit', [$id])->withErrors(['message' => 'Unable to edit server.'])->withInput(); } if (!$logged_in) { return Redirect::action('ServerController@getEdit', [$id, $password])->withErrors(['message' => 'Unable to edit server.'])->withInput(); } return Redirect::action('ServerController@getEdit', [$id])->withErrors(['message' => 'Unable to edit server.'])->withInput(); }