public function testModpackBuild() { $modpack = Modpack::find(1); $build = $modpack->builds->first(); $response = $this->call('GET', 'api/modpack/' . $modpack->slug . '/' . $build->version); $this->assertResponseOk(); $this->assertTrue(is_a($response, 'Illuminate\\Http\\JsonResponse')); $json = $response->getData(true); $this->assertTrue(array_key_exists('minecraft', $json)); $this->assertTrue(array_key_exists('forge', $json)); $this->assertTrue(array_key_exists('java', $json)); $this->assertTrue(array_key_exists('memory', $json)); $this->assertTrue(array_key_exists('mods', $json)); }
public function getModpack($id) { $mods = []; $raw_modpack = Modpack::find($id); if (!$raw_modpack) { return Response::json(['error' => 'No modpack with that ID found.']); } $raw_mods = $raw_modpack->mods; foreach ($raw_mods as $mod) { $mods[] = ['id' => $mod->id, 'name' => $mod->name, 'short_description' => $mod->deck, 'website' => $mod->website, 'download_link' => $mod->download_link, 'donate_link' => $mod->website, 'wiki_link' => $mod->wiki_link, 'description' => $mod->description, 'slug' => $mod->slug, 'created_at' => $mod->created_at, 'updated_at' => $mod->updated_at]; } $result = ['id' => $raw_modpack->id, 'name' => $raw_modpack->name, 'short_description' => $raw_modpack->deck, 'website' => $raw_modpack->website, 'download_link' => $raw_modpack->download_link, 'donate_link' => $raw_modpack->website, 'wiki_link' => $raw_modpack->wiki_link, 'description' => $raw_modpack->description, 'mods' => $mods, 'slug' => $raw_modpack->slug, 'created_at' => $raw_modpack->created_at, 'updated_at' => $raw_modpack->updated_at]; return Response::json($result); }
public function getContact() { $correction_type = false; $correction_id = false; $correction_object = false; $input = Input::only('modpack', 'mod'); if ($input['modpack']) { $correction_type = 'Modpack'; $correction_id = $input['modpack']; $correction_object = Modpack::find($correction_id); } if ($input['mod']) { $correction_type = 'Mod'; $correction_id = $input['mod']; $correction_object = Mod::find($correction_id); } $title = 'Contact Us - ' . $this->site_name; $meta_description = 'Contact us if something is incorrect, if you have a question, or for anything else.'; return View::make('pages.contact', ['title' => $title, 'meta_description' => $meta_description, 'correction_type' => $correction_type, 'correction_id' => $correction_id, 'correction_object' => $correction_object]); }
/** * AJAX Methods for Modpack Manager **/ public function action_modify($action = null) { if (empty($action)) { return Response::error('500'); } switch ($action) { case "version": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->update(array('modversion_id' => Input::get('version'))); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->delete(); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = ModVersion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $build->modversions()->attach($ver->id); return Response::json(array('pretty_name' => $mod->pretty_name, 'version' => $ver->version)); break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); } }
/** * AJAX Methods for Modpack Manager **/ public function anyModify($action = null) { if (!Request::ajax()) { return Response::view('errors.missing', array(), 404); } if (empty($action)) { return Response::view('errors.500', array(), 500); } switch ($action) { case "version": $version_id = Input::get('version'); $modversion_id = Input::get('modversion_id'); $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', $modversion_id)->update(array('modversion_id' => $version_id)); if ($affected == 0) { if ($modversion_id != $version_id) { $status = 'failed'; } else { $status = 'aborted'; } } else { $status = 'success'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', Input::get('modversion_id'))->delete(); $status = 'success'; if ($affected == 0) { $status = 'failed'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = Modversion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $affected = DB::table('build_modversion')->where('build_id', '=', $build->id)->where('modversion_id', '=', $ver->id)->get(); $duplicate = !empty($affected); if ($duplicate) { return Response::json(array('status' => 'failed', 'reason' => 'Duplicate Modversion found')); } else { $build->modversions()->attach($ver->id); return Response::json(array('status' => 'success', 'pretty_name' => $mod->pretty_name, 'version' => $ver->version)); } break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); case "private": $build = Build::find(Input::get('build')); $private = Input::get('private'); $build->private = $private ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s private status.")); } }
public function getTableDataFile($type, $version, $name = null) { $table_id = 'table-1'; $table_sdom = '<"top"fp><"clear">t<"bottom"ip><"clear">'; $table_empty = 'No data available in table.'; $table_length = 15; $table_fixed_header = false; $table_order = true; switch ($type) { case 'mods': $columns_array = ['name', 'versions', 'deck', 'authors', 'links']; $ajax_source = action('JSONController@getTableMods', $version); break; case 'modpacks': $columns_array = ['name', 'version', 'deck', 'creators', 'icon_html', 'links']; $table_empty = 'No Modpacks found.'; $ajax_source = action('JSONController@getTableModpacks', [$version]); break; case 'launchers': $columns_array = ['name', 'version', 'deck', 'creators', 'icon_html', 'links']; $ajax_source = action('JSONController@getTableLaunchers', [$name, $version]); break; case 'modpackmods': $columns_array = ['name', 'versions', 'deck', 'authors', 'links']; $ajax_source = action('JSONController@getTableModpackMods', [$name]); break; case 'modmodpacks': $columns_array = ['name', 'version', 'deck', 'creators', 'icon_html', 'links']; $ajax_source = action('JSONController@getModModpacks', [$name]); break; case 'compare': $table_length = 1000; $table_fixed_header = true; $input = Input::only('modpacks'); $modpack_ids = explode(',', $input['modpacks']); $columns_array = ['name']; foreach ($modpack_ids as $id) { $modpack = Modpack::find($id); $columns_array[] = $modpack->id; } $ajax_source = action('JSONController@getModpackCompare') . '?modpacks=' . $input['modpacks']; break; case 'modpackfinder': $input = Input::only('mods', 'tags'); $columns_array = ['name', 'version', 'deck', 'creators', 'icon_html', 'links']; $table_empty = 'No Modpacks found.'; if ($input['tags'] && $input['mods']) { $ajax_source = action('JSONController@getModpackSearch', [$version]) . '?mods=' . $input['mods'] . '&tags=' . $input['tags']; } elseif ($input['mods']) { $ajax_source = action('JSONController@getModpackSearch', [$version]) . '?mods=' . $input['mods']; } elseif ($input['tags']) { $ajax_source = action('JSONController@getModpackSearch', [$version]) . '?tags=' . $input['tags']; } else { $ajax_source = action('JSONController@getModpackSearch', [$version]); } break; case 'servers': $table_id = 'servers-table'; $table_order = false; $table_empty = 'No servers found.'; $query_array = []; $query_string = ''; $input = Input::only('modpack', 'tags', 'country', 'permission'); $columns_array = ['options', 'name', 'modpack', 'server_address', 'players', 'deck']; if ($input['modpack']) { $query_array[] = 'modpack=' . $input['modpack']; } if ($input['tags']) { $tag_string = 'tags='; $exploded_tags = explode(',', strtolower($input['tags'])); foreach ($exploded_tags as $t) { $tag_string .= $t . ','; } $query_array[] = rtrim($tag_string, ','); } if ($input['country']) { $query_array[] = 'country=' . $input['country']; } if ($input['permission']) { $query_array[] = 'permission=' . $input['permission']; } $query_count = 0; foreach ($query_array as $q) { if ($query_count == 0) { $query_string .= '?'; } else { $query_string .= '&'; } $query_string .= $q; $query_count++; } $ajax_source = action('JSONController@getServers') . $query_string; break; case 'serverplayers': $columns_array = ['name']; $table_id = 'server-players'; $table_sdom = '<"top"p><"clear">t<"bottom"ip><"clear">'; $table_empty = 'Player list is private or no players are present.'; $input = Input::only('id'); $ajax_source = action('JSONController@getServerPlayers', [$input['id']]); break; case 'servermods': $columns_array = ['name', 'version']; $table_id = 'server-mods'; $table_sdom = '<"top"p><"clear">t<"bottom"ip><"clear">'; $table_empty = 'No mods returned from server.'; $input = Input::only('id'); $ajax_source = action('JSONController@getServerMods', [$input['id']]); break; } return Response::view('api.table.data', ['type' => $type, 'ajax_source' => $ajax_source, 'columns' => $columns_array, 'table_id' => $table_id, 'table_sdom' => $table_sdom, 'table_empty' => $table_empty, 'table_length' => $table_length, 'table_fixed_header' => $table_fixed_header, 'table_order' => $table_order], 200, ['Content-Type' => 'application/json']); }
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(); }
public function postEdit($id) { $mod_select_array = []; $selected_mods = []; $selected_tags = []; $selected_creators = []; $selected_maintainers = []; $can_edit_maintainers = false; $title = 'Edit A Modpack - ' . $this->site_name; $modpack = Modpack::find($id); if (Auth::check()) { $maintainer = $modpack->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'); } $minecraft_version = MinecraftVersion::where('id', '=', $modpack->minecraft_version_id)->first(); $creators = $modpack->creators; $mods = $modpack->mods; $tags = $modpack->tags; $maintainers = $modpack->maintainers; $input = Input::only('name', 'launcher', 'selected_mods', 'selected_creators', 'selected_tags', 'selected_maintainers', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug'); $messages = ['unique' => 'This modpack 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:modpacks,name,' . $modpack->id, 'launcher' => 'required', 'selected_mods' => 'required', 'selected_creators' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('ModController@getEdit', [$modpack->id])->withErrors($validator)->withInput(); } $modpack->name = $input['name']; $modpack->launcher_id = $input['launcher']; $modpack->deck = $input['deck']; $modpack->website = $input['website']; $modpack->download_link = $input['download_link']; $modpack->donate_link = $input['donate_link']; $modpack->wiki_link = $input['wiki_link']; $modpack->description = $input['description']; if ($input['slug'] == '' || $input['slug'] == $modpack->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $modpack->slug = $slug; $modpack->last_ip = Request::getClientIp(); $success = $modpack->save(); if ($success) { foreach ($creators as $c) { $modpack->creators()->detach($c->id); } $modpack->creators()->attach($input['selected_creators']); foreach ($mods as $m) { $modpack->mods()->detach($m->id); } $modpack->mods()->attach($input['selected_mods']); foreach ($tags as $t) { $modpack->tags()->detach($t->id); } if ($input['selected_tags']) { $modpack->tags()->attach($input['selected_tags']); } if ($can_edit_maintainers) { foreach ($maintainers as $m) { $modpack->maintainers()->detach($m->id); } if ($input['selected_maintainers']) { $modpack->maintainers()->attach($input['selected_maintainers']); } } $version_mods = $minecraft_version->mods; $updated_modpack = Modpack::find($modpack->id); foreach ($updated_modpack->mods as $m) { $selected_mods[] = $m->id; } foreach ($updated_modpack->tags as $t) { $selected_tags[] = $t->id; } foreach ($updated_modpack->creators as $c) { $selected_creators[] = $c->id; } foreach ($updated_modpack->maintainers as $m) { $selected_maintainers[] = $m->id; } foreach ($version_mods as $mod) { $id = $mod->id; $mod_select_array[$id] = $mod->name; } foreach ($mods as $mod) { $id = $mod->id; $mod_select_array[$id] = $mod->name; } Cache::tags('modpacks')->flush(); Cache::tags('modpackmods')->flush(); Cache::tags('modmodpacks')->flush(); Queue::push('BuildCache'); return View::make('modpacks.edit', ['title' => $title, 'chosen' => true, 'success' => true, 'modpack' => $updated_modpack, 'version' => $minecraft_version->name, 'mods' => $mod_select_array, 'selected_mods' => $selected_mods, 'selected_creators' => $selected_creators, 'selected_tags' => $selected_tags, 'selected_maintainers' => $selected_maintainers, 'can_edit_maintainers' => $can_edit_maintainers]); } return Redirect::action('ModController@getEdit', [$modpack->id])->withErrors(['message' => 'Unable to edit modpack.'])->withInput(); }
public function testModpackEditPost() { $modpack = Modpack::find(1); $data = array('name' => 'TestTest', 'slug' => 'test-test', 'hidden' => true, 'private' => true); $response = $this->call('POST', '/modpack/edit/' . $modpack->id, $data); $this->assertRedirectedTo('/modpack/view/' . $modpack->id); $modpack = Modpack::find(1); $this->assertEquals('TestTest', $modpack->name); $this->assertEquals('test-test', $modpack->slug); $this->assertTrue((bool) $modpack->hidden); $this->assertTrue((bool) $modpack->private); }