From 72c770dd0a320c5b53771bcbb39ac1c9574308aa Mon Sep 17 00:00:00 2001 From: Flashover Date: Wed, 4 Mar 2020 23:50:38 +0100 Subject: [PATCH] Improvement for Sendfleet --- handlers.go | 10 +++++++++- ogame.go | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/handlers.go b/handlers.go index 6c40c05e..0e375e30 100644 --- a/handlers.go +++ b/handlers.go @@ -773,6 +773,7 @@ func SendFleetHandler(c echo.Context) error { var unionID int64 payload := Resources{} speed := HundredPercent + ensure := false for key, values := range c.Request().PostForm { switch key { case "ships": @@ -852,10 +853,17 @@ func SendFleetHandler(c echo.Context) error { return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid deuterium")) } payload.Deuterium = deuterium + case "ensure": + ensure, _ = strconv.ParseBool(values[0]) } } - fleet, err := bot.SendFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID) + var fleet interface{} + if ensure { + fleet, err = bot.EnsureFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID) + } else { + fleet, err = bot.SendFleet(CelestialID(planetID), ships, speed, where, mission, payload, duration, unionID) + } if err != nil && (err == ErrInvalidPlanetID || err == ErrNoShipSelected || diff --git a/ogame.go b/ogame.go index 36d5e950..a73eb867 100644 --- a/ogame.go +++ b/ogame.go @@ -2790,6 +2790,11 @@ type CheckTargetResponse struct { Type int `json:"type"` Name string `json:"name"` } `json:"targetPlanet"` + Errors *struct { + Message string `json:"message"` + Error int `json:"error"` + + } `json:"errors"` TargetOk bool `json:"targetOk"` Components []interface{} `json:"components"` } @@ -2935,6 +2940,10 @@ func (b *OGame) sendFleetV7(celestialID CelestialID, ships []Quantifiable, speed } if !checkRes.TargetOk { + if len(checkRes.Errors.Message) > 0 { + return Fleet{}, errors.New(checkRes.Errors.Message) + } + return Fleet{}, errors.New("target is not ok") } @@ -3330,7 +3339,7 @@ func (b *OGame) sendFleetV6(celestialID CelestialID, ships []Quantifiable, speed // EspionageReportType type of espionage report (action or report) type EspionageReportType int -// Action message received when an enemy is seen naer your planet +// Action message received when an enemy is seen near your planet const Action EspionageReportType = 0 // Report message received when you spied on someone