Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: GalaxyEspionage #50

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@ POST /bot/planets/:planetID/cancel-research
GET /bot/planets/:planetID/resources
POST /bot/planets/:planetID/send-fleet
POST /bot/planets/:planetID/send-ipm
GET /bot/planets/:celestialID/espionage/:galaxy/:system/:position/:type/:probecount
GET /bot/planets/celestial/:celestialID/espionage/galaxy/:galaxy/system/:system/position/:position/type/:type/probecount/:probecount
```
5 changes: 5 additions & 0 deletions cmd/ogamed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func start(c *cli.Context) error {
e.POST("/bot/delete-report/:messageID", ogame.DeleteMessageHandler)
e.POST("/bot/delete-all-espionage-reports", ogame.DeleteEspionageMessagesHandler)
e.POST("/bot/delete-all-reports/:tabIndex", ogame.DeleteMessagesFromTabHandler)

// Galaxy Espionage
e.GET("/bot/planets/:celestialID/espionage/:galaxy/:system/:position/:type/:probecount", ogame.GalaxyEspionageHandler)
e.GET("/bot/planets/celestial/:celestialID/espionage/galaxy/:galaxy/system/:system/position/:position/type/:type/probecount/:probecount", ogame.GalaxyEspionageHandler)

e.GET("/bot/attacks", ogame.GetAttacksHandler)
e.GET("/bot/galaxy-infos/:galaxy/:system", ogame.GalaxyInfosHandler)
e.GET("/bot/get-research", ogame.GetResearchHandler)
Expand Down
54 changes: 54 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,57 @@ func SendIPMHandler(c echo.Context) error {
}
return c.JSON(http.StatusOK, SuccessResp(duration))
}

// GalaxyEspionage ...
func GalaxyEspionageHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)

// PlanetID
planetID, err := strconv.ParseInt(c.Param("celestialID"), 10, 64)
if err != nil || planetID < 0 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid planet id"))
}

// Galaxy
galaxy, err := strconv.ParseInt(c.Param("galaxy"), 10, 64)
if err != nil || galaxy < 1 || galaxy > 9 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid galaxy"))
}

// System
system, err := strconv.ParseInt(c.Param("system"), 10, 64)
if err != nil || system < 1 || system > 499 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid system"))
}

// Position
position, err := strconv.ParseInt(c.Param("position"), 10, 64)
if err != nil || position < 1 || position > 15 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid position"))
}

// Type
planettype, err := strconv.ParseInt(c.Param("type"), 10, 64)
if err != nil || planettype < 1 || planettype > 3 || planettype == 2 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid type"))
}

// Probecount
probecount, err := strconv.ParseInt(c.Param("probecount"), 10, 64)
if err != nil || position < 0 {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid probecount"))
}

// --------------------------------------------------------------------------------------

coord := Coordinate{Type: PlanetType, Galaxy: galaxy, System: system, Position: position}
celestialID := CelestialID(planetID)

espionage, err := bot.GalaxyEspionage(celestialID, coord, probecount)
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResp(500, err.Error()))
}

return c.JSON(http.StatusOK, SuccessResp(espionage))
}

Loading