Skip to content

Commit

Permalink
Merge branch 'release/42.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Jun 14, 2020
2 parents b40cbfc + 3c31879 commit 9d6a9d2
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 499 deletions.
4 changes: 2 additions & 2 deletions extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,12 @@ func extractFleetsFromDocV6(doc *goquery.Document, clock clockwork.Clock) (res [
func extractSlotsFromDocV6(doc *goquery.Document) Slots {
slots := Slots{}
page := extractBodyIDFromDocV6(doc)
if page == "movement" {
if page == MovementPage {
slots.InUse = ParseInt(doc.Find("span.fleetSlots > span.current").Text())
slots.Total = ParseInt(doc.Find("span.fleetSlots > span.all").Text())
slots.ExpInUse = ParseInt(doc.Find("span.expSlots > span.current").Text())
slots.ExpTotal = ParseInt(doc.Find("span.expSlots > span.all").Text())
} else if page == "fleet1" || page == "fleetdispatch" {
} else if page == FleetdispatchPage || page == "fleet1" {
r := regexp.MustCompile(`(\d+)/(\d+)`)
txt := doc.Find("div#slots>div").Eq(0).Text()
m := r.FindStringSubmatch(txt)
Expand Down
33 changes: 8 additions & 25 deletions fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import (

// Page names
const (
// V6 full pages
OverviewPage = "overview"
PreferencesPage = "preferences"
ResourceSettingsPage = "resourceSettings"
ResourcesPage = "resources"
DefensePage = "defense"
DefensesPage = "defenses"
SuppliesPage = "supplies"
FacilitiesPage = "facilities"
FleetdispatchPage = "fleetdispatch"
ShipyardPage = "shipyard"
StationPage = "station"
MovementPage = "movement"
ResearchPage = "research"
PlanetlayerPage = "planetlayer"
LogoutPage = "logout"
Fleet1Page = "fleet1"
JumpgatelayerPage = "jumpgatelayer"
FetchResourcesPage = "fetchResources"
TraderOverviewPage = "traderOverview"
Expand All @@ -33,7 +32,7 @@ const (
MessagesPage = "messages"
ChatPage = "chat"

// V6 ajax pages
// ajax pages
FetchEventboxAjaxPage = "fetchEventbox"
FetchResourcesAjaxPage = "fetchResources"
GalaxyContentAjaxPage = "galaxyContent"
Expand All @@ -57,28 +56,12 @@ const (
BuffActivationAjaxPage = "buffActivation"
AuctioneerAjaxPage = "auctioneer"
HighscoreContentAjaxPage = "highscoreContent"

// V7 pages
DefensesPage = "defenses"
SuppliesPage = "supplies"
FacilitiesPage = "facilities"
FleetdispatchPage = "fleetdispatch"
)

var pageV7Mapping = map[string]string{
DefensePage: DefensesPage,
ResourcesPage: SuppliesPage,
StationPage: FacilitiesPage,
Fleet1Page: FleetdispatchPage,
}

func (b *OGame) getPage(page string, celestialID CelestialID, opts ...Option) ([]byte, error) {
vals := url.Values{"page": {page}}
if b.IsV7() && page != FetchResourcesPage {
if newPage, ok := pageV7Mapping[page]; ok {
page = newPage
}
vals = url.Values{"page": {"ingame"}, "component": {page}}
vals := url.Values{"page": {"ingame"}, "component": {page}}
if page == FetchResourcesPage {
vals = url.Values{"page": {page}}
}
if celestialID != 0 {
vals.Add("cp", strconv.FormatInt(int64(celestialID), 10))
Expand Down
4 changes: 2 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ogame
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -907,12 +906,13 @@ func GetStaticHandler(c echo.Context) error {
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResp(500, err.Error()))
}
req.Header.Add("Accept-Encoding", "gzip, deflate, br")
resp, err := bot.Client.Do(req)
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResp(500, err.Error()))
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, _, err := readBody(resp)
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResp(500, err.Error()))
}
Expand Down
Loading

0 comments on commit 9d6a9d2

Please sign in to comment.