Skip to content

Commit

Permalink
Merge branch 'release/42.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 26, 2020
2 parents 0ae08ef + a3dff0e commit 74f08f6
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 6 deletions.
6 changes: 3 additions & 3 deletions extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,21 +527,21 @@ func extractOfferOfTheDayFromDocV6(doc *goquery.Document) (price int64, importTo
}
price = ParseInt(s.Text())
script := doc.Find("script").Text()
m := regexp.MustCompile(`var importToken="([^"]*)";`).FindSubmatch([]byte(script))
m := regexp.MustCompile(`var importToken\s?=\s?"([^"]*)";`).FindSubmatch([]byte(script))
if len(m) != 2 {
err = errors.New("failed to extract offer of the day import token")
return
}
importToken = string(m[1])
m = regexp.MustCompile(`var planetResources=({[^;]*});`).FindSubmatch([]byte(script))
m = regexp.MustCompile(`var planetResources\s?=\s?({[^;]*});`).FindSubmatch([]byte(script))
if len(m) != 2 {
err = errors.New("failed to extract offer of the day raw planet resources")
return
}
if err = json.Unmarshal(m[1], &planetResources); err != nil {
return
}
m = regexp.MustCompile(`var multiplier=({[^;]*});`).FindSubmatch([]byte(script))
m = regexp.MustCompile(`var multiplier\s?=\s?({[^;]*});`).FindSubmatch([]byte(script))
if len(m) != 2 {
err = errors.New("failed to extract offer of the day raw multiplier")
return
Expand Down
6 changes: 3 additions & 3 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2803,7 +2803,7 @@ func calcResources(price int64, planetResources PlanetResources, multiplier Mult
}

func (b *OGame) buyOfferOfTheDay() error {
pageHTML, err := b.postPageContent(url.Values{"page": {"traderOverview"}}, url.Values{"show": {"importexport"}, "ajax": {"1"}})
pageHTML, err := b.postPageContent(url.Values{"page": {"ajax"}, "component": {"traderimportexport"}}, url.Values{"show": {"importexport"}, "ajax": {"1"}})
if err != nil {
return err
}
Expand All @@ -2817,7 +2817,7 @@ func (b *OGame) buyOfferOfTheDay() error {
payload.Add("bid[honor]", "0")
payload.Add("token", importToken)
payload.Add("ajax", "1")
pageHTML1, err := b.postPageContent(url.Values{"page": {"import"}}, payload)
pageHTML1, err := b.postPageContent(url.Values{"page": {"ajax"}, "component": {"traderimportexport"}, "ajax": {"1"}, "action": {"trade"}, "asJson": {"1"}}, payload)
if err != nil {
return err
}
Expand All @@ -2835,7 +2835,7 @@ func (b *OGame) buyOfferOfTheDay() error {
}

payload2 := url.Values{"action": {"takeItem"}, "token": {tmp.NewToken}, "ajax": {"1"}}
pageHTML2, err := b.postPageContent(url.Values{"page": {"import"}}, payload2)
pageHTML2, err := b.postPageContent(url.Values{"page": {"ajax"}, "component": {"traderimportexport"}, "ajax": {"1"}, "action": {"takeItem"}, "asJson": {"1"}}, payload2)
var tmp2 struct {
Message string
Error bool
Expand Down
7 changes: 7 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,13 @@ func TestExtractOfferOfTheDayPrice(t *testing.T) {
assert.Equal(t, "8128c0ba0c9981599a87d818003f95e1", token)
}

func TestExtractOfferOfTheDayPrice1(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/v7.4/en/traderOverview.html")
price, token, _, _, _ := NewExtractorV6().ExtractOfferOfTheDay(pageHTMLBytes)
assert.Equal(t, int64(822159), price)
assert.Equal(t, "2c829372796443bf6994cbfa051e4cd2", token)
}

func TestExtractAttacks(t *testing.T) {
clock := clockwork.NewFakeClockAt(time.Date(2016, 8, 23, 17, 48, 13, 0, time.UTC))
pageHTMLBytes, _ := ioutil.ReadFile("samples/event_list_attack.html")
Expand Down
Loading

0 comments on commit 74f08f6

Please sign in to comment.