Skip to content

Commit

Permalink
Merge branch 'release/42.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Jan 31, 2021
2 parents 4881d2a + bc23691 commit c2fa8d8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ cmd/bot*
cover.out
vendor
/ogame.code-workspace
cmd/ogamed/bin
4 changes: 4 additions & 0 deletions cmd/ogamed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func start(c *cli.Context) error {
e.POST("/bot/captcha/solve", ogame.GetCaptchaSolverHandler)

e.GET("/bot/server", ogame.GetServerHandler)
e.GET("/bot/server-data", ogame.GetServerDataHandler)
e.POST("/bot/set-user-agent", ogame.SetUserAgentHandler)
e.GET("/bot/server-url", ogame.ServerURLHandler)
e.GET("/bot/language", ogame.GetLanguageHandler)
Expand All @@ -252,7 +253,9 @@ func start(c *cli.Context) error {
e.GET("/bot/server/version", ogame.ServerVersionHandler)
e.GET("/bot/server/time", ogame.ServerTimeHandler)
e.GET("/bot/is-under-attack", ogame.IsUnderAttackHandler)
e.GET("/bot/is-vacation-mode", ogame.IsVacationModeHandler)
e.GET("/bot/user-infos", ogame.GetUserInfosHandler)
e.GET("/bot/character-class", ogame.GetCharacterClassHandler)
e.POST("/bot/send-message", ogame.SendMessageHandler)
e.GET("/bot/fleets", ogame.GetFleetsHandler)
e.GET("/bot/fleets/slots", ogame.GetSlotsHandler)
Expand All @@ -278,6 +281,7 @@ func start(c *cli.Context) error {
e.GET("/bot/planets", ogame.GetPlanetsHandler)
e.GET("/bot/planets/:planetID", ogame.GetPlanetHandler)
e.GET("/bot/planets/:galaxy/:system/:position", ogame.GetPlanetByCoordHandler)
e.GET("/bot/planets/:planetID/resources-details", ogame.GetResourcesDetailsHandler)
e.GET("/bot/planets/:planetID/resource-settings", ogame.GetResourceSettingsHandler)
e.POST("/bot/planets/:planetID/resource-settings", ogame.SetResourceSettingsHandler)
e.GET("/bot/planets/:planetID/resources-buildings", ogame.GetResourcesBuildingsHandler)
Expand Down
33 changes: 33 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func GetServerHandler(c echo.Context) error {
return c.JSON(http.StatusOK, SuccessResp(bot.GetServer()))
}

// GetServerDataHandler ...
func GetServerDataHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
return c.JSON(http.StatusOK, SuccessResp(bot.serverData))
}

// SetUserAgentHandler ...
// curl 127.0.0.1:1234/bot/set-user-agent -d 'userAgent="New user agent"'
func SetUserAgentHandler(c echo.Context) error {
Expand Down Expand Up @@ -155,12 +161,25 @@ func IsUnderAttackHandler(c echo.Context) error {
return c.JSON(http.StatusOK, SuccessResp(isUnderAttack))
}

// IsVacationModeHandler ...
func IsVacationModeHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
isVacationMode := bot.isVacationModeEnabled
return c.JSON(http.StatusOK, SuccessResp(isVacationMode))
}

// GetUserInfosHandler ...
func GetUserInfosHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
return c.JSON(http.StatusOK, SuccessResp(bot.GetUserInfos()))
}

// GetCharacterClassHandler ...
func GetCharacterClassHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
return c.JSON(http.StatusOK, SuccessResp(bot.CharacterClass()))
}

// GetEspionageReportMessagesHandler ...
func GetEspionageReportMessagesHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
Expand Down Expand Up @@ -404,6 +423,20 @@ func GetPlanetByCoordHandler(c echo.Context) error {
return c.JSON(http.StatusOK, SuccessResp(planet))
}

// GetResourcesDetailsHandler ...
func GetResourcesDetailsHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
planetID, err := strconv.ParseInt(c.Param("planetID"), 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, ErrorResp(400, "invalid planet id"))
}
resources, err := bot.GetResourcesDetails(CelestialID(planetID))
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResp(500, err.Error()))
}
return c.JSON(http.StatusOK, SuccessResp(resources))
}

// GetResourceSettingsHandler ...
func GetResourceSettingsHandler(c echo.Context) error {
bot := c.Get("bot").(*OGame)
Expand Down

0 comments on commit c2fa8d8

Please sign in to comment.