Something went wrong. Try again.
Perl game server for TLE Community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293use strict;use lib ('/home/lacuna/server/lib');use 5.010;use Config::JSON;use Plack::App::URLMap;use Log::Log4perl;use Log::Any::Adapter;use Lacuna;use Plack::Builder;use JSON qw(encode_json);$|=1;my $config = Config::JSON->new("/home/lacuna/server/etc/lacuna.conf");use Log::Log4perl;Log::Log4perl::init('/home/lacuna/server/etc/log4perl.conf');Log::Any::Adapter->set('Log::Log4perl');my $offline = [ 500, [ 'Content-Type' => 'application/json-rpc' ], [ encode_json( { "jsonrpc" => "2.0", "error" => { "code" => -32000, "message" => "The server is offline for maintenance.", } } ) ],];my $gameover = [ 500, [ 'Content-Type' => 'application/json-rpc' ], [ encode_json( { "jsonrpc" => "2.0", "error" => { "code" => 1200, "message" => "Game Over", "data" => "http://community.lacunaexanse.com/wiki/hall-of-fame", } } ) ],];my $app = builder { if ($^O ne 'darwin' && not defined $ENV{'TLE_NO_MIDDLEWARE'} ) { ##Wrapper to fully enable size limiting. The psgix.harakiri has to be set for it to work. enable sub { my $app = shift; return sub { my ($env) = @_; $env->{'psgix.harakiri'} = 1; return $app->($env); } }; enable "Plack::Middleware::SizeLimit" => ( max_unshared_size_in_kb => '51200', # 50MB # min_shared_size_in_kb => '8192', # 8MB max_process_size_in_kb => '125000', # 125MB check_every_n_requests => 3 ); enable "Plack::Middleware::LightProfile"; } enable 'CrossOrigin', origins => '*', methods => ['GET', 'POST'], max_age => 60*60*24*30, headers => '*'; enable sub { my $app = shift; return sub { my ($env) = @_; my $status = Lacuna->cache->get('server','status'); if ($status eq 'Offline') { return $offline; } elsif ($status eq 'Game Over') { return $gameover; } $app->($env); } }; mount '/starman_ping' => sub { [200, [ 'Content-Type' => 'text/plain'], [ 'pong' ]] }; mount "/map" => Lacuna::RPC::Map->new->to_app; mount "/body" => Lacuna::RPC::Body->new->to_app; mount "/empire" => Lacuna::RPC::Empire->new->to_app; mount "/alliance" => Lacuna::RPC::Alliance->new->to_app; mount "/inbox" => Lacuna::RPC::Inbox->new->to_app; mount "/stats" => Lacuna::RPC::Stats->new->to_app; mount "/pay" => Lacuna::Web::Pay->new->to_app; mount "/entertainment/vote" => Lacuna::Web::EntertainmentVote->new->to_app; mount "/announcement" => Lacuna::Web::Announcement->new->to_app; mount "/apikey" => Lacuna::Web::ApiKey->new->to_app; mount "/essentia-code" => Lacuna::RPC::EssentiaCode->new->to_app; mount "/captcha" => Lacuna::RPC::Captcha->new->to_app; for my $building (qw( Lacuna::RPC::Building::Shipyard Lacuna::RPC::Building::SpacePort Lacuna::RPC::Building::Intelligence Lacuna::RPC::Building::IntelTraining Lacuna::RPC::Building::MayhemTraining Lacuna::RPC::Building::PoliticsTraining Lacuna::RPC::Building::TheftTraining Lacuna::RPC::Building::Security Lacuna::RPC::Building::Trade Lacuna::RPC::Building::Transporter Lacuna::RPC::Building::Archaeology Lacuna::RPC::Building::DistributionCenter Lacuna::RPC::Building::SAW Lacuna::RPC::Building::AtmosphericEvaporator Lacuna::RPC::Building::GreatBallOfJunk Lacuna::RPC::Building::JunkHengeSculpture Lacuna::RPC::Building::MetalJunkArches Lacuna::RPC::Building::PyramidJunkSculpture Lacuna::RPC::Building::SpaceJunkPark Lacuna::RPC::Building::ThemePark Lacuna::RPC::Building::BlackHoleGenerator Lacuna::RPC::Building::TheDillonForge Lacuna::RPC::Building::HallsOfVrbansk Lacuna::RPC::Building::GratchsGauntlet Lacuna::RPC::Building::KasternsKeep Lacuna::RPC::Building::SubspaceSupplyDepot Lacuna::RPC::Building::SupplyPod Lacuna::RPC::Building::PantheonOfHagness Lacuna::RPC::Building::Capitol Lacuna::RPC::Building::Stockpile Lacuna::RPC::Building::Algae Lacuna::RPC::Building::Apple Lacuna::RPC::Building::Bean Lacuna::RPC::Building::Beeldeban Lacuna::RPC::Building::Bread Lacuna::RPC::Building::Burger Lacuna::RPC::Building::Cheese Lacuna::RPC::Building::Chip Lacuna::RPC::Building::Cider Lacuna::RPC::Building::Corn Lacuna::RPC::Building::CornMeal Lacuna::RPC::Building::EssentiaVein Lacuna::RPC::Building::Volcano Lacuna::RPC::Building::MassadsHenge Lacuna::RPC::Building::LibraryOfJith Lacuna::RPC::Building::NaturalSpring Lacuna::RPC::Building::OracleOfAnid Lacuna::RPC::Building::TempleOfTheDrajilites Lacuna::RPC::Building::GeoThermalVent Lacuna::RPC::Building::InterDimensionalRift Lacuna::RPC::Building::CitadelOfKnope Lacuna::RPC::Building::CrashedShipSite Lacuna::RPC::Building::KalavianRuins Lacuna::RPC::Building::Grove Lacuna::RPC::Building::Sand Lacuna::RPC::Building::Lagoon Lacuna::RPC::Building::Crater Lacuna::RPC::Building::Dairy Lacuna::RPC::Building::Denton Lacuna::RPC::Building::Development Lacuna::RPC::Building::Embassy Lacuna::RPC::Building::EnergyReserve Lacuna::RPC::Building::Entertainment Lacuna::RPC::Building::Espionage Lacuna::RPC::Building::Fission Lacuna::RPC::Building::FoodReserve Lacuna::RPC::Building::Fusion Lacuna::RPC::Building::DeployedBleeder Lacuna::RPC::Building::GasGiantLab Lacuna::RPC::Building::GasGiantPlatform Lacuna::RPC::Building::Geo Lacuna::RPC::Building::Hydrocarbon Lacuna::RPC::Building::Lapis Lacuna::RPC::Building::Malcud Lacuna::RPC::Building::Mine Lacuna::RPC::Building::MiningMinistry Lacuna::RPC::Building::Network19 Lacuna::RPC::Building::Observatory Lacuna::RPC::Building::OreRefinery Lacuna::RPC::Building::OreStorage Lacuna::RPC::Building::Pancake Lacuna::RPC::Building::Park Lacuna::RPC::Building::Pie Lacuna::RPC::Building::PlanetaryCommand Lacuna::RPC::Building::Potato Lacuna::RPC::Building::Propulsion Lacuna::RPC::Building::Oversight Lacuna::RPC::Building::RockyOutcrop Lacuna::RPC::Building::Lake Lacuna::RPC::Building::Shake Lacuna::RPC::Building::Singularity Lacuna::RPC::Building::Soup Lacuna::RPC::Building::Syrup Lacuna::RPC::Building::TerraformingLab Lacuna::RPC::Building::GeneticsLab Lacuna::RPC::Building::TerraformingPlatform Lacuna::RPC::Building::University Lacuna::RPC::Building::WasteEnergy Lacuna::RPC::Building::WasteExchanger Lacuna::RPC::Building::WasteRecycling Lacuna::RPC::Building::WasteSequestration Lacuna::RPC::Building::WasteDigester Lacuna::RPC::Building::WasteTreatment Lacuna::RPC::Building::WaterProduction Lacuna::RPC::Building::WaterPurification Lacuna::RPC::Building::WaterReclamation Lacuna::RPC::Building::WaterStorage Lacuna::RPC::Building::Wheat Lacuna::RPC::Building::Beach1 Lacuna::RPC::Building::Beach2 Lacuna::RPC::Building::Beach3 Lacuna::RPC::Building::Beach4 Lacuna::RPC::Building::Beach5 Lacuna::RPC::Building::Beach6 Lacuna::RPC::Building::Beach7 Lacuna::RPC::Building::Beach8 Lacuna::RPC::Building::Beach9 Lacuna::RPC::Building::Beach10 Lacuna::RPC::Building::Beach11 Lacuna::RPC::Building::Beach12 Lacuna::RPC::Building::Beach13 Lacuna::RPC::Building::PilotTraining Lacuna::RPC::Building::MissionCommand Lacuna::RPC::Building::CloakingLab Lacuna::RPC::Building::MunitionsLab Lacuna::RPC::Building::LuxuryHousing Lacuna::RPC::Building::Fissure Lacuna::RPC::Building::Ravine Lacuna::RPC::Building::AlgaePond Lacuna::RPC::Building::LapisForest Lacuna::RPC::Building::BeeldebanNest Lacuna::RPC::Building::MalcudField Lacuna::RPC::Building::SSLa Lacuna::RPC::Building::SSLb Lacuna::RPC::Building::SSLc Lacuna::RPC::Building::SSLd Lacuna::RPC::Building::AmalgusMeadow Lacuna::RPC::Building::DentonBrambles Lacuna::RPC::Building::MercenariesGuild Lacuna::RPC::Building::StationCommand Lacuna::RPC::Building::OperaHouse Lacuna::RPC::Building::ArtMuseum Lacuna::RPC::Building::CulinaryInstitute Lacuna::RPC::Building::IBS Lacuna::RPC::Building::Warehouse Lacuna::RPC::Building::Parliament Lacuna::RPC::Building::PoliceStation Lacuna::RPC::Building::LCOTa Lacuna::RPC::Building::LCOTb Lacuna::RPC::Building::LCOTc Lacuna::RPC::Building::LCOTd Lacuna::RPC::Building::LCOTe Lacuna::RPC::Building::LCOTf Lacuna::RPC::Building::LCOTg Lacuna::RPC::Building::LCOTh Lacuna::RPC::Building::LCOTi )) { mount $building->new->to_app_with_url; } # Dev-only test setup/teardown endpoints. Gated on LACUNA_TEST_SETUP_API, # which docker-compose.yml sets for server and # docker-compose.deployed.yml deliberately does not -- so /test simply does # not exist in production. See lib/Lacuna/Web/TestSetup.pm. if ($ENV{LACUNA_TEST_SETUP_API}) { mount "/test" => Lacuna::Web::TestSetup->new->to_app; } mount '/admin' => builder { enable "Auth::Basic", authenticator => sub { my ($username, $password) = @_; return 0 unless $username; my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name => $username, is_admin => 1})->first; return 0 unless defined $empire; return $empire->is_password_valid($password); }; Lacuna::Web::Admin->new->to_app; }; mount "/missioncurator" => builder { enable "Auth::Basic", authenticator => sub { my ($username, $password) = @_; return 0 unless $username; my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name => $username, is_mission_curator => 1})->first; return 0 unless defined $empire; return $empire->is_password_valid($password); }; Lacuna::Web::MissionCurator->new->to_app; };};say "Server Started";$app;