alaingilbert / ogame

Golang ogame wrapper
https://godoc.org/github.com/alaingilbert/ogame
MIT License
90 stars 51 forks source link

Is there any way to change working port & use jumpgate via ogamed? #75

Open farta1986 opened 4 years ago

farta1986 commented 4 years ago

Has ogamed exposed any http interface to

  1. change working port from default 8080
  2. use moon jump gate?

I did't find them in document & I'm not familiar with go. Would you have a look about it? Thank you.

alaingilbert commented 4 years ago

You can start it with the --port flag. eg: ./ogamed --port 8090

I just added an endpoint for "jump-gate". Hopefully it works, I didn't try it.

curl http://127.0.0.1:8080/bot/moons/<ORIGIN_MOON_ID>/jump-gate -d "moonDestination=12345&ships=204,1&ships=205,2"

You need >= 0.39.1

farta1986 commented 4 years ago

Thanks a lot. BTW is there any interface for

  1. read/mark messages?
  2. check a jump gate's status?
  3. check a fleet's data(time/fuel cost) without actually sending it? Thank you again.
Floraly commented 4 years ago
  1. You can check for some message Types in the wrapper.
  2. Jumpgate endpoint reports you if there is a cooldown present.
  3. With Function FlightTime you get fuel costs and time of the flights. But there is actually no endpoint in the service.
0xE232FE commented 4 years ago

You can Add an Endpoint to the OGamed Service very easy.

Add Endpoint Example

e.POST("/api/v1/flighttime", APIFlightTime)
func APIFlightTime(c echo.Context) error {
    bot := c.Get("bot").(*ogame.OGame)
    cachedData := bot.GetCachedData()

    formdata, _ := c.MultipartForm()

    var ships ogame.ShipsInfos
    var origin int64
    var destination ogame.Coordinate
    var speed ogame.Speed

    for k, v := range formdata.Value {
        log.Printf("%s, %s", k, v[0])
        switch k {
        case "LightFighter":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.LightFighter = nbr
            break
        case "HeavyFighter":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.HeavyFighter = nbr
            break
        case "Cruiser":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Cruiser = nbr
            break
        case "Battleship":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Battleship = nbr
            break
        case "Battlecruiser":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Battlecruiser = nbr
            break
        case "Bomber":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Bomber = nbr
            break
        case "Destroyer":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Destroyer = nbr
            break
        case "Deathstar":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Deathstar = nbr
            break
        case "SmallCargo":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.SmallCargo = nbr
            break
        case "LargeCargo":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.LargeCargo = nbr
            break
        case "ColonyShip":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.ColonyShip = nbr
            break
        case "Recycler":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Recycler = nbr
            break
        case "EspionageProbe":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.EspionageProbe = nbr
            break
        case "Crawler":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Crawler = nbr
            break
        case "Reaper":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Reaper = nbr
            break
        case "Pathfinder":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            ships.Pathfinder = nbr
            break

        case "origin":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            origin = nbr
            break
        case "speed":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            speed = ogame.Speed(nbr)
            break
        case "destGalaxy":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            destination.Galaxy = nbr
            break
        case "destSystem":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            destination.System = nbr
            break
        case "destPosition":
            nbr, _ := strconv.ParseInt(v[0], 10, 64)
            destination.Position = nbr
            break
        }
    }

    cel := bot.GetCachedCelestial(origin)
    secs, fuel := bot.FlightTime(cel.GetCoordinate(), destination, speed, ships)
    cargo := ships.Cargo(cachedData.Researches, false, bot.CharacterClass() == ogame.Collector)

    human_time := time.Duration(secs) * time.Second
    data := struct {
        Secs       int64  `json:"secs"`
        Fuel       int64  `json:"fuel"`
        Cargo      int64  `json:"cargo"`
        Human_time string `json:"human_time"`
    }{
        Secs:       secs,
        Fuel:       fuel,
        Cargo:      cargo,
        Human_time: human_time.String(),
    }
    return c.JSON(http.StatusOK, data)
}