Skip to content

Commit

Permalink
Merge branch 'release/32.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Mar 6, 2020
2 parents e20207c 322b1dd commit 0a5fb4d
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 11 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 1,9 @@
language: go
go:
- "1.11"

before_install:
- go get -t -v ./...
- "1.12"

script:
- go test -coverprofile=coverage.txt -covermode=atomic
- go test -mod=vendor -coverprofile=coverage.txt -covermode=atomic

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 51,5 @@ var (
ErrNoMoonAvailable = errors.New("no moon available")
ErrNoRecyclerAvailable = errors.New("no recycler available")
ErrNoEventsRunning = errors.New("there are currently no events running")
ErrPlanetAlreadyReservecForRelocation = errors.New("this planet has already been reserved for a relocation")
ErrPlanetAlreadyReservedForRelocation = errors.New("this planet has already been reserved for a relocation")
)
6 changes: 6 additions & 0 deletions extractor_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 277,12 @@ func (e ExtractorV6) ExtractTechnocrat(pageHTML []byte) bool {
return e.ExtractTechnocratFromDoc(doc)
}

// ExtractOGameSession ...
func (e ExtractorV6) ExtractOGameSession(pageHTML []byte) string {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
return e.ExtractOGameSessionFromDoc(doc)
}

// <Extract from doc> ---------------------------------------------------------

// ExtractHiddenFieldsFromDoc utils function to extract hidden input from a page
Expand Down
14 changes: 13 additions & 1 deletion extracts_v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 388,19 @@ func extractResearchFromDocV6(doc *goquery.Document) Researches {
}

func extractOGameSessionFromDocV6(doc *goquery.Document) string {
return doc.Find("meta[name=ogame-session]").AttrOr("content", "")
sessionMeta := doc.Find("meta[name=ogame-session]")
if sessionMeta.Size() == 0 {
r := regexp.MustCompile(`var session = "([^"] )";`)
scripts := doc.Find("script")
for i := 0; i < scripts.Size(); i {
scriptText := scripts.Eq(i).Text()
m := r.FindStringSubmatch(scriptText)
if len(m) == 2 {
return m[1]
}
}
}
return sessionMeta.AttrOr("content", "")
}

func extractAttacksFromDocV6(doc *goquery.Document, clock clockwork.Clock) ([]AttackEvent, error) {
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 869,7 @@ func SendFleetHandler(c echo.Context) error {
err == ErrNoMoonAvailable ||
err == ErrNoRecyclerAvailable ||
err == ErrNoEventsRunning ||
err == ErrPlanetAlreadyReservecForRelocation) {
err == ErrPlanetAlreadyReservedForRelocation) {
return c.JSON(http.StatusBadRequest, ErrorResp(400, err.Error()))
}
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 684,7 @@ func (b *OGame) loginPart3(userAccount account, pageHTML []byte) error {
}
b.ogameSession = b.extractor.ExtractOGameSessionFromDoc(doc)
if b.ogameSession == "" {
return errors.New("bad credentials")
return ErrBadCredentials
}

serverTime, _ := b.extractor.ExtractServerTime(pageHTML)
Expand Down Expand Up @@ -1038,6 1038,7 @@ func IsAjaxPage(vals url.Values) bool {
page = vals.Get("component")
}
ajax := vals.Get("ajax")
asJson := vals.Get("asJson")
return page == FetchEventboxAjaxPage ||
page == FetchResourcesAjaxPage ||
page == GalaxyContentAjaxPage ||
Expand All @@ -1061,7 1062,8 @@ func IsAjaxPage(vals url.Values) bool {
page == BuffActivationAjaxPage ||
page == AuctioneerAjaxPage ||
page == HighscoreContentAjaxPage ||
ajax == "1"
ajax == "1" ||
asJson == "1"
}

func canParseEventBox(by []byte) bool {
Expand Down Expand Up @@ -3218,7 3220,7 @@ func (b *OGame) sendFleetV6(celestialID CelestialID, ships []Quantifiable, speed
case "15":
return Fleet{}, ErrNoEventsRunning
case "16":
return Fleet{}, ErrPlanetAlreadyReservecForRelocation
return Fleet{}, ErrPlanetAlreadyReservedForRelocation
}

// Page 3 : select coord, mission, speed
Expand Down
10 changes: 10 additions & 0 deletions ogame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2827,3 2827,13 @@ func TestExtractBuffActivation(t *testing.T) {
assert.Equal(t, "081876002bf5791011097597836d3f5c", token)
assert.Equal(t, 31, len(items))
}

func TestExtractOGameSession(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("samples/v7/overview.html")
session := NewExtractorV6().ExtractOGameSession(pageHTMLBytes)
assert.Equal(t, "0a724276a3ddbe9949f62bdae48d71c1a16adf20", session)

pageHTMLBytes, _ = ioutil.ReadFile("samples/v7/overview_mobile.html")
session = NewExtractorV6().ExtractOGameSession(pageHTMLBytes)
assert.Equal(t, "c1626ce8228ac5986e3808a7d42d4afc764c1b68", session)
}
256 changes: 256 additions & 0 deletions samples/v7.2/en/eventlist_trade_ships.html
Original file line number Diff line number Diff line change
@@ -0,0 1,256 @@
<div id="eventListWrap">
<div id="eventHeader">
<a class="close_details eventToggle" href="javascript:toggleEvents();">
</a>
<h2>Events</h2>
</div>
<table id="eventContent">
<tbody>
<tr class="eventFleet" id="eventRow-611612"
data-mission-type="3"
data-return-flight="true"
data-arrival-time="1583478971"
>
<td class="countDown">
<span id="counter-eventlist-611612" class="friendly textBeefy">
load...
</span>
</td>
<td class="arrivalTime">07:16:11 Clock</td>
<td class="missionFleet">
<img src="https://gf1.geo.gfsrv.net/cdn38/2af2939219d8227a11a50ff4df7b51.gif" class="tooltipHTML" title="Own fleet | Transport (R)" alt=""/>
</td>

<td class="originFleet">
<figure class="planetIcon planet"></figure>Colony
</td>
<td class="coordsOrigin">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=4&amp;system=116" target="_top">
[4:116:9]
</a>
</td>

<td class="detailsFleet">
<span>17</span>
</td>
<td class="icon_movement_reserve">
<span class="tooltip tooltipRight tooltipClose"
title="&lt;div class=&quot;htmlTooltip&quot;&gt;
&lt;h1&gt;Fleet details:&lt;/h1&gt;
&lt;div class=&quot;splitLine&quot;&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;fleetinfo&quot;&gt;
&lt;tr&gt;
&lt;th colspan=&quot;3&quot;&gt;Ships:&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Large Cargo:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;3&quot;&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th colspan=&quot;3&quot;&gt;Shipment:&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Metal:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Crystal:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Deuterium:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
">
&nbsp;
</span>
</td>

<td class="destFleet">
<figure class="planetIcon planet tooltip js_hideTipOnMobile" title="Planet"></figure>Colony
</td>
<td class="destCoords">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=4&amp;system=208" target="_top">
[4:208:8]
</a>
</td>

<td class="sendProbe">
</td>
<td class="sendMail">
</td>

</tr>

<tr class="eventFleet" id="eventRow-611876"
data-mission-type="16"
data-return-flight="false"
data-arrival-time="1583480264"
>
<td class="countDown">
<span id="counter-eventlist-611876" class="neutral textBeefy">
load...
</span>
</td>
<td class="arrivalTime">07:37:44 Clock</td>
<td class="missionFleet">
<img src="https://gf2.geo.gfsrv.net/cdnde/3f1fad85c1aa249973e52e8e106468.gif" class="tooltipHTML" title="Friendly fleet | Trading Fleet" alt=""/>
</td>

<td class="originFleet">
<figure class="planetIcon planet"></figure>Salister
</td>
<td class="coordsOrigin">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=3&amp;system=407" target="_top">
[3:407:10]
</a>
</td>

<td class="detailsFleet">
<span>5600</span>
</td>
<td class="icon_movement">
<span class="tooltip tooltipRight tooltipClose"
title="&lt;div class=&quot;htmlTooltip&quot;&gt;
&lt;h1&gt;Fleet details:&lt;/h1&gt;
&lt;div class=&quot;splitLine&quot;&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;fleetinfo&quot;&gt;
&lt;tr&gt;
&lt;th colspan=&quot;3&quot;&gt;Ships:&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Trade Ship:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;5.600&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
">
&nbsp;
</span>
</td>

<td class="destFleet">
<figure class="planetIcon planet tooltip js_hideTipOnMobile" title="Planet"></figure>Colony
</td>
<td class="destCoords">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=4&amp;system=208" target="_top">
[4:208:8]
</a>
</td>

<td class="sendProbe">
</td>
<td class="sendMail">
<a href="javascript:void(0)"
class="sendMail js_openChat tooltip"
data-playerId="105992"
title="Zum"><span class="icon icon_chat"></span></a>
</td>

</tr>

<tr class="eventFleet" id="eventRow-611878"
data-mission-type="16"
data-return-flight="false"
data-arrival-time="1583480685"
>
<td class="countDown">
<span id="counter-eventlist-611878" class="neutral textBeefy">
load...
</span>
</td>
<td class="arrivalTime">07:44:45 Clock</td>
<td class="missionFleet">
<img src="https://gf2.geo.gfsrv.net/cdnde/3f1fad85c1aa249973e52e8e106468.gif" class="tooltipHTML" title="Friendly fleet | Trading Fleet" alt=""/>
</td>

<td class="originFleet">
<figure class="planetIcon planet"></figure>Tonsan
</td>
<td class="coordsOrigin">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=3&amp;system=407" target="_top">
[3:407:9]
</a>
</td>

<td class="detailsFleet">
<span>5200</span>
</td>
<td class="icon_movement">
<span class="tooltip tooltipRight tooltipClose"
title="&lt;div class=&quot;htmlTooltip&quot;&gt;
&lt;h1&gt;Fleet details:&lt;/h1&gt;
&lt;div class=&quot;splitLine&quot;&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;fleetinfo&quot;&gt;
&lt;tr&gt;
&lt;th colspan=&quot;3&quot;&gt;Ships:&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;Trade Ship:&lt;/td&gt;
&lt;td class=&quot;value&quot;&gt;5.200&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
">
&nbsp;
</span>
</td>

<td class="destFleet">
<figure class="planetIcon planet tooltip js_hideTipOnMobile" title="Planet"></figure>Colony
</td>
<td class="destCoords">
<a href="http://127.0.0.1:8080/game/index.php?page=ingame&amp;component=galaxy&amp;galaxy=4&amp;system=208" target="_top">
[4:208:8]
</a>
</td>

<td class="sendProbe">
</td>
<td class="sendMail">
<a href="javascript:void(0)"
class="sendMail js_openChat tooltip"
data-playerId="105992"
title="Zum"><span class="icon icon_chat"></span></a>
</td>

</tr>

</tbody>
</table>
<div id="eventFooter"></div>
</div>
<script type="text/javascript">
var timeDelta = 1583477234000 - (new Date()).getTime();
var LocalizationStrings = {"timeunits":{"short":{"year":"y","month":"m","week":"w","day":"d","hour":"h","minute":"m","second":"s"}},"status":{"ready":"done"},"decimalPoint":".","thousandSeperator":".","unitMega":"Mn","unitKilo":"K","unitMilliard":"Bn","question":"Question","error":"Error","loading":"load...","notice":"Reference","yes":"yes","no":"No","ok":"Ok","attention":"Caution","outlawWarning":"You are about to attack a stronger player. If you do this, your attack defences will be shut down for 7 days and all players will be able to attack you without punishment. Are you sure you want to continue?","lastSlotWarningMoon":"This building will use the last available building slot. Expand your Lunar Base to receive more space. Are you sure you want to build this building?","lastSlotWarningPlanet":"This building will use the last available building slot. Expand your Terraformer or buy a Planet Field item to obtain more slots. Are you sure you want to build this building?","forcedVacationWarning":"Confirm your lobby account now and we\u2019ll gift you Dark Matter in each universe!","planetMoveBreakUpWarning":"Caution! This mission may still be running once the relocation period starts and if this is the case, the process will be cancelled. Do you really want to continue with this job?","moreDetails":"More details","lessDetails":"Less detail","planetOrder":{"lock":"Lock arrangement","unlock":"Unlock arrangement"},"darkMatter":"Dark Matter","errorNotEnoughDM":"Not enough Dark Matter available! Do you want to buy some now?","activateItem":{"upgradeItemQuestion":"Would you like to replace the existing item? The old bonus will be lost in the process.","upgradeItemQuestionHeader":"Replace item?"},"characterClassItem":{"buyAndActivateItemQuestion":"Do you want to activate the #characterClassName# class for #darkmatter# Dark Matter? In doing so, you will lose your current class.","activateItemQuestion":"Do you want to activate the #characterClassName# class? In doing so, you will lose your current class."},"LOCA_ALL_NETWORK_ATTENTION":"Caution","LOCA_ALL_YES":"yes","LOCA_ALL_NO":"No"};
(function($) {
new eventboxCountdown(
$("#counter-eventlist-611612"),
1583478971 - 1583477234,
$("#eventListWrap"),
"http:\/\/127.0.0.1:8080\/game\/index.php?page=componentOnly&component=eventList&action=checkEvents&ajax=1&asJson=1",
[0,1,2]
);
new eventboxCountdown(
$("#counter-eventlist-611876"),
1583480264 - 1583477234,
$("#eventListWrap"),
"http:\/\/127.0.0.1:8080\/game\/index.php?page=componentOnly&component=eventList&action=checkEvents&ajax=1&asJson=1",
[0,1,2]
);
new eventboxCountdown(
$("#counter-eventlist-611878"),
1583480685 - 1583477234,
$("#eventListWrap"),
"http:\/\/127.0.0.1:8080\/game\/index.php?page=componentOnly&component=eventList&action=checkEvents&ajax=1&asJson=1",
[0,1,2]
);
})(jQuery);
</script>


0 comments on commit 0a5fb4d

Please sign in to comment.