From e39079d557bb2891f4d0ec768708de7b3fbb64f7 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sun, 28 Aug 2022 02:49:47 -0700 Subject: [PATCH 1/3] add lifeform buildings constants for every races --- pkg/ogame/constants.go | 38 +++++++++++++++++++++++++++++++++++++- pkg/ogame/id.go | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/pkg/ogame/constants.go b/pkg/ogame/constants.go index 332aa98b..3c91e784 100644 --- a/pkg/ogame/constants.go +++ b/pkg/ogame/constants.go @@ -178,7 +178,7 @@ const ( IntergalacticResearchNetworkID ID = 123 AstrophysicsID ID = 124 GravitonTechnologyID ID = 199 - ResidentialSectorID ID = 11101 // Lifeform + ResidentialSectorID ID = 11101 // Lifeform (humans) BiosphereFarmID ID = 11102 ResearchCentreID ID = 11103 AcademyOfSciencesID ID = 11104 @@ -190,6 +190,42 @@ const ( BiotechLabID ID = 11110 MetropolisID ID = 11111 PlanetaryShieldID ID = 11112 + MeditationEnclaveID ID = 12101 // Lifeform (rocktal) + CrystalFarmID ID = 12102 + RuneTechnologiumID ID = 12103 + RuneForgeID ID = 12104 + OriktoriumID ID = 12105 + MagmaForgeID ID = 12106 + DisruptionChamberID ID = 12107 + MegalithID ID = 12108 + CrystalRefineryID ID = 12109 + DeuteriumSynthesiserID ID = 12110 + MineralResearchCentreID ID = 12111 + MetalRecyclingPlantID ID = 12112 + AssemblyLineID ID = 13101 // Lifeform (mechas) + FusionCellFactoryID ID = 13102 + RoboticsResearchCentreID ID = 13103 + UpdateNetworkID ID = 12304 + QuantumComputerCentreID ID = 13105 + AutomatisedAssemblyCentreID ID = 13106 + HighPerformanceTransformerID ID = 13107 + MicrochipAssemblyLineID ID = 13108 + ProductionAssemblyHallID ID = 13109 + HighPerformanceSynthesiserID ID = 13110 + ChipMassProductionID ID = 13111 + NanoRepairBotsID ID = 13112 + SanctuaryID ID = 14101 // Lifeform (kaelesh) + AntimatterCondenserID ID = 14102 + VortexChamberID ID = 14103 + HallsOfRealisationID ID = 14104 + ForumOfTranscendenceID ID = 14105 + AntimatterConvectorID ID = 14106 + CloningLaboratoryID ID = 14107 + ChrysalisAcceleratorID ID = 14108 + BioModifierID ID = 14109 + PsionicModulatorID ID = 14110 + ShipManufacturingHallID ID = 14111 + SupraRefractorID ID = 14112 IntergalacticEnvoysID ID = 11201 // Lifeform tech HighPerformanceExtractorsID ID = 11202 FusionDrivesID ID = 11203 diff --git a/pkg/ogame/id.go b/pkg/ogame/id.go index d7493616..b0f441f4 100644 --- a/pkg/ogame/id.go +++ b/pkg/ogame/id.go @@ -198,7 +198,7 @@ func (o ID) IsResourceBuilding() bool { } func (o ID) IsLfBuilding() bool { - return o == ResidentialSectorID || + return o == ResidentialSectorID || // humans o == BiosphereFarmID || o == ResearchCentreID || o == AcademyOfSciencesID || @@ -209,7 +209,43 @@ func (o ID) IsLfBuilding() bool { o == SkyscraperID || o == BiotechLabID || o == MetropolisID || - o == PlanetaryShieldID + o == PlanetaryShieldID || // rocktal + o == MeditationEnclaveID || + o == CrystalFarmID || + o == RuneTechnologiumID || + o == RuneForgeID || + o == OriktoriumID || + o == MagmaForgeID || + o == DisruptionChamberID || + o == MegalithID || + o == CrystalRefineryID || + o == DeuteriumSynthesiserID || + o == MineralResearchCentreID || + o == MetalRecyclingPlantID || + o == AssemblyLineID || // mechas + o == FusionCellFactoryID || + o == RoboticsResearchCentreID || + o == UpdateNetworkID || + o == QuantumComputerCentreID || + o == AutomatisedAssemblyCentreID || + o == HighPerformanceTransformerID || + o == MicrochipAssemblyLineID || + o == ProductionAssemblyHallID || + o == HighPerformanceSynthesiserID || + o == ChipMassProductionID || + o == NanoRepairBotsID || + o == SanctuaryID || // kaelesh + o == AntimatterCondenserID || + o == VortexChamberID || + o == HallsOfRealisationID || + o == ForumOfTranscendenceID || + o == AntimatterConvectorID || + o == CloningLaboratoryID || + o == ChrysalisAcceleratorID || + o == BioModifierID || + o == PsionicModulatorID || + o == ShipManufacturingHallID || + o == SupraRefractorID } // IsBuilding returns either or not the id is a building (facility, resource building) From 41bbec30250ea3a4e6d6831f21d0d6ba4fbfbdb4 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Sun, 28 Aug 2022 10:26:45 -0700 Subject: [PATCH 2/3] add tests ensure construction being built still work with/without lifeform --- pkg/extractor/v9/extractor.go | 6 + pkg/extractor/v9/extractor_test.go | 21 + pkg/extractor/v9/extracts.go | 17 + .../en/lifeform/overview_all_queues2.html | 2224 +++++++++++++++++ 4 files changed, 2268 insertions(+) create mode 100644 samples/v9.0.2/en/lifeform/overview_all_queues2.html diff --git a/pkg/extractor/v9/extractor.go b/pkg/extractor/v9/extractor.go index 49c5a673..ccf7c36c 100644 --- a/pkg/extractor/v9/extractor.go +++ b/pkg/extractor/v9/extractor.go @@ -3,6 +3,7 @@ package v9 import ( "bytes" "github.com/PuerkitoBio/goquery" + "github.com/alaingilbert/clockwork" "github.com/alaingilbert/ogame/pkg/extractor/v874" "github.com/alaingilbert/ogame/pkg/ogame" ) @@ -77,3 +78,8 @@ func (e *Extractor) ExtractResourcesDetailsFromFullPage(pageHTML []byte) ogame.R func (e *Extractor) ExtractResourcesDetailsFromFullPageFromDoc(doc *goquery.Document) ogame.ResourcesDetails { return extractResourcesDetailsFromFullPageFromDoc(doc) } + +// ExtractConstructions ... +func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64) { + return ExtractConstructions(pageHTML, clockwork.NewRealClock()) +} diff --git a/pkg/extractor/v9/extractor_test.go b/pkg/extractor/v9/extractor_test.go index d9e6cf4d..f5bf6bd2 100644 --- a/pkg/extractor/v9/extractor_test.go +++ b/pkg/extractor/v9/extractor_test.go @@ -1,6 +1,7 @@ package v9 import ( + "github.com/alaingilbert/clockwork" "github.com/alaingilbert/ogame/pkg/ogame" "github.com/stretchr/testify/assert" "io/ioutil" @@ -95,3 +96,23 @@ func TestCancelBuilding(t *testing.T) { assert.Equal(t, int64(1), id) assert.Equal(t, int64(3469488), listID) } + +func TestGetConstructions(t *testing.T) { + // Without lifeform + pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.2/en/overview_all_queues.html") + clock := clockwork.NewFakeClockAt(time.Date(2022, 8, 20, 12, 43, 11, 0, time.UTC)) + buildingID, buildingCountdown, researchID, researchCountdown := ExtractConstructions(pageHTMLBytes, clock) + assert.Equal(t, ogame.MetalMineID, buildingID) + assert.Equal(t, int64(5413), buildingCountdown) + assert.Equal(t, ogame.ComputerTechnologyID, researchID) + assert.Equal(t, int64(7), researchCountdown) + + // With lifeform + pageHTMLBytes, _ = ioutil.ReadFile("../../../samples/v9.0.2/en/lifeform/overview_all_queues2.html") + clock = clockwork.NewFakeClockAt(time.Date(2022, 8, 28, 17, 22, 26, 0, time.UTC)) + buildingID, buildingCountdown, researchID, researchCountdown = ExtractConstructions(pageHTMLBytes, clock) + assert.Equal(t, ogame.MetalStorageID, buildingID) + assert.Equal(t, int64(33483), buildingCountdown) + assert.Equal(t, ogame.ComputerTechnologyID, researchID) + assert.Equal(t, int64(18355), researchCountdown) +} diff --git a/pkg/extractor/v9/extracts.go b/pkg/extractor/v9/extracts.go index dd396f02..ecd9b4a7 100644 --- a/pkg/extractor/v9/extracts.go +++ b/pkg/extractor/v9/extracts.go @@ -3,6 +3,7 @@ package v9 import ( "errors" "github.com/PuerkitoBio/goquery" + "github.com/alaingilbert/clockwork" "github.com/alaingilbert/ogame/pkg/extractor/v6" v7 "github.com/alaingilbert/ogame/pkg/extractor/v7" "github.com/alaingilbert/ogame/pkg/extractor/v71" @@ -13,6 +14,22 @@ import ( "time" ) +func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64) { + buildingCountdownMatch := regexp.MustCompile(`var restTimebuilding = (\d+) -`).FindSubmatch(pageHTML) + if len(buildingCountdownMatch) > 0 { + buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1])) - clock.Now().Unix() + buildingIDInt := utils.ToInt(regexp.MustCompile(`onclick="cancelbuilding\((\d+),`).FindSubmatch(pageHTML)[1]) + buildingID = ogame.ID(buildingIDInt) + } + researchCountdownMatch := regexp.MustCompile(`var restTimeresearch = (\d+) -`).FindSubmatch(pageHTML) + if len(researchCountdownMatch) > 0 { + researchCountdown = int64(utils.ToInt(researchCountdownMatch[1])) - clock.Now().Unix() + researchIDInt := utils.ToInt(regexp.MustCompile(`onclick="cancelresearch\((\d+),`).FindSubmatch(pageHTML)[1]) + researchID = ogame.ID(researchIDInt) + } + return +} + func extractCancelLfBuildingInfos(pageHTML []byte) (token string, id, listID int64, err error) { return v7.ExtractCancelInfos(pageHTML, "cancelLinklfbuilding", "cancellfbuilding", 1) } diff --git a/samples/v9.0.2/en/lifeform/overview_all_queues2.html b/samples/v9.0.2/en/lifeform/overview_all_queues2.html new file mode 100644 index 00000000..ad93eda3 --- /dev/null +++ b/samples/v9.0.2/en/lifeform/overview_all_queues2.html @@ -0,0 +1,2224 @@ + + + + + Halley OGame + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ + +
+ + + + + + +
+ +
+ + + + + +
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ + 444.544 + +
+
+
+
+
+ + 62.115 + +
+
+
+
+
+ + 863.828 + +
+
+
+
+
+ + -2.267 + +
+
+
+
+
+ + 1.513.728.05 + +
+
+
+
+
+ + 0 + +
+
+
+
+ + +
+
+ + 8.000 + +
+
+
+ +
+ +
+
+ + + 25 + + + + + 0 + + +
+ +
+ ajax spinner + load... +
+ +
+
+ +
+
+
+ +
+
+
+
+ ? +
+
+
+
+
+ + + +
+
+
+
+
+
+
+ + +

Events

+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+ + +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + +
+
+ + +
+
+ +
+
+ +
+ +
+ + +
+
+
+
+
+
+
+

Buildings

+
+
+ + + + + + + + + + + + + + + + + + + +
Metal Storage
+ + Improve to + Level 11 +
Duration:
+ load... +
+ +
+ + Halve time + + + Costs: + 14.250 DM + + Purchase Dark Matter +
+
+
+ +
+ +
+
+
+

Lifeform Buildings

+
+
+ + + + + + + + + + + + + + + + + + + +
Biosphere Farm
+ + Improve to + Level 30 +
Duration:
+ load... +
+ +
+ + Halve time + + + Costs: + 9.750 DM + + Purchase Dark Matter +
+
+
+ +
+ +
+
+
+
+
+

Research

+
+
+ + + + + + + + + + + + + + + + + + + +
Computer Technology
+ + Research to + Level 11 +
Duration:
+ load... +
+ +
+ + Halve time + + + Costs: + 8.250 DM + + Purchase Dark Matter +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+

Shipyard

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Small Cargo
+
+ + Small Cargo + +
+
1
+
Building duration
+ load... +
Total time:
+ load... +
+ +
+ + Halve time + + + Costs: + 750 DM + +
+
+ + + + + + + + + +
+ Small Cargo
+ 1 +
+ Small Cargo
+ 1 +
+ Small Cargo
+ 1 +
+
+ +
+ +
+
+
+ + + +
+
+ +
+
+
+ + + + + +
+
+ +
+ +
+
    +
  • +
    +
    + 0 Contact(s) online +
  • +
+ + +
+
+ + + + From 55a82a57f92d104eda78aa110d3350dee5cc1cd2 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Tue, 30 Aug 2022 05:47:38 -0700 Subject: [PATCH 3/3] better error --- pkg/wrapper/gameforge.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/wrapper/gameforge.go b/pkg/wrapper/gameforge.go index 29bd6229..710a17ab 100644 --- a/pkg/wrapper/gameforge.go +++ b/pkg/wrapper/gameforge.go @@ -560,7 +560,8 @@ type ServerData struct { // GetServerData gets the server data from xml api func GetServerData(client httpclient.IHttpClient, ctx context.Context, serverNumber int64, serverLang string) (ServerData, error) { var serverData ServerData - req, err := http.NewRequest(http.MethodGet, "https://s"+utils.FI64(serverNumber)+"-"+serverLang+".ogame.gameforge.com/api/serverData.xml", nil) + serverDataURL := "https://s" + utils.FI64(serverNumber) + "-" + serverLang + ".ogame.gameforge.com/api/serverData.xml" + req, err := http.NewRequest(http.MethodGet, serverDataURL, nil) if err != nil { return serverData, err } @@ -576,7 +577,7 @@ func GetServerData(client httpclient.IHttpClient, ctx context.Context, serverNum return serverData, err } if err := xml.Unmarshal(by, &serverData); err != nil { - return serverData, err + return serverData, fmt.Errorf("failed to xml unmarshal %s : %w", serverDataURL, err) } return serverData, nil }