Skip to content

Commit

Permalink
Merge branch 'release/50.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 24, 2022
2 parents c841c2f + f5ef137 commit 1235a73
Show file tree
Hide file tree
Showing 27 changed files with 2,024 additions and 318 deletions.
6 changes: 3 additions & 3 deletions cmd/c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ func BuildShips(planetID, shipID, nbr C.int) (errorMsg *C.char) {
// TODO: GetProduction(PlanetID) ([]Quantifiable, error)

//export ConstructionsBeingBuilt
func ConstructionsBeingBuilt(planetID C.int) (buildingID, buildingCountdown, researchID, researchCountdown, lfBuildingID, lfBuildingCountdown C.int) {
a, b, c, d, e, f := bot.ConstructionsBeingBuilt(ogame2.CelestialID(planetID))
return C.int(a), C.int(b), C.int(c), C.int(d), C.int(e), C.int(f)
func ConstructionsBeingBuilt(planetID C.int) (buildingID, buildingCountdown, researchID, researchCountdown, lfBuildingID, lfBuildingCountdown, lfTechID, lfTechCountdown C.int) {
a, b, c, d, e, f, g, h := bot.ConstructionsBeingBuilt(ogame2.CelestialID(planetID))
return C.int(a), C.int(b), C.int(c), C.int(d), C.int(e), C.int(f), C.int(g), C.int(h)
}

//export CancelBuilding
Expand Down
1 change: 1 addition & 0 deletions cmd/ogamed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func start(c *cli.Context) error {
e.POST("/bot/planets/:planetID/resource-settings", wrapper.SetResourceSettingsHandler)
e.GET("/bot/planets/:planetID/resources-buildings", wrapper.GetResourcesBuildingsHandler)
e.GET("/bot/planets/:planetID/lifeform-buildings", wrapper.GetLfBuildingsHandler)
e.GET("/bot/planets/:planetID/lifeform-techs", wrapper.GetLfTechsHandler)
e.GET("/bot/planets/:planetID/defence", wrapper.GetDefenseHandler)
e.GET("/bot/planets/:planetID/ships", wrapper.GetShipsHandler)
e.GET("/bot/planets/:planetID/facilities", wrapper.GetFacilitiesHandler)
Expand Down
17 changes: 16 additions & 1 deletion pkg/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type OverviewExtractorBytes interface {
ExtractCancelLfBuildingInfos(pageHTML []byte) (token string, id, listID int64, err error)
ExtractCancelResearchInfos(pageHTML []byte) (token string, techID, listID int64, err error)
ExtractCharacterClass(pageHTML []byte) (ogame.CharacterClass, error)
ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64)
ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64)
ExtractDMCosts(pageHTML []byte) (ogame.DMCosts, error)
ExtractFleetDeutSaveFactor(pageHTML []byte) float64
ExtractOverviewProduction(pageHTML []byte) ([]ogame.Quantifiable, int64, error)
Expand Down Expand Up @@ -423,6 +423,20 @@ type LfBuildingsExtractorBytesDoc interface {
LfBuildingsExtractorDoc
}

type LfTechsExtractorBytes interface {
ExtractUpgradeToken(pageHTML []byte) (string, error)
ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error)
}

type LfTechsExtractorDoc interface {
ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error)
}

type LfTechsExtractorBytesDoc interface {
LfTechsExtractorBytes
LfTechsExtractorDoc
}

// ResourcesBuildingsExtractorBytes supplies page
type ResourcesBuildingsExtractorBytes interface {
ExtractResourcesBuildings(pageHTML []byte) (ogame.ResourcesBuildings, error)
Expand Down Expand Up @@ -478,6 +492,7 @@ type Extractor interface {
FullPageExtractorBytesDoc
HighscoreExtractorBytesDoc
LfBuildingsExtractorBytesDoc
LfTechsExtractorBytesDoc
MessagesCombatReportExtractorBytesDoc
MessagesEspionageReportExtractorBytesDoc
MessagesExpeditionExtractorBytesDoc
Expand Down
12 changes: 11 additions & 1 deletion pkg/extractor/v6/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ func (e *Extractor) ExtractFederation(pageHTML []byte) url.Values {
}

// ExtractConstructions ...
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64) {
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
return extractConstructions(pageHTML)
}

Expand Down Expand Up @@ -893,3 +893,13 @@ func (e *Extractor) ExtractLfBuildings(pageHTML []byte) (ogame.LfBuildings, erro
func (e *Extractor) ExtractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error) {
panic("not implemented")
}

// ExtractLfTechs ...
func (e *Extractor) ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error) {
panic("not implemented")
}

// ExtractLfTechsFromDoc ...
func (e *Extractor) ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {
panic("not implemented")
}
2 changes: 1 addition & 1 deletion pkg/extractor/v6/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ func TestCancelResearch(t *testing.T) {

func TestGetConstructions(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/unversioned/overview_active.html")
buildingID, buildingCountdown, researchID, researchCountdown, _, _ := NewExtractor().ExtractConstructions(pageHTMLBytes)
buildingID, buildingCountdown, researchID, researchCountdown, _, _, _, _ := NewExtractor().ExtractConstructions(pageHTMLBytes)
assert.Equal(t, ogame.CrystalMineID, buildingID)
assert.Equal(t, int64(731), buildingCountdown)
assert.Equal(t, ogame.CombustionDriveID, researchID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v6/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ func extractFederation(pageHTML []byte) url.Values {
return payload
}

func extractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64) {
func extractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
buildingCountdownMatch := regexp.MustCompile(`getElementByIdWithCache\("Countdown"\),(\d+),`).FindSubmatch(pageHTML)
if len(buildingCountdownMatch) > 0 {
buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1]))
Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v7/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (e Extractor) ExtractResourcesDetails(pageHTML []byte) (out ogame.Resources
}

// ExtractConstructions ...
func (e Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64) {
func (e Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
return ExtractConstructions(pageHTML, clockwork.NewRealClock())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v7/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestExtractFleetSlot_FleetDispatch(t *testing.T) {
func TestGetConstructionsV7(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v7/overview_supplies_in_construction.html")
clock := clockwork.NewFakeClockAt(time.Date(2019, 11, 12, 9, 6, 43, 0, time.UTC))
buildingID, buildingCountdown, researchID, researchCountdown, _, _ := ExtractConstructions(pageHTMLBytes, clock)
buildingID, buildingCountdown, researchID, researchCountdown, _, _, _, _ := ExtractConstructions(pageHTMLBytes, clock)
assert.Equal(t, ogame.MetalMineID, buildingID)
assert.Equal(t, int64(62), buildingCountdown)
assert.Equal(t, ogame.EnergyTechnologyID, researchID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/extractor/v7/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func extractResourcesDetails(pageHTML []byte) (out ogame.ResourcesDetails, err e
return
}

func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64) {
func ExtractConstructions(pageHTML []byte, clock clockwork.Clock) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
buildingCountdownMatch := regexp.MustCompile(`var restTimebuilding = (\d+) -`).FindSubmatch(pageHTML)
if len(buildingCountdownMatch) > 0 {
buildingCountdown = int64(utils.ToInt(buildingCountdownMatch[1])) - clock.Now().Unix()
Expand Down
13 changes: 12 additions & 1 deletion pkg/extractor/v9/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (e *Extractor) ExtractResourcesDetailsFromFullPageFromDoc(doc *goquery.Docu
}

// ExtractConstructions ...
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64) {
func (e *Extractor) ExtractConstructions(pageHTML []byte) (buildingID ogame.ID, buildingCountdown int64, researchID ogame.ID, researchCountdown int64, lfBuildingID ogame.ID, lfBuildingCountdown int64, lfTechID ogame.ID, lfTechCountdown int64) {
return ExtractConstructions(pageHTML, clockwork.NewRealClock())
}

Expand All @@ -101,3 +101,14 @@ func (e *Extractor) ExtractLfBuildings(pageHTML []byte) (ogame.LfBuildings, erro
func (e *Extractor) ExtractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error) {
return extractLfBuildingsFromDoc(doc)
}

// ExtractLfTechs ...
func (e *Extractor) ExtractLfTechs(pageHTML []byte) (ogame.LfTechs, error) {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
return e.ExtractLfTechsFromDoc(doc)
}

// ExtractLfTechsFromDoc ...
func (e *Extractor) ExtractLfTechsFromDoc(doc *goquery.Document) (ogame.LfTechs, error) {
return extractLfTechsFromDoc(doc)
}
4 changes: 2 additions & 2 deletions pkg/extractor/v9/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ 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)
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)
Expand All @@ -119,7 +119,7 @@ func TestGetConstructions(t *testing.T) {
// 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)
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)
Expand Down
Loading

0 comments on commit 1235a73

Please sign in to comment.